Skip to content

Commit

Permalink
more rearranging, add edwards mod for arkworks defs
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Jan 30, 2024
1 parent db5c6ea commit beae623
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 932 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std = ["alloc", "tracing/std", "anyhow/std", "tracing-subscriber/std", "zeroize/
parallel = ["ark-ff/parallel", "ark-ec/parallel", "ark-groth16/parallel", "ark-std/parallel", "ark-r1cs-std/parallel"]
# TODO: eventually, feature-gate all arkworks deps behind this feature.
arkworks = ["std", "ark-std", "ark-ec", "ark-ff", "ark-serialize", "ark-bls12-377", "ark-ed-on-bls12-377"]
r1cs = ["ark-groth16", "ark-r1cs-std", "ark-relations", "ark-snark"]
r1cs = ["arkworks", "ark-groth16", "ark-r1cs-std", "ark-relations", "ark-snark"]
u32_backend = []

[dev-dependencies]
Expand Down
Empty file removed src/ark_curve.rs
Empty file.
71 changes: 71 additions & 0 deletions src/ark_curve/edwards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::Fq;

#[derive(Clone, Default, PartialEq, Eq)]
pub struct Decaf377EdwardsConfig;

// These types should not be exported. They are similar to `EdwardsAffine` and
// `EdwardsProjective` from the `ark_ed_on_bls12_377` crate, except using our own
// `Decaf377Config` that has the cofactor set to 1. Consumers of this
// library should use the `AffineElement` and `Element` (projective)
// types.
pub type EdwardsAffine = Affine<Decaf377EdwardsConfig>;

Check failure on line 11 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Affine` in this scope

Check failure on line 11 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Affine` in this scope

Check failure on line 11 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Affine` in this scope

Check failure on line 11 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find type `Affine` in this scope

Check failure on line 11 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find type `Affine` in this scope
pub type EdwardsProjective = Projective<Decaf377EdwardsConfig>;

Check failure on line 12 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Projective` in this scope

Check failure on line 12 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Projective` in this scope

Check failure on line 12 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Projective` in this scope

Check failure on line 12 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find type `Projective` in this scope

Check failure on line 12 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find type `Projective` in this scope

impl CurveConfig for Decaf377EdwardsConfig {

Check failure on line 14 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find trait `CurveConfig` in this scope

Check failure on line 14 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find trait `CurveConfig` in this scope

Check failure on line 14 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find trait `CurveConfig` in this scope

Check failure on line 14 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find trait `CurveConfig` in this scope

Check failure on line 14 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find trait `CurveConfig` in this scope
type BaseField = Fq;
type ScalarField = Fr;

Check failure on line 16 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Fr` in this scope

Check failure on line 16 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Fr` in this scope

Check failure on line 16 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Fr` in this scope

Check failure on line 16 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find type `Fr` in this scope

Check failure on line 16 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find type `Fr` in this scope

const COFACTOR: &'static [u64] = &[1];

const COFACTOR_INV: Fr = Fr::one();

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Fr` in this scope

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

failed to resolve: use of undeclared type `Fr`

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Fr` in this scope

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

failed to resolve: use of undeclared type `Fr`

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Fr` in this scope

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

failed to resolve: use of undeclared type `Fr`

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find type `Fr` in this scope

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

failed to resolve: use of undeclared type `Fr`

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find type `Fr` in this scope

Check failure on line 20 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

failed to resolve: use of undeclared type `Fr`
}

impl TECurveConfig for Decaf377EdwardsConfig {

Check failure on line 23 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find trait `TECurveConfig` in this scope

Check failure on line 23 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find trait `TECurveConfig` in this scope

Check failure on line 23 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find trait `TECurveConfig` in this scope

Check failure on line 23 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find trait `TECurveConfig` in this scope

Check failure on line 23 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find trait `TECurveConfig` in this scope
/// COEFF_A = -1
const COEFF_A: Fq = Fq::from_montgomery_limbs_64([
10157024534604021774,
16668528035959406606,
5322190058819395602,
387181115924875961,
]);

/// COEFF_D = 3021
const COEFF_D: Fq = Fq::from_montgomery_limbs_64([
15008245758212136496,
17341409599856531410,
648869460136961410,
719771289660577536,
]);

const GENERATOR: EdwardsAffine = EdwardsAffine::new_unchecked(GENERATOR_X, GENERATOR_Y);

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find value `GENERATOR_X` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find value `GENERATOR_Y` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find value `GENERATOR_X` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find value `GENERATOR_Y` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find value `GENERATOR_X` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find value `GENERATOR_Y` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find value `GENERATOR_X` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find value `GENERATOR_Y` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find value `GENERATOR_X` in this scope

Check failure on line 40 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find value `GENERATOR_Y` in this scope

type MontCurveConfig = Decaf377EdwardsConfig;

/// Multiplication by `a` is just negation.
#[inline(always)]
fn mul_by_a(elem: Self::BaseField) -> Self::BaseField {
-elem
}

fn is_in_correct_subgroup_assuming_on_curve(_: &Affine<Self>) -> bool {

Check failure on line 50 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `Affine` in this scope

Check failure on line 50 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / no_std compatibility check

cannot find type `Affine` in this scope

Check failure on line 50 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / build without alloc

cannot find type `Affine` in this scope

Check failure on line 50 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs,u32_backend)

cannot find type `Affine` in this scope

Check failure on line 50 in src/ark_curve/edwards.rs

View workflow job for this annotation

GitHub Actions / Test Suite (r1cs)

cannot find type `Affine` in this scope
true
}
}

impl MontCurveConfig for Decaf377EdwardsConfig {
const COEFF_A: Fq = Fq::from_montgomery_limbs_64([
13800168384327121454,
6841573379969807446,
12529593083398462246,
853978956621483129,
]);

const COEFF_B: Fq = Fq::from_montgomery_limbs_64([
7239382437352637935,
14509846070439283655,
5083066350480839936,
1265663645916442191,
]);

type TECurveConfig = Decaf377EdwardsConfig;
}
1 change: 1 addition & 0 deletions src/ark_curve/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod edwards;
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use cfg_if::cfg_if;

pub mod fields;
pub mod smol_curve;
pub mod min_curve;
pub use fields::{fp::Fp, fq::Fq, fr::Fr};

pub mod ark_curve;

mod sign;

mod on_curve;
Expand Down
2 changes: 1 addition & 1 deletion src/min_curve/invsqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use subtle::{ConditionallySelectable, ConstantTimeEq};

use crate::{fields::fq::arkworks_constants::*, Fq};

use crate::smol_curve::constants::ZETA;
use crate::min_curve::constants::ZETA;

impl Fq {
/// For square elements, calculate their square root, otherwise return an undefined element.
Expand Down
2 changes: 1 addition & 1 deletion src/min_curve/ops.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};

use crate::{smol_curve::element::Element, Fr};
use crate::{min_curve::element::Element, Fr};

// Element addition

Expand Down
39 changes: 0 additions & 39 deletions src/smol_curve/constants.rs

This file was deleted.

Loading

0 comments on commit beae623

Please sign in to comment.