RewardThrottle:handleReward gas optimizations #144
Labels
bug
Something isn't working
G (Gas Optimization)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
GiveMeTestEther
Vulnerability details
Impact
Storage variable _activeEpoch is read a lot and can be cached in a local variable (epochTmp, maybe choose a better name =)) to save gas. Also the State struct can be loaded into a State storage (currentState, maybe also choose a better name) variable such that we don't have to access the storage array each time.
In the gas optimized code of "Recommended Mitigation Steps" section, the _activeEpoch only gets read once.
Also note after the first "if" we write epoch to the storage variable "_activeEpoch" but then also write epoch to the local var "epochTmp" so we can use this local var in the whole function.
Proof of Concept
https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/RewardSystem/RewardThrottle.sol#L63
Tools Used
Recommended Mitigation Steps
function handleReward() public {
uint256 balance = rewardToken.balanceOf(address(this));
}
The text was updated successfully, but these errors were encountered: