Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #208

Open
code423n4 opened this issue May 24, 2022 · 0 comments
Open

Gas Optimizations #208

code423n4 opened this issue May 24, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Default values

When initizalising a variable to the default value it can be left blank to save some gas.

AuraBalRewardPool.sol#L35
AuraBalRewardPool.sol#L38-L39
AuraLocker.sol#L72
AuraMerkleDrop.sol#L29
BaseRewardPool.sol#L71-L77
Booster.sol#L29
ConvexMasterChef.sol#L63
CrvDepositor.sol#L36
VirtualBalanceRewardPool.sol#L89-L95

For Loop Optimisations

Looping over state variables is expensive (roughly 100 gas per iteration), recommend storing to the stack and looping over that. For a small gas optimization per loop can also replace i++ with ++i. Will save a temp variable being created every loop (roughly 5 gas per iteration).

Booster.sol#L379
BaseRewardPool.sol#L214
BaseRewardPool.sol#L230
BaseRewardPool.sol#L262
BaseRewardPool.sol#L296

Update Variable With Same Value

isShutdown is already set to false on contract creation as the default value and does not need to be reassigned to false in constructor.

Booster.sol#L108

The same with treasure being set to address(0) as the default value and then reassigned in the constructor.
Booster.sol#L114

Custom Errors

For the contracts using a compiler version > 0.8.4 you can replace their revert strings with custom errors. This is both cheaper in deployment and on runtime costs.

Uints > 0 in require Statements

If not using custom errors, in require statements if checking whether a uint is > 0 it is cheaper to replace with != 0.

Aura.sol#L68
AuraBalRewardPool.sol#L121
AuraBalRewardPool.sol#L139
AuraBalRewardPool.sol#L157
AuraBalRewardPool.sol#L210
AuraLocker.sol#L259
AuraLocker.sol#L359
AuraLocker.sol#L385
AuraLocker.sol#L431
AuraLocker.sol#L471
AuraLocker.sol#L822
AuraLocker.sol#L851
AuraMerkleDrop.sol#L122
AuraPenaltyForwarder.sol#L52
BalLiquidityProvider.sol#L57
BalLiquidityProvider.sol#L70
ExtraRewardsDistributor.sol#L171
PoolManagerSecondaryProxy.sol#L104
CrvDepositor.sol#L169
BaseRewardPool.sol#L211
BaseRewardPool.sol#L227

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 24, 2022
code423n4 added a commit that referenced this issue May 24, 2022
@0xMaharishi 0xMaharishi added the duplicate This issue or pull request already exists label May 27, 2022
@dmvt dmvt removed the duplicate This issue or pull request already exists label Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

3 participants