QuickSwap and StellaSwap contest - gianganhnguyen's results

A concentrated liquidity DEX with dynamic fees.

General Information

Platform: Code4rena

Start Date: 26/09/2022

Pot Size: $50,000 USDC

Total HM: 13

Participants: 113

Period: 5 days

Judge: 0xean

Total Solo HM: 6

Id: 166

League: ETH

QuickSwap and StellaSwap

Findings Distribution

Researcher Performance

Rank: 113/113

Findings: 1

Award: $24.02

🌟 Selected for report: 0

🚀 Solo Findings: 0

1. [G-1] ++number (--number) cost less gas compare number++ (number--) or number += 1 (number -= 1)

1.1. File DataStorage.sol, line 119:

index -= 1;

Becomes:

--index;

1.2. File DataStorage.sol, line 307:

for (uint256 i = 0; i < secondsAgos.length; i++) {

Becomes:

for (uint256 i = 0; i < secondsAgos.length; ++i) {

1.3. File TickTable.sol, line 100:

tick += 1;

Becomes:

++tick;

2. [G-2] Initialize variable without assign equal 0 is cheaper than initialize with assign equal 0

File DataStorage.sol, line 307:

for (uint256 i = 0; i < secondsAgos.length; i++) {

Becomes:

for (uint256 i; i < secondsAgos.length; ++i) {

3. [G-3] Cache the length of arrays in the loops for saving gas

File DataStorage.sol, line 307:

for (uint256 i = 0; i < secondsAgos.length; i++) {

Becomes:

uint256 length = secondsAgos.length; for (uint256 i; i < length; ++i) {

4. [G-4] Cache read variables in memory to save gas

4.1. File AlgebraPool.sol, line 722 - 728:

currentPrice = globalState.price; currentTick = globalState.tick; cache.fee = globalState.fee; cache.timepointIndex = globalState.timepointIndex; uint256 _communityFeeToken0 = globalState.communityFeeToken0; uint256 _communityFeeToken1 = globalState.communityFeeToken1; bool unlocked = globalState.unlocked;

Becomes:

GlobalState memory globalStateCache = globalState; currentPrice = globalStateCache.price; currentTick = globalStateCache.tick; cache.fee = globalStateCache.fee; cache.timepointIndex = globalStateCache.timepointIndex; uint256 _communityFeeToken0 = globalStateCache.communityFeeToken0; uint256 _communityFeeToken1 = globalStateCache.communityFeeToken1; bool unlocked = globalStateCache.unlocked;

4.2. File AlgebraPool.sol, line 116:

TickManager.Tick storage _lower = ticks[bottomTick];

Becomes:

TickManager.Tick memory _lower = ticks[bottomTick];
Instances include:

File AlgebraPool.sol, line 127. File DataStorage.sol line 120, 228, 392, 411. File TickManager.sol, line 47, 48.

#0 - vladyan18

2022-10-04T17:17:48Z

4.1 Please note that writing to memory also costs gas. Moreover, the memory is not cleared inside the call. So reading directly onto the stack/destination will be cheaper if the optimizer can do it in one SLOAD (it can).

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