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

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

Gas Optimizations #247

code423n4 opened this issue May 24, 2022 · 0 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

[G-01] Boolean declaration not necessary

require(pool.shutdown == false, "pool is closed"); could be changed to require(!pool.shutdown, "pool is closed"); to save gas.

It also presents inconsistency to other instances where bools do not have explicit declaration.

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/convex-platform/contracts/contracts/Booster.sol#L400

[G-02] For loop optimization

for(uint i=0; i < extraRewards.length; i++){ 
     IRewards(extraRewards[i]).stake(_receiver, _amount);
}

Gas could be saved by:

  • Not initializing variable to default value of zero
  • Caching array length
  • Using a prefix (++i) instead of a postfix (i++)
  • Unchecking increment count

Example:

uint size = extraRewards.length
for(uint i=0; i < size;){ 
      IRewards(extraRewards[i]).stake(_receiver, _amount);
      unchecked { ++i; }
}

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L174-L185

@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 28, 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 duplicate This issue or pull request already exists G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants