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

Merged
merged 10 commits into from
Jun 27, 2025

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
Siteproxy
beeb added 4 commits June 11, 2025 12:08

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
beeb added 2 commits June 11, 2025 13:27
@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 added 2 commits June 11, 2025 16:34

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@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

Copy link
Member

@klkvr klkvr left a comment

Choose a reason for hiding this comment

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

nice

@mattsse mattsse merged commit ba2821d into foundry-rs:master Jun 27, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants