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

Prefix increments are cheaper than postfix increments #7

Closed
code423n4 opened this issue Dec 9, 2021 · 2 comments
Closed

Prefix increments are cheaper than postfix increments #7

code423n4 opened this issue Dec 9, 2021 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

robee

Vulnerability details

Prefix increments are cheaper than postfix increments.
Further more, using unchecked {++x} is even more gas efficient, and the gas saving accumulates every iteration and can make a real change
There is no risk of overflow caused by increamenting the iteration index in for loops (the ++i in for (uint256 i = 0; i < numIterations; ++i)).
But increments perform overflow checks that are not necessary in this case.
These functions use not using prefix increments (++x) or not using the unchecked keyword:

    change to prefix increment and unchecked: Incentivizer.sol, i, 144
    change to prefix increment and unchecked: Incentivizer.sol, i, 174
    change to prefix increment and unchecked: Incentivizer.sol, i, 190
    change to prefix increment and unchecked: Incentivizer.sol, i, 233
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 9, 2021
code423n4 added a commit that referenced this issue Dec 9, 2021
@kbrizzle
Copy link
Collaborator

kbrizzle commented Dec 17, 2021

Duplicate of: #34

@CloudEllie CloudEllie added the duplicate This issue or pull request already exists label Dec 21, 2021
@GalloDaSballo
Copy link
Collaborator

Duplicate of: #34

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

4 participants