From 5044ae115eabe9429f19623420b5fe450c661101 Mon Sep 17 00:00:00 2001 From: M Alghazwi Date: Thu, 3 Jul 2025 10:26:41 +0200 Subject: [PATCH] remove tests --- .../src/bn254_wrapper/wrap.rs | 67 ----------- codex-plonky2-circuits/src/recursion/leaf.rs | 73 ------------ codex-plonky2-circuits/src/recursion/node.rs | 112 ------------------ codex-plonky2-circuits/src/recursion/tree.rs | 59 --------- codex-plonky2-circuits/src/recursion/utils.rs | 105 ---------------- 5 files changed, 416 deletions(-) diff --git a/codex-plonky2-circuits/src/bn254_wrapper/wrap.rs b/codex-plonky2-circuits/src/bn254_wrapper/wrap.rs index 335257f..faf37d2 100755 --- a/codex-plonky2-circuits/src/bn254_wrapper/wrap.rs +++ b/codex-plonky2-circuits/src/bn254_wrapper/wrap.rs @@ -147,71 +147,4 @@ impl< } } -#[cfg(test)] -mod tests { - use plonky2::field::goldilocks_field::GoldilocksField; - use plonky2::field::types::Field; - use plonky2::gates::noop::NoopGate; - use plonky2::plonk::circuit_builder::CircuitBuilder; - use plonky2::plonk::circuit_data::CircuitConfig; - use plonky2::plonk::config::PoseidonGoldilocksConfig; - use crate::bn254_wrapper::config::PoseidonBN254GoldilocksConfig; - use super::*; - #[test] - fn test_full_wrap() -> anyhow::Result<()>{ - const D: usize = 2; - - type F = GoldilocksField; - type InnerParameters = PoseidonGoldilocksConfig; - type OuterParameters = PoseidonBN254GoldilocksConfig; - - let build_path = "./verifier_data".to_string(); - let test_path = format!("{}/test_small/", build_path); - - let conf = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(conf); - - for _ in 0..(4096+10) { - builder.add_gate(NoopGate, vec![]); - } - // Add one virtual public input so that the circuit has minimal structure. - let t = builder.add_virtual_public_input(); - - // Set up the dummy circuit and wrapper. - let dummy_circuit = builder.build::(); - let mut pw = PartialWitness::new(); - pw.set_target(t, F::ZERO).expect("faulty assign"); - println!( - "dummy circuit degree: {}", - dummy_circuit.common.degree_bits() - ); - let dummy_inner_proof = dummy_circuit.prove(pw).unwrap(); - assert!(dummy_circuit.verify(dummy_inner_proof.clone()).is_ok()); - println!("Verified dummy_circuit"); - - // wrap this in the outer circuit. - let wrapper = WrapCircuit::::new(dummy_circuit.verifier_data()); - let (targ, data) = wrapper.build_with_standard_config().unwrap(); - println!( - "wrapper circuit degree: {}", - data.common.degree_bits() - ); - let verifier_data = data.verifier_data(); - let prover_data = data.prover_data(); - let wrap_input = WrapInput{ - inner_proof: dummy_inner_proof, - }; - let proof = wrapper.prove(&targ, &wrap_input,&prover_data).unwrap(); - - let wrap_circ = WrappedOutput::{ - proof, - common_data: prover_data.common, - verifier_data: verifier_data.verifier_only, - }; - - wrap_circ.save(test_path).unwrap(); - println!("Saved test wrapped circuit"); - Ok(()) - } -} diff --git a/codex-plonky2-circuits/src/recursion/leaf.rs b/codex-plonky2-circuits/src/recursion/leaf.rs index 2887f5c..9bdd682 100755 --- a/codex-plonky2-circuits/src/recursion/leaf.rs +++ b/codex-plonky2-circuits/src/recursion/leaf.rs @@ -172,77 +172,4 @@ impl< } -#[cfg(test)] -mod tests { - use super::*; - use plonky2::plonk::config::PoseidonGoldilocksConfig; - use plonky2::plonk::circuit_builder::CircuitBuilder; - use plonky2::plonk::config::GenericConfig; - use plonky2_field::types::PrimeField64; - use plonky2::plonk::circuit_data::{CircuitConfig, CommonCircuitData}; - use plonky2_poseidon2::poseidon2_hash::poseidon2::Poseidon2Hash; - - // For our tests, we define: - const D: usize = 2; - type C = PoseidonGoldilocksConfig; - type F = >::F; - type H = Poseidon2Hash; - - /// A helper to build a minimal circuit and return the common circuit data. - fn dummy_common_circuit_data() -> CommonCircuitData { - let config = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(config); - // Add one virtual public input so that the circuit has minimal structure. - builder.add_virtual_public_input(); - let circuit = builder.build::(); - circuit.common.clone() - } - - // ---------------------------------------------------------------------------- - // End-to-End test for the entire leaf circuit. - #[test] - fn test_full_leaf_circuit() -> anyhow::Result<()> { - // get inner common - let common_data = dummy_common_circuit_data(); - - // Generate a dummy inner proof for the leaf using DummyProofGen - let (dummy_inner_proof, vd) = DummyProofGen::::gen_dummy_proof_and_vd_zero_pi(&common_data)?; - // let dummy_verifier_data = DummyProofGen::::gen_dummy_verifier_data(&common_data); - - // the leaf circuit. - let leaf = LeafCircuit::::new(vd.clone()); - - // Build the leaf circuit. - let (targets, circuit_data) = leaf.build_with_standard_config()?; - let verifier_data = circuit_data.verifier_data(); - let prover_data = circuit_data.prover_data(); - - // test leaf input - let input = LeafInput { - inner_proof: dummy_inner_proof, - flag: true, - index: 45, - }; - - let proof = leaf.prove(&targets, &input, &prover_data)?; - - // Verify the proof. - assert!(verifier_data.verify(proof.clone()).is_ok(), "Proof verification failed"); - - println!("Public inputs: {:?}", proof.public_inputs); - - // the flag buckets appeared at positions 8..12. - let flag_buckets: Vec = proof.public_inputs[9..13] - .iter() - .map(|f| f.to_canonical_u64()) - .collect(); - - // With index = 45, we expect bucket[1] = 2^13 = 8192, and the rest 0. - let expected = vec![0, 8192, 0, 0]; - assert_eq!(flag_buckets, expected, "Flag bucket values mismatch"); - - Ok(()) - } -} - diff --git a/codex-plonky2-circuits/src/recursion/node.rs b/codex-plonky2-circuits/src/recursion/node.rs index 6c3531b..5de7713 100755 --- a/codex-plonky2-circuits/src/recursion/node.rs +++ b/codex-plonky2-circuits/src/recursion/node.rs @@ -252,115 +252,3 @@ impl< } } -#[cfg(test)] -mod tests { - use super::*; - use plonky2::plonk::config::PoseidonGoldilocksConfig; - use plonky2::plonk::circuit_builder::CircuitBuilder; - use plonky2::plonk::config::GenericConfig; - use plonky2_field::types::{Field, PrimeField64}; - use plonky2::plonk::circuit_data::{CircuitConfig, CircuitData}; - use plonky2_poseidon2::poseidon2_hash::poseidon2:: Poseidon2Hash; - use crate::recursion::leaf::BUCKET_SIZE; - - - // For our tests, we define: - const D: usize = 2; - type C = PoseidonGoldilocksConfig; - type F = >::F; - type H = Poseidon2Hash; - - /// A helper to build a minimal leaf circuit (with 9+B public inputs) - /// and return the circuit data and targets - fn dummy_leaf() -> (CircuitData, Vec) { - let config = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(config); - let mut pub_input = vec![]; - for _i in 0..9+B { - pub_input.push(builder.add_virtual_public_input()); - } - let data = builder.build::(); - (data, pub_input) - } - - /// A helper to generate test leaf proofs with given data, targets, and indices. - fn dummy_leaf_proofs(data: CircuitData, pub_input: Vec, indices: Vec) -> Vec> { - let mut proofs = vec![]; - for k in 0..indices.len() { - let mut pw = PartialWitness::new(); - for i in 0..8 { - pw.set_target(pub_input[i], F::ZERO).expect("assign error"); - } - pw.set_target(pub_input[8], F::from_canonical_u64(indices[k] as u64)).expect("assign error"); - let f_buckets = fill_buckets(indices[k], BUCKET_SIZE, B); - for i in 0..f_buckets.len() { - pw.set_target(pub_input[9 + i], f_buckets[i]).expect("assign error"); - } - // Run all the generators. (This method is typically called in the proving process.) - proofs.push(data.prove(pw).expect("prove failed")); - } - proofs - } - - /// helper: returns the flag buckets with the single bit at given `index` set to true `1` - fn fill_buckets(index: usize, bucket_size: usize, num_buckets: usize) -> Vec{ - assert!(index < bucket_size * num_buckets, "Index out of range"); - - let q = index / bucket_size; // bucket index - let r = index % bucket_size; // bucket bit - - let mut buckets = vec![F::ZERO; num_buckets]; - // Set the selected bucket to 2^r. - buckets[q] = F::from_canonical_u64(1 << r); - buckets - } - - /// End-to-End test for the entire node circuit. - #[test] - fn test_full_node_circuit() -> anyhow::Result<()> { - const N: usize = 2; - const B: usize = 4; // bucket size - const T: usize = 128; - - let (leaf_data, leaf_pi) = dummy_leaf::(); - let leaf_vd = leaf_data.verifier_data(); - - let indices = vec![0,1]; - let leaf_proofs = dummy_leaf_proofs::(leaf_data,leaf_pi,indices); - - let node = NodeCircuit::::new(leaf_vd.clone()); - - // Build the node circuit. - let (targets, circuit_data) = node.build_with_standard_config()?; - let verifier_data = circuit_data.verifier_data(); - let prover_data = circuit_data.prover_data(); - - // node input - let input = NodeInput { - inner_proofs: leaf_proofs, - verifier_only_data: leaf_vd.verifier_only.clone(), - condition: false, - flags: vec![true, true], - index: 0, - }; - - let proof = node.prove(&targets, &input, &prover_data)?; - - // Verify the proof. - assert!(verifier_data.verify(proof.clone()).is_ok(), "Proof verification failed"); - - println!("Public inputs: {:?}", proof.public_inputs); - - // the flag buckets appeared at positions 8..12. - let flag_buckets: Vec = proof.public_inputs[9..(9+B)] - .iter() - .map(|f| f.to_canonical_u64()) - .collect(); - - // With index = 45, we expect bucket 1 = 2^13 = 8192, and the rest 0. - let expected = vec![3, 0, 0, 0]; - assert_eq!(flag_buckets, expected, "Flag bucket values mismatch"); - - Ok(()) - } -} diff --git a/codex-plonky2-circuits/src/recursion/tree.rs b/codex-plonky2-circuits/src/recursion/tree.rs index ab33e22..93c6bdd 100755 --- a/codex-plonky2-circuits/src/recursion/tree.rs +++ b/codex-plonky2-circuits/src/recursion/tree.rs @@ -301,62 +301,3 @@ impl< Ok(()) } } - -#[cfg(test)] -mod tests { - use plonky2::gates::noop::NoopGate; - use super::*; - use plonky2::plonk::config::PoseidonGoldilocksConfig; - use plonky2::plonk::circuit_builder::CircuitBuilder; - use plonky2::plonk::config::GenericConfig; - use plonky2_field::types::Field; - use plonky2::plonk::circuit_data::CircuitConfig; - use plonky2_poseidon2::poseidon2_hash::poseidon2::Poseidon2Hash; - use plonky2::iop::witness::WitnessWrite; - - const D: usize = 2; - type C = PoseidonGoldilocksConfig; - type F = >::F; - type H = Poseidon2Hash; - - // A helper to build a minimal circuit and returns T proofs & circuit data. - fn dummy_proofs() -> (CircuitData, Vec>) { - let config = CircuitConfig::standard_recursion_config(); - let mut builder = CircuitBuilder::::new(config); - for _ in 0..(4096+10) { - builder.add_gate(NoopGate, vec![]); - } - // Add one virtual public input so that the circuit has minimal structure. - let t = builder.add_virtual_public_input(); - let circuit = builder.build::(); - println!("inner circuit size = {}", circuit.common.degree_bits()); - let mut pw = PartialWitness::::new(); - pw.set_target(t, F::ZERO).expect("faulty assign"); - let proofs = (0..T).map(|_i| circuit.prove(pw.clone()).unwrap()).collect(); - (circuit, proofs) - } - - - // End-to-End test for the entire Tree circuit. - #[test] - fn test_full_tree_circuit() -> anyhow::Result<()> { - const N: usize = 2; - const T: usize = 128; - - let (data, proofs) = dummy_proofs::(); - - let mut tree = TreeRecursion::::build_with_standard_config(data.verifier_data())?; - - // aggregate - no compression - let root = tree.prove_tree(&proofs)?; - println!("pub input size = {}", root.public_inputs.len()); - println!("proof size = {:?} bytes", root.to_bytes().len()); - - assert!( - tree.verify_proof(root, false).is_ok(), - "proof verification failed" - ); - - Ok(()) - } -} \ No newline at end of file diff --git a/codex-plonky2-circuits/src/recursion/utils.rs b/codex-plonky2-circuits/src/recursion/utils.rs index a55bef1..42562d5 100755 --- a/codex-plonky2-circuits/src/recursion/utils.rs +++ b/codex-plonky2-circuits/src/recursion/utils.rs @@ -158,109 +158,4 @@ pub fn get_hash_of_verifier_data< H::hash_no_pad(&vd) } -#[cfg(test)] -mod tests { - use super::*; - use plonky2::plonk::config::PoseidonGoldilocksConfig; - use plonky2::plonk::circuit_builder::CircuitBuilder; - use plonky2::plonk::config::GenericConfig; - use plonky2_field::types::{Field, PrimeField64}; - use plonky2::plonk::circuit_data::CircuitConfig; - // use plonky2_poseidon2::poseidon2_hash::poseidon2::Poseidon2; - use plonky2::iop::witness::PartialWitness; - - // For our tests, we define: - const D: usize = 2; - type C = PoseidonGoldilocksConfig; - type F = >::F; - - // Helper: Build, prove, and return public inputs --- - fn build_and_prove(builder: CircuitBuilder) -> Vec { - // Build the circuit. - let circuit = builder.build::(); - let pw = PartialWitness::new(); - // prove - let p= circuit.prove(pw).expect("prove failed"); - - p.public_inputs - } - - #[test] - fn test_split_index() -> anyhow::Result<()> { - // Create a circuit where we register the outputs q and r of split_index. - let mut builder = CircuitBuilder::::new(CircuitConfig::standard_recursion_config()); - // Let index = 45. - let index_val: u64 = 45; - let index_target = builder.constant(F::from_canonical_u64(index_val)); - // Call split_index with bucket_size=32 and num_buckets=4. We expect q = 1 and r = 13. - let (q_target, r_target) = - split_index::(&mut builder, index_target, BUCKET_SIZE, 4)?; - // Register outputs as public inputs. - builder.register_public_input(q_target); - builder.register_public_input(r_target); - // Build and prove the circuit. - let pub_inputs = build_and_prove(builder); - // We expect the first public input to be q = 1 and the second r = 13. - assert_eq!(pub_inputs[0].to_canonical_u64(), 1, "q should be 1"); - assert_eq!(pub_inputs[1].to_canonical_u64(), 13, "r should be 13"); - Ok(()) - } - - #[test] - fn test_compute_power_of_two() -> anyhow::Result<()> { - // Create a circuit to compute 2^r. - let mut builder = CircuitBuilder::::new(CircuitConfig::standard_recursion_config()); - // Let r = 13. - let r_val: u64 = 13; - let r_target = builder.constant(F::from_canonical_u64(r_val)); - let pow_target = - compute_power_of_two::(&mut builder, r_target)?; - builder.register_public_input(pow_target); - let pub_inputs = build_and_prove(builder); - // Expect 2^13 = 8192. - assert_eq!( - pub_inputs[0].to_canonical_u64(), - 1 << 13, - "2^13 should be 8192" - ); - Ok(()) - } - - #[test] - fn test_compute_flag_buckets() -> anyhow::Result<()> { - // Create a circuit to compute flag buckets. - // Let index = 45 and flag = true. - let mut builder = CircuitBuilder::::new(CircuitConfig::standard_recursion_config()); - let index_val: u64 = 45; - let index_target = builder.constant(F::from_canonical_u64(index_val)); - // Create a boolean constant target for flag = true. - let flag_target = builder.constant_bool(true); - // Compute the flag buckets with bucket_size = 32 and num_buckets = 4. - let buckets = compute_flag_buckets::( - &mut builder, - index_target, - flag_target, - BUCKET_SIZE, - 4, - )?; - // Register each bucket as a public input. - for bucket in buckets.iter() { - builder.register_public_input(*bucket); - } - let pub_inputs = build_and_prove(builder); - // With index = 45, we expect: - // q = 45 / 32 = 1 and r = 45 % 32 = 13, so bucket 1 should be 2^13 = 8192 and the others 0. - let expected = vec![0, 8192, 0, 0]; - for (i, &expected_val) in expected.iter().enumerate() { - let computed = pub_inputs[i].to_canonical_u64(); - assert_eq!( - computed, expected_val, - "Bucket {}: expected {} but got {}", - i, expected_val, computed - ); - } - Ok(()) - } -} -