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

unchecked { ++i } is more gas efficient than i++ for loops #25

Open
code423n4 opened this issue Nov 13, 2021 · 1 comment
Open

unchecked { ++i } is more gas efficient than i++ for loops #25

code423n4 opened this issue Nov 13, 2021 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

GiveMeTestEther

Vulnerability details

Impact

The loop index increments can be written as unchecked { ++i } instead of simply i++ to save gas.
Two reasons:

  • unchecked because the loop variable i is of type uint256, therefore we would run out of gas before triggering an overflow
  • ++i instead of i++ because it is slightly more efficient

Proof of Concept

see discussion here ethereum/solidity#10695

Tools Used

Visual Code Studio

Recommended Mitigation Steps

replace i++ with unchecked { ++i }

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 13, 2021
code423n4 added a commit that referenced this issue Nov 13, 2021
@adrien-supizet
Copy link
Collaborator

adrien-supizet commented Nov 18, 2021

As already discussed here in another audit code-423n4/2021-10-pooltogether-findings#6 (comment)

We are not going to fix this as it reduces clarity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

2 participants