Repository navigation
fix(explorers): return ParseOverflow instead of wrapping or panicking in parse_units - #283
Merged
Merged
Conversation
ninglinLiu
requested review from
0xrusowsky,
DaniPopes,
figtracer,
grandizzy,
mablr,
mattsse,
onbjerg and
stevencartavia
as code owners
October 26, 2026 21:05
mablr
approved these changes
Oct 27, 2026
mablr
enabled auto-merge (squash)
October 27, 2026 10:38
stevencartavia
approved these changes
Oct 27, 2026
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.
parse_unitsscales the parsed amount by10^(units - decimals), but the final multiplication was unchecked:U256 *=wraps silently.parse_units("115792089237316195423570985008687907853269984665640564039458", "ether")(one more thanU256::MAX / 1e18) returnedOk(U256(415992086870360064)), which is about 0.4 ether instead of an error;I256 *=panics withoverflowfor the same amount with a leading-.Both branches now use
checked_muland return the existingConversionError::ParseOverflow, which the function already returns when10^exponentitself overflows. Amounts that fit are unchanged. I also dropped the unused_filocal in the negative branch.Tests. Added
parse_units_rejects_overflow. It checks that the overflowing amount is rejected on both the positive and negative paths, and that1.5ether and the largest whole-ether amounts still parse.cargo test -p foundry-block-explorers --libpasses (31 tests), andcargo +nightly fmtandcargo clippy -p foundry-block-explorers --all-targetsare clean.This change was prepared with the help of an AI coding assistant.