Timeswap contest - W0RR1O's results

Like Uniswap, but for lending & borrowing.

General Information

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

Timeswap

Findings Distribution

Researcher Performance

Rank: 59/59

Findings: 1

Award: $48.54

Gas:
grade-b

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

48.5424 USDC - $48.54

Labels

bug
G (Gas Optimization)
grade-b
edited-by-warden
G-22

External Links

Combining the overflow and out-of-bounds checks in a single require() statement

problematic 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 } }

Use require()/revert() to check for zero liquidity before performing calculations

Problematic 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

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter