Auction.sol: currentAuctionId should be cached in functions using it frequently #378
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
Handle
harleythedog
Vulnerability details
Impact
In Auction.sol, the storage variable
currentAuctionId
is frequently used across the contract. In functions that read from this variable multiple times, it would save gas to copy it into a local memory variable first and then use the memory variable for calculations. This is because SLOAD operations are much more expensive than MLOAD operations.Proof of Concept
For example, see
_checkAuctionFinalization
here: https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L746It would save a lot of gas if
currentAuctionId
was read from storage once at the start and then the local memory variable was used on subsequent reads.Tools Used
Inspection
Recommended Mitigation Steps
Cache
currentAuctionId
reads when there are multiple reads in a function.The text was updated successfully, but these errors were encountered: