Skip to content

fix(test-specs): use integer division for genesis base fee#3189

Open
cuiweixie wants to merge 1 commit into
ethereum:forks/amsterdamfrom
cuiweixie:fix/state-test-base-fee-integer-division
Open

fix(test-specs): use integer division for genesis base fee#3189
cuiweixie wants to merge 1 commit into
ethereum:forks/amsterdamfrom
cuiweixie:fix/state-test-base-fee-integer-division

Conversation

@cuiweixie

Copy link
Copy Markdown

Description

When deriving the genesis base_fee_per_gas from a state test's block#1 env (* 8 / 7), the previous code used float division (/float), then cast back with int(...).

IEEE-754 float64 only has a 53-bit mantissa, so integers larger than 2^53 are not represented exactly. For large base_fee_per_gas values this can silently round before the integer conversion, producing an incorrect genesis base fee.

This change switches to pure integer arithmetic (* 8 // 7) so the scaling stays exact for arbitrary-size integers.

Related Issues or PRs

N/A.

Checklist

  • Ran fast static checks to avoid CI fails, see Code Standards & Verifying Changes: just static
  • PR title has the form <type>(<area>): <title>, where <type> and <area> come from an appropriate C-<type>, respectively A-<area>, label. The title should match the target squash commit message.

Cute Animal Picture

integer beaver

Avoid float64 (53-bit mantissa) precision loss when scaling
base_fee_per_gas by 8/7 for values beyond 2^53.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant