Closed code423n4 closed 2 years ago
hyh
Storage accessed more than needed, increasing gas costs.
records[_nftId].reserve is accessed several times.
records[_nftId].reserve
https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedRecords.sol#L61
Add memory variable and use it in the logic:
address memory nft_reserve = records[_nftId].reserve;
Do reserve update only if needed: Now:
records[_nftId].reserve = _reserve;
To be:
if (nft_reserve == address(0)) { records[_nftId].reserve = _reserve; }
Data location can only be specified for array, struct or mapping types and will cost more to store in a variable in this case (4 gas more).
Dispute accepted
Handle
hyh
Vulnerability details
Impact
Storage accessed more than needed, increasing gas costs.
Proof of Concept
records[_nftId].reserve
is accessed several times.https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedRecords.sol#L61
Recommended Mitigation Steps
Add memory variable and use it in the logic:
Do reserve update only if needed: Now:
To be: