Skip to content

feat(cheatcodes): extend usable range in assertApproxEqRel #10758

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

beeb
Copy link
Contributor

@beeb beeb commented Jun 11, 2025

Motivation

For large values, the current implementation of the cheatcode assertApproxEqRel overflows during calculation of the relative delta. However, using a larger type for this calculation allows to prevent overflows and use the full range of uint256.

Solution

The calculation was modified to use U512 for the calculation and only check that the final value for the delta fits inside a uint256 (a requirement of the error type).

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@zerosnacks zerosnacks requested a review from grandizzy as a code owner June 11, 2025 14:23
zerosnacks
zerosnacks previously approved these changes Jun 11, 2025
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

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

Makes sense! Thanks

@beeb
Copy link
Contributor Author

beeb commented Jun 11, 2025

@zerosnacks let me add an overflow test quickly, I noticed it's missing

@zerosnacks
Copy link
Member

cc @klkvr would you mind double checking this proposed change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants