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

Endo #128

Merged
merged 39 commits into from
Nov 3, 2021
Merged

Endo #128

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ad8851b
Initial functions
DanieleDiBenedetto Feb 16, 2021
99ad511
Endomorphism implementation
phoinic Feb 22, 2021
8b10e09
Tweedle added to r1cs
phoinic Feb 22, 2021
cb4cc6e
Endomorphism implementation for all curves
phoinic Feb 22, 2021
9079f75
mnt6 feature removed from full
phoinic Feb 22, 2021
2ea76ad
Endo gadget experiments
phoinic Feb 28, 2021
5d629da
merge: endo branch merged with audit_fixes
phoinic Jul 13, 2021
5e408d8
endo mul gadget: first steps
phoinic Jul 15, 2021
20b0888
sc_testnet_2 initial commit
DanieleDiBenedetto Sep 2, 2021
2117d44
Merge branch 'proof_size_optimization' into endo
phoinic Sep 26, 2021
b29963e
Endo mul gadget implementation
phoinic Sep 30, 2021
e8b21bd
Fix endo_rep_to_scalar algorithm
phoinic Oct 3, 2021
7b5b53d
Merge branch 'sc_testnet_2' into endo_proof_size_opt
phoinic Oct 5, 2021
8030388
Updating UTs for endo gadget
phoinic Oct 5, 2021
bc56da4
Endo gadget optimization
phoinic Oct 5, 2021
468295a
Cleanup comments
phoinic Oct 5, 2021
8804cf2
Comment for endo_mul updated
phoinic Oct 5, 2021
42aee87
endo merge and optimization
phoinic Oct 9, 2021
d65e6f6
Added the Sage scripts for checking field parameters. With respect to…
Oct 11, 2021
e5b32f7
added endo mul inline docu
UlrichHaboeck75 Oct 18, 2021
7c7545a
Applied the changes suggested by Ulrich about endo_mul parameters.
Oct 19, 2021
1791773
Refactored endo mul native implementation
phoinic Oct 25, 2021
30e0c89
Refactored endo implementation
phoinic Oct 27, 2021
89904fc
Endo mul for 'short_weierstrass_projective' model
phoinic Oct 27, 2021
780ae5f
Additional implementations and bits paddings
phoinic Oct 27, 2021
5007fca
nonnative endo implementation
phoinic Oct 27, 2021
f9a9e44
Modified to check_curve_parameters.sage according to Ulrich's request…
Oct 27, 2021
690abe5
Modified to check_curve_parameters.sage according to Ulrich's request…
Oct 27, 2021
8cf7170
Modified to check_curve_parameters.sage according to Ulrich's request…
Oct 27, 2021
4c9232c
Merge branch 'endo' of https://github.com/HorizenOfficial/ginger-lib …
Oct 27, 2021
7fafe74
Endo generic test
phoinic Oct 28, 2021
40cb120
Merge branch 'rc/audit_chain' into endo_merge
phoinic Oct 28, 2021
116d558
Merge branch 'development' into endo_merge
phoinic Oct 28, 2021
5687c47
Generic endo mul UT optimized
phoinic Oct 28, 2021
6787407
Branch switched to endo
phoinic Oct 28, 2021
177e813
Sync with pc/marlin endo branches
phoinic Oct 28, 2021
bcd8fd6
additional inline doc
UlrichHaboeck75 Nov 2, 2021
3b51d3f
Resolved conflicts in check_curve_parameters.sage
Nov 3, 2021
42470dc
Parameter LAMBDA read from from the curve file, as requested by Ulrich.
Nov 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion r1cs/gadgets/std/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,12 @@ pub(crate) fn scalar_bits_to_constant_length<

#[cfg(test)]
pub(crate) mod test {
use algebra::{Field, PrimeField, FpParameters, BigInteger, Group, UniformRand, ToBits};
use algebra::{Field, PrimeField, FpParameters, BigInteger, Group, UniformRand, ToBits, EndoMulCurve, ProjectiveCurve};
use r1cs_core::ConstraintSystem;

use crate::{prelude::*, test_constraint_system::TestConstraintSystem};
use rand::thread_rng;
use crate::groups::EndoMulCurveGadget;

#[allow(dead_code)]
pub(crate) fn group_test<
Expand Down Expand Up @@ -731,4 +732,32 @@ pub(crate) mod test {
mul_bits_additivity_test::<ConstraintF, G, GG>();
}
}

