foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(cheatcodes): extend usable range in `assertApproxEqRel`

Open beeb opened this issue 6 months ago • 2 comments

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

  • [x] Added Tests
  • [ ] Added Documentation
  • [ ] Breaking changes

beeb avatar Jun 11 '25 11:06 beeb

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

beeb avatar Jun 11 '25 14:06 beeb

cc @klkvr would you mind double checking this proposed change

zerosnacks avatar Jun 11 '25 15:06 zerosnacks