Gas Optimizations #90
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
contracts\BkdLocker.sol#L144
Currently it replaces stashedWithdraws[i] even if "i" equals to "stashedWithdraws.length - 1".
And it calculates stashedWithdraws.length every time after pop right, you can reduce gas by changing the length variable.
You can replace L144 like below.
--length;
if(i != length) {
stashedWithdraws[i] = stashedWithdraws[length];
}
contracts\tokenomics\InflationManager.sol#L575
contracts\tokenomics\InflationManager.sol#L589
contracts\tokenomics\InflationManager.sol#L602
From the logic of the contract, "totalKeeperPoolWeight" will be always non-negative.
Even if this value could be negative, it will be revoked with underflow error before.
Use != 0 instead of > 0 for uint variables
contracts\BkdLocker.sol#L91
contracts\BkdLocker.sol#L92
contracts\BkdLocker.sol#L137
contracts\BkdLocker.sol#L139
contracts\BkdLocker.sol#L254
contracts\BkdLocker.sol#L301
contracts\tokenomics\AmmGauge.sol#L88
contracts\tokenomics\AmmGauge.sol#L104
contracts\tokenomics\AmmGauge.sol#L125
contracts\tokenomics\AmmGauge.sol#L147
contracts\tokenomics\FeeBurner.sol#L117
contracts\tokenomics\KeeperGauge.sol#L140
contracts\tokenomics\LpGauge.sol#L68
contracts\tokenomics\LpGauge.sol#L114
contracts\tokenomics\VestedEscrow.sol#L84
contracts\RewardHandler.sol#L63
Change storage to memory if possible
contracts\BkdLocker.sol#L251
An array’s length should be cached to save gas in for-loops
contracts\StakerVault.sol#L259
contracts\tokenomics\FeeBurner.sol#L56
contracts\tokenomics\InflationManager.sol#L116
contracts\tokenomics\VestedEscrow.sol#L94
contracts\zaps\PoolMigrationZap.sol#L22
contracts\zaps\PoolMigrationZap.sol#L39
Usage of unchecked can reduce the gas cost
contracts\StakerVault.sol#L387
allowances[src][msg.sender] = allowance.uncheckedSub(unstaked);
The text was updated successfully, but these errors were encountered: