Basin - lsaudit's results

A composable EVM-native decentralized exchange protocol.

General Information

Platform: Code4rena

Start Date: 03/07/2023

Pot Size: $40,000 USDC

Total HM: 14

Participants: 74

Period: 7 days

Judge: alcueca

Total Solo HM: 9

Id: 259

League: ETH

Basin

Findings Distribution

Researcher Performance

Rank: 32/74

Findings: 1

Award: $58.47

Gas:
grade-a

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

58.4732 USDC - $58.47

Labels

bug
G (Gas Optimization)
grade-a
high quality report
sponsor confirmed
G-16

External Links

[G-01] Ineffective loop in _getIJ

Current implementation of looking for I and J tokens is very ineffective. It always loops through the whole array, even when I and J are at the beginning of the array.

File: /src/Well.sol function _getIJ( IERC20[] memory _tokens, IERC20 iToken, IERC20 jToken ) internal pure returns (uint256 i, uint256 j) { bool foundI = false; bool foundJ = false; for (uint256 k; k < _tokens.length; ++k) { if (iToken == _tokens[k]) { i = k; foundI = true; } else if (jToken == _tokens[k]) { j = k; foundJ = true; } } if (!foundI) revert InvalidTokens(); if (!foundJ) revert InvalidTokens(); }

_getIJ should be reimplemented to save gas (loop's iterations) for scenarios where I and J are at the beginning of the array. Firstly, loop once, until you find either I or J token (assume one of them has been found at index X of the array). Break from the loop and enter another loop from X + 1 to the end of array. If you find either I or J again, break once more (as this means that both I and J are found). This approach will save a lot of gas when I and J are at the beginning of the array. Otherwise, (in the worst case scenario: either I or J is the last element) - you will still loop over the whole array - as in the current implementation.

#0 - c4-pre-sort

2023-07-13T12:49:48Z

141345 marked the issue as high quality report

#1 - c4-sponsor

2023-07-24T14:49:52Z

publiuss marked the issue as sponsor confirmed

#2 - c4-judge

2023-08-05T11:18:18Z

alcueca marked the issue as grade-b

#3 - c4-judge

2023-08-05T11:18:23Z

alcueca marked the issue as grade-a

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