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

Extension field #44

Merged
merged 4 commits into from
May 7, 2024
Merged

Extension field #44

merged 4 commits into from
May 7, 2024

Conversation

lonerapier
Copy link
Collaborator

@lonerapier lonerapier commented May 7, 2024

This PR closes issue #40

It changes the following:

  • adds 2 degree extension field for PlutoField. I've not made field extension generic over degree. let me know if that is required.

@0xJepsen 0xJepsen requested a review from Autoparallel May 7, 2024 01:16
use crate::field::FiniteField;

/// Pluto curve with modulus 101 supports two degree extension field. This can be verified
/// by finding out embedding degree of the curve, i.e. smallest k: r|q^k-1
Copy link
Contributor

Choose a reason for hiding this comment

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

When reading about the embedding degree I was trying to see this by hand but came across some questions. In our case r is our curve order which is 17 and p is field order which is 101. How does 17 | 101 ^2 - 1 which is 17 | 10200. 17 doesn't divide 10200. Also 10200 mod 101 is just 17 | 100. Do I have an error in my arithmetic? Are we working in a field here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

17 doesn't divide 10200.

Umm, Waylon 17 does divide 10200.

In our case r is our curve order which is 17

Also, our curve order is 102 (101 points + 1 point at infinity). 17 is the largest prime factor of $r$, thus, 17 is the order of the largest subgroup generated by the curve. Verified using this sage script.

E1 = EllipticCurve(F, [0, 3])
print(E1.order())

P1 = E1(1, 2)
print(P1.order())
k = 17
cofactor = 6

# use cofactor clearing to find generator of prime order subgroup
# take a random point, and multiply by cofactor until it's INF point

G = E1.random_point()
INF = E1(0)

print(G, cofactor * G)
while cofactor * G == INF:
    print("as")
    G = E1.random_point()

Ps = cofactor * G
print(cofactor * G, Ps.order()) 

Copy link
Contributor

@0xJepsen 0xJepsen May 7, 2024

Choose a reason for hiding this comment

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

that's a classic 😅

#[derive(Clone, Default, Copy, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]

/// Quadratic Extension field element represented as polynomial of degree 1 in form:
/// a_0 + a_1*t where {a_0, a_1} \in \mathhbb{F}. Uses irreducible poly of the form:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the right approach but curious how or if we should use this in our polynomial module. I know @Autoparallel you have been working on the FFTs and polynomial interface. Maybe you have some insight here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me get the polynomial PR up.


