Open code423n4 opened 2 years ago
Czar102
Assign the value of a storage variable to a local one when possible to avoid multiple reads.
Values in the brackets are indicating potential SLOAD opcode number decrease.
Relevant to, for example:
ERC20Facet::increaseApproval(...)
ERC20Facet::decreaseApproval(...)
BasketFacet::joinPool(...)
BasketFacet::exitPool(...)
BasketFacet::getLock()
BasketFacet::removeToken(...)
bs.tokens.length
BasketFacet::calcTokensForAmount(...)
BasketFacet::calcTokensForAmountExit(...)
Handle
Czar102
Vulnerability details
Optimization
Assign the value of a storage variable to a local one when possible to avoid multiple reads.
Proof of Concept
Values in the brackets are indicating potential SLOAD opcode number decrease.
Relevant to, for example:
ERC20Facet::increaseApproval(...)
(1 read)ERC20Facet::decreaseApproval(...)
(1 read)BasketFacet::joinPool(...)
(2 reads)BasketFacet::exitPool(...)
(2 reads)BasketFacet::getLock()
(1 read)BasketFacet::removeToken(...)
(statistically (bs.tokens.length
+ 1) / 2, which is currently max 15.5 reads)BasketFacet::joinPool(...)
(bs.tokens.length
- 1 reads, which is currently max 29 reads)BasketFacet::exitPool(...)
(bs.tokens.length
- 1 reads, which is currently max 29 reads)BasketFacet::calcTokensForAmount(...)
(bs.tokens.length
+ 1, which is currently max 31 reads)BasketFacet::calcTokensForAmountExit(...)
(bs.tokens.length
+ 1, which is currently max 31 reads)