Skip to content

[feat] Add support for Twisted Edwards Curves into the elliptic curve VM extension #1255

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

Open
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

Avaneesh-axiom
Copy link
Contributor

@Avaneesh-axiom Avaneesh-axiom commented Jan 22, 2025

Primary change:

  • Added a chip that adds two Twisted Edwards curve points and also implements a setup instruction. This chip is built using the mod-builder framework
  • The setup instruction checks that the modulus is correct and the coefficients a and d from the equation of a Twisted Edwards curve are correct
  • The chip's constructor checks that a is a quadratic residue and that d is not a quadratic residue. This property of a Twisted Edwards curve ensures that the addition operation is the same for all input points
  • Added the Ed25519 curve to the guest library for ease-of-use

Related changes:

  • Updated the mod-builder framework to handle setup rows that verify more than one constant
  • Updated the mod-builder framework to the new method of padding rows. That is, by using a temporary range checker and constructing a dummy row (see fix: EcDoubleChip dummy row #1239)
  • Updated the doubling chip for Weierstrass curves to use the updated mod-builder framework
  • Changed the CurveConfig struct to accommodate for curves in Twisted Edwards curve form
  • Updated the OpenVM book to explain how to use twisted Edwards curves

Closes INT-2999

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch from 39db1c0 to 87757aa Compare January 23, 2025 01:13

This comment has been minimized.

@@ -21,6 +21,7 @@ openvm-rv32-adapters = { workspace = true }
openvm-ecc-transpiler = { workspace = true }

num-bigint = { workspace = true }
num-bigint-dig = { workspace = true }
Copy link
Contributor

Choose a reason for hiding this comment

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

we got rid of num-bigint-dig, let's only use num-bigint from now on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

num-bigint-dig has jacobi symbol computation while num-bigint doesn't. I'll try to replicate it with num-bigint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need jacobi symbol for checking if a is QR and d is not QR for completeness

Copy link
Contributor

Choose a reason for hiding this comment

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

hm... that is really unfortunate (I don't want two bigint crates, and num-bigint-dig is less maintained than num-bigint) let me investigate

Copy link
Contributor Author

@Avaneesh-axiom Avaneesh-axiom Jan 31, 2025

Choose a reason for hiding this comment

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

I forgot to update you, but I have removed the dependency on num-bigint-dig. I copied over the jacobi symbol code into extensions/ecc/circuit/src/edwards_chip/utils.rs

This comment has been minimized.

This comment has been minimized.

@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch from 3672c6b to 0d99466 Compare January 23, 2025 21:00
@Avaneesh-axiom Avaneesh-axiom marked this pull request as ready for review January 23, 2025 21:08
@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch 2 times, most recently from 4bb302d to 963e4f7 Compare January 24, 2025 23:52
@jonathanpwang jonathanpwang changed the base branch from main to develop January 27, 2025 18:44
@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch 2 times, most recently from b6aaa08 to e46b959 Compare January 28, 2025 00:45
@Avaneesh-axiom Avaneesh-axiom marked this pull request as draft January 28, 2025 21:53
@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch 2 times, most recently from ad295b3 to 2fbe8e7 Compare January 29, 2025 00:33
@Avaneesh-axiom
Copy link
Contributor Author

FYI: I added some more changes that fix a bug that I found (weierstrass and edwards opcodes would overlap in some cases)

I also added decompression hints (just like for weierstrass) to the edwards curves since I will use it in eddsa

@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch from ff27e26 to c689ccc Compare January 29, 2025 19:25
@Avaneesh-axiom
Copy link
Contributor Author

Update: rebased onto develop

Avaneesh-axiom and others added 24 commits April 4, 2025 16:39
A bug involving opcode collisions between short Weierstrass and twisted Edwards curves was found.

To fix this, CurveConfig was rewritten and separate opcodes were given to the two types of curves.
@Avaneesh-axiom Avaneesh-axiom force-pushed the feat/edwards-curve-support branch from 840135f to 9a1c396 Compare April 4, 2025 20:40
Copy link

github-actions bot commented Apr 4, 2025

group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (-14 [-1.1%]) 1,268 334,142 17,677,298 - - -
fibonacci_program (+45 [+1.7%]) 2,729 1,500,277 50,589,503 - - -
regex_program (-125 [-1.5%]) 8,048 4,165,226 166,511,152 - - -
ecrecover_program (+17 [+1.2%]) 1,425 289,447 14,470,186 - - -
pairing (-5 [-0.1%]) 4,901 1,820,436 95,832,407 - - -

Commit: 9a1c396

Benchmark Workflow

// ANCHOR_END: imports
openvm_algebra_guest::moduli_macros::moduli_declare! {
// The Secp256k1 modulus and scalar field modulus are already declared in the k256 module
Copy link
Contributor

Choose a reason for hiding this comment

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

oudated comment

});

#[derive(Clone, Debug, derive_new::new, Serialize, Deserialize)]
pub struct WeierstrassExtension {
pub supported_curves: Vec<CurveConfig>,
pub struct EccExtension {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see it's easier to say "ECC Extension" but here I feel like we could have done WeierstrassExtension and TwistedEdwardsExtension as two separate structs. I don't have strong feelings either way

pub struct WeierstrassExtension {
pub supported_curves: Vec<CurveConfig>,
pub struct EccExtension {
pub supported_sw_curves: Vec<CurveConfig<SwCurveCoeffs>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

another option is to keep a single vector but use enum to specify different curve types within CurveConfig. That seems like a might be a little nicer ux wise?

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