Skip to content

[Bug] AnyHeader fails to deserialize baseFeePerGas values exceeding u64::MAX #3741

Closed

Description

@incrypto32

Component

consensus, eips, genesis

What version of Alloy are you on?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

AnyHeader::base_fee_per_gas is typed as Option<u64>, which causes deserialization failures on chains where baseFeePerGas exceeds u64::MAX.

We encountered this on a live EVM-compatible chain (Stable, chain ID 988) that returns baseFeePerGas: "0x3635c9adc5dea00000" (10^21) for a range of historical blocks. Deserializing the RPC response fails with:

invalid type: integer `1000000000000000000000`, expected u64

Spec vs implementation

The Ethereum execution spec defines base_fee_per_gas as Uint (arbitrary-precision), while explicitly choosing U64 for blob_gas_used and excess_blob_gas. This distinction appears intentional.

In alloy, AnyHeader uses Option<u64> for base_fee_per_gas, and the BlockHeader trait constrains the return type to Option<u64>.

Suggestion

Change AnyHeader::base_fee_per_gas from Option<u64> to Option<U256> (or Option<u128>). This would be consistent with AnyHeader's documented purpose of accounting for "possible differences in network implementations". Ideally the BlockHeader trait method would also be widened, but even just changing AnyHeader would eliminate the deserialization failure.

The same consideration may apply to gas_limit and gas_used, which the spec also defines as Uint.

Activity

  1. added
    bug
    on Feb 25, 2026
  2. mattsse commented on Feb 25, 2026

    @mattsse
    Member

    yeah maybe they shouldnt use a value > u64::max for a field that is supposed to be u64

  3. incrypto32 commented on Feb 25, 2026

    @incrypto32
    ContributorAuthor

    Whether the value is "reasonable" isn't really the point; the spec says Uint and AnyHeader exists for non-standard chains. I'd expect AnyHeader to follow the spec here is there a reason for not doing so?

  4. mattsse commented on Feb 25, 2026

    @mattsse
    Member

    the "spec" says a lot of things

    I'd expect chains not do to hacks like this.

    I assume this was done to prevent any txs to land in earlier blocks.

    would simply saturating this on deserde be an option? this could also lead to some issues but I'm hesitant to change the types here

  5. incrypto32 commented on Feb 25, 2026

    @incrypto32
    ContributorAuthor

    Saturating on deser would fix the deserialization failure, which is the main blocker. For our use case we'd still need the full value because expose baseFeePerGas to subgraph wasm mappings as BigInt, and it needs to be determinisitc across versions. The previous web3 crate used U256, so we'd need to preserve that to avoid a determinism break. I guess we'll need to use a custom header type on our end for this to keep supporting the chain. But saturating in AnyHeader would at least unblock other consumers hitting this.

  6. gastonmichel commented on May 5, 2026

    @gastonmichel

    Hello folks!
    big fan of the project! appreciate every bit of it.

    This issue hit us on the face after stable bumped the baseFeePerGas to 1000000000000000000000.

    Is there a plan to change this baseFeePerGas from u64 to u128 at least?

  7. satyakwok commented on May 11, 2026

    @satyakwok
    Contributor

    Taking this with the saturating-on-deser direction.

    Plan: custom deserialize_with on AnyHeader::base_fee_per_gas that accepts any numeric input and saturates to u64::MAX when the value exceeds u64. Wraps alloy_serde::quantity so hex strings and plain numbers both work, with overflow handled instead of erroring. Unit tests covering: in-range hex, in-range decimal, u64::MAX, exactly u64::MAX + 1, the chain-988 case (0x3635c9adc5dea00000 = 1e21), and null/absent (preserves None).

    → PR opened: #

  8. moved this from Todo to Done in Alloyon May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions