Skip to content

fix(cast): consistent serialization of Uint/Ints depending on actual type#14824

Open
0xferrous wants to merge 1 commit into
foundry-rs:masterfrom
0xferrous:push-rtzzspzvvklr
Open

fix(cast): consistent serialization of Uint/Ints depending on actual type#14824
0xferrous wants to merge 1 commit into
foundry-rs:masterfrom
0xferrous:push-rtzzspzvvklr

Conversation

@0xferrous
Copy link
Copy Markdown
Contributor

Motivation

The current implementation dynamically tries to determine if the runtime value can fit in 64 bits, but this leads to inconsistent serialization. For instance if you were decoding an uint[], some of the values that fit in 64 bits will serialize as number while others serialize as string making it require special handling on the user that is consuming the json.

Solution

Use the type information to determine the serialization. So the user will always know that specific types will always serialize to a number or a string depending on the number of bits that type uses.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Copy Markdown
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @0xferrous, thanks for the PR! Apologies the other one went stale.

Some notes, overall lgtm 👍

Comment thread crates/common/fmt/Cargo.toml Outdated
Comment thread crates/common/fmt/src/dynamic.rs
Comment thread crates/common/fmt/src/dynamic.rs
…type

The current implementation dynamically tries to determine if the runtime
value can fit in 64 bits, but this leads to inconsistent serialization.
For instance if you were decoding an `uint[]`, some of the values that
fit in 64 bits will serialize as number while others serialize as string
making it require special handling on the user that is consuming the
json. This change makes it so it uses the type information to determine
the serialization. So the user will always know that specific types
will always serialize to a number or a string depending on the number
of bits that type uses.
@0xferrous 0xferrous force-pushed the push-rtzzspzvvklr branch from 84c1f3d to 4bb7bcf Compare May 19, 2026 11:56
@0xferrous 0xferrous requested a review from zerosnacks May 19, 2026 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants