new exp gate takes in CircuitConfig and determines num_bits

This commit is contained in:
Nicholas Ward 2021-07-29 10:26:46 -07:00
parent df03c22c48
commit 56b62f1964
2 changed files with 21 additions and 3 deletions

View File

@ -178,7 +178,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
exponent_bits: impl Iterator<Item = impl Borrow<Target>>, exponent_bits: impl Iterator<Item = impl Borrow<Target>>,
) -> Target { ) -> Target {
let exp_bits_vec: Vec<Target> = exponent_bits.map(|b| *b.borrow()).collect(); let exp_bits_vec: Vec<Target> = exponent_bits.map(|b| *b.borrow()).collect();
let gate = ExponentiationGate::new(exp_bits_vec.len()); let gate = ExponentiationGate::new(self.config.clone());
let gate_index = self.add_gate(gate.clone(), vec![]); let gate_index = self.add_gate(gate.clone(), vec![]);
let two = self.constant(F::TWO); let two = self.constant(F::TWO);

View File

@ -1,6 +1,7 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use crate::circuit_builder::CircuitBuilder; use crate::circuit_builder::CircuitBuilder;
use crate::circuit_data::CircuitConfig;
use crate::field::extension_field::target::ExtensionTarget; use crate::field::extension_field::target::ExtensionTarget;
use crate::field::extension_field::Extendable; use crate::field::extension_field::Extendable;
use crate::field::field::Field; use crate::field::field::Field;
@ -20,7 +21,8 @@ pub(crate) struct ExponentiationGate<F: Extendable<D>, const D: usize> {
} }
impl<F: Extendable<D>, const D: usize> ExponentiationGate<F, D> { impl<F: Extendable<D>, const D: usize> ExponentiationGate<F, D> {
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 { Self {
num_power_bits, num_power_bits,
_phantom: PhantomData, _phantom: PhantomData,
@ -281,9 +283,11 @@ mod tests {
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use crate::circuit_data::CircuitConfig;
use crate::field::crandall_field::CrandallField; use crate::field::crandall_field::CrandallField;
use crate::field::extension_field::quartic::QuarticCrandallField; use crate::field::extension_field::quartic::QuarticCrandallField;
use crate::field::field::Field; use crate::field::field::Field;
use crate::fri::FriConfig;
use crate::gates::exponentiation::ExponentiationGate; use crate::gates::exponentiation::ExponentiationGate;
use crate::gates::gate::Gate; use crate::gates::gate::Gate;
use crate::gates::gate_testing::test_low_degree; use crate::gates::gate_testing::test_low_degree;
@ -311,7 +315,21 @@ mod tests {
#[test] #[test]
fn low_degree() { fn low_degree() {
test_low_degree::<CrandallField, _, 4>(ExponentiationGate::new(5)); let config = CircuitConfig {
num_wires: 120,
num_routed_wires: 30,
security_bits: 0,
rate_bits: 0,
num_challenges: 0,
zero_knowledge: false,
fri_config: FriConfig {
proof_of_work_bits: 0,
reduction_arity_bits: Vec::new(),
num_query_rounds: 0,
},
};
test_low_degree::<CrandallField, _, 4>(ExponentiationGate::new(config));
} }
#[test] #[test]