fix(audit/M03): revert with FixedDecimalOverflow on toFixedDecimalLossy uint256 overflow#203
Conversation
toFixedDecimalLossy used to scale up via checked-math `unsignedCoefficient * scale`, panicking with the bare 0x11 selector when either `10 ** finalExponent` or `coefficient * scale` overflowed uint256. Two complaints: the panic carries no structured info about which inputs caused it, and silent (0, false) decapitates the high bits of a real value that callers may need to rescale. Adds `FixedDecimalOverflow(signedCoefficient, exponent, decimals)` and two pre-checks in the positive-exponent branch (finalExponent > 77, then unsignedCoefficient > uint256.max / scale), wrapping the now-safe multiplication in `unchecked` since both overflow paths are guarded. Regression tests: - testToFixedDecimalLossyPositiveExponentScaleOverflow pins the scale guard (finalExponent = 78). - testToFixedDecimalLossyPositiveExponentMulOverflow pins the mul guard (int224.max coefficient with finalExponent = 50). Each guard mutation-tested independently — removing one trips its corresponding test only. Updates the existing testToFixedDecimalLossyScaleUpOverflow fuzz to expect FixedDecimalOverflow instead of stdError.arithmeticError. Rust crate's DecimalFloatErrorSelector enum and FixedBytes<4> dispatch gain a FixedDecimalOverflow variant so callers can match on it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reflects the new bytecode after the #192 fix: - ZOLTU_DEPLOYED_DECIMAL_FLOAT_ADDRESS: 588F... -> Bee0... - DECIMAL_FLOAT_CONTRACT_HASH: 0xa44a... -> 0x7a93... Deploy broadcast on this branch via manual-sol-artifacts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment: S/M/L PR Classification Guidelines:This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed. Small (S)Characteristics:
Review Effort: Would have taken 5-10 minutes Examples:
Medium (M)Characteristics:
Review Effort: Would have taken 15-30 minutes Examples:
Large (L)Characteristics:
Review Effort: Would have taken 45+ minutes Examples:
Additional Factors to ConsiderWhen deciding between sizes, also consider:
Notes:
|
Closes #192.
Summary
toFixedDecimalLossyused to scale up via checked-mathunsignedCoefficient * scale, panicking with the bare0x11selector when either10 ** finalExponentorcoefficient * scaleoverflowed uint256.Both complaints: the panic carries no structured info about which inputs caused it, and returning silent
(0, false)would decapitate the high bits of a real value that callers may need to rescale.Adds
FixedDecimalOverflow(signedCoefficient, exponent, decimals)and two pre-checks in the positive-exponent branch:finalExponent > 77—10 ** finalExponentwould itself overflow uint256.unsignedCoefficient > uint256.max / scale— the multiplication would overflow.The now-safe multiplication is wrapped in
uncheckedsince both overflow paths are guarded.Regression tests
testToFixedDecimalLossyPositiveExponentScaleOverflow—finalExponent = 78.testToFixedDecimalLossyPositiveExponentMulOverflow—int224.maxcoefficient atfinalExponent = 50.Each guard mutation-tested independently — removing one trips its corresponding test only.
Updates the existing
testToFixedDecimalLossyScaleUpOverflowfuzz to expectFixedDecimalOverflowinstead ofstdError.arithmeticError.Rust crate's
DecimalFloatErrorSelectorenum andFixedBytes<4>dispatch gain aFixedDecimalOverflowvariant.Deploy
Manual deploy workflow triggered on this branch; constants will be bumped once the run lands and
testDeployAddress/testExpectedCodeHashDecimalFloatregenerate.🤖 Generated with Claude Code