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

Scalar::pow not ergonomic between two Scalars #11

Open
Wassasin opened this issue Aug 16, 2019 · 3 comments
Open

Scalar::pow not ergonomic between two Scalars #11

Wassasin opened this issue Aug 16, 2019 · 3 comments

Comments

@Wassasin
Copy link

Exponentiation between two scalars is currently difficult because exponentiation is implemented as fn pow(&self, by: &[u64; 4]) -> Self. Whilst Scalar::to_bytes converts to a little endian byte encoded integer, it is not directly usable for pow as it does not yield an array of [u64; 4].

Consider adding a variant of pow that directly accepts Scalars.

@Wassasin Wassasin changed the title Scalar::pow not ergonomic between two Scalars. Scalar::pow not ergonomic between two Scalars Aug 16, 2019
@ebfull
Copy link
Contributor

ebfull commented Nov 14, 2019

Perhaps instead we could implement From<Scalar> for [u64; 4].

@CPerezz
Copy link

CPerezz commented Apr 25, 2020

That implementation will apply the montg. reduction I assume no?
Since it will probably be the opposite of:

pub const fn from_raw(val: [u64; 4]) -> Self {
        (&Scalar(val)).mul(&R2)
    }

We could mabe call it as_raw or something similar to be clear in respect of the application of the montgomery reduction to the Scalar before returning the array.

What about implement pow taking a &Scalar and apply the montgomery reduction iside?

@str4d
Copy link
Member

str4d commented Apr 25, 2020

For the pow_vartime() API in the ff crate, I've generalised it to accept both &[u64] and &[u8]; once bls12_381 implements the ff traits, that can be used here.

It might still be useful for it to also accept same-typed field elements (or perhaps elements implementing a specific ScalarField trait), because the encoded representation of a scalar is not guaranteed to be the endianness that pow requires. For the same reason that we aren't specifying the endianness of PrimeField::Repr, I'm dubious that we want From<Scalar> for [u64; 4] in generic code; instead we'd either want a specific endianness-tagged method, or enable field elements to be exponentiated by themselves (which keeps the endianness an implementation detail). The main decision then is about what the ergonomics should be - it does not make sense for elements of arbitrary fields to be exponentiated by each other, but it does make sense for fields specifically used to represent scalars.

0xWOLAND pushed a commit to 0xWOLAND/bls12_381 that referenced this issue Aug 13, 2024
…kcrypto#11)

* wip: Remove unnecessary copies in miller loop

* finish zkvm version of addition_step (zkcrypto#10)

* remove even more copies in Fp::sum_of_products

* fix: Remove debug cycle-tracking prints

---------

Co-authored-by: Arthur Paulino <[email protected]>
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

4 participants