-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix(common): manually handle DynSolValue
json serialization
#11396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
2 tasks
DaniPopes
reviewed
Aug 25, 2025
mattsse
previously approved these changes
Aug 25, 2025
DaniPopes
approved these changes
Aug 25, 2025
Thanks for doing it @0xrusowsky. In which release will it be included? |
this will be 1.4, we can consider adding it to a 1.3.3 bug fix release if we need to |
MerkleBoy
pushed a commit
to MerkleBoy/foundry
that referenced
this pull request
Sep 17, 2025
…y-rs#11396) Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com>
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.
cheatcodes
): eitherserializeJsonType
oreip712HashTypedData
fails when dealing with largeuint128
values #11366Motivation
the reported bug was originated by the fact that alloy's
DynSolType
coercion ofserde_json::Value
intoU256
andI256
, only supports those values which can be expressed as:.as_u64()
/.as_i64()
for numbers within 64-bit range.as_str()
for string representationssee impl here: https://github.com/alloy-rs/core/blob/main/crates/dyn-abi/src/eip712/coerce.rs#L59-L77
however, since
fn serialize_value_as_json()
delegates json serialization to serde, large numbers (> u64::MAX) were being serialized.as_float()
. This means that they would returnNone
in the different coercion attempts of the fns described above, and end up throwing an error.Solution
modified JSON serialization to preserve precision for large numbers:
fn serialize_value_as_json()
: rather than delegating json serialization to serde, check if numbers fit in i64/u64:serde_json::Number
fn json_value_to_token()
: needed to be adjusted to not break thefn test_json_roundtrip_guessed
test. I tried keeping the functionality as close as possible to the original, by only parsing strings asI256
/U256
when they exceedi64
/u64
capacityfn parse_json_as()
: Support string-to-number coercion for uint/int typesDespite i believe that the applied changes are correct + i tried to minimize the impact of the changes + the fact that they don't strictly break functionality, they alter the behavior and could impact some users.
PR Checklist