Skip to content

Commit

Permalink
Add tests for reentrancy in _rentStorage function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawar7349 committed Jan 16, 2025
1 parent d414c3b commit f0ee162
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/IdGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,26 @@ contract IdGateway is IIdGateway, Guardians, Signatures, EIP712, Nonces {
//////////////////////////////////////////////////////////////*/

function _rentStorage(
uint256 fid,
uint256 extraUnits,
uint256 payment,
address payer
uint256 fid,
uint256 extraUnits,
uint256 payment,
address payer
) internal returns (uint256 overpayment) {
overpayment = storageRegistry.rent{value: payment}(fid, 1 + extraUnits);

if (overpayment > 0) {
payer.sendNative(overpayment);
}
// Calculate the overpayment before making any external calls
uint256 amountToRent = 1 + extraUnits;
overpayment = payment - storageRegistry.price(amountToRent);

// Make the external call to rent storage
storageRegistry.rent{value: payment}(fid, amountToRent);

// Return the overpayment after the external call
if (overpayment > 0) {
(bool success, ) = payer.call{value: overpayment}("");
require(success, "Transfer failed");
}
}


receive() external payable {
if (msg.sender != address(storageRegistry)) revert Unauthorized();
}
Expand Down

0 comments on commit f0ee162

Please sign in to comment.