/// Quadratic Extension field element represented as polynomial of degree 1 in form:
/// a_0 + a_1*t where {a_0, a_1} \in \mathhbb{F}. Uses irreducible poly of the form:
/// (X^2-K).
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be X^2 -K or X^2 + K? X^2 + 2 is irreducible in F_{101} and should be used to generate our extension field.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both work as (correct me if I'm wrong) 2 is not a square in GF_{101}.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, both of them are irreducible, added it in the field sage script as well

Ft.<t> = F[]
# irreducible element: t^2-2
P = Ft(t ^ 2 - 2)
assert P.is_irreducible()

src/field/gf_101_2.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Autoparallel Autoparallel left a comment

Choose a reason for hiding this comment

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

I'm good with this to go in as is :)

@@ -83,6 +83,8 @@ impl FiniteField for GF101 {
fn neg_one() -> Self { Self::new(Self::ORDER - 1) }

fn generator() -> Self { Self::new(2) }

fn from_canonical_u32(n: u32) -> Self { Self::new(n) } // TODO: recheck
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nit, but we don't really need this if we just use GF101::new() right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but then that's struct specific function right? We need a trait specific function to create new values, for example: in extension fields, each subvalue in extension field element is base field element.

Self { value: [F::from_canonical_u32(15), F::from_canonical_u32(20)] }

Is there a better way in Rust to do this? Sorry, still in my learning path for Rust.

#[derive(Clone, Default, Copy, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]

/// Quadratic Extension field element represented as polynomial of degree 1 in form:
/// a_0 + a_1*t where {a_0, a_1} \in \mathhbb{F}. Uses irreducible poly of the form:
Copy link
Contributor

Choose a reason for hiding this comment

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

Let me get the polynomial PR up.


/// Quadratic Extension field element represented as polynomial of degree 1 in form:
/// a_0 + a_1*t where {a_0, a_1} \in \mathhbb{F}. Uses irreducible poly of the form:
/// (X^2-K).
Copy link
Contributor

Choose a reason for hiding this comment

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

I think both work as (correct me if I'm wrong) 2 is not a square in GF_{101}.

src/field/gf_101_2.rs Outdated Show resolved Hide resolved
@0xJepsen 0xJepsen linked an issue May 7, 2024 that may be closed by this pull request
@lonerapier
Copy link
Collaborator Author

@0xJepsen @Autoparallel changes done. let me know if any others are needed

@0xJepsen 0xJepsen merged commit ab0d374 into pluto:main May 7, 2024
4 checks passed
@lonerapier lonerapier deleted the extension_field branch May 8, 2024 05:16
Autoparallel added a commit that referenced this pull request May 9, 2024
commit 2637594
Author: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com>
Date:   Thu May 9 10:38:12 2024 -0600

    curves: Second curve group and some test (#49)

    * chore: tests + scalar multiplication

    * fmt

    * wip: compiles, but generator point is broken

    * wip

    * fix mul, generator and add hardcoded tests (#51)

    * fix mul, generator and add hardcoded tests

    * fix generator test

    * wip

    * fix: test fails when rng has no inverse

    ---------

    Co-authored-by: Sambhav <lonerapier@proton.me>

commit def9371
Author: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com>
Date:   Thu May 9 09:36:25 2024 -0600

    docs: readme (#46)

    * docs: readme

    * wip: pairing check

    * docs

    * Update README.md

    Co-authored-by: Colin Roberts <colin@autoparallel.xyz>

    * Update README.md

    Co-authored-by: Colin Roberts <colin@autoparallel.xyz>

    ---------

    Co-authored-by: Colin Roberts <colin@autoparallel.xyz>

commit ab0d374
Author: Sambhav <lonerapier@proton.me>
Date:   Wed May 8 03:00:15 2024 +0530

    Extension field (#44)

    * feat: extension field init

    * add test

    * add more tests and comments

    * move pow impl default to trait

commit f9aa66e
Author: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com>
Date:   Tue May 7 09:00:35 2024 -0600

    curves in sage (#39)

commit 63ce62f
Author: Waylon Jepsen <waylonjepsen1@gmail.com>
Date:   Mon May 6 17:46:22 2024 -0600

    fix: lock

commit d1c84eb
Author: Colin Roberts <colin@autoparallel.xyz>
Date:   Mon May 6 16:39:25 2024 -0700

    feat: home-baked `FiniteField` trait (#38)

    * feat: new `FiniteField` trait

    Now everything compiles again. Will work to clean this all up and get all the tests to pass.

    * fix: `GF101` tests pass

    * fix: reimplement monty optimizations

    * clean: udeps

    ---------

    Co-authored-by: Waylon Jepsen <57912727+0xJepsen@users.noreply.github.com>

commit 96c8b66
Merge: fb27e5f 62a9a57
Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Date:   Mon May 6 23:26:56 2024 +0000

    Merge pull request #42 from pluto/dependabot/cargo/anyhow-1.0.83

    Bump anyhow from 1.0.82 to 1.0.83

commit 62a9a57
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon May 6 23:26:43 2024 +0000

    Bump anyhow from 1.0.82 to 1.0.83

    Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.82 to 1.0.83.
    - [Release notes](https://github.com/dtolnay/anyhow/releases)
    - [Commits](dtolnay/anyhow@1.0.82...1.0.83)

    ---
    updated-dependencies:
    - dependency-name: anyhow
      dependency-type: direct:production
      update-type: version-update:semver-patch
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
@github-actions github-actions bot mentioned this pull request Jul 1, 2024
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.

Extension fields
3 participants