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

replace secp256k1 to libsecp256k1-rs #44

Closed
wants to merge 3 commits into from
Closed

Conversation

namuyan
Copy link

@namuyan namuyan commented Jul 2, 2019

#43
test passed by cargo test --features ec_secp256k1

type before after test code link
1 of 1 aggregate 112ms 3ms aggregate_1_of_1.py
n of n aggregate 458ms 7ms aggregate_n_of_n.py
t of n threshold 2475ms 68ms thresholdbig_t_of_n.py

performance improved!
please check my code, thank you.

test by `cargo test --features "curvesecp256k1 ecc"`
namuyan added a commit to namuyan/multi-party-schnorr that referenced this pull request Jul 2, 2019
@namuyan
Copy link
Author

namuyan commented Jul 3, 2019

Now I find two library libsecp256k1-rs and libsecp256k1, I use libsecp256k1-rs.
libsecp256k1-rs is fork of libsecp256k1, and have Copy trait and overwrite operators but is not main stream and no production code.
libsecp256k1 require wide modification and have influence to others, how do you think?

@omershlo
Copy link
Contributor

omershlo commented Jul 3, 2019

Hi @namuyan - looks like great work.
We started experimenting with this idea in another project: https://github.com/KZen-networks/emerald-city
there we took only the secp256k1 relevant parts of curv and replaced them with libsecp256k1 (the second lib, the native one).

@namuyan
Copy link
Author

namuyan commented Jul 3, 2019

Thank you for reply.
I now use curv for my project, but emerald-city looks more functional and pure-Rust implement (and compatibility with curv?).
I may use the latter, thank you.

@namuyan
Copy link
Author

namuyan commented Jul 4, 2019

I just change README.md?
UNLUCKY DICE, It looks a low repeatability bug.
https://github.com/KZen-networks/curv/blob/master/src/cryptographic_primitives/commitments/hash_commitment.rs#L78

@omershlo
Copy link
Contributor

omershlo commented Jul 4, 2019

you are right, we just need to run it again. The problem is that it is unknown for me how to do unit test for probabilistic code. We got stuck on this a while ago (#10).

Any suggestions will be welcome.

@vhnatyk
Copy link

vhnatyk commented Jul 7, 2019

Thank you for reply.
I now use curv for my project, but emerald-city looks more functional and pure-Rust implement (and compatibility with curv?).
I may use the latter, thank you.

rust-bitcoin/rust-secp256k1#125 (comment)

According to latest merged PR in original rust-secp256k1 - it now supports WASM that was only benefit of libsecp256k1. Performance benefit over rust-secp256k1 is supposedly due to later being constant time. Additionally rust-secp256k1 is a wrapper over original Bitcoin's secp256k1 that is most tested and commonly used library out there. So maybe it's a good idea to switch back to it in emerald-city as well.

@omershlo
Copy link
Contributor

omershlo commented Jul 7, 2019

@vhnatyk I agree. Let's switch back.
@elichai kudos

@elichai
Copy link
Contributor

elichai commented Jul 7, 2019

Glad to hear :)
Using good vetted crypto libraries is important.

@elichai
Copy link
Contributor

elichai commented Jul 23, 2019

FYI After this: rust-bitcoin/rust-secp256k1#132
There should be a ~15% performance improvement in verification time.

@elichai
Copy link
Contributor

elichai commented Jul 23, 2019

Oh.
I just realized why your performance is so bad.
you launched a new context for every operation: https://github.com/KZen-networks/emerald-city/pull/6/files#diff-cd37acb447aaca91b67e2e383e1b43afL391

Context creation in Secp256k1 is the most intensive part of the library.

You should use lazy_static! or std::syn::Once()(example: https://github.com/elichai/ecc-secp256k1/blob/master/src/secp256k1.rs#L480)
to create the context once and then use it everywhere.
(the context is thread safe as it doesn't mutate after creation)

@elichai
Copy link
Contributor

elichai commented Jul 23, 2019

Ok. let's put the benchmarking stats to bed once and for all:
I used this repo: https://github.com/namuyan/multi-party-schnorr on commit: namuyan/multi-party-schnorr@6c11c40

Before I changed anything I got consistently these stats:
1-of-1 = 142 mSec
n-of-n = 447 mSec
t of n threshold = 3048 mSec

After I changed the context to be created before the tests and then used it globally I got these stats:
1-of-1 = 1mSec
n-of-n = 1.5 mSec
t of n threshold = 42mSec

And this is with a lot of over head.
in secp256k1 sign/verify time are measured in uSec(micro). not mSec(mili).

@omershlo @namuyan.
If you want I can open a PR for lazy_static/sync::Once

And this is before the 15% faster verification using gmp

@omershlo
Copy link
Contributor

@elichai please!

@elichai
Copy link
Contributor

elichai commented Jul 23, 2019

Will do.
Do you prefer unsafe code or a new dependency? (in reality their doing almost the same thing)

@omershlo
Copy link
Contributor

unsafe

@namuyan
Copy link
Author

namuyan commented Jul 24, 2019

Thank you for quality up!

After I changed the context to be created before the tests and then used it globally I got these stats:
1-of-1 = 1mSec
n-of-n = 1.5 mSec
t of n threshold = 42mSec

Is this performance with emerald-city? or curv?

I replaced to https://github.com/elichai/emerald-city/tree/secp
patch: https://pastebin.com/pMvmPdB0
But I cannot measure performance, 1-of-1 and n-of-n show 0nS, t-of-n shows 32mS.

@elichai
Copy link
Contributor

elichai commented Jul 25, 2019

curv. and create a key before you measure performance so that the context will be available already (you shouldn't count the context creation as part of the performance test) (and change your performance tests to use nanoseconds)

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.

4 participants