Small nits for the exponentiation gate

This commit is contained in:
wborgeaud 2021-08-02 13:12:50 +02:00
parent 36a1386c6f
commit fc9d64defe
2 changed files with 6 additions and 4 deletions

View File

@ -112,11 +112,12 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
base: Target, base: Target,
exponent_bits: impl Iterator<Item = impl Borrow<Target>>, exponent_bits: impl Iterator<Item = impl Borrow<Target>>,
) -> Target { ) -> Target {
let zero = self.zero();
let gate = ExponentiationGate::new(self.config.clone()); let gate = ExponentiationGate::new(self.config.clone());
let num_power_bits = gate.num_power_bits; let num_power_bits = gate.num_power_bits;
let mut exp_bits_vec: Vec<Target> = exponent_bits.map(|b| *b.borrow()).collect(); let mut exp_bits_vec: Vec<Target> = exponent_bits.map(|b| *b.borrow()).collect();
while exp_bits_vec.len() < num_power_bits { while exp_bits_vec.len() < num_power_bits {
exp_bits_vec.push(self.constant(F::ZERO)); exp_bits_vec.push(zero);
} }
let gate_index = self.add_gate(gate.clone(), vec![]); let gate_index = self.add_gate(gate.clone(), vec![]);

View File

@ -29,8 +29,9 @@ impl<F: Extendable<D>, const D: usize> ExponentiationGate<F, D> {
} }
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; // 2 wires are reserved for the base and output.
let max_for_wires = (num_wires - 3) / 2; let max_for_routed_wires = num_routed_wires - 2;
let max_for_wires = (num_wires - 2) / 2;
max_for_routed_wires.min(max_for_wires) max_for_routed_wires.min(max_for_wires)
} }
@ -147,7 +148,7 @@ impl<F: Extendable<D>, const D: usize> Gate<F, D> for ExponentiationGate<F, D> {
let mut constraints = Vec::new(); let mut constraints = Vec::new();
let one = builder.constant_extension(F::Extension::ONE); let one = builder.one_extension();
for i in 0..self.num_power_bits { for i in 0..self.num_power_bits {
let prev_intermediate_value = if i == 0 { let prev_intermediate_value = if i == 0 {
one one