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: 92/113
Findings: 1
Award: $24.22
🌟 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.223 USDC - $24.22
Marking variables as internal saves gas on deployment as the compiler does not have to create getter functions for these variables. Variables can still be read from the verified source code or the bytecode
uint32 public constant WINDOW = 1 days;
Reading array length in each iteration consumes more gas than necessary. Cache array length in a variable and use it in the for-loop to save gas
for (uint256 i = 0; i < secondsAgos.length; i++)
owner
in functions that use onlyOwner modifierIn functions that use onlyOwner modifier, using msg.sender instead of reading owner variable from storage reduces gas
function setOwner(address _owner) external override onlyOwner { require(owner != _owner); emit Owner(_owner); owner = _owner; }
SSTORE from false to true costs more than SSTORE from non-zero to another non-zero value, and boolean varialbes costs more gas than uint256 since additional conversion operations has to be performed
Replace boolean with uint256
modifier lock() { require(globalState.unlocked, 'LOK'); globalState.unlocked = false; _; globalState.unlocked = true; }
Repeated external calls can be stored in a variable and re-used to save gas
_blockTimestamp()
liquidityNext > 0 ? (liquidityDelta > 0 ? _blockTimestamp() : lastLiquidityAddTimestamp) : 0
globalState.fee = _getNewFee(_blockTimestamp(), cache.tick, newTimepointIndex, liquidityBefore);
Require statements including conditions with && operator can be split into multiple require statements to save gas
require(newLiquidityCooldown <= Constants.MAX_LIQUIDITY_COOLDOWN && liquidityCooldown != newLiquidityCooldown);
require(_feeConfig.gamma1 != 0 && _feeConfig.gamma2 != 0 && _feeConfig.volumeGamma != 0, 'Gammas must be > 0');