#[allow(dead_code)]
pub(crate) fn endo_mul_test<
ConstraintF: Field + PrimeField,
G: ProjectiveCurve<Affine = GE>,
GG: EndoMulCurveGadget<G, ConstraintF, Value = G>,
GE: EndoMulCurve<Projective = G>,
DanieleDiBenedetto marked this conversation as resolved.
Show resolved Hide resolved
>()
{
let mut cs = TestConstraintSystem::<ConstraintF>::new();

let a_native_proj = G::rand(&mut thread_rng());
let a_native: GE = a_native_proj.into_affine();
let a = GG::alloc(&mut cs.ns(|| "generate_a"), || Ok(a_native_proj)).unwrap();

let scalar: G::ScalarField = u128::rand(&mut thread_rng()).into();

let b_native = scalar.into_repr().to_bits().as_slice()[0..128].to_vec();
let b = b_native
.iter()
.map(|&bit| Boolean::constant(bit))
.collect::<Vec<_>>();

let r_native = a_native.endo_mul(b_native).unwrap();
let r = a.endo_mul(cs.ns(|| "endo mul"), &b).unwrap().get_value().unwrap();

assert_eq!(r_native, r);
}
}
109 changes: 23 additions & 86 deletions r1cs/gadgets/std/src/instantiated/tweedle/curves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,91 +10,28 @@ use crate::{
pub type TweedleDeeGadget = AffineGadget<TweedledeeParameters, Fq, FqGadget>;
pub type TweedleDumGadget = AffineGadget<TweedledumParameters, Fr, FrGadget>;

#[cfg(test)]
mod test {
use r1cs_core::ConstraintSystem;
use crate::{
prelude::*,
test_constraint_system::TestConstraintSystem,
instantiated::tweedle::{
TweedleDeeGadget,
TweedleDumGadget,
},
groups::EndoMulCurveGadget,
};
use algebra::{UniformRand, AffineCurve, ProjectiveCurve, EndoMulCurve, fields::tweedle::{
Fq, Fr,
}, curves::tweedle::{
dee::Projective as DeeProjective,
dum::Projective as DumProjective,
}, PrimeField, BigInteger};
use rand::thread_rng;

#[test]
fn test_dee() {
crate::groups::test::group_test_with_incomplete_add::<
_, _, TweedleDeeGadget
>();
crate::groups::test::mul_bits_test::<
_, _, TweedleDeeGadget
>();
}

#[test]
fn test_dum() {
crate::groups::test::group_test_with_incomplete_add::<
_, _, TweedleDumGadget
>();
crate::groups::test::mul_bits_test::<
_, _, TweedleDumGadget
>();
}

#[test]
/// Tests equality of the result enforced by `endo_mul()`
/// with the corresponding scalar multiple.
fn test_endo_dee()
{
let mut cs = TestConstraintSystem::<Fq>::new();

let a_native = DeeProjective::rand(&mut thread_rng()).into_affine();
let a = TweedleDeeGadget::alloc(&mut cs.ns(|| "generate_a"), || Ok(a_native.into_projective())).unwrap();

let scalar: Fr = u128::rand(&mut thread_rng()).into();

let b_native = scalar.into_repr().to_bits().as_slice()[0..128].to_vec();
let b = b_native
.iter()
.map(|&bit| Boolean::constant(bit))
.collect::<Vec<_>>();

let r_native = a_native.endo_mul(b_native).unwrap().into_affine();
let r = a.endo_mul(cs.ns(|| "endo mul"), &b).unwrap().get_value().unwrap().into_affine();

assert_eq!(r_native, r);
}

#[test]
/// Tests equality of the result enforced by `endo_mul()`
/// with the corresponding scalar multiple.
fn test_endo_dum()
{
let mut cs = TestConstraintSystem::<Fr>::new();

let a_native = DumProjective::rand(&mut thread_rng()).into_affine();
let a = TweedleDumGadget::alloc(&mut cs.ns(|| "generate_a"), || Ok(a_native.into_projective())).unwrap();

let scalar: Fq = u128::rand(&mut thread_rng()).into();

let b_native = scalar.into_repr().to_bits().as_slice()[0..128].to_vec();
let b = b_native
.iter()
.map(|&bit| Boolean::constant(bit))
.collect::<Vec<_>>();

let r_native = a_native.endo_mul(b_native).unwrap().into_affine();
let r = a.endo_mul(cs.ns(|| "endo mul"), &b).unwrap().get_value().unwrap().into_affine();
#[test]
fn test_dee() {
crate::groups::test::group_test_with_incomplete_add::<
_, _, TweedleDeeGadget
>();
crate::groups::test::mul_bits_test::<
_, _, TweedleDeeGadget
>();
crate::groups::test::endo_mul_test::<
_, _, TweedleDeeGadget, _
>();
}

assert_eq!(r_native, r);
}
#[test]
fn test_dum() {
crate::groups::test::group_test_with_incomplete_add::<
_, _, TweedleDumGadget
>();
crate::groups::test::mul_bits_test::<
_, _, TweedleDumGadget
>();
crate::groups::test::endo_mul_test::<
_, _, TweedleDumGadget, _
>();
}