From 0b75b24c0980c51922bca2f05e3868da9fa21ab1 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Wed, 20 Oct 2021 23:43:35 -0700 Subject: [PATCH] Have split_low_high use range_check (#311) --- src/gadgets/range_check.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gadgets/range_check.rs b/src/gadgets/range_check.rs index 547abe25..f3b58d4a 100644 --- a/src/gadgets/range_check.rs +++ b/src/gadgets/range_check.rs @@ -24,10 +24,9 @@ impl, const D: usize> CircuitBuilder { /// Returns `(a,b)` such that `x = a + 2^n_log * b` with `a < 2^n_log`. /// `x` is assumed to be range-checked for having `num_bits` bits. pub fn split_low_high(&mut self, x: Target, n_log: usize, num_bits: usize) -> (Target, Target) { - let low_gate = self.add_gate(BaseSumGate::<2>::new(n_log), vec![]); - let high_gate = self.add_gate(BaseSumGate::<2>::new(num_bits - n_log), vec![]); - let low = Target::wire(low_gate, BaseSumGate::<2>::WIRE_SUM); - let high = Target::wire(high_gate, BaseSumGate::<2>::WIRE_SUM); + let low = self.add_virtual_target(); + let high = self.add_virtual_target(); + self.add_simple_generator(LowHighGenerator { integer: x, n_log, @@ -35,6 +34,9 @@ impl, const D: usize> CircuitBuilder { high, }); + self.range_check(low, n_log); + self.range_check(high, num_bits - n_log); + let pow2 = self.constant(F::from_canonical_u64(1 << n_log)); let comp_x = self.mul_add(high, pow2, low); self.connect(x, comp_x);