From 49e4307820bb298e9b1bcbff2a8ca91905b5bf23 Mon Sep 17 00:00:00 2001 From: wborgeaud Date: Mon, 15 Nov 2021 13:35:21 +0100 Subject: [PATCH] Comments + test for reducing 100 extension elements --- src/gates/reducing_extension.rs | 16 +++++++--------- src/util/reducing.rs | 5 +++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/gates/reducing_extension.rs b/src/gates/reducing_extension.rs index 99d40fba..532b484f 100644 --- a/src/gates/reducing_extension.rs +++ b/src/gates/reducing_extension.rs @@ -23,6 +23,8 @@ impl ReducingExtensionGate { } pub fn max_coeffs_len(num_wires: usize, num_routed_wires: usize) -> usize { + // `3*D` routed wires are used for the output, alpha and old accumulator. + // Need `num_coeffs*D` routed wires for coeffs, and `(num_coeffs-1)*D` wires for accumulators. ((num_routed_wires - 3 * D) / D).min((num_wires - 2 * D) / (D * 2)) } @@ -43,6 +45,7 @@ impl ReducingExtensionGate { Self::START_COEFFS + self.num_coeffs * D } fn wires_accs(&self, i: usize) -> Range { + debug_assert!(i < self.num_coeffs); if i == self.num_coeffs - 1 { // The last accumulator is the output. return Self::wires_output(); @@ -176,23 +179,19 @@ impl, const D: usize> SimpleGenerator for ReducingGenerator< } fn run_once(&self, witness: &PartitionWitness, out_buffer: &mut GeneratedValues) { - let extract_extension = |range: Range| -> F::Extension { + let local_extension = |range: Range| -> F::Extension { let t = ExtensionTarget::from_range(self.gate_index, range); witness.get_extension_target(t) }; - let alpha = extract_extension(ReducingExtensionGate::::wires_alpha()); - let old_acc = extract_extension(ReducingExtensionGate::::wires_old_acc()); + let alpha = local_extension(ReducingExtensionGate::::wires_alpha()); + let old_acc = local_extension(ReducingExtensionGate::::wires_old_acc()); let coeffs = (0..self.gate.num_coeffs) - .map(|i| extract_extension(ReducingExtensionGate::::wires_coeff(i))) + .map(|i| local_extension(ReducingExtensionGate::::wires_coeff(i))) .collect::>(); let accs = (0..self.gate.num_coeffs) .map(|i| ExtensionTarget::from_range(self.gate_index, self.gate.wires_accs(i))) .collect::>(); - let output = ExtensionTarget::from_range( - self.gate_index, - ReducingExtensionGate::::wires_output(), - ); let mut acc = old_acc; for i in 0..self.gate.num_coeffs { @@ -200,7 +199,6 @@ impl, const D: usize> SimpleGenerator for ReducingGenerator< out_buffer.set_extension_target(accs[i], computed_acc); acc = computed_acc; } - out_buffer.set_extension_target(output, acc); } } diff --git a/src/util/reducing.rs b/src/util/reducing.rs index f10f412d..1cddc3e7 100644 --- a/src/util/reducing.rs +++ b/src/util/reducing.rs @@ -330,4 +330,9 @@ mod tests { fn test_reduce_gadget_base_100() -> Result<()> { test_reduce_gadget_base(100) } + + #[test] + fn test_reduce_gadget_100() -> Result<()> { + test_reduce_gadget(100) + } }