Skip to content

fix(stdlib): prevent precision loss in GasFees.mul() for large bigint values#21544

Open
Maddiaa0 wants to merge 1 commit intonextfrom
fix/137-gas-fees-mul-precision
Open

fix(stdlib): prevent precision loss in GasFees.mul() for large bigint values#21544
Maddiaa0 wants to merge 1 commit intonextfrom
fix/137-gas-fees-mul-precision

Conversation

@Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Mar 13, 2026

part of #21514

Summary

Previously truncated this to number which is risky for lossyness, this pr implements mulDiv with 18 decimal base - same as solidity bigint math

Callers

All production callers pass small fractional scalars (1.0–2.0 range):

  • wallet.mul(1 + this.minFeePadding) where padding defaults to 0.5
  • fees.mul(1.5) in e2e tests
  • gas.mul(1 + pad) in gas limit estimation

… values

The old code converted bigint fees to Number before multiplying by a
fractional scalar, losing precision for values above 2^53. Use scaled
bigint arithmetic (mulDiv with ceiling) at 18 decimal precision instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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