mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 00:33:06 +00:00
Renaming + Clippy
This commit is contained in:
parent
e647e17720
commit
5edaab59e6
@ -246,7 +246,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `a * b`, where `b` is in the extension field and `a` is in the base field.
|
/// Returns `a * b`, where `b` is in the extension field and `a` is in the base field.
|
||||||
pub fn scalar_mul_ext(&mut self, a: Target, mut b: ExtensionTarget<D>) -> ExtensionTarget<D> {
|
pub fn scalar_mul_ext(&mut self, a: Target, b: ExtensionTarget<D>) -> ExtensionTarget<D> {
|
||||||
let a_ext = self.convert_to_ext(a);
|
let a_ext = self.convert_to_ext(a);
|
||||||
self.mul_extension(a_ext, b)
|
self.mul_extension(a_ext, b)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use crate::circuit_builder::CircuitBuilder;
|
|||||||
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::target::Target;
|
use crate::target::Target;
|
||||||
use crate::util::bits_u64;
|
|
||||||
|
|
||||||
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||||
/// Inserts a `Target` in a vector at a non-deterministic index. This is done by rotating to the
|
/// Inserts a `Target` in a vector at a non-deterministic index. This is done by rotating to the
|
||||||
@ -12,7 +11,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
&mut self,
|
&mut self,
|
||||||
index: Target,
|
index: Target,
|
||||||
element: ExtensionTarget<D>,
|
element: ExtensionTarget<D>,
|
||||||
mut v: Vec<ExtensionTarget<D>>,
|
v: Vec<ExtensionTarget<D>>,
|
||||||
) -> Vec<ExtensionTarget<D>> {
|
) -> Vec<ExtensionTarget<D>> {
|
||||||
let mut v = self.rotate_left(index, &v);
|
let mut v = self.rotate_left(index, &v);
|
||||||
v.insert(0, element);
|
v.insert(0, element);
|
||||||
|
|||||||
@ -50,7 +50,7 @@ impl<F: Field> SimpleGenerator<F> for LowHighGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartialWitness<F>) -> PartialWitness<F> {
|
fn run_once(&self, witness: &PartialWitness<F>) -> PartialWitness<F> {
|
||||||
let mut integer_value = witness.get_target(self.integer).to_canonical_u64();
|
let integer_value = witness.get_target(self.integer).to_canonical_u64();
|
||||||
let low = integer_value & ((1 << self.n_log) - 1);
|
let low = integer_value & ((1 << self.n_log) - 1);
|
||||||
let high = integer_value >> self.n_log;
|
let high = integer_value >> self.n_log;
|
||||||
|
|
||||||
|
|||||||
@ -22,13 +22,13 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asserts that `x`'s bit representation has at least `trailing_zeros` trailing zeros.
|
/// Asserts that `x`'s big-endian bit representation has at least `trailing_zeros` trailing zeros.
|
||||||
pub(crate) fn assert_trailing_zeros<const B: usize>(&mut self, x: Target, trailing_zeros: u32) {
|
pub(crate) fn assert_trailing_zeros<const B: usize>(&mut self, x: Target, trailing_zeros: u32) {
|
||||||
let num_limbs = num_limbs(64, B);
|
let num_limbs = num_limbs(64, B);
|
||||||
let num_limbs_to_check = num_limbs_to_check(trailing_zeros, B);
|
let num_limbs_to_check = num_limbs_to_check(trailing_zeros, B);
|
||||||
let limbs = self.split_le_base::<B>(x, num_limbs);
|
let limbs = self.split_le_base::<B>(x, num_limbs);
|
||||||
assert!(
|
assert!(
|
||||||
num_limbs_to_check < self.config.num_routed_wires,
|
num_limbs_to_check <= self.config.num_routed_wires,
|
||||||
"Not enough routed wires."
|
"Not enough routed wires."
|
||||||
);
|
);
|
||||||
for i in 0..num_limbs_to_check {
|
for i in 0..num_limbs_to_check {
|
||||||
|
|||||||
@ -32,29 +32,30 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
if num_bits == 0 {
|
if num_bits == 0 {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
let num_limbs = self.config.num_routed_wires - BaseSumGate::<2>::START_LIMBS;
|
let bits_per_gate = self.config.num_routed_wires - BaseSumGate::<2>::START_LIMBS;
|
||||||
let k = ceil_div_usize(num_bits, num_limbs);
|
let k = ceil_div_usize(num_bits, bits_per_gate);
|
||||||
let gates = (0..k)
|
let gates = (0..k)
|
||||||
.map(|_| self.add_gate_no_constants(BaseSumGate::<2>::new(num_limbs)))
|
.map(|_| self.add_gate_no_constants(BaseSumGate::<2>::new(bits_per_gate)))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let mut bits = Vec::with_capacity(num_bits);
|
let mut bits = Vec::with_capacity(num_bits);
|
||||||
for &gate in &gates {
|
for &gate in &gates {
|
||||||
bits.extend(Target::wires_from_range(
|
bits.extend(Target::wires_from_range(
|
||||||
gate,
|
gate,
|
||||||
BaseSumGate::<2>::START_LIMBS..BaseSumGate::<2>::START_LIMBS + num_limbs,
|
BaseSumGate::<2>::START_LIMBS..BaseSumGate::<2>::START_LIMBS + bits_per_gate,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
bits.drain(num_bits..);
|
bits.drain(num_bits..);
|
||||||
|
|
||||||
let zero = self.zero();
|
let zero = self.zero();
|
||||||
|
let one = self.one();
|
||||||
let mut acc = zero;
|
let mut acc = zero;
|
||||||
for &gate in gates.iter().rev() {
|
for &gate in gates.iter().rev() {
|
||||||
let sum = Target::wire(gate, BaseSumGate::<2>::WIRE_SUM);
|
let sum = Target::wire(gate, BaseSumGate::<2>::WIRE_SUM);
|
||||||
acc = self.arithmetic(
|
acc = self.arithmetic(
|
||||||
F::from_canonical_usize(1 << num_limbs),
|
F::from_canonical_usize(1 << bits_per_gate),
|
||||||
acc,
|
acc,
|
||||||
zero,
|
one,
|
||||||
F::ONE,
|
F::ONE,
|
||||||
sum,
|
sum,
|
||||||
);
|
);
|
||||||
@ -64,7 +65,7 @@ impl<F: Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
self.add_generator(WireSplitGenerator {
|
self.add_generator(WireSplitGenerator {
|
||||||
integer,
|
integer,
|
||||||
gates,
|
gates,
|
||||||
num_limbs,
|
num_limbs: bits_per_gate,
|
||||||
});
|
});
|
||||||
|
|
||||||
bits
|
bits
|
||||||
|
|||||||
@ -11,7 +11,8 @@ use crate::target::Target;
|
|||||||
use crate::vars::{EvaluationTargets, EvaluationVars};
|
use crate::vars::{EvaluationTargets, EvaluationVars};
|
||||||
use crate::witness::PartialWitness;
|
use crate::witness::PartialWitness;
|
||||||
|
|
||||||
/// A gate which can sum base B limbs and the reversed limbs.
|
/// A gate which can decompose a number into base B little-endian limbs,
|
||||||
|
/// and compute the limb-reversed (i.e. big-endian) sum.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BaseSumGate<const B: usize> {
|
pub struct BaseSumGate<const B: usize> {
|
||||||
num_limbs: usize,
|
num_limbs: usize,
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
use std::convert::TryInto;
|
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use crate::circuit_builder::CircuitBuilder;
|
use crate::circuit_builder::CircuitBuilder;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user