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

feat(stdlib): Implement elliptic curve primitives #964

Merged
merged 2 commits into from
Mar 15, 2023

Conversation

ax0
Copy link
Contributor

@ax0 ax0 commented Mar 8, 2023

Related issue(s)

Partially resolves #393

Description

This PR implements elliptic curve primitives over Field, specifically the group operations (addition, subtraction, scalar multiplication) and curve mappings required for hash_to_curve (Simplified SWU and Elligator 2 methods). The implementation includes Montgomery, Short Weierstraß and Twisted Edwards curve configurations, though the Montgomery curve implementation is minimal and included only for the purpose of curve mappings (i.e. the group operations are induced by those for the corresponding Twisted Edwards curve). All curves include both affine and 'CurveGroup' (i.e. projective or extended) coordinate representations. The structure and choice of terminology are loosely based on those of ark-ec. A more detailed description of the implementation is included in ec.nr.

Multi-scalar multiplication is implemented as well but does not work at the moment due to the lack of support for arrays of structs. Also, I was hoping to avoid code duplication e.g. in the definition of bit_mul (multiplication by a scalar represented by a bit array) for each curve configuration by using higher-order functions (cf. the commented-out definition of bit_mul in ec.nr), but I ran into the problem where I couldn't generate proofs.

Summary of changes

  • Addition of elliptic curve configurations and operations in ec.nr and under ec/
  • Addition of parity method in field.nr

Dependency additions / changes

Test additions / changes

One test case in nargo/tests/test_data/ec_baby_jubjub, which tests the library on the Baby Jubjub curve.

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

Additional context

@guipublic guipublic added this pull request to the merge queue Mar 15, 2023
Merged via the queue into noir-lang:master with commit 30d612d Mar 15, 2023
}

// SWU map-to-curve method (via rational map)
fn swu_map(self, z: Field, u: Field) -> Point {

Choose a reason for hiding this comment

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

Shouldn't z be fixed to a constant satisfying the conditions here https://datatracker.ietf.org/doc/id/draft-irtf-cfrg-hash-to-curve-06.html#section-6.6.2
rather than a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should indeed. At the time of this PR, it wasn't possible to compute the constant in Noir without adding unnecessary constraints, which is why I left it as a parameter here, unlike the case of the Elligator 2 method whose constant depends only on the field and not on the curve. Now that unconstrained functions are a thing, this should be easy to resolve.

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.

Create Elliptic Curve Arithmetic utilities
3 participants