Platform: Code4rena
Start Date: 14/04/2022
Pot Size: $75,000 USDC
Total HM: 8
Participants: 72
Period: 7 days
Judge: Jack the Pug
Total Solo HM: 2
Id: 110
League: ETH
Rank: 66/72
Findings: 1
Award: $54.33
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Dravee
Also found by: 0v3rf10w, 0x1f8b, 0xAsm0d3us, 0xBug, 0xDjango, 0xNazgul, 0xkatana, CertoraInc, Cityscape, Funen, Hawkeye, IllIllI, MaratCerby, SolidityScan, TerrierLover, TomFrenchBlockchain, Tomio, TrungOre, bae11, berndartmueller, csanuragjain, defsec, delfin454000, ellahi, fatherOfBlocks, gs8nrv, gzeon, horsefacts, ilan, jah, joestakey, joshie, kebabsec, kenta, nahnah, oyc_109, rayn, rfa, robee, saian, securerodd, simon135, slywaters, sorrynotsorry, tchkvsky, teryanarmen, z3s
54.333 USDC - $54.33
require()
, Use != 0
Instead of > 0
With Uint ValuesContext: Funding.sol#L163-L191
, Funding.sol#L315-L330
, Funding.sol#L334-L344
, Funding.sol#L414-L441
, Funding.sol#L447-L468
, KnightingRound.sol#L109-L149 (For L124 and L128)
, KnightingRound.sol#L162-L204
, KnightingRound.sol#L209-L223
, KnightingRound.sol#L308-L321
, KnightingRound.sol#L327-L339
, KnightingRound.sol#L402-L415
, StakedCitadelVester.sol#L132-L152
, SupplySchedule.sol#L55-L65
, SupplySchedule.sol#L84-L126
, SupplySchedule.sol#L178-L233
Description:
In a require, when checking a uint, using != 0
instead of > 0
saves 6 gas. This will jump over or avoid an extra ISZERO
opcode.
Recommendation:
Use != 0
instead of > 0
with uint values but only in require()
statements.
Context: GlobalAccessControlManaged.sol#L46-L57
Description: One can save gas by caching the array length (in stack) and using that set variable in the loop. Replace state variable reads and writes within loops with local variable reads and writes. This is done by assigning state variable values to new local variables, reading and/or writing the local variables in a loop, then after the loop assigning any changed local variables to their equivalent state variables.
Recommendation:
Simply do something like so before the for loop: uint length = variable.length
. Then add length
in place of variable.length
in the for loop.
Context: All Contracts
Description:
Contracts most called functions could simply save gas by function ordering via Method ID. Calling a function at runtime will be cheaper if the function is positioned earlier in the order (has a relatively lower Method ID) because 22 gas are added to the cost of a function for every position that came before it. The caller can save on gas if you prioritize most called functions. One could use This tool
to help find alternative function names with lower Method IDs while keeping the original name intact.
Recommendation:
Find a lower method ID name for the most called functions for example mostCalled()
vs. mostCalled_41q()
is cheaper by 44 gas.
++index
instead of index++
to increment a loop counterContext: CitadelMinter.sol#L143-L159
, SupplySchedule.sol#L178-L233
, GlobalAccessControlManaged.sol#L46-L57
Description:
Due to reduced stack operations, using ++index
saves 5 gas per iteration.
Recommendation:
Use ++index
to increment a loop counter.
if()
, Use > 0
Instead of !=0
With Uint ValuesContext: StakedCitadel.sol#L396-L429
, StakedCitadel.sol#L764-L777
, StakedCitadel.sol#L808-L824
, StakedCitadel.sol#L898-L933 (For L921 and L925
, StakedCitadelVester.sol#L85-L97
Description:
In a require, when checking a uint, using != 0
instead of > 0
saves 6 gas. This will jump over or avoid an extra ISZERO
opcode. But this only works in require()
and not in other situations hence it is cheaper to use > 0
instead of !=0
with uint values in an if()
.
Recommendation:
Use != 0
instead of > 0
with uint values but only in require()
statements and use > 0
instead of != 0
in other situations.