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: 98/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.0196 USDC - $24.02
Title: Gas savings for using solidity 0.8.10
Proof of Concept: All contract in scope
Recommended Mitigation Steps: Consider to upgrade pragma to at least 0.8.10.
Solidity 0.8.10 has a useful change which reduced gas costs of external calls Reference: here
Title: Unchecking arithmetics operations that can't underflow/overflow
Proof of Concept: TokenDeltaMath.sol#L52 Should be unchecked due to L#51
Recommended Mitigation Steps:
Use unchecked
Title: Using !=
in require
statement is more gas efficient
Proof of Concept: PriceMovementMath.sol#L52-L53 AlgebraPool.sol#L434 AlgebraPool.sol#L469
Recommended Mitigation Steps:
Change > 0
to != 0
Title: >=
is cheaper than >
Impact:
Strict inequalities (>
) are more expensive than non-strict ones (>=
). This is due to some supplementary checks (ISZERO, 3 gas)
Proof of Concept: AlgebraPool.sol#L237
Recommended Mitigation Steps:
Consider using >=
instead of >
to avoid some opcodes
Title: Default value initialization
Impact: If a variable is not set/initialized, it is assumed to have the default value (0, false, 0x0 etc depending on the data type). Explicitly initializing it with its default value is an anti-pattern and wastes gas.
Proof of Concept: DataStorage.sol#L307
Recommended Mitigation Steps: Remove explicit initialization for default values.
Title: Caching length
for loop can save gas
Proof of Concept: DataStorage.sol#L307
Recommended Mitigation Steps: Change to:
uint256 Length = secondsAgos.length; for (uint256 i = 0; i < Length; i++) {
Title: Using unchecked and prefix increment is more effective for gas saving:
Proof of Concept: DataStorage.sol#L307
Recommended Mitigation Steps: Change to:
for (uint256 i = 0; i < secondsAgos.length;) { // ... unchecked { ++i; } }
Title: Using multiple require
instead &&
can save gas
Proof of Concept: DataStorageOperator.sol#L46 AlgebraPool.sol#L739 AlgebraPool.sol#L743
Recommended Mitigation Steps: Change to:
require(_feeConfig.gamma1 != 0, 'Gammas must be > 0'); require(_feeConfig.gamma2 != 0, 'Gammas must be > 0'); require(_feeConfig.volumeGamma != 0, 'Gammas must be > 0');
Title: abi.encode() is less efficient than abi.encodePacked()
Proof of Concept: AlgebraPoolDeployer.sol#L51
Title: Set as immutable
can save gas
Proof of Concept: AlgebraPoolDeployer.sol#L19
Recommended Mitigation Steps: can be set as immutable, which already set once in the constructor