Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(crypto): native bip38 #1941

Merged
merged 12 commits into from
Jan 4, 2019
Merged

perf(crypto): native bip38 #1941

merged 12 commits into from
Jan 4, 2019

Conversation

spkjp
Copy link
Contributor

@spkjp spkjp commented Jan 3, 2019

Proposed changes

The used bip38 library is abysmal slow.

For example take a look at the Delegate tests which invoke bip38 code:

Test Suites: 1 passed, 1 total
Tests:       14 passed, 14 total
Snapshots:   0 total
Time:        46.666s
Ran all test suites matching /__tests__\/models\/delegate.test.ts/i.

Even though they don't do anything demanding, they alone usually take 60-90 seconds to complete
when run by CI.

Looking over the bip38 code and open GH issues, it becomes apparent that it is mainly due to the used scryptsy library:

bitcoinjs/bip38#40
cryptocoinjs/scryptsy#8

So I decided to fork the bip38 code and made the following changes:

  • use Node's own version of scrypt instead of scryptsy
  • drop the used JavaScript ECC and use equivalent functions from the secp256k1 library

With my changes the same tests from above:

Test Suites: 1 passed, 1 total
Tests:       14 passed, 14 total
Snapshots:   0 total
Time:        2.983s, estimated 5s
Ran all test suites matching /__tests__\/models\/delegate.test.ts/i.

On my machine that is more than ~15x faster.

@arkecosystem/crypto now ships the modified bip38 version and core-forger and core-json-rpc were updated accordingly. It maybe makes sense to publish it as a standalone package so other people can use it as well, but since it uses some of our own crypto, I didn't bother. 🤷‍♂️

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build (changes that affect the build system)
  • Docs (documentation only changes)
  • Test (adding missing tests or fixing existing tests)
  • Other... Please describe:

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

@spkjp spkjp requested a review from faustbrian January 3, 2019 23:38
@codecov-io
Copy link

codecov-io commented Jan 3, 2019

Codecov Report

Merging #1941 into develop will increase coverage by 0.88%.
The diff coverage is 95.12%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1941      +/-   ##
===========================================
+ Coverage    40.41%   41.29%   +0.88%     
===========================================
  Files          350      351       +1     
  Lines         7624     7742     +118     
  Branches      1143     1125      -18     
===========================================
+ Hits          3081     3197     +116     
- Misses        4528     4532       +4     
+ Partials        15       13       -2
Impacted Files Coverage Δ
...son-rpc/src/server/methods/wallets/bip38/create.ts 0% <0%> (ø) ⬆️
...ages/core-json-rpc/src/server/utils/decrypt-wif.ts 0% <0%> (ø) ⬆️
packages/crypto/src/models/delegate.ts 78.26% <100%> (ø) ⬆️
packages/crypto/src/crypto/bip38.ts 96.66% <96.66%> (ø)
packages/core-logger-winston/src/formatter.ts 38.88% <0%> (ø) ⬆️
packages/core-test-utils/src/generators/wallets.ts 14.28% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d240d9...2ad8c65. Read the comment docs.

@faustbrian faustbrian merged commit 02467f3 into ArkEcosystem:develop Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants