Closed code423n4 closed 2 years ago
Disagree with the finding.
quoteToken
and baseToken
are immutable, they get inlined in the bytecode at deploy time.
This means that they are effectively already being cached, no storage read cost is ever applied to using them.
The advice would be correct if the variables weren't immutable
, but because they are, am marking as invaldi
Handle
Jujic
Vulnerability details
Impact
State variables
baseToken
andquoteToken
addresses are read several times respectively inaddLiquidity()
. Caching them in local variables at the beginning of the function and using those local variables can save gas.The same situation is in the
removeLiquidity()
Proof of Concept
https://github.com/code-423n4/2022-01-elasticswap/blob/d107a198c0d10fbe254d69ffe5be3e40894ff078/elasticswap/src/contracts/Exchange.sol#L87-L156
Tools Used
Remux
Recommended Mitigation Steps
Cache
baseToken
andquoteToken
state variables in local variables at the beginning of the function