This repository was archived by the owner on Jan 22, 2025. It is now read-only.
[web3.js] Replace sha256 and secp256k1 impls#27390
Merged
steveluscher merged 2 commits intosolana-labs:masterfrom Aug 25, 2022
steveluscher:replace-sha256-and-secp256k1-impl
Merged
[web3.js] Replace sha256 and secp256k1 impls#27390steveluscher merged 2 commits intosolana-labs:masterfrom steveluscher:replace-sha256-and-secp256k1-impl
steveluscher merged 2 commits intosolana-labs:masterfrom
steveluscher:replace-sha256-and-secp256k1-impl
Conversation
Codecov Report
@@ Coverage Diff @@
## master solana-labs/solana#27390 +/- ##
=========================================
- Coverage 76.9% 76.7% -0.2%
=========================================
Files 48 48
Lines 2505 2516 +11
Branches 355 359 +4
=========================================
+ Hits 1927 1931 +4
- Misses 448 456 +8
+ Partials 130 129 -1 |
jnwng
approved these changes
Aug 25, 2022
Contributor
jnwng
left a comment
There was a problem hiding this comment.
lgtm! thank you for the copious amounts of data backing up this change
5 tasks
This was referenced Oct 13, 2024
This was referenced Oct 20, 2024
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.
Problem
Notwithstanding the fact that the
web3.jslibrary arguably should not include theSecp256k1Programutilities (they should be their own package) the dependency tree that utility pulls in is massive. This PR aims to replace the signing and hashing algorithms therein with smaller ones having fewer dependencies.Summary of Changes
@ethersproject/sha2with@noble/hashes/sha256secp256k1with@noble/secp256k1Bundle size
Published the development build to npm and compared it to the latest version using bundlephobia.
Bundle size is reduced by ~39% after gzip.
Dependency tree
Using NPMGraph:
Number of modules depended upon was reduced by ~14% and number of maintainers in the transitive dependency chain by ~13%.
Performance
Consider the performance of generating public keys using a seed. Use this script:
Before
After
Public keys get generated in ~63% less time.
Consider the performance of generating secp256k1 program instructions. Use this script:
Before
After
No change in runtime.
Compatibility notes
@noble/secp256k1is incompatible with React Native because of a dependency onSubtleCrypto, the particular codepaths that we use in theSecp256k1program utils don't exercise any of those codepaths.Addresses solana-foundation/solana-web3.js#1103.
Unintentionally fixes #26371.