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

Closed
code423n4 opened this issue May 24, 2022 · 1 comment
Closed

Gas Optimizations #220

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

Comments

@code423n4
Copy link
Contributor

FOR-LOOPS: ++i COSTS LESS GAS THAN i++

++i costs less gas than I++ for unsigned integer, it costs 5 gas per iteration.
And also i suggest to change uint256 i=0 to uint256 i. The default value of variable is 0 for unsigned integer. So explicitly initializing it with its default value is an anti-pattern and wastes gas.

for (uint256 i = 0; i < rewardTokensLength; i++) {

I suggest you to change those line into:

for (uint256 i; i < rewardTokensLength; i++){

This already done here:
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L306
for (uint256 i; i < rewardTokensLength; i++) {

Instance include:
https://github.com/code-423n4/2022-05-aura/blob/main/convex-platform/contracts/contracts/Booster.sol#L222
https://github.com/code-423n4/2022-05-aura/blob/main/convex-platform/contracts/contracts/Booster.sol#L379
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L174

@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
Copy link
Collaborator

dmvt commented Jul 8, 2022

Grouping this with the warden’s gas report, #216

@dmvt dmvt closed this as completed Jul 8, 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

3 participants