Repository navigation
test: fix uint128 overflow in IndexingMath round-trip fuzz - #57
Closed
PierrickGT wants to merge 1 commit into
Closed
PierrickGT wants to merge 1 commit into
PierrickGT wants to merge 1 commit into
Conversation
`_EXP_SCALED_ONE` is a uint56, so Solidity evaluated `_EXP_SCALED_ONE + index - 1` in uint128. Any index within 1e12 of `type(uint128).max` overflowed that addition. The test then reverted with Panic(0x11) before reaching its assertion. This failed the suite on roughly 1 in 20 fuzz seeds. Widen the headroom computation to uint256. Pin the top of the index range with a deterministic regression test.
|
|
Changes to gas cost
🧾 Summary (20% most significant diffs)
Full diff report 👇
|
LCOV of commit
|
Member
Author
|
Closing since the issue was addressed in 10702a0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #56.
testFuzz_roundTripfails on roughly 1 in 20 fuzz seeds, so it will break CI intermittently on this branch and on anything stacked on it.Cause
The test reserves worst-case round-trip inflation headroom with:
_EXP_SCALED_ONEis auint56andindexis auint128, so Solidity evaluates that expression inuint128. For anyindexwithin1e12oftype(uint128).maxthe addition overflows, and the test reverts withPanic(0x11)before it ever reaches the assertion it is meant to make. The library itself is fine — this is purely a defect in the test's own arithmetic.Reproduce on
d21c0ef:Counterexample:
principal = 1,index = 2**128 - 4.Approach
Widen the computation to
uint256before the addition. I kept the+ index - 1ceiling-division form rather than boundingindexaway from its maximum: bounding would paper over the overflow and silently drop the top of the index range from coverage, which is exactly where the round-trip inflation bound is tightest and most worth pinning.The added
test_roundTrip_atMaxIndexcalls the fuzz body directly atindex == type(uint128).maxfor both the smallest and largest principal, so the regression is pinned deterministically instead of depending on a seed to rediscover it.Verification
forge test— 373 passed, 0 failed.FOUNDRY_FUZZ_RUNS=20000 forge test --match-path test/IndexingMath.t.sol— 27 passed, to confirm no other seed-dependent flake is hiding in the file.src/libs/IndexingMath.solcoverage stays at 100.00% lines / 100.00% branches / 100.00% funcs.forge fmt --checkdoes not flag this file. It does report pre-existing diffs acrosssrc/andscript/, untouched here.