This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[web3.js] Replace sha256 and secp256k1 impls #27390
Merged
steveluscher
merged 2 commits into
solana-labs:master
from
steveluscher:replace-sha256-and-secp256k1-impl
Aug 25, 2022
Merged
[web3.js] Replace sha256 and secp256k1 impls #27390
steveluscher
merged 2 commits into
solana-labs:master
from
steveluscher:replace-sha256-and-secp256k1-impl
Aug 25, 2022
Conversation
This file contains 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
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thank you for the copious amounts of data backing up this change
jordaaash
approved these changes
Aug 25, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
5 tasks
This was referenced Oct 1, 2022
This was referenced Oct 13, 2024
This was referenced Oct 20, 2024
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.js
library arguably should not include theSecp256k1Program
utilities (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/sha2
with@noble/hashes/sha256
secp256k1
with@noble/secp256k1
Bundle 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/secp256k1
is incompatible with React Native because of a dependency onSubtleCrypto
, the particular codepaths that we use in theSecp256k1
program utils don't exercise any of those codepaths.Addresses solana-labs/solana-web3.js#1103.
Unintentionally fixes #26371.