Skip to content

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

Open
0xferrous wants to merge 2 commits into
foundry-rs:masterfrom
0xferrous:push-rtzzspzvvklr
Open

fix(cast): consistent serialization of Uint/Ints depending on actual type#14824
0xferrous wants to merge 2 commits 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

@zerosnacks zerosnacks left a comment

Copy link
Copy Markdown
Contributor

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
@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
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

This pull request is stale because it has been open for 14 days with no activity. It will be closed in 7 days if there is no further activity.

@github-actions github-actions Bot added the stale label Jun 3, 2026
…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.
@figtracer figtracer force-pushed the push-rtzzspzvvklr branch from 4bb7bcf to edc13fe Compare June 3, 2026 06:39
@figtracer figtracer removed the stale label Jun 3, 2026
@figtracer figtracer added the T-likely-breaking Type: requires changes that can be breaking label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-likely-breaking Type: requires changes that can be breaking

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants