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

feat: add combinePubkeys and privkeyAddTweak #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

angel-manuel
Copy link

  • Updates libsecp256k1 up to the hash used currently on bitcoind
  • Make build.sh executable and add #!/bin/bash. Otherwise it would fail on /bin/sh
  • Expose two new methods on wasm compile
  • Wrap both methods: combinePubkeys and privkeyAddTweak
  • Basic test on node and browser

@angel-manuel angel-manuel force-pushed the feat-new-methods branch 2 times, most recently from 003176e to e72635f Compare April 3, 2021 08:58
feat: add privkeyMulTweak

feat: new methods
@angel-manuel
Copy link
Author

  • Added *MulTweak, PrivkeyNegate, PubkeyParse methods
  • Create memory scratchpads to avoid malloc+free on each call. Benchmark shows it is faster

@@ -46,6 +46,7 @@ secp256k1Async().then(function (secp256k1Wasm) {

new benchmark.Suite('Verify')
.add('Secp256k1 WASM (current)', () => secp256k1Wasm.verify(msg, sig.signature, pubkey))
.add('Secp256k1 0.2.1 WASM (current)', () => secp256k121Wasm.verify(msg, sig.signature, pubkey))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any changes that add another benchmark of verify?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it's for memory scratch.

And I have these questions:

  • Should we wipe the scratch buffer before calling copyToBuffer (or in copyToBuffer)?
  • Should we free these memory when the object destroy?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the idea from libauth https://github.com/bitauth/libauth/blob/13454f1f6b3d9e87b6361cc71f082950fe6abf3a/src/lib/crypto/secp256k1.ts#L56-L64

I think wiping the memory is not necessary before calling copyToBuffer, overwriting is fine.
Private key buffers could be wiped out after used just-in-case

WebAssembly mostly reserves a big chunk of memory on the instantiate() call. GC should free the whole chunk when possible, no matter how much malloc is used inside WASM

Sorry for not being that active responding

@angel-manuel
Copy link
Author

Also, I didn't get around benchmarking some of the new methods

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.

None yet

2 participants