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 #219

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

Gas Optimizations #219

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

Comments

@code423n4
Copy link
Contributor

  1. Non-strict inequalities are cheaper than strict ones
    AuraLocker.sol#L724
    AuraVestedEscrow.sol#L158 (when _time = startTime, the final result will be 0 anyway)

  2. Check require() at the beginning of function
    AuraBalRewardPool.sol#L77
    AuraLocker.sol#L385 (You can move this line to #L381 so that you can avoid unnecessary calculation for expiryTime)
    AuraMerkleDrop.sol#L69
    AuraMerkleDrop.sol#L152
    AuraPenaltyForwarder.sol#L51-L52 (You can move these lines to #L49)
    AuraVestedEscrow.sol#L63-L66 (You can move these lines to #L58)

  3. Declare memory variable instead of calling locks[i] several times
    AuraLocker.sol#L696-L707

  4. Change storage to memory if possible
    AuraLocker.sol#L172
    AuraLocker.sol#L377
    AuraLocker.sol#L469
    AuraLocker.sol#L659
    AuraLocker.sol#L692
    AuraLocker.sol#L693
    Booster.sol#L399
    Booster.sol#L454
    Booster.sol#L573
    ConvexMasterChef.sol#L157
    ConvexMasterChef.sol#L158
    ConvexMasterChef.sol#L263

  5. Don't use storage value if possible
    AuraVestedEscrow.sol#L65 (You can use starttime_, endtime_ instead of startTime, endTime)

  6. Use != 0 instead of > 0 for uint variables
    There are more than 30 cases and I will show just one example.
    I think you can change them easily if you want.
    Aura.sol#L68

  7. Use ++i instead of i++, i+=1 (also for --i)
    There are more than 30 cases and I will show just one example.
    Also you can use "unchecked" for such increments.
    AuraClaimZap.sol#L143

  8. No need to initialize variables with default values
    There are more than 30 cases and I will show just one example for uint and all for bool.
    AuraBalRewardPool.sol#L35
    AuraLocker.sol#L114
    AuraVestedEscrow.sol#L33

  9. An array’s length should be cached to save gas in for-loops
    AuraClaimZap.sol#L143
    AuraClaimZap.sol#L147
    AuraClaimZap.sol#L151
    AuraLocker.sol#L696
    AuraLocker.sol#L699
    AuraVestedEscrow.sol#L100
    ArbitartorVault.sol#L49
    BaseRewardPool.sol#L214
    BaseRewardPool.sol#L230
    BaseRewardPool.sol#L262
    BaseRewardPool.sol#L296
    Booster.sol#L379
    Booster.sol#L538
    PoolManagerSecondaryProxy.sol#L69

  10. Use if(flag) instead of if(flag == true) [use if(!flag) instead of if(flag == false)]
    RewardFactory.sol#L72
    VoterProxy.sol#L107
    VoterProxy.sol#L168
    VoterProxy.sol#L171
    VoterProxy.sol#L190
    AuraMerkleDrop.sol#L123
    Booster.sol#L400
    Booster.sol#L574

@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