20,000 USDC
View results
Submission Details
Severity: gas
Valid

Cache storage variables

Summary

Storage variables should be cached as it is cheaper to read from memory

Vulnerability Details

msg.sender can be cached to save gas.

Impact

msg.sender and other storage variables can be cached to save significant amount of gas. There are about 15 instances of this.

https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Staking.sol#L53-L58
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Staking.sol#L46-L50
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Staking.sol#L38-L42

Tools Used

Manual review

Recommendations

Example:

function claim() external {
address caller = msg.sender;
updateFor(caller);
WETH.transfer(caller, claimable[caller]);
claimable[caller] = 0;
balance = WETH.balanceOf(address(this));
}

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!