Platform: Code4rena
Start Date: 27/11/2023
Pot Size: $60,500 USDC
Total HM: 7
Participants: 72
Period: 7 days
Judge: Picodes
Total Solo HM: 2
Id: 309
League: ETH
Rank: 47/72
Findings: 1
Award: $19.82
🌟 Selected for report: 0
🚀 Solo Findings: 0
19.8173 USDC - $19.82
Gas Optimization:
1.Pack storage slots. We can pack same type of variables to save gas . We can optimize LeftRight.sol L161-165 , TokenId.sol L68-71 , SemiFungiblePositionManager.sol L868-871 . Take LeftRight.sol L161-165 for example:
Now: int256 left256 = int256(x.leftSlot()) + y.leftSlot(); int128 left128 = int128(left256); int256 right256 = int256(x.rightSlot()) + y.rightSlot(); int128 right128 = int128(right256);
Optimization: int256 left256 = int256(x.leftSlot()) + y.leftSlot(); int256 right256 = int256(x.rightSlot()) + y.rightSlot(); int128 left128 = int128(left256); int128 right128 = int128(right256);
Use constants instead of type(uintx).max. We can optimize SemiFungiblePositionManager L917, L1390 , Math L86, LeftRight L213.
2**<n> should be re-written as type(uint<n>).max . We can optimize SemiFungiblePositionManager.sol L384 ,L1281,L1284
Use hardcode address instead of address(this) . We can optimize Multicall.sol L15, SemiFungiblePositionManager.sol L1106,L1148.
Caching global variables is more expensive than using the actual variable (use msg.sender instead of caching it) . We can optimize following contents: SemiFungiblePositionManager.sol L415、L421、L428、L449、L460、L487、L490、L523、L767、L825、L948、L1141, ERC1155.sol L78、L80、L97、L112、L135、L165、L220
Can Make The Variable Outside The Loop To Save Gas. We can optimize Multicall.sol L15, SemiFungiblePositionManager.sol L867-L871,TokenId.sol L503-L508.
Using calldata instead of memory for read-only arguments to save gas. We can optimize CallbackLib.sol L31
Duplicated require()/if() checks should be refactored to a modifier or function.We can optimize following contents:
PanopticMath.sol L149、 L172
"sqrtPriceX96 < 340275971719517849884101479065584693834"
ERC1155.sol L97、 L135
" if (!(msg.sender == from || isApprovedForAll[from][msg.sender])) revert NotAuthorized();"
LeftRight.sol L167、 L185
"if (left128 != left256 || right128 != right256) revert Errors.UnderOverFlow();"
x += y (x -= y) costs more gas than x = x + y (x = x - y) for state variables. We can optimize following contents: SemiFungiblePositionManager.sol L899、L901、L999、L979 ERC1155.sol L99 L103 L145 L149 L217 L237
Use a more recent version of solidity.There different versions of solidity,and we have to optimize. pragma solidity =0.8.18; pragma solidity =0.8.0;
Using private rather than public for variables, saves gas. We can optimize ERC1155.sol L62、L68
#0 - c4-judge
2023-12-14T17:14:19Z
Picodes marked the issue as grade-b