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

Implement CurveExt for G1Projective #4

Merged
merged 20 commits into from
Oct 26, 2023
Merged

Implement CurveExt for G1Projective #4

merged 20 commits into from
Oct 26, 2023

Conversation

CPerezz
Copy link
Member

@CPerezz CPerezz commented Sep 11, 2023

This monstrosity which makes almost no-sense (Bls12-381 depending on pasta-curves) is the workaround that unblocks Bls12-381 usage in halo2curves.

For more context on the unblock, see: zkcrypto/group#48 && privacy-scaling-explorations/halo2curves#75

Left to do for the future:

  • hash_to_curve impl within CurveExt impl.

@CPerezz
Copy link
Member Author

CPerezz commented Sep 14, 2023

This needs a big cleanup and set a lot of features correctly.
But it at least compiles. Which allows me if the integration with halo2curves is feasible or not.

@CPerezz
Copy link
Member Author

CPerezz commented Sep 14, 2023

So we're on a weird situation here where we do have all of the tests passing for all the features. But the endomorphism seems to not work although the params have been derived twice ending in the same result.

On the way the lib is constructed, the compiler is unable to figure out
that the impl of `Add` and `Mul` that needs to be used (as is the
`const` one is the one done in the module.

Hence why the `&` are used in many places to perform operations.
This means, we need to exclude the clippy checks.
@CPerezz CPerezz marked this pull request as ready for review September 27, 2023 08:04
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some constants of Fp need to be updated since it doesn't have from_raw to use, I've generated locally and add some comments.

Also perhaps we could add a test for these constans below like:

#[test]
fn constants() {
    assert_eq!(Fp::ONE.double(), GENERATOR);
    assert_eq!(Fp::ONE, Fp::ONE.double() * TWO_INV);
    assert_eq!(Fp::ONE, ROOT_OF_UNITY.pow([1 << Fp::S]));
    assert_eq!(Fp::ONE, ROOT_OF_UNITY * ROOT_OF_UNITY_INV);
    // sage: modulus = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
    // sage: hex((modulus - 1) >> 1)
    // '0xd0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd555'
    let t = [
        0xdcff7fffffffd555,
        0x0f55ffff58a9ffff,
        0xb39869507b587b12,
        0xb23ba5c279c2895f,
        0x258dd3db21a5d66b,
        0xd0088f51cbff34d,
    ];
    assert_eq!(Fp::ONE, DELTA.pow(t));
    assert_eq!(Fp::ONE, ZETA.pow([3]));
}

src/g1.rs Outdated Show resolved Hide resolved
src/g1.rs Outdated Show resolved Hide resolved
src/g1.rs Outdated Show resolved Hide resolved
src/scalar.rs Outdated Show resolved Hide resolved
src/fp.rs Outdated Show resolved Hide resolved
src/fp.rs Outdated Show resolved Hide resolved
src/fp.rs Outdated Show resolved Hide resolved
src/fp.rs Outdated Show resolved Hide resolved
src/fp.rs Outdated Show resolved Hide resolved
src/fp.rs Show resolved Hide resolved
These mostly consist on moving all the `Fp` constants into the `Montgomery form` since `Scalar::from_raw` is missing.

Co-authored-by: Han <[email protected]>
@CPerezz
Copy link
Member Author

CPerezz commented Sep 28, 2023

Some constants of Fp need to be updated since it doesn't have from_raw to use, I've generated locally and add some comments.

Also perhaps we could add a test for these constans below like:

#[test]
fn constants() {
    assert_eq!(Fp::ONE.double(), GENERATOR);
    assert_eq!(Fp::ONE, Fp::ONE.double() * TWO_INV);
    assert_eq!(Fp::ONE, ROOT_OF_UNITY.pow([1 << Fp::S]));
    assert_eq!(Fp::ONE, ROOT_OF_UNITY * ROOT_OF_UNITY_INV);
    // sage: modulus = 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab
    // sage: hex((modulus - 1) >> 1)
    // '0xd0088f51cbff34d258dd3db21a5d66bb23ba5c279c2895fb39869507b587b120f55ffff58a9ffffdcff7fffffffd555'
    let t = [
        0xdcff7fffffffd555,
        0x0f55ffff58a9ffff,
        0xb39869507b587b12,
        0xb23ba5c279c2895f,
        0x258dd3db21a5d66b,
        0xd0088f51cbff34d,
    ];
    assert_eq!(Fp::ONE, DELTA.pow(t));
    assert_eq!(Fp::ONE, ZETA.pow([3]));
}

I indeed had this kind of test in https://github.com/privacy-scaling-explorations/bls12_381/blob/tmp_curve_ext/src/scalar.rs#L819-L849

And assumed I had it too for Fp. Adding it!!

Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CPerezz CPerezz merged commit 9e59592 into main Oct 26, 2023
21 checks passed
@CPerezz CPerezz deleted the tmp_curve_ext branch October 26, 2023 08:06
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

Successfully merging this pull request may close these issues.

3 participants