From 36305e724703917dfead83c6d48379a1b21f507c Mon Sep 17 00:00:00 2001 From: Youssef El Housni Date: Wed, 1 Jul 2020 21:25:02 +0200 Subject: [PATCH] Implement ed_on_bn254 curve (baby-jubjub) (#230) --- r1cs-std/Cargo.toml | 3 ++- r1cs-std/src/instantiated/ed_on_bn254/curves.rs | 11 +++++++++++ r1cs-std/src/instantiated/ed_on_bn254/fields.rs | 8 ++++++++ r1cs-std/src/instantiated/ed_on_bn254/mod.rs | 5 +++++ r1cs-std/src/instantiated/mod.rs | 3 +++ r1cs-std/src/lib.rs | 3 +++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 r1cs-std/src/instantiated/ed_on_bn254/curves.rs create mode 100644 r1cs-std/src/instantiated/ed_on_bn254/fields.rs create mode 100644 r1cs-std/src/instantiated/ed_on_bn254/mod.rs diff --git a/r1cs-std/Cargo.toml b/r1cs-std/Cargo.toml index b46a07f..9646ee0 100644 --- a/r1cs-std/Cargo.toml +++ b/r1cs-std/Cargo.toml @@ -36,12 +36,13 @@ algebra = { path = "../algebra", default-features = false, features = [ "bls12_3 [features] default = ["std"] full = [ - "bls12_377", "ed_on_bls12_381", "ed_on_bls12_377", "ed_on_cp6_782", + "bls12_377", "ed_on_bn254", "ed_on_bls12_381", "ed_on_bls12_377", "ed_on_cp6_782", "ed_on_bw6_761", "ed_on_mnt4_298", "ed_on_mnt4_753", "mnt4_298", "mnt4_753", "mnt6_298", "mnt6_753" ] bls12_377 = [ "algebra/bls12_377" ] ed_on_bls12_381 = [ "algebra/ed_on_bls12_381" ] +ed_on_bn254 = [ "algebra/ed_on_bn254" ] ed_on_bls12_377 = [ "algebra/ed_on_bls12_377" ] ed_on_cp6_782 = [ "algebra/ed_on_cp6_782" ] ed_on_bw6_761 = [ "algebra/ed_on_bw6_761", "algebra/ed_on_cp6_782" ] diff --git a/r1cs-std/src/instantiated/ed_on_bn254/curves.rs b/r1cs-std/src/instantiated/ed_on_bn254/curves.rs new file mode 100644 index 0000000..06ab063 --- /dev/null +++ b/r1cs-std/src/instantiated/ed_on_bn254/curves.rs @@ -0,0 +1,11 @@ +use crate::groups::curves::twisted_edwards::AffineGadget; +use algebra::ed_on_bn254::*; + +use crate::ed_on_bn254::FqGadget; + +pub type EdwardsGadget = AffineGadget; + +#[test] +fn test() { + crate::groups::curves::twisted_edwards::test::(); +} diff --git a/r1cs-std/src/instantiated/ed_on_bn254/fields.rs b/r1cs-std/src/instantiated/ed_on_bn254/fields.rs new file mode 100644 index 0000000..5d423b7 --- /dev/null +++ b/r1cs-std/src/instantiated/ed_on_bn254/fields.rs @@ -0,0 +1,8 @@ +use crate::fields::fp::FpGadget; + +pub type FqGadget = FpGadget; + +#[test] +fn test() { + crate::fields::tests::field_test::<_, algebra::ed_on_bn254::Fq, FqGadget>(); +} diff --git a/r1cs-std/src/instantiated/ed_on_bn254/mod.rs b/r1cs-std/src/instantiated/ed_on_bn254/mod.rs new file mode 100644 index 0000000..cd5e758 --- /dev/null +++ b/r1cs-std/src/instantiated/ed_on_bn254/mod.rs @@ -0,0 +1,5 @@ +mod curves; +mod fields; + +pub use curves::*; +pub use fields::*; diff --git a/r1cs-std/src/instantiated/mod.rs b/r1cs-std/src/instantiated/mod.rs index 09a616c..0ca6c2c 100644 --- a/r1cs-std/src/instantiated/mod.rs +++ b/r1cs-std/src/instantiated/mod.rs @@ -13,6 +13,9 @@ pub(crate) mod ed_on_cp6_782; #[cfg(feature = "ed_on_bw6_761")] pub mod ed_on_bw6_761; +#[cfg(feature = "ed_on_bn254")] +pub mod ed_on_bn254; + #[cfg(feature = "ed_on_bls12_381")] pub mod ed_on_bls12_381; diff --git a/r1cs-std/src/lib.rs b/r1cs-std/src/lib.rs index dafa822..fba60f5 100644 --- a/r1cs-std/src/lib.rs +++ b/r1cs-std/src/lib.rs @@ -60,6 +60,9 @@ pub use instantiated::ed_on_mnt4_753; #[cfg(feature = "ed_on_cp6_782")] pub use instantiated::ed_on_cp6_782; +#[cfg(feature = "ed_on_bn254")] +pub use instantiated::ed_on_bn254; + #[cfg(feature = "ed_on_bls12_381")] pub use instantiated::ed_on_bls12_381;