diff --git a/src/gadgets/arithmetic.rs b/src/gadgets/arithmetic.rs index b79e4da4..bf3c188d 100644 --- a/src/gadgets/arithmetic.rs +++ b/src/gadgets/arithmetic.rs @@ -176,8 +176,12 @@ impl, const D: usize> CircuitBuilder { base: Target, exponent_bits: impl Iterator>, ) -> Target { - let exp_bits_vec: Vec = exponent_bits.map(|b| *b.borrow()).collect(); - let gate = ExponentiationGate::new(exp_bits_vec.len()); + let gate = ExponentiationGate::new(self.config.clone()); + let num_power_bits = gate.num_power_bits; + let mut exp_bits_vec: Vec = exponent_bits.map(|b| *b.borrow()).collect(); + while exp_bits_vec.len() < num_power_bits { + exp_bits_vec.push(self.constant(F::ZERO)); + } let gate_index = self.add_gate(gate.clone(), vec![]); self.route(base, Target::wire(gate_index, gate.wire_base())); diff --git a/src/gates/exponentiation.rs b/src/gates/exponentiation.rs index 4ef52d49..2f33e5d9 100644 --- a/src/gates/exponentiation.rs +++ b/src/gates/exponentiation.rs @@ -1,6 +1,7 @@ use std::marker::PhantomData; use crate::circuit_builder::CircuitBuilder; +use crate::circuit_data::CircuitConfig; use crate::field::extension_field::target::ExtensionTarget; use crate::field::extension_field::Extendable; use crate::field::field::Field; @@ -19,14 +20,15 @@ pub(crate) struct ExponentiationGate, const D: usize> { } impl, const D: usize> ExponentiationGate { - pub fn new(num_power_bits: usize) -> Self { + pub fn new(config: CircuitConfig) -> Self { + let num_power_bits = Self::max_power_bits(config.num_wires, config.num_routed_wires); Self { num_power_bits, _phantom: PhantomData, } } - pub fn max_power_bits(num_wires: usize, num_routed_wires: usize) -> usize { + fn max_power_bits(num_wires: usize, num_routed_wires: usize) -> usize { let max_for_routed_wires = num_routed_wires - 3; let max_for_wires = (num_wires - 3) / 2; max_for_routed_wires.min(max_for_wires) @@ -261,9 +263,11 @@ mod tests { use rand::Rng; + use crate::circuit_data::CircuitConfig; use crate::field::crandall_field::CrandallField; use crate::field::extension_field::quartic::QuarticCrandallField; use crate::field::field::Field; + use crate::fri::FriConfig; use crate::gates::exponentiation::ExponentiationGate; use crate::gates::gate::Gate; use crate::gates::gate_testing::test_low_degree; @@ -290,7 +294,13 @@ mod tests { #[test] fn low_degree() { - test_low_degree::(ExponentiationGate::new(5)); + let config = CircuitConfig { + num_wires: 120, + num_routed_wires: 30, + ..CircuitConfig::large_config() + }; + + test_low_degree::(ExponentiationGate::new(config)); } #[test]