From 432d72f462ed47ccf5c93b1111afed14c95db52b Mon Sep 17 00:00:00 2001 From: han0110 Date: Tue, 20 Sep 2022 01:30:20 +0800 Subject: [PATCH] fix: iterate on `instance_queries` to calculate correct `instance_evals` --- halo2_proofs/src/plonk/verifier.rs | 35 +++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/halo2_proofs/src/plonk/verifier.rs b/halo2_proofs/src/plonk/verifier.rs index 1dc7f26f..e6a2327e 100644 --- a/halo2_proofs/src/plonk/verifier.rs +++ b/halo2_proofs/src/plonk/verifier.rs @@ -175,21 +175,40 @@ pub fn verify_proof< .collect::, _>>()? } else { let xn = x.pow(&[params.n() as u64, 0, 0, 0]); + let (min_rotation, max_rotation) = + vk.cs + .instance_queries + .iter() + .fold((0, 0), |(min, max), (_, rotation)| { + if rotation.0 < min { + (rotation.0, max) + } else if rotation.0 > max { + (min, rotation.0) + } else { + (min, max) + } + }); + let max_instance_len = instances + .iter() + .flat_map(|instance| instance.iter().map(|instance| instance.len())) + .max_by(Ord::cmp) + .unwrap_or_default(); let l_i_s = &vk.domain.l_i_range( *x, xn, - 0..instances - .iter() - .flat_map(|instance| instance.iter().map(|instance| instance.len())) - .max_by(Ord::cmp) - .unwrap_or_default() as i32, + -max_rotation..max_instance_len as i32 + min_rotation.abs(), ); instances .iter() - .map(|instance| { - instance + .map(|instances| { + vk.cs + .instance_queries .iter() - .map(|instance| compute_inner_product(instance, &l_i_s[..instance.len()])) + .map(|(column, rotation)| { + let instances = instances[column.index()]; + let offset = (max_rotation - rotation.0) as usize; + compute_inner_product(instances, &l_i_s[offset..offset + instances.len()]) + }) .collect::>() }) .collect::>()