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 Optimization #38

Open
code423n4 opened this issue May 14, 2022 · 1 comment
Open

Gas Optimization #38

code423n4 opened this issue May 14, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Gas Optimizations Report

Table of contents

Gas Findings

[Gas-1] Do not cache msg.sender

We recommend not to cache msg.sender since calling it is 2 gas while reading a variable is more.

    Aura.solL#50
    AuraClaimZap.solL#81
    AuraStakingProxy.solL#75
    BalLiquidityProvider.solL#37
    ArbitartorVault.solL#33

[Gas-2] Use != 0 instead of > 0

Using != 0 is slightly cheaper than > 0. We recommend to replace > with != in the following places:

    Aura.solL#68
    AuraBalRewardPool.solL#121
    AuraBalRewardPool.solL#139
    AuraBalRewardPool.solL#157
    AuraClaimZap.solL#196

[Gas-3] Rearrange state variables

You can change the order of the storage variables to decrease memory uses. This is because the new suggested new orders will use less storage slots.

    AuraLocker.sol: 

old number of slots: 17
new number of slots: 15
the new order of types is
1. ArrayTypeName - address
2. uint256
3. uint256
4. uint256
5. uint256
6. uint256
7. ArrayTypeName - Epoch
8. IERC20
9. uint256
10. uint256
11. uint256
12. string
13. string
14. address
15. uint8
16. bool
17. address
AuraVestedEscrow.sol:
old number of slots: 7
new number of slots: 6
the new order of types is
1. IERC20
2. IAuraLocker
3. uint256
4. uint256
5. uint256
6. address
7. bool
BoosterOwner.sol:
old number of slots: 9
new number of slots: 8
the new order of types is
1. uint256
2. uint256
3. address
4. bool
5. bool
6. address
7. address
8. address
9. address
10. address
CrvDepositor.sol:
old number of slots: 13
new number of slots: 12
the new order of types is
1. uint256
2. uint256
3. uint256
4. uint256
5. uint256
6. uint256
7. address
8. bool
9. address
10. address
11. address
12. address
13. address

[Gas-4] Unnecessary index init

In for loops you initialize the index to start from 0, but it already initialized to 0 in default and this assignment cost gas. It is more clear and gas efficient to declare without assigning 0 and will have the same meaning:

    AuraClaimZap.solL#143
    AuraClaimZap.solL#147
    AuraClaimZap.solL#151
    AuraLocker.solL#773
    AuraVestedEscrow.solL#100
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 14, 2022
code423n4 added a commit that referenced this issue May 14, 2022
@0xMaharishi 0xMaharishi added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label May 25, 2022
@0xMaharishi
Copy link

Will rearrange state vars to save on memory slots

@0xMaharishi 0xMaharishi added sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons and removed sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") labels May 30, 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) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

2 participants