ZenGo-X / curv

Rust language general purpose elliptic curve cryptography.
MIT License
265 stars 111 forks source link

suggested additions to Polynomial #142

Open omershlo opened 3 years ago

omershlo commented 3 years ago

I am working with Polynomial. As part of my work I am required to manipulate them in certain ways. Here are a few suggestions for new functions to add to Polynomial (If I will have more ideas as I continue working I will add them here):

survived commented 3 years ago

Great suggestions, @omershlo!

1) Polynomial multiplication could be easily added. I assume FFT is not difficult to implement. 2) What if I expose this method:

   impl<E> Polynomial<E> { 
       pub fn coefficients_mut(&mut self) -> &mut [Scalar<E>] { ... }
   }

Would this allow to achieve what you want? Basically, you can sample a random polynomial Polynomial::sample_exact(), and then you can overwrite its coefficients, eg. : polynomial.coefficients_mut()[3] = Scalar::from(4) 3) That's a reasonable suggestion. To allow construction from bigints, I would change from_coefficients constructor to be:

   impl<E> Polynomial<E> { 
       pub fn from_coefficients<S>(coefficients: impl IntoIterator<Item = S>) -> Self
       where Scalar<E>: From<S>
       { ... }
   }

So this method will work with both Vec<Scalar<E>> and Vec<Bigint>. But this changes public API and requires major version bump. For now, it may be sufficient to add constructor from_bigint_coefficients that takes Vec<Bigint>.

omershlo commented 3 years ago

more: