Skip to content

feat: add combinePubkeys and privkeyAddTweak - #5

Open
angel-manuel wants to merge 2 commits into
sc0Vu:masterfrom
angel-manuel:feat-new-methods
Open

feat: add combinePubkeys and privkeyAddTweak#5
angel-manuel wants to merge 2 commits into
sc0Vu:masterfrom
angel-manuel:feat-new-methods

Conversation

@angel-manuel

Copy link
Copy Markdown
  • 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
Copy Markdown
Author
  • Added *MulTweak, PrivkeyNegate, PubkeyParse methods
  • Create memory scratchpads to avoid malloc+free on each call. Benchmark shows it is faster

Comment thread benchmarks/index.js

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants