Skip to content

Commit 851d468

Browse files
rubdosRobrechtsamvandeveldePratyush
authored
ec: implement double-odd curves (#986)
* ec: implement double-odd curves Implements Thomas Pornin's “A Prime-Order Group with Complete Formulas from Even-Order Elliptic Curves” [1], often referred to as "double odd" curves. Includes the double-odd curve “JQ255s” as presented in the paper. [1] T. Pornin, “A Prime-Order Group with Complete Formulas from Even-Order Elliptic Curves,” IACR CiC, vol. 1, no. 1, p. 33, Apr. 2024, doi: 10.62056/akmp-4c2h. * docs: link to Double Odd website for double_in_place * ec: generalize add_assign for curves different from jq255s * fix: addresses errors and most warnings raised by cargo doc * fix: implemented missing is_zero fn for DO AffineRepr * fix: unescaped backtick in documentation * impl: no_std check for jq255s similar to other curves * fix: cargo fmt hotfix * copied curve25519 field tests to jq255s * perf: removed one mul from add functions * fix: slightly faster addition for two affines * fix: removed unneccessary projectiverefs * fix: comply models/double_odd/mod.rs with clippy rules * Update COEFF_A in curves/jq255s/src/curves/mod.rs Although the same value, this rewrite more clearly indicates the value of COEFF_A (equal to -1 as described in https://eprint.iacr.org/2022/1052) Co-authored-by: Pratyush Mishra <pratyush795@gmail.com> * fix: Add clarifying documentation and missing refs * deduplicating obtaining e from u * remove n()-function and redundancy, better docs, faster is_zero checka, formatting fix: faster projective eq check fix: code deduplication + removal of additional n-function extra comment linking test to encoding standard fixed unescaped backtick warning fix cargo fmt error fix: n() back for testing fix: style fix: style (bracket) fix: lint deadcode ignore n migration --------- Co-authored-by: Robrecht <robrecht.blancquaert@gmail.com> Co-authored-by: prismaman <svdv2000@gmail.com> Co-authored-by: Sam Van de Velde <58397500+samvandevelde@users.noreply.github.com> Co-authored-by: Pratyush Mishra <pratyush795@gmail.com>
1 parent 277024b commit 851d468

File tree

22 files changed

+1490
-6
lines changed

22 files changed

+1490
-6
lines changed

curves/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ members = [
4242
"ed25519",
4343

4444
"starkcurve",
45+
"jq255s",
4546
]
4647
resolver = "2"
4748

curves/jq255s/Cargo.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[package]
2+
name = "ark-jq255s"
3+
version.workspace = true
4+
authors.workspace = true
5+
description = "The do255s curve"
6+
homepage.workspace = true
7+
repository.workspace = true
8+
documentation = "https://docs.rs/ark-secp256r1/"
9+
keywords.workspace = true
10+
categories.workspace = true
11+
include.workspace = true
12+
license.workspace = true
13+
edition.workspace = true
14+
15+
[dependencies]
16+
ark-ff = { workspace = true }
17+
ark-ec = { workspace = true }
18+
ark-r1cs-std = { workspace = true, optional = true }
19+
ark-std = { workspace = true }
20+
hex = "0.4.3"
21+
22+
[dev-dependencies]
23+
ark-relations = { workspace = true }
24+
ark-serialize = { workspace = true }
25+
ark-algebra-test-templates = { workspace = true }
26+
ark-curve-constraint-tests = { path = "../curve-constraint-tests" }
27+
28+
[features]
29+
default = []
30+
std = [ "ark-std/std", "ark-ff/std", "ark-ec/std" ]
31+
r1cs = [ "ark-r1cs-std" ]
32+
asm = [ "ark-ff/asm" ]
33+
34+
#[patch.crates-io]
35+
#ark-ec = { path = "../../algebra/ec" }
36+
#ark-ff = { path = "../../algebra/ff" }
37+
#ark-poly = { path = "../../algebra/poly" }
38+
#ark-serialize = { path = "../../algebra/serialize" }

curves/jq255s/LICENSE-APACHE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-APACHE

curves/jq255s/LICENSE-MIT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../LICENSE-MIT
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use crate::{constraints::FqVar, *};
2+
use ark_r1cs_std::groups::curves::short_weierstrass::ProjectiveVar;
3+
4+
/// A group element in the Jq255s curve.
5+
pub type GVar = ProjectiveVar<Config, FqVar>;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use ark_r1cs_std::fields::fp::FpVar;
2+
3+
use crate::fq::Fq;
4+
5+
/// A variable that is the R1CS equivalent of `crate::Fq`.
6+
pub type FqVar = FpVar<Fq>;
7+
8+
#[test]
9+
fn test() {
10+
ark_curve_constraint_tests::fields::field_test::<_, _, FqVar>().unwrap();
11+
}

curves/jq255s/src/constraints/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! This module implements the R1CS equivalent of `ark_jq255s`.
2+
3+
mod curves;
4+
mod fields;
5+
6+
pub use curves::*;
7+
pub use fields::*;

curves/jq255s/src/curves/mod.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use ark_ec::{
2+
double_odd::{self as doo, DOCurveConfig},
3+
models::CurveConfig,
4+
};
5+
use ark_ff::MontFp;
6+
7+
use crate::{fq::Fq, fr::Fr};
8+
9+
#[cfg(test)]
10+
mod tests;
11+
12+
pub type Affine = doo::Affine<Config>;
13+
pub type Projective = doo::Projective<Config>;
14+
15+
#[derive(Copy, Clone, Default, PartialEq, Eq)]
16+
pub struct Config;
17+
18+
impl CurveConfig for Config {
19+
type BaseField = Fq;
20+
type ScalarField = Fr;
21+
22+
/// COFACTOR = 2
23+
const COFACTOR: &'static [u64] = &[2];
24+
25+
#[rustfmt::skip]
26+
const COFACTOR_INV: Fr = MontFp!("14474011154664524427946373126085988481687200150840406918337755177497658435940");
27+
}
28+
29+
impl DOCurveConfig for Config {
30+
/// COEFF_A = -1
31+
const COEFF_A: Fq = MontFp!("-1");
32+
33+
/// COEFF_B = 1/2
34+
const COEFF_B: Fq =
35+
MontFp!("28948022309329048855892746252171976963317496166410141009864396001978282408006");
36+
37+
/// GENERATOR = (G_GENERATOR_X, G_GENERATOR_Y)
38+
const GENERATOR: Affine = Affine::new_unchecked(G_GENERATOR_E, G_GENERATOR_U);
39+
}
40+
41+
/// G_GENERATOR_X =
42+
/// 0x0076aab95b2acbae4747482ba7081f7b94193dad9f96fdd2516283980459b09eaa
43+
pub const G_GENERATOR_E: Fq =
44+
MontFp!("6929650852805837546485348833751579670837850621479164143703164723313568683024");
45+
46+
/// G_GENERATOR_Y =
47+
/// 0x00b7d601b4cb25f8249b65e89b8f584a5494e592f3895d54f9002202b0530e6fbc
48+
pub const G_GENERATOR_U: Fq = MontFp!("3");

0 commit comments

Comments
 (0)