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
Rank: 110/113
Findings: 1
Award: $24.02
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0x1f8b, 0x5rings, 0xNazgul, 0xRoxas, 0xSmartContract, 0xbepresent, 0xmatt, Aeros, Amithuddar, Awesome, Aymen0909, B2, Bnke0x0, ChristianKuri, CodingNameKiki, Deivitto, Diraco, Fitraldys, HardlyCodeMan, JC, Mukund, Noah3o6, Olivierdem, RaymondFam, ReyAdmirado, RockingMiles, Rolezn, Ruhum, Saintcode_, Shinchan, SnowMan, TomJ, Tomio, Tomo, V_B, Waze, __141345__, ajtra, asutorufos, aysha, beardofginger, bobirichman, brgltd, bulej93, c3phas, ch0bu, cryptonue, defsec, delfin454000, dharma09, durianSausage, emrekocak, erictee, fatherOfBlocks, francoHacker, gianganhnguyen, gogo, imare, kaden, karanctf, ladboy233, lukris02, m_Rassska, martin, medikko, mics, natzuu, oyc_109, peiw, rbserver, ret2basic, rotcivegaf, saian, shark, slowmoses, tnevler, trustindistrust, zeesaw, zishansami
24.0189 USDC - $24.02
15000 - 3000
can be changed to 12000
and save some gasInstead of performing mathematical operations, the result can be written directly.
require()
, Use != 0
Instead of > 0
With Uint ValuesIn a require, when checking a uint, using != 0
instead of > 0
saves 6 gas. This will jump over or avoid an extra ISZERO
opcode.
Instances include:
src/core/contracts/AlgebraPool.sol:224
src/core/contracts/AlgebraPool.sol:434
src/core/contracts/AlgebraPool.sol:454
src/core/contracts/AlgebraPool.sol:455
src/core/contracts/AlgebraPool.sol:469
src/core/contracts/AlgebraPool.sol:898
src/core/contracts/libraries/PriceMovementMath.sol:52
src/core/contracts/libraries/PriceMovementMath.sol:53
++i
COSTS LESS GAS COMPARED TO i++
OR i += 1
++i
costs less gas compared to i++
or i += 1
for unsigned integer, as pre-increment is cheaper (about 5 gas per iteration). This statement is true even with the optimizer enabled.
i++
increments i
and returns the initial value of i
. Which means:
uint i = 1; i++; // == 1 but i == 2
But ++i
returns the actual incremented value:
uint i = 1; ++i; // == 2 and i == 2 too, so no need for a temporary variable
In the first case, the compiler has to create a temporary variable (when used) for returning 1
instead of 2
Instance includes:
src/core/contracts/libraries/DataStorage.sol:307
I suggest using ++i instead of i++ to increment the value of a uint variable.
Reading array length at each iteration of the loop takes 6 gas (3 for mload and 3 to place memory_offset) in the stack.
Caching the array length in the stack saves around 3 gas per iteration.
Instances include:
src/core/contracts/libraries/DataStorage.sol:307
unit
variable to default value of zeroInstance includes:
src/core/contracts/libraries/DataStorage.sol:307
Use a solidity version of at least 0.8.0 to get overflow protection without LowGasSafeMath
Use a solidity version of at least 0.8.2 to get simple compiler automatic inlining Use a solidity version of at least 0.8.3 to get better struct packing and cheaper multiple storage reads Use a solidity version of at least 0.8.4 to get custom errors, which are cheaper at deployment than revert()/require()
strings Use a solidity version of at least 0.8.10 to have external calls skip contract existence checks if the external call has a return value.
Instances include:
src/core/contracts/AlgebraFactory.sol:2
src/core/contracts/AlgebraPool.sol:2
src/core/contracts/AlgebraPoolDeployer.sol:2
src/core/contracts/DataStorageOperator.sol:2
src/core/contracts/libraries/AdaptiveFee.sol:2
src/core/contracts/libraries/Constants.sol:2
src/core/contracts/libraries/DataStorage.sol:2
src/core/contracts/libraries/PriceMovementMath.sol:2
src/core/contracts/libraries/TickManager.sol:2
src/core/contracts/libraries/TickTable.sol:2
src/core/contracts/libraries/TokenDeltaMath.sol
:2](https://github.com/code-423n4/2022-09-quickswap/blob/main/src/core/contracts/libraries/TokenDeltaMath.sol#L2) [
src/core/contracts/base/PoolImmutables.sol:2](https://github.com/code-423n4/2022-09-quickswap/blob/main/src/core/contracts/base/PoolImmutables.sol#L2) [
src/core/contracts/base/PoolState.sol:2`