feat: replace BN with native BigInt#18473
Merged
sethkfman merged 8 commits intoOct 8, 2025
Merged
Conversation
Contributor
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
8042d5e to
d6ddc81
Compare
georgewrmarshall
previously approved these changes
Sep 16, 2025
Contributor
georgewrmarshall
left a comment
There was a problem hiding this comment.
Approving changes to component-library components on behalf of @MetaMask/design-system-engineers ✅
1909901
d6ddc81 to
1909901
Compare
owencraston
approved these changes
Sep 17, 2025
1909901 to
f9738d5
Compare
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
27c55f8 to
6ea5e81
Compare
owencraston
approved these changes
Oct 6, 2025
64d2a07
into
MetaMask:feat/replace-bn-with-bigint-margelo
111 of 126 checks passed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
This draft of migration from BN.js to native
BigInt. It needs MetaMask/utils#255 to be merged and released first.Native BigInt is much much faster than JS only BN implementation. This could improve app performance in many places like account list, login, dashboard etc. I already measured
useAccountshook and it made it 7x faster220ms => 30ms.Proposal for handling migration:
I moved cloned previous file
index.jstolegacy.jsand updated imports everywhere to use this old implementation. Then I migrated whole oldindex.jsto TS and to useBigInt. I also marked all legacy functions as deprecated so they could be spotted more easily during future refactoring and replaced with new implementation.I think this approach is best in current situation because:
any.TODOs:
toHexadecimaland while migrating it to new implementation with bigint I noticed that i receives params likesolana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp. In old implementation it causestoHexadecimal returnNaNand in my new implementation it throws error. I guess this might be causing bug even in current implementation like total balance not being correct if there is more than one Solana account or something like that.Changelog
CHANGELOG entry:
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduce BigInt-backed number utilities while re-pointing existing code to legacy implementations, updating balance/fee logic and tests accordingly.
util/number/index.tswith BigInt-based conversions/formatting (hexToBigInt,bigIntToHex,toWei,fromWei, fiat/token helpers, etc.).util/number/legacy.js(marked deprecated) and add comprehensivelegacy.test.ts.BigInt.util/numberwithutil/number/legacyacross app (Swaps, Ramp, Earn, Stake, Bridge, Transactions, selectors, hooks, components, tests).Hexcast, tweak chainId handling for images/selectors).hexToBigInt,bigIntmath) and avoid string BN math; fix chainId map lookups (use rawchainId).0xprefix.Written by Cursor Bugbot for commit 6ea5e81. This will update automatically on new commits. Configure here.