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

Milagro Rust implementation seems very slow #2

Open
mratsim opened this issue Jun 5, 2020 · 1 comment
Open

Milagro Rust implementation seems very slow #2

mratsim opened this issue Jun 5, 2020 · 1 comment

Comments

@mratsim
Copy link

mratsim commented Jun 5, 2020

I run your benchmark on my machine and confirmed your result:

image

However, I wrapped Milagro C in Nim at https://github.com/status-im/nim-blscurve
and did preliminary benchmarks status-im/nim-blscurve#47 (comment)

image

Note that the scalar multiplication was done with 381-bit scalar instead of 255-bit as I forgot to take into account the curve order. so there is 50% more operations (Milagro is constant-time for scalar-mul)

Generation of 1000 signatures should take about 1s (HashToG2) + 280ms (scalar mul via 1/(2.4*1.50)) not 27s. This is about 27 slower than expected.

Signature verification should also be much faster despite Milagro not doing the subgroup checks as required by the hash-to-curve draft


Also the repo you are linking to is archived and its hash-to-curve is not the common hash-to-curve draft v7 that Algorand, Ethereum 2 and other blockchain are targeting. See https://github.com/apache/incubator-milagro-crypto-rust cc @kirk-baird who might have more recent benches.

If Milagro Rust is still much slower than C, I do have some idea on the reasons, the Rust code for example is returning huge objects like ECP on the stack while the C code never does that (https://github.com/apache/incubator-milagro-crypto-rust/blob/23d1fac6f/src/ecp.rs#L980) and I expect the compiler does not try to optimize those away via return-value-optimization or copy-elision.

@kirk-baird
Copy link

Let me know if you'd like some bench marks for apache milagro rust :)

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

No branches or pull requests

2 participants