Platform: Code4rena
Start Date: 20/01/2023
Pot Size: $90,500 USDC
Total HM: 10
Participants: 59
Period: 7 days
Judge: Picodes
Total Solo HM: 4
Id: 206
League: ETH
Rank: 57/59
Findings: 1
Award: $48.54
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xSmartContract
Also found by: 0x1f8b, 0xackermann, Aymen0909, Beepidibop, IllIllI, Iurii3, Rageur, RaymondFam, ReyAdmirado, Rolezn, SaeedAlipoor01988, Udsen, Viktor_Cortess, W0RR1O, W_Max, atharvasama, c3phas, chaduke, descharre, fatherOfBlocks, kaden, matrix_0wl, shark
48.5424 USDC - $48.54
require
and assert
should not be used due to gas issues. I suggest using custom errors instead.(length - 4) % 32 == 0
can be replaced by:
length % 32 == 4
to save gas.uint256(transaction) >= 4
should be replaced with uint256(transaction) > 3
to save gas.uint256 long0Requested
uint256 long1Requested
uint256 shortRequested
should be cached to save gas as they are used for more thanm twice in the function.pool.lastTimestamp
should be cached to save gas.uint256 maturity, uint256 long0Fees, uint256 long1Fees, uint256 shortFees, uint96 blockTimestamp
should be cached as the are used more than once to save gas.maturity
should be cached to save gas as it is used for more than once.uint256 transactionFee, uint256 protocolFee, uint96 blockTimestamp
should be cached to save gas as they are used for more than once.&&
should not be used to save gas. (Can be saperated)uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth
should be cached to save gas as they are used for more than onceuint256 long0Requested,uint256 long1Requested,uint256 shortRequested
should be cached to save gas as they are used for more than oncependingOwner
should not be used in emit, use memory variables instead.in line 167: &&
should not be used. can be saperated to save gas.
in line 52:
mapping(uint256 => mapping(uint256 => uint96)) private reentrancyGuards;
There are lots of mappings using type uint96 instead of uint256, this is more gas-cost than using uint256
in line 57-60, line 66-69:
strike
and maturity
of calldata are used more than once so should be cacheed to save gas.
in line 152:
uint256 strike, uint256 maturity, address to, uint160 liquidityAmount
these variables should all be cached as they are used more than once in the function.
in line 165:
uint256 strike, uint256 maturity, address to, uint256 long0Fees, uint256 long1Fees, uint256 shortFees
these variables should all be cached as they are used more than once in the function.
in line 175:
uint256 strike, uint256 maturity, uint160 rate
these variables should all be cached as they are used more than once in the function.
in line 184,202, 253,318, 378, 431, 469:
vars in param
should be cached to save gas as they are used more than once in the function.
in line 231:
uint256 strike, uint256 maturity, address long0To, address long1To, address shortTo, uint256 long0Amount, uint256 long1Amount, uint256 shortAmount
these variables should all be cached as they are used more than once in the function.
fees
is used more than once in the function so should be cached.mapping(bytes32 => uint96) private reentrancyGuards;
costs more gas than using uint256 type maps.address from, address to, TimeswapV2LiquidityTokenPosition calldata position, uint256 long0Fees, uint256 long1Fees, uint256 shortFees
should be cached to save gas.param
should be cached to save gas.address from, address to, uint256 id
shoule be cached to save gas.(address owner, uint256 id)
shoule be cached to save gas.#0 - c4-judge
2023-02-02T12:09:31Z
Picodes marked the issue as grade-b