Platform: Code4rena
Start Date: 13/12/2021
Pot Size: $75,000 USDC
Total HM: 11
Participants: 30
Period: 7 days
Judge: leastwood
Total Solo HM: 4
Id: 68
League: ETH
Rank: 26/30
Findings: 2
Award: $18.96
🌟 Selected for report: 1
🚀 Solo Findings: 0
4.6832 USDC - $4.68
Dravee
Increased gas cost
(As seen on this contest: https://github.com/code-423n4/2021-10-slingshot-findings/issues/63) Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Instances include:
RebalanceManager.sol#rebalance()
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/callManagers/RebalanceManager.sol#L218
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/callManagers/RebalanceManager.sol#L234RebalanceManagerV2.sol#rebalance()
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/callManagers/RebalanceManagerV2.sol#L155RebalanceManagerV3.sol#rebalance()
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/callManagers/RebalanceManagerV3.sol#L166
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/callManagers/RebalanceManagerV3.sol#L171BasketFacet.sol#removeToken
,BasketFacet.sol#joinPool
,BasketFacet.sol#exitPool
,BasketFacet.sol#getTokens
,BasketFacet.sol#calcTokensForAmount
,BasketFacet.sol#calcTokensForAmountExit
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L50
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L160
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L202
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L321
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L348
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/BasketFacet.sol#L381CallFacet.sol#call
,CallFacet.sol#removeCaller
,CallFacet.sol#callNoValue
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Call/CallFacet.sol#L55
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Call/CallFacet.sol#L82
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Call/CallFacet.sol#L95SingleNativeTokenExit.sol#exitEth
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExit.sol#L69SingleNativeTokenExitV2.sol#_exit
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L74
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L76SingleTokenJoin.sol#_joinTokenSingle
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleTokenJoin.sol#L108SingleTokenJoinV2.sol#_joinTokenSingle
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleTokenJoinV2.sol#L86
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleTokenJoinV2.sol#L91
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleTokenJoinV2.sol#L100
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleTokenJoinV2.sol#L117VS Code
Store the array's length in a variable before the for-loop, and use it instead.
#0 - 0xleastwood
2022-01-23T22:07:17Z
Duplicate of #249
Dravee
Increased gas costs
"constants" expressions are expressions. As such, keccak
assigned to a constant
variable are re-computed at each use of the variable, which will consume gas unnecessarily. To save gas, Changing the variable from constant
to immutable
will make the computation run only once and therefore save gas.
Places with the issue: https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Basket/LibBasketStorage.sol#L7-L8 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/Call/LibCallStorage.sol#L5-L6 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/ERC20/LibERC20Storage.sol#L5-L9 https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/facets/shared/Reentry/LibReentryProtectionStorage.sol#L5-L6
VS Code
Change the variable from constant
to immutable