pasta_curves
pasta_curves copied to clipboard
Reduce code duplication in field implementations
Currently this library has two field implementations, the Pallas field and the Vesta field. They only differ in their prime modulus, and are otherwise almost identically implemented. This makes the library harder to maintain, as every change needs to be duplicated.
There are several possible approaches we could take to improve the situation:
- Use a declarative macro.
- We already use a declarative macro for implementing the curves, so it would be in keeping with the rest of the library.
- This has been proposed and implemented here: https://github.com/zcash/pasta_curves/pull/44/commits/e150cc5670ba3559dd9a89609ffb41495ee560e3
- Use a procedural macro, i.e.
ff_derive
- This is how we originally implemented BLS12-381 in the
pairing
crate, but we replaced that with a direct implementation of the field in thebls12_381
crate, andff_derive
hasn't been as effectively maintained since. If we switched to it, the majority of our field maintenance effort could go intoff_derive
instead of here.
- This is how we originally implemented BLS12-381 in the
- Use
crypto-bigint
to implement the internal field details.- This would reduce the amount of code we need to maintain, which would just be the mapping from a big integer element to a prime field element.
- This would be quite a divergence from previous approaches. I also don't know how feature-complete
crypto-bigint
is, though progress is being made. - If this is a practical and performant approach, we could also combine it with either the declarative macro or
ff_derive
approach to make it easier to maintain as well.