From 859cc3ada91d344eca9781f57f20e87d6a4c29f5 Mon Sep 17 00:00:00 2001 From: caojiafeng Date: Wed, 24 Jan 2024 14:38:27 +0800 Subject: [PATCH] fix instance (#68) when no instance column exists, we should not pass empty instances --- .../src/examples/circuit_layout.rs | 14 ++++---- .../vk-gen-examples/src/examples/shuffle.rs | 4 +-- crates/vk-gen-examples/src/main.rs | 36 ++++++++++--------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/crates/vk-gen-examples/src/examples/circuit_layout.rs b/crates/vk-gen-examples/src/examples/circuit_layout.rs index 95dd224..4bb6519 100644 --- a/crates/vk-gen-examples/src/examples/circuit_layout.rs +++ b/crates/vk-gen-examples/src/examples/circuit_layout.rs @@ -271,19 +271,17 @@ impl Circuit for MyCircuit { } } -pub fn get_example_circuit() -> (MyCircuit, Vec) { +pub fn get_example_circuit() -> MyCircuit { // Prepare the circuit you want to render. // You don't need to include any witness variables. let a = F::random(OsRng); let instance = F::ONE + F::ONE; let lookup_table = vec![instance, a, a, F::ZERO]; - ( - MyCircuit { - a: Value::unknown(), - lookup_table, - }, - vec![], - ) + + MyCircuit { + a: Value::unknown(), + lookup_table, + } } // // ANCHOR: dev-graph diff --git a/crates/vk-gen-examples/src/examples/shuffle.rs b/crates/vk-gen-examples/src/examples/shuffle.rs index c738935..02cca92 100644 --- a/crates/vk-gen-examples/src/examples/shuffle.rs +++ b/crates/vk-gen-examples/src/examples/shuffle.rs @@ -321,8 +321,8 @@ fn test_prover( assert_eq!(accepted, expected); } -pub fn get_example_circuit() -> (MyCircuit, Vec) { - (MyCircuit::::rand(&mut OsRng), vec![]) +pub fn get_example_circuit() -> MyCircuit { + MyCircuit::::rand(&mut OsRng) } // fn main() { diff --git a/crates/vk-gen-examples/src/main.rs b/crates/vk-gen-examples/src/main.rs index f65c84e..45e1d02 100644 --- a/crates/vk-gen-examples/src/main.rs +++ b/crates/vk-gen-examples/src/main.rs @@ -139,7 +139,7 @@ fn main() -> anyhow::Result<()> { Examples::CircuitLayout => { let circuit = circuit_layout::get_example_circuit::(); - generate_circuit_info(¶ms, &circuit.0)? + generate_circuit_info(¶ms, &circuit)? } Examples::Serialization => { let circuit = serialization::get_example_circuit(); @@ -147,7 +147,7 @@ fn main() -> anyhow::Result<()> { } Examples::Shuffle => { let circuit = shuffle::get_example_circuit(); - generate_circuit_info(¶ms, &circuit.0)? + generate_circuit_info(¶ms, &circuit)? } Examples::SimpleExample => { let circuit = simple_example::get_example_circuit(); @@ -206,49 +206,49 @@ fn main() -> anyhow::Result<()> { }; let (proof, instances) = match example { Examples::CircuitLayout => { - let (circuit, instances) = circuit_layout::get_example_circuit::(); + let circuit = circuit_layout::get_example_circuit::(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); - let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + let proof = prove_with_keccak256(circuit, &[], ¶ms, pk, kzg); + (proof, vec![]) } Examples::Serialization => { let (circuit, instances) = serialization::get_example_circuit(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + (proof, vec![instances]) } Examples::Shuffle => { - let (circuit, instances) = shuffle::get_example_circuit::(); + let circuit = shuffle::get_example_circuit::(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); - let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + let proof = prove_with_keccak256(circuit, &[], ¶ms, pk, kzg); + (proof, vec![]) } Examples::SimpleExample => { let (circuit, instances) = simple_example::get_example_circuit::(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + (proof, vec![instances]) } Examples::TwoChip => { let (circuit, instances) = two_chip::get_example_circuit::(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + (proof, vec![instances]) } Examples::VectorMul => { let (circuit, instances) = vector_mul::get_example_circuit::(); let vk = keygen_vk(¶ms, &circuit).unwrap(); let pk = keygen_pk(¶ms, vk, &circuit).unwrap(); let proof = prove_with_keccak256(circuit, &[&instances], ¶ms, pk, kzg); - (proof, instances) + (proof, vec![instances]) } }; - let instances: Vec<_> = instances.iter().map(|fr| fr.to_bytes().to_vec()).collect(); + //let instances: Vec<_> = instances.iter().map(|fr| fr.to_bytes().to_vec()).collect(); let json = EntryFunctionArgumentsJSON { function_id: format!( "{}::{}::{}", @@ -266,10 +266,14 @@ fn main() -> anyhow::Result<()> { }, ArgWithTypeJSON { arg_type: "hex".to_string(), - value: json!(vec![instances + value: json!(instances .into_iter() - .map(|i| HexEncodedBytes(i).to_string()) - .collect::>()]), + .map(|is| is + .iter() + .map(|fr| fr.to_bytes().to_vec()) + .map(|d| HexEncodedBytes(d).to_string()) + .collect::>()) + .collect::>()), }, ArgWithTypeJSON { arg_type: "hex".to_string(),