From b9adf84d1c08f649efe7d6b089d62522003ad0c7 Mon Sep 17 00:00:00 2001 From: Steven Gu Date: Tue, 7 Nov 2023 17:01:47 +0800 Subject: [PATCH] Update unit test for single-layer-aggregation. --- snark-verifier-sdk/src/tests/mod.rs | 14 ++++++++++++-- .../src/tests/single_layer_aggregation.rs | 6 +++--- snark-verifier-sdk/src/tests/test_circuit_1.rs | 11 +++++++++++ snark-verifier-sdk/src/tests/test_circuit_2.rs | 11 +++++++++++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/snark-verifier-sdk/src/tests/mod.rs b/snark-verifier-sdk/src/tests/mod.rs index 22d0737c..1ed39dd7 100644 --- a/snark-verifier-sdk/src/tests/mod.rs +++ b/snark-verifier-sdk/src/tests/mod.rs @@ -1,7 +1,7 @@ use halo2_base::halo2_proofs; use halo2_proofs::{ halo2curves::bn256::Fr, - plonk::{Advice, Column, ConstraintSystem, Fixed, Instance}, + plonk::{Advice, Column, ConstraintSystem, Fixed, Instance, TableColumn}, poly::Rotation, }; use test_circuit_1::TestCircuit1; @@ -25,6 +25,7 @@ pub struct StandardPlonkConfig { constant: Column, #[allow(dead_code)] instance: Column, + table: TableColumn, } impl StandardPlonkConfig { @@ -32,6 +33,7 @@ impl StandardPlonkConfig { let [a, b, c] = [(); 3].map(|_| meta.advice_column()); let [q_a, q_b, q_c, q_ab, constant] = [(); 5].map(|_| meta.fixed_column()); let instance = meta.instance_column(); + let table = meta.lookup_table_column(); [a, b, c].map(|column| meta.enable_equality(column)); @@ -53,6 +55,14 @@ impl StandardPlonkConfig { }, ); - StandardPlonkConfig { a, b, c, q_a, q_b, q_c, q_ab, constant, instance } + // Lookup for multiple times to test mv-lookup. + (0..5).for_each(|_| { + meta.lookup("lookup a", |meta| { + let a = meta.query_advice(a, Rotation::cur()); + vec![(a, table)] + }) + }); + + StandardPlonkConfig { a, b, c, q_a, q_b, q_c, q_ab, constant, instance, table } } } diff --git a/snark-verifier-sdk/src/tests/single_layer_aggregation.rs b/snark-verifier-sdk/src/tests/single_layer_aggregation.rs index c937d667..36f3d25c 100644 --- a/snark-verifier-sdk/src/tests/single_layer_aggregation.rs +++ b/snark-verifier-sdk/src/tests/single_layer_aggregation.rs @@ -18,7 +18,7 @@ use std::path::Path; fn test_shplonk_then_sphplonk_with_evm_verification() { std::env::set_var("VERIFY_CONFIG", "./configs/example_evm_accumulator.config"); let k = 8; - let k_agg = 21; + let k_agg = 24; let mut rng = test_rng(); let params_outer = gen_srs(k_agg); @@ -46,7 +46,7 @@ fn test_shplonk_then_sphplonk_with_evm_verification() { let snarks_2 = gen_snark_shplonk( ¶ms_inner, &pk_inner_2, - circuit_1.clone(), + circuit_2.clone(), &mut rng, Some(Path::new("data/inner_2.snark")), ); @@ -54,7 +54,7 @@ fn test_shplonk_then_sphplonk_with_evm_verification() { // Proof for circuit 2 let circuit_3 = TestCircuit2::rand(&mut rng); - let pk_inner_3 = gen_pk(¶ms_inner, &circuit_1, Some(Path::new("data/inner_3.pkey"))); + let pk_inner_3 = gen_pk(¶ms_inner, &circuit_3, Some(Path::new("data/inner_3.pkey"))); let snarks_3 = gen_snark_shplonk( ¶ms_inner, &pk_inner_3, diff --git a/snark-verifier-sdk/src/tests/test_circuit_1.rs b/snark-verifier-sdk/src/tests/test_circuit_1.rs index f2e1f7ac..c5a429e0 100644 --- a/snark-verifier-sdk/src/tests/test_circuit_1.rs +++ b/snark-verifier-sdk/src/tests/test_circuit_1.rs @@ -66,6 +66,17 @@ impl Circuit for TestCircuit1 { a.copy_advice(|| "", &mut region, config.b, 3)?; a.copy_advice(|| "", &mut region, config.c, 4)?; + Ok(()) + }, + )?; + + layouter.assign_table( + || "lookup table for values of `a`", + |mut table| { + for (i, value) in [self.0, Fr::zero(), Fr::one(), -Fr::from(5)].iter().enumerate() { + table.assign_cell(|| "", config.table, i, || Value::known(value))?; + } + Ok(()) }, ) diff --git a/snark-verifier-sdk/src/tests/test_circuit_2.rs b/snark-verifier-sdk/src/tests/test_circuit_2.rs index 687cbcc5..c1953eca 100644 --- a/snark-verifier-sdk/src/tests/test_circuit_2.rs +++ b/snark-verifier-sdk/src/tests/test_circuit_2.rs @@ -61,6 +61,17 @@ impl Circuit for TestCircuit2 { a.copy_advice(|| "", &mut region, config.b, 3)?; a.copy_advice(|| "", &mut region, config.c, 4)?; + Ok(()) + }, + )?; + + layouter.assign_table( + || "lookup table for values of `a`", + |mut table| { + for (i, value) in [self.0, Fr::zero(), Fr::one(), -Fr::from(5)].iter().enumerate() { + table.assign_cell(|| "", config.table, i, || Value::known(value))?; + } + Ok(()) }, )