Add tests for reentrancy in _rentStorage function #458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
This pull request addresses potential reentrancy vulnerabilities in the _rentStorage function of the IdGateway contract. It is crucial to secure the contract against reentrancy attacks to prevent unintended behaviors and potential financial losses.
Change Summary
Implemented a new test contract RentStorageTest to specifically target and test for reentrancy issues in the _rentStorage function.
Added comprehensive test cases to verify the robustness of the _rentStorage function against reentrancy attacks.
Ensured that the function handles overpayment, exact payment, and edge case scenarios correctly.
Merge Checklist
Choose all relevant options below by adding an
x
now or at any time before submitting for review[x] The PR title adheres to the conventional commits standard.
[x] The PR has been tagged with change type label(s) (i.e., feature, bugfix).
[x] The PR's changes adhere to all the requirements in the contribution guidelines.
[x] All commits have been signed.
Additional Context
The test suite covers various edge cases, ensuring the _rentStorage function's reliability and security. These tests help maintain the integrity and trustworthiness of the IdGateway contract.
PR-Codex overview
This PR refines the
_rentStorage
function inIdGateway.sol
by changing how overpayment is calculated and transferred to thepayer
. It introduces a more secure method for sending funds and ensures proper calculation before external calls.Detailed summary
_rentStorage
function to calculateoverpayment
after determining theamountToRent
.overpayment
is sent topayer
usingcall
instead ofsendNative
.require
statement to check the success of the payment transfer.receive
function to restrict access tostorageRegistry
.