Skip to content

Optimize safe casting of signed numbers#3565

Merged
frangio merged 3 commits into
OpenZeppelin:masterfrom
CodeSandwich:cheaper_cast
Jul 20, 2022
Merged

Optimize safe casting of signed numbers#3565
frangio merged 3 commits into
OpenZeppelin:masterfrom
CodeSandwich:cheaper_cast

Conversation

@CodeSandwich

Copy link
Copy Markdown
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

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

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