Open code423n4 opened 2 years ago
Use unchecked lib to increment safe variables Agree, this should save about 17 gas (20 gas minus the cost of the intermediary result, 3 gas) 3 * 17 = 51
Use unchecked for decrement i Agree, this should save around 25 gas (20 for unchecked + 5 for pre-decrement)
Cache .length Saves the cost of computing the offset, 3 gas 3*3 = 9
Use require(foo != 0) instead of require(foo > 0) Valid until 0.8.13, saves 3 gas per instance only with optimizer 7 * 3 = 21
Total Gas Saved 83
Gas optimizations
Use unchecked lib to increment safe variables
PoolMigrationZap.sol
You can add the unchecked math lib like you do on the others contracts to safely increment the
i
var, saving gas and make contract consistent with the others by enforcing the same style.Recommendation, add
using UncheckedMath for uint256
And on linePoolMigrationZap.sol#L22
change;To
TopUpKeeperHelper.sol
On line TopUpKeeperHelper.sol#L52 you coul use unchecked math lib to increment the variable. Change:
To:
KeeperGauge.sol
On lines #L98 and L59 you could use unchecked math lib, consider change;
To;
Use unchecked for decrement
i
On BkdLocker.sol#L140 you can do a unchecked decrement (or add a function to the Unchecked math to do it) change;
to;
Cache
.length
You could cache lenght of arrays to save gas;
RewardHandler.sol#L41-L42
StakerVault.sol#L259
VestedEscrow.sol#L94
Use
require(foo != 0)
instead ofrequire(foo > 0)
>0
is less gas efficient than!0
if you enable the optimizer at 10k AND you’re in a require statement.BkdLocker.sol#L91
BkdLocker.sol#L92
BkdLocker.sol#L137
VestedEscrow.sol#L84
KeeperGauge.sol#L140
AmmGauge.sol#L104
AmmGauge.sol#L125