Repository navigation
fix(dyn-abi): coerce JSON int values above i64::MAX for signed types - #1158
Merged
DaniPopes merged 1 commit intoJul 24, 2026
Merged
Conversation
eip712 coerce_json read signed integers only through serde_json's as_i64, while the sibling uint path uses as_u64. serde_json stores any integer in (i64::MAX, u64::MAX] as a u64, so a valid positive value for int72..int256 (e.g. 2^63 into int128) returned None and coerce_json failed, even though the same value is accepted as a JSON string and accepted by uint as a number. Add a u64 fallback mirroring uint, plus a regression test.
nikolauspschuetz
force-pushed
the
fix/eip712-coerce-int-u64-json
branch
from
July 24, 2026 04:57
cb5ad14 to
e7926dd
Compare
| if let Some(num) = value.as_i64() { | ||
| return Some(I256::try_from(num).unwrap()); | ||
| } | ||
| if let Some(num) = value.as_u64() { |
Contributor
Author
There was a problem hiding this comment.
Rationale: serde_json stores any integer in (i64::MAX, u64::MAX] as a u64, so as_i64() above returns None for it. Without this as_u64 fallback a valid positive value for int72..int256 (e.g. 2^63 as int128) falls through to the string branch and is rejected — even though the sibling uint() accepts the same JSON number. A u64 always fits positively in I256, so the try_from is infallible here.
DaniPopes
approved these changes
Jul 24, 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.
Motivation
eip712JSON coercion reads signed integers only throughserde_json'sas_i64, while the siblinguintpath usesas_u64.serde_jsonstores any integer literal in(i64::MAX, u64::MAX]as au64, so a valid positive value forint72..int256— e.g.2^63coerced toint128— never reaches the bounds check andcoerce_jsonfails with aTypeMismatch, even though:FromStrpath), anduintaccepts the same JSON number.So
int128accepts9223372036854775808as a string but rejects the identical JSON number.Solution
Add a
u64fallback inint()mirroringuint()— au64always fits positively inI256, soI256::try_from(num)cannot fail here. The bounds check (x.bits() <= n) is unchanged.Verification
New regression test
int_coerces_json_number_above_i64_maxasserts the number form coerces identically to the string form forInt(128). It fails onmain:and passes with the fix.
cargo test -p alloy-dyn-abi --features eip712 eip712::coerce→ 4 passed.PR Checklist