mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-07 08:13:11 +00:00
Merge pull request #134 from mir-protocol/exp_gate_config
Exponentiation gate calculates number of bit wires
This commit is contained in:
commit
c02d48036e
@ -176,8 +176,12 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
base: Target,
|
||||
exponent_bits: impl Iterator<Item = impl Borrow<Target>>,
|
||||
) -> Target {
|
||||
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 num_power_bits = gate.num_power_bits;
|
||||
let mut exp_bits_vec: Vec<Target> = 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()));
|
||||
|
||||
@ -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<F: Extendable<D>, const D: usize> {
|
||||
}
|
||||
|
||||
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 {
|
||||
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::<CrandallField, _, 4>(ExponentiationGate::new(5));
|
||||
let config = CircuitConfig {
|
||||
num_wires: 120,
|
||||
num_routed_wires: 30,
|
||||
..CircuitConfig::large_config()
|
||||
};
|
||||
|
||||
test_low_degree::<CrandallField, _, 4>(ExponentiationGate::new(config));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user