From 86e3d221059a4e70ef5942d3fffd39547d2072e6 Mon Sep 17 00:00:00 2001 From: Goktug Poyraz Date: Thu, 14 May 2026 11:38:32 +0200 Subject: [PATCH 1/3] fix(transaction-pay-controller): convert exchange rate numbers to strings before passing to BigNumber BigNumber throws when a JS number has more than 15 significant digits. In getTokenFiatRate, three number values from external sources are passed to BigNumber constructor and .multipliedBy(): - tokenToNativeRate (from marketData) -> new BigNumber() - nativeToUsdRate (from CurrencyRateController) -> .multipliedBy() - nativeToFiatRate (from CurrencyRateController) -> .multipliedBy() All three can exceed 15 significant digits, especially for weak-currency locales where conversion rates are large numbers like 40115252.21304121 (16 significant digits). Wrapping in String() avoids the crash since BigNumber's string inputs have no precision limit. --- packages/transaction-pay-controller/src/utils/token.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/transaction-pay-controller/src/utils/token.ts b/packages/transaction-pay-controller/src/utils/token.ts index 493b268e1a..4534a048c9 100644 --- a/packages/transaction-pay-controller/src/utils/token.ts +++ b/packages/transaction-pay-controller/src/utils/token.ts @@ -212,12 +212,12 @@ export function getTokenFiatRate( const usdRate = isStablecoin ? '1' - : new BigNumber(tokenToNativeRate ?? 1) - .multipliedBy(nativeToUsdRate) + : new BigNumber(String(tokenToNativeRate ?? 1)) + .multipliedBy(String(nativeToUsdRate)) .toString(10); - const fiatRate = new BigNumber(tokenToNativeRate ?? 1) - .multipliedBy(nativeToFiatRate) + const fiatRate = new BigNumber(String(tokenToNativeRate ?? 1)) + .multipliedBy(String(nativeToFiatRate)) .toString(10); return { usdRate, fiatRate }; From 1a46e42d335268c63838e5bac5aed9d27eb06857 Mon Sep 17 00:00:00 2001 From: Goktug Poyraz Date: Thu, 14 May 2026 11:49:01 +0200 Subject: [PATCH 2/3] docs: add changelog entry for BigNumber fix --- packages/transaction-pay-controller/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index 5495abc37f..e1fb58a522 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add Polymarket deposit-wallet support to the Relay strategy for `predictWithdraw` transactions, routed via the `isPolymarketDepositWallet` flag on `TransactionConfig` ([#8754](https://github.com/MetaMask/core/pull/8754)) +### Fixed + +- Fix BigNumber crash when exchange rate numbers exceed 15 significant digits ([#8808](https://github.com/MetaMask/core/pull/8808)) + ## [22.4.0] ### Added From 33f442d17c711aa7f72b54901a785e09413b8e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20G=C3=B6ktu=C4=9F=20Poyraz?= Date: Fri, 15 May 2026 14:48:47 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- packages/transaction-pay-controller/CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/transaction-pay-controller/CHANGELOG.md b/packages/transaction-pay-controller/CHANGELOG.md index ae6104b1a4..c8e15ac9fc 100644 --- a/packages/transaction-pay-controller/CHANGELOG.md +++ b/packages/transaction-pay-controller/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix BigNumber crash when exchange rate numbers exceed 15 significant digits ([#8808](https://github.com/MetaMask/core/pull/8808)) + ## [22.5.0] ### Added @@ -18,10 +22,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Move the Relay gasless execution feature flag to `confirmations_pay_extended.payStrategies.relay.gaslessEnabled` ([#8810](https://github.com/MetaMask/core/pull/8810)) -### Fixed - -- Fix BigNumber crash when exchange rate numbers exceed 15 significant digits ([#8808](https://github.com/MetaMask/core/pull/8808)) - ## [22.4.0] ### Added