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

[Certora Audit] G-10. ++i costs less gas compared to i++ or i+=1 #897

Merged
merged 2 commits into from
Jan 10, 2025
Merged

Conversation

remedcu
Copy link
Member

@remedcu remedcu commented Jan 9, 2025

This pull request includes several changes to increment and decrement operations in various Solidity contract files. The primary goal is to decrease gas usage.

Pre-increments and pre-decrements are cheaper.
For a uint256 i variable, the following is true with the Optimizer enabled at 10k:
Increment:

  • i += 1 is the most expensive form
  • i++ costs 6 gas less than i += 1
  • ++i costs 5 gas less than i++ (11 gas less than i += 1)

Decrement:

  • i -= 1 is the most expensive form
  • i-- costs 11 gas less than i -= 1
  • --i costs 5 gas less than i-- (16 gas less than i -= 1)

Changes to increment and decrement operations:

@remedcu remedcu self-assigned this Jan 9, 2025
@remedcu remedcu marked this pull request as ready for review January 9, 2025 14:24
@remedcu remedcu requested review from akshay-ap and mmv08 January 9, 2025 14:26
@remedcu remedcu merged commit 8137b68 into main Jan 10, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants