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

Closed
code423n4 opened this issue Jan 27, 2022 · 2 comments
Closed

Prefix increments are cheaper than postfix increments #9

code423n4 opened this issue Jan 27, 2022 · 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.

    change to prefix increment and unchecked: TreasuryAction.sol, i, 157
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 27, 2022
code423n4 added a commit that referenced this issue Jan 27, 2022
@jeffywu jeffywu added the duplicate This issue or pull request already exists label Feb 6, 2022
@jeffywu
Copy link
Collaborator

jeffywu commented Feb 6, 2022

Duplicate #228

@pauliax
Copy link
Collaborator

pauliax commented Feb 13, 2022

#228

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