zkcrypto / bls12_381

Implementation of the BLS12-381 pairing-friendly elliptic curve group
Other
296 stars 178 forks source link

Expose the MODULUS const #39

Closed tuxxy closed 4 years ago

tuxxy commented 4 years ago

Hi, we're using this lib for something at @nucypher and it'd be nice to have the modulus of the Scalar exposed. It's presently private, and this PR makes it pub.

Thanks! :)

ebfull commented 4 years ago

The reason this is not exposed is because it's not an element of the field, so it breaks the contract of the Scalar type. We should expose the underlying [u64; 4] representation though; in fact, we'll do so as part of incorporating this library with the ff crate, which has a MODULUS associated constant in the Field trait.

tuxxy commented 4 years ago

Ah, that makes sense.

Sorta off topic for the PR, but remember hearing somewhere that y’all were working on making ff constant time, is this the case? If so, any idea when we might be able to see that?

ebfull commented 4 years ago

Yeah, in development are some changes to ff which intend to produce constant-time implementations of all the arithmetic. Currently that's happening in https://github.com/zcash/librustzcash while we do some refactorings.

If you change your PR to expose the [u64; 4] portion of the modulus instead, and replace MODULUS with Scalar(MODULUS) elsewhere in the file, that would be fine ~temporarily~ permanently, as the Field trait stuff will be a purely additive change to the API.