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

Optimize safe casting of signed numbers #3565

Merged
merged 3 commits into from
Jul 20, 2022

Conversation

CodeSandwich
Copy link
Contributor

Fixes #nothing

This PR reduces gas needed to perform safe downcasting of signed integers by 23 gas ('gasleft' microbenchmark went down from 110 to 87 gas). Both underflows and overflows are still caught, but instead of two comparisons there's only one.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very simple, I like it. Thanks!

Keep them coming!

@frangio frangio merged commit 580b7ab into OpenZeppelin:master Jul 20, 2022
@CodeSandwich CodeSandwich deleted the cheaper_cast branch July 20, 2022 17:16
ronhuafeng added a commit to ronhuafeng/openzeppelin-contracts that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants