fix(runtime): read getBalance BigInt-safely — TronWeb's JSON.parse quantizes balances > 2ˆ53 - #32
Merged
Merged
Conversation
…antizes balances > 2^53
km631
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stubProvider.getBalancereturned balances via TronWeb'strx.getBalance, which parses the account JSON with a lossyJSON.parse. Any balance above 2^53 is quantized to the nearest IEEE-754 double — at a ~5e18 balance (a pre-funded signer) the ULP is 2^(62-52) = 1024 sun. So balance deltas smaller than ~1024 sun read as 0, even though the on-chain transfer happened.This surfaced as OpenZeppelin's
ERC2771Forwarder.executeBatchrefunding a tiny value (10 sun) to a fundedrefundReceiver: the refund landed on-chain, butgetBalance(refundReceiver)reported no change, so the test'sbalance == initial + refundassertion failed and the value looked "lost."A value-magnitude sweep of the same refund confirms it's pure read-precision, not a transfer problem:
(1e12/1e15/1e18 are multiples of 1024, so they round-trip exactly; smaller, non-aligned values are rounded to the double ULP.)
Fix
Read
balanceout of the raw/wallet/getaccountresponse text (BigInt-exact) instead of going through TronWeb's lossy parser — the same>2^53hazardwait.js'sjsonParseBigSafealready avoids for transaction receipts.Verification
Files
src/runtime/ethers-bridge.js—getBalancereads/wallet/getaccountBigInt-safely.