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: 59/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()
statementproblematic code:
In the slice()
function the require()
statement is checking two conditions which is overflow and out-of-bounds. By combining these two checks into a single require()
statement this helps the number of time require()
checks are being performed and helps to save gas.
Here is an example to fix this issue:
pragma solidity =0.8.8; contract test1{ function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) { require((_length + 31 >= _length) && (_bytes.length >= _start + _length) , "slice_overflow or slice_outOfBounds"); // rest of the code } }
require()/revert()
to check for zero liquidity before performing calculationsProblematic functions:
Unessasary gas will be consumed if the liquidity is zero and the calculations are not needed. By adding the require()
or revert()
function unesassary gas consumption can be avoided when when the liquidity is zero.
Recomended fix:
function feesEarnedOf( LiquidityPosition memory liquidityPosition, uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth ) internal pure returns (uint256 long0Fee, uint256 long1Fee, uint256 shortFee) { require(liquidityPosition.liquidity > 0, "Liquidity is zero"); uint160 liquidity = liquidityPosition.liquidity; //continue the code here } function update(LiquidityPosition storage liquidityPosition, uint256 long0FeeGrowth, uint256 long1FeeGrowth, uint256 shortFeeGrowth) internal { require(liquidityPosition.liquidity > 0, "Liquidity is zero"); uint160 liquidity = liquidityPosition.liquidity; //continue the code here }
#0 - c4-judge
2023-02-02T12:40:58Z
Picodes marked the issue as grade-b