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

optimizing for loops by using unchecked{++i} over i++ #12

Closed
code423n4 opened this issue Nov 4, 2021 · 1 comment
Closed

optimizing for loops by using unchecked{++i} over i++ #12

code423n4 opened this issue Nov 4, 2021 · 1 comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

pants

Vulnerability details

optimizing for loops by using unchecked{++i} over i++

For example in line 535 of SwapUtils.sol you have

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

While a more effiient looping would be:

    for (uint256 i = 0; i < numTokens; unchecked{++i}) {

One cannot reach uint256 maximal value so it's overflow safe.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 4, 2021
code423n4 added a commit that referenced this issue Nov 4, 2021
@chickenpie347 chickenpie347 added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 3, 2022
@0xean
Copy link
Collaborator

0xean commented Jan 8, 2022

duplicate of #261

@0xean 0xean closed this as completed Jan 8, 2022
@0xean 0xean added the duplicate This issue or pull request already exists label Jan 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) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants