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

Add Grumpkin cycle implementation #181

Merged
merged 12 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ flate2 = "1.0"
bitvec = "1.0"
byteorder = "1.4.3"
thiserror = "1.0"
halo2curves = { version="0.1.0", features = [ "derive_serde" ] }

[target.'cfg(any(target_arch = "x86_64", target_arch = "aarch64"))'.dependencies]
pasta-msm = { version = "0.1.4" }

[target.wasm32-unknown-unknown.dependencies]
# see https://github.com/rust-random/rand/pull/948
getrandom = { version = "0.2.0", default-features = false, features = ["js"]}

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
rand = "0.8.4"
Expand Down
4 changes: 2 additions & 2 deletions src/bellperson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod tests {

#[test]
fn test_alloc_bit() {
type G = pasta_curves::pallas::Point;
test_alloc_bit_with::<G>();
test_alloc_bit_with::<pasta_curves::pallas::Point>();
test_alloc_bit_with::<crate::provider::bn256_grumpkin::bn256::Point>();
}
}
18 changes: 17 additions & 1 deletion src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ mod tests {
type PastaG2 = pasta_curves::vesta::Point;

use crate::constants::{BN_LIMB_WIDTH, BN_N_LIMBS};
use crate::provider;
use crate::{
bellperson::r1cs::{NovaShape, NovaWitness},
gadgets::utils::scalar_as_base,
Expand Down Expand Up @@ -471,7 +472,7 @@ mod tests {
}

#[test]
fn test_recursive_circuit() {
fn test_recursive_circuit_pasta() {
let params1 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true);
let params2 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false);
let ro_consts1: ROConstantsCircuit<PastaG2> = PoseidonConstantsCircuit::new();
Expand All @@ -481,4 +482,19 @@ mod tests {
params1, params2, ro_consts1, ro_consts2, 9815, 10347,
);
}

#[test]
fn test_recursive_circuit_grumpkin() {
let params1 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, true);
let params2 = NovaAugmentedCircuitParams::new(BN_LIMB_WIDTH, BN_N_LIMBS, false);
let ro_consts1: ROConstantsCircuit<provider::bn256_grumpkin::grumpkin::Point> =
PoseidonConstantsCircuit::new();
let ro_consts2: ROConstantsCircuit<provider::bn256_grumpkin::bn256::Point> =
PoseidonConstantsCircuit::new();

test_recursive_circuit_with::<
provider::bn256_grumpkin::bn256::Point,
provider::bn256_grumpkin::grumpkin::Point,
>(params1, params2, ro_consts1, ro_consts2, 9983, 10536);
}
}
14 changes: 13 additions & 1 deletion src/gadgets/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ mod tests {
r1cs::{NovaShape, NovaWitness},
{shape_cs::ShapeCS, solver::SatisfyingAssignment},
};
use crate::provider::bn256_grumpkin::{bn256, grumpkin};
use ff::{Field, PrimeFieldBits};
use pasta_curves::{arithmetic::CurveAffine, group::Curve, pallas, vesta};
use rand::rngs::OsRng;
Expand All @@ -768,7 +769,6 @@ mod tests {
is_infinity: bool,
}

#[cfg(test)]
impl<G> Point<G>
where
G: Group,
Expand Down Expand Up @@ -896,6 +896,9 @@ mod tests {
fn test_ecc_ops() {
test_ecc_ops_with::<pallas::Affine, pallas::Point>();
test_ecc_ops_with::<vesta::Affine, vesta::Point>();

test_ecc_ops_with::<bn256::Affine, bn256::Point>();
test_ecc_ops_with::<grumpkin::Affine, grumpkin::Point>();
}

fn test_ecc_ops_with<C, G>()
Expand Down Expand Up @@ -977,6 +980,9 @@ mod tests {
fn test_ecc_circuit_ops() {
test_ecc_circuit_ops_with::<pallas::Point, vesta::Point>();
test_ecc_circuit_ops_with::<vesta::Point, pallas::Point>();

test_ecc_circuit_ops_with::<bn256::Point, grumpkin::Point>();
test_ecc_circuit_ops_with::<grumpkin::Point, bn256::Point>();
}

fn test_ecc_circuit_ops_with<G1, G2>()
Expand Down Expand Up @@ -1027,6 +1033,9 @@ mod tests {
fn test_ecc_circuit_add_equal() {
test_ecc_circuit_add_equal_with::<pallas::Point, vesta::Point>();
test_ecc_circuit_add_equal_with::<vesta::Point, pallas::Point>();

test_ecc_circuit_add_equal_with::<bn256::Point, grumpkin::Point>();
test_ecc_circuit_add_equal_with::<grumpkin::Point, bn256::Point>();
}

fn test_ecc_circuit_add_equal_with<G1, G2>()
Expand Down Expand Up @@ -1081,6 +1090,9 @@ mod tests {
fn test_ecc_circuit_add_negation() {
test_ecc_circuit_add_negation_with::<pallas::Point, vesta::Point>();
test_ecc_circuit_add_negation_with::<vesta::Point, pallas::Point>();

test_ecc_circuit_add_negation_with::<bn256::Point, grumpkin::Point>();
test_ecc_circuit_add_negation_with::<grumpkin::Point, bn256::Point>();
}

fn test_ecc_circuit_add_negation_with<G1, G2>()
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ fn compute_digest<G: Group, T: Serialize>(o: &T) -> G::Scalar {

#[cfg(test)]
mod tests {
use crate::provider::bn256_grumpkin::{bn256, grumpkin};
use crate::provider::pedersen::CommitmentKeyExtTrait;

use super::*;
Expand Down Expand Up @@ -895,6 +896,23 @@ mod tests {
trivial_circuit2,
"3f7b25f589f2da5ab26254beba98faa54f6442ebf5fa5860caf7b08b576cab00",
);

let trivial_circuit1_grumpkin =
TrivialTestCircuit::<<bn256::Point as Group>::Scalar>::default();
let trivial_circuit2_grumpkin =
TrivialTestCircuit::<<grumpkin::Point as Group>::Scalar>::default();
let cubic_circuit1_grumpkin = CubicCircuit::<<bn256::Point as Group>::Scalar>::default();

test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _>(
trivial_circuit1_grumpkin,
trivial_circuit2_grumpkin.clone(),
"967acca1d6b4731cd65d4072c12bbaca9648f24d7bcc2877aee720e4265d4302",
);
test_pp_digest_with::<bn256::Point, grumpkin::Point, _, _>(
cubic_circuit1_grumpkin,
trivial_circuit2_grumpkin,
"44629f26a78bf6c4e3077f940232050d1793d304fdba5e221d0cf66f76a37903",
);
}

fn test_ivc_trivial_with<G1, G2>()
Expand Down Expand Up @@ -949,6 +967,8 @@ mod tests {
type G1 = pasta_curves::pallas::Point;
type G2 = pasta_curves::vesta::Point;
test_ivc_trivial_with::<G1, G2>();

test_ivc_trivial_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_nontrivial_with<G1, G2>()
Expand Down Expand Up @@ -1030,6 +1050,7 @@ mod tests {
type G2 = pasta_curves::vesta::Point;

test_ivc_nontrivial_with::<G1, G2>();
test_ivc_nontrivial_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_nontrivial_with_compression_with<G1, G2>()
Expand Down Expand Up @@ -1124,6 +1145,7 @@ mod tests {
type G2 = pasta_curves::vesta::Point;

test_ivc_nontrivial_with_compression_with::<G1, G2>();
test_ivc_nontrivial_with_compression_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_nontrivial_with_spark_compression_with<G1, G2>()
Expand Down Expand Up @@ -1221,6 +1243,7 @@ mod tests {
type G2 = pasta_curves::vesta::Point;

test_ivc_nontrivial_with_spark_compression_with::<G1, G2>();
test_ivc_nontrivial_with_spark_compression_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_nondet_with_compression_with<G1, G2>()
Expand Down Expand Up @@ -1377,6 +1400,7 @@ mod tests {
type G2 = pasta_curves::vesta::Point;

test_ivc_nondet_with_compression_with::<G1, G2>();
test_ivc_nondet_with_compression_with::<bn256::Point, grumpkin::Point>();
}

fn test_ivc_base_with<G1, G2>()
Expand Down Expand Up @@ -1443,5 +1467,6 @@ mod tests {
type G2 = pasta_curves::vesta::Point;

test_ivc_base_with::<G1, G2>();
test_ivc_base_with::<bn256::Point, grumpkin::Point>();
}
}
3 changes: 3 additions & 0 deletions src/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ mod tests {
#[test]
fn test_tiny_r1cs_bellperson() {
test_tiny_r1cs_bellperson_with::<G>();

test_tiny_r1cs_bellperson_with::<crate::provider::bn256_grumpkin::bn256::Point>();
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -384,5 +386,6 @@ mod tests {
#[test]
fn test_tiny_r1cs() {
test_tiny_r1cs_with::<pasta_curves::pallas::Point>();
test_tiny_r1cs_with::<crate::provider::bn256_grumpkin::bn256::Point>();
}
}
Loading