Caching badger and badgerSett can save 400 gas in redeemToken() #39
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
Handle
0xRajeev
Vulnerability details
Impact
State variables badger and badgerSett addresses are read three times each in redeemToken(). Caching them in local variables at the beginning of the function and using those local variables can save 400 gas from avoiding 2 repeated SLOADs for each of them.
Impact: Gas savings of 400
Proof of Concept
Three badger reads:
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L64
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L75
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L79
Three badgerSett reads:
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L58
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L61
https://github.com/code-423n4/2021-06-pooltogether/blob/85f8d044e7e46b7a3c64465dcd5dffa9d70e4a3e/contracts/yield-source/BadgerYieldSource.sol#L73
Tools Used
Manual Analysis
Recommended Mitigation Steps
Cache badger and badgerSett state variables in local variables at the beginning of the function and use those local variables instead.
The text was updated successfully, but these errors were encountered: