Open code423n4 opened 2 years ago
Would save 2.1k * 2 = 4200 each time they are called
Rest would save between 100 and 500 gas
Not anymore
Saves 25 gas per instance
25
3 gas per instance 10 * 3 = 30
6 gas per instance 14 * 6 = 84
20 per instance 26 * 20 = 520
4200 per above
Will not save gas
Report is short and sweet, total saved: 4859
G01 - Using
!= 0
instead of> 0
in require statement withuint
!= 0
costs less gas compared to> 0
for unsigned integers inrequire
statements with the optimizer enabled:G02 - More gas efficient
for
loop with++i
increment andunchecked
blockLoop index increments can be written as unchecked { ++i } instead of simply i++ to save gas.
G03 - Cache array length in
for
Caching the array length before
for
loop could save gas here:G04 - Avoid long revert strings
Shortening revert strings to fit in 32 bytes will decrease deployment time gas and will decrease runtime gas when the revert condition has been met. Next revert strings are longer than 32 bytes:
G04 -
unchecked
block can be used for gas efficiency of the expression that can't overflow/underflowCheck comments
G05 - Variables that can be changed to
immutable
https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Pair.sol#L13-L14
G06 - Reachable
assert
statementsDue to solidity docs:
Assert
should only be used to test for internal errors, and to check invariants. Properly functioning code should never create a Panic, not even on invalid external input. If this happens, then there is a bug in your contract which you should fix.Multiple
assert
statements represented in code should be replaced torequire
, for example:https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/RewardsDistributor.sol#L97-L100