arkworks-rs / algebra

Libraries for finite field, elliptic curve, and polynomial arithmetic
https://arkworks.rs
Apache License 2.0
608 stars 240 forks source link

Implement faster square-roots for prime fields that have high two-adicity #40

Open Pratyush opened 3 years ago

Pratyush commented 3 years ago

See https://eprint.iacr.org/2020/1407

Pratyush commented 3 years ago

cc @kobigurk

ValarDragon commented 3 years ago

One question before implementing this is how should we be handling precomputation results for Square root algorithms. Different square root algorithms will need different precomputations

Pratyush commented 3 years ago

Does this new algorithm need precomputation? For the time being we can keep it simple, because the existing square-root algorithm doesn't require precomputation

ValarDragon commented 3 years ago

The table methods with better efficiency do. The minimal-precomputation one in that paper precomputes log(n) powers of g, which is fine to just compute on the fly as a first impl

ValarDragon commented 3 years ago

@daira has a really helpful sage prototype for this square root algorithm (with the table optimizations) for the pasta curves!

This will probably be a very helpful reference when going to implement it here

daira commented 3 years ago

The table-based variant does need precomputation, yes.

daira commented 3 years ago

The current square root implementation (https://github.com/arkworks-rs/algebra/blob/master/ff/src/fields/arithmetic.rs#L225-L280) could be improved in two ways that are orthogonal to the improvements in the new algorithm: