mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-05-02 16:23:11 +00:00
Fix all clippy lints
This commit is contained in:
parent
549ce0d8e9
commit
2c06309cf7
@ -1,5 +1,7 @@
|
|||||||
//! Generates random constants using ChaCha20, seeded with zero.
|
//! Generates random constants using ChaCha20, seeded with zero.
|
||||||
|
|
||||||
|
#![allow(clippy::needless_range_loop)]
|
||||||
|
|
||||||
use plonky2::field::field_types::PrimeField;
|
use plonky2::field::field_types::PrimeField;
|
||||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||||
use rand::{Rng, SeedableRng};
|
use rand::{Rng, SeedableRng};
|
||||||
|
|||||||
@ -35,6 +35,7 @@ impl<const D: usize> ExtensionTarget<D> {
|
|||||||
let arr = self.to_target_array();
|
let arr = self.to_target_array();
|
||||||
let k = (F::order() - 1u32) / (D as u64);
|
let k = (F::order() - 1u32) / (D as u64);
|
||||||
let z0 = F::Extension::W.exp_biguint(&(k * count as u64));
|
let z0 = F::Extension::W.exp_biguint(&(k * count as u64));
|
||||||
|
#[allow(clippy::needless_collect)]
|
||||||
let zs = z0
|
let zs = z0
|
||||||
.powers()
|
.powers()
|
||||||
.take(D)
|
.take(D)
|
||||||
|
|||||||
@ -38,12 +38,12 @@ fn fft_dispatch<F: Field>(
|
|||||||
zero_factor: Option<usize>,
|
zero_factor: Option<usize>,
|
||||||
root_table: Option<&FftRootTable<F>>,
|
root_table: Option<&FftRootTable<F>>,
|
||||||
) -> Vec<F> {
|
) -> Vec<F> {
|
||||||
let computed_root_table = if let Some(_) = root_table {
|
let computed_root_table = if root_table.is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(fft_root_table(input.len()))
|
Some(fft_root_table(input.len()))
|
||||||
};
|
};
|
||||||
let used_root_table = root_table.or(computed_root_table.as_ref()).unwrap();
|
let used_root_table = root_table.or_else(|| computed_root_table.as_ref()).unwrap();
|
||||||
|
|
||||||
fft_classic(input, zero_factor.unwrap_or(0), used_root_table)
|
fft_classic(input, zero_factor.unwrap_or(0), used_root_table)
|
||||||
}
|
}
|
||||||
@ -122,8 +122,8 @@ fn fft_classic_simd<P: PackedField>(
|
|||||||
|
|
||||||
// Set omega to root_table[lg_half_m][0..half_m] but repeated.
|
// Set omega to root_table[lg_half_m][0..half_m] but repeated.
|
||||||
let mut omega_vec = P::zero().to_vec();
|
let mut omega_vec = P::zero().to_vec();
|
||||||
for j in 0..omega_vec.len() {
|
for (j, omega) in omega_vec.iter_mut().enumerate() {
|
||||||
omega_vec[j] = root_table[lg_half_m][j % half_m];
|
*omega = root_table[lg_half_m][j % half_m];
|
||||||
}
|
}
|
||||||
let omega = P::from_slice(&omega_vec[..]);
|
let omega = P::from_slice(&omega_vec[..]);
|
||||||
|
|
||||||
@ -201,9 +201,9 @@ pub(crate) fn fft_classic<F: Field>(input: &[F], r: usize, root_table: &FftRootT
|
|||||||
if lg_n <= lg_packed_width {
|
if lg_n <= lg_packed_width {
|
||||||
// Need the slice to be at least the width of two packed vectors for the vectorized version
|
// Need the slice to be at least the width of two packed vectors for the vectorized version
|
||||||
// to work. Do this tiny problem in scalar.
|
// to work. Do this tiny problem in scalar.
|
||||||
fft_classic_simd::<Singleton<F>>(&mut values[..], r, lg_n, &root_table);
|
fft_classic_simd::<Singleton<F>>(&mut values[..], r, lg_n, root_table);
|
||||||
} else {
|
} else {
|
||||||
fft_classic_simd::<<F as Packable>::PackedType>(&mut values[..], r, lg_n, &root_table);
|
fft_classic_simd::<<F as Packable>::PackedType>(&mut values[..], r, lg_n, root_table);
|
||||||
}
|
}
|
||||||
values
|
values
|
||||||
}
|
}
|
||||||
@ -267,7 +267,7 @@ mod tests {
|
|||||||
|
|
||||||
let values = subgroup
|
let values = subgroup
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| evaluate_at_naive(&coefficients, x))
|
.map(|x| evaluate_at_naive(coefficients, x))
|
||||||
.collect();
|
.collect();
|
||||||
PolynomialValues::new(values)
|
PolynomialValues::new(values)
|
||||||
}
|
}
|
||||||
@ -276,8 +276,8 @@ mod tests {
|
|||||||
let mut sum = F::ZERO;
|
let mut sum = F::ZERO;
|
||||||
let mut point_power = F::ONE;
|
let mut point_power = F::ONE;
|
||||||
for &c in &coefficients.coeffs {
|
for &c in &coefficients.coeffs {
|
||||||
sum = sum + c * point_power;
|
sum += c * point_power;
|
||||||
point_power = point_power * point;
|
point_power *= point;
|
||||||
}
|
}
|
||||||
sum
|
sum
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#![allow(clippy::eq_op)]
|
||||||
use crate::field::extension_field::Extendable;
|
use crate::field::extension_field::Extendable;
|
||||||
use crate::field::extension_field::Frobenius;
|
use crate::field::extension_field::Frobenius;
|
||||||
use crate::field::field_types::Field;
|
use crate::field::field_types::Field;
|
||||||
|
|||||||
@ -335,7 +335,7 @@ pub trait Field:
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn kth_root_u64(&self, k: u64) -> Self {
|
fn kth_root_u64(&self, k: u64) -> Self {
|
||||||
let p = Self::order().clone();
|
let p = Self::order();
|
||||||
let p_minus_1 = &p - 1u32;
|
let p_minus_1 = &p - 1u32;
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
Self::is_monomial_permutation_u64(k),
|
Self::is_monomial_permutation_u64(k),
|
||||||
@ -422,6 +422,7 @@ pub trait PrimeField: Field {
|
|||||||
unsafe { self.sub_canonical_u64(1) }
|
unsafe { self.sub_canonical_u64(1) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
/// Equivalent to *self + Self::from_canonical_u64(rhs), but may be cheaper. The caller must
|
/// Equivalent to *self + Self::from_canonical_u64(rhs), but may be cheaper. The caller must
|
||||||
/// ensure that 0 <= rhs < Self::ORDER. The function may return incorrect results if this
|
/// ensure that 0 <= rhs < Self::ORDER. The function may return incorrect results if this
|
||||||
/// precondition is not met. It is marked unsafe for this reason.
|
/// precondition is not met. It is marked unsafe for this reason.
|
||||||
@ -431,6 +432,7 @@ pub trait PrimeField: Field {
|
|||||||
*self + Self::from_canonical_u64(rhs)
|
*self + Self::from_canonical_u64(rhs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// # Safety
|
||||||
/// Equivalent to *self - Self::from_canonical_u64(rhs), but may be cheaper. The caller must
|
/// Equivalent to *self - Self::from_canonical_u64(rhs), but may be cheaper. The caller must
|
||||||
/// ensure that 0 <= rhs < Self::ORDER. The function may return incorrect results if this
|
/// ensure that 0 <= rhs < Self::ORDER. The function may return incorrect results if this
|
||||||
/// precondition is not met. It is marked unsafe for this reason.
|
/// precondition is not met. It is marked unsafe for this reason.
|
||||||
|
|||||||
@ -24,7 +24,7 @@ where
|
|||||||
ExpectedOp: Fn(u64) -> u64,
|
ExpectedOp: Fn(u64) -> u64,
|
||||||
{
|
{
|
||||||
let inputs = test_inputs(F::ORDER);
|
let inputs = test_inputs(F::ORDER);
|
||||||
let expected: Vec<_> = inputs.iter().map(|x| expected_op(x.clone())).collect();
|
let expected: Vec<_> = inputs.iter().map(|&x| expected_op(x)).collect();
|
||||||
let output: Vec<_> = inputs
|
let output: Vec<_> = inputs
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|||||||
@ -216,7 +216,7 @@ impl<F: RichField> PolynomialBatchCommitment<F> {
|
|||||||
lde_final_poly,
|
lde_final_poly,
|
||||||
lde_final_values,
|
lde_final_values,
|
||||||
challenger,
|
challenger,
|
||||||
&common_data,
|
common_data,
|
||||||
timing,
|
timing,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -407,7 +407,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
arity_bits,
|
arity_bits,
|
||||||
evals,
|
evals,
|
||||||
betas[i],
|
betas[i],
|
||||||
&common_data
|
common_data
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -142,9 +142,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
|
|
||||||
let mut combined_limbs = vec![];
|
let mut combined_limbs = vec![];
|
||||||
let mut carry = self.zero_u32();
|
let mut carry = self.zero_u32();
|
||||||
for i in 0..total_limbs {
|
for summands in &mut to_add {
|
||||||
to_add[i].push(carry);
|
summands.push(carry);
|
||||||
let (new_result, new_carry) = self.add_many_u32(&to_add[i].clone());
|
let (new_result, new_carry) = self.add_many_u32(summands);
|
||||||
combined_limbs.push(new_result);
|
combined_limbs.push(new_result);
|
||||||
carry = new_carry;
|
carry = new_carry;
|
||||||
}
|
}
|
||||||
@ -172,9 +172,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
});
|
});
|
||||||
|
|
||||||
let div_b = self.mul_biguint(&div, &b);
|
let div_b = self.mul_biguint(&div, b);
|
||||||
let div_b_plus_rem = self.add_biguint(&div_b, &rem);
|
let div_b_plus_rem = self.add_biguint(&div_b, &rem);
|
||||||
self.connect_biguint(&a, &div_b_plus_rem);
|
self.connect_biguint(a, &div_b_plus_rem);
|
||||||
|
|
||||||
let cmp_rem_b = self.cmp_biguint(&rem, b);
|
let cmp_rem_b = self.cmp_biguint(&rem, b);
|
||||||
self.assert_one(cmp_rem_b.target);
|
self.assert_one(cmp_rem_b.target);
|
||||||
|
|||||||
@ -378,7 +378,7 @@ mod tests {
|
|||||||
let pw = PartialWitness::new();
|
let pw = PartialWitness::new();
|
||||||
let mut builder = CircuitBuilder::<F, D>::new(config);
|
let mut builder = CircuitBuilder::<F, D>::new(config);
|
||||||
|
|
||||||
let lst: Vec<F> = (0..size * 2).map(|n| F::from_canonical_usize(n)).collect();
|
let lst: Vec<F> = (0..size * 2).map(F::from_canonical_usize).collect();
|
||||||
let a: Vec<Vec<Target>> = lst[..]
|
let a: Vec<Vec<Target>> = lst[..]
|
||||||
.chunks(2)
|
.chunks(2)
|
||||||
.map(|pair| vec![builder.constant(pair[0]), builder.constant(pair[1])])
|
.map(|pair| vec![builder.constant(pair[0]), builder.constant(pair[1])])
|
||||||
|
|||||||
@ -224,7 +224,7 @@ mod tests {
|
|||||||
izip!(is_write_vals, address_vals, timestamp_vals, value_vals)
|
izip!(is_write_vals, address_vals, timestamp_vals, value_vals)
|
||||||
.zip(combined_vals_u64)
|
.zip(combined_vals_u64)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
input_ops_and_keys.sort_by_key(|(_, val)| val.clone());
|
input_ops_and_keys.sort_by_key(|(_, val)| *val);
|
||||||
let input_ops_sorted: Vec<_> = input_ops_and_keys.iter().map(|(x, _)| x).collect();
|
let input_ops_sorted: Vec<_> = input_ops_and_keys.iter().map(|(x, _)| x).collect();
|
||||||
|
|
||||||
let output_ops =
|
let output_ops =
|
||||||
|
|||||||
@ -261,17 +261,11 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
let mut deps = Vec::with_capacity(3);
|
vec![
|
||||||
deps.push(local_target(
|
local_target(U32ArithmeticGate::<F, D>::wire_ith_multiplicand_0(self.i)),
|
||||||
U32ArithmeticGate::<F, D>::wire_ith_multiplicand_0(self.i),
|
local_target(U32ArithmeticGate::<F, D>::wire_ith_multiplicand_1(self.i)),
|
||||||
));
|
local_target(U32ArithmeticGate::<F, D>::wire_ith_addend(self.i)),
|
||||||
deps.push(local_target(
|
]
|
||||||
U32ArithmeticGate::<F, D>::wire_ith_multiplicand_1(self.i),
|
|
||||||
));
|
|
||||||
deps.push(local_target(U32ArithmeticGate::<F, D>::wire_ith_addend(
|
|
||||||
self.i,
|
|
||||||
)));
|
|
||||||
deps
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
@ -307,23 +301,19 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
|
|
||||||
let num_limbs = U32ArithmeticGate::<F, D>::num_limbs();
|
let num_limbs = U32ArithmeticGate::<F, D>::num_limbs();
|
||||||
let limb_base = 1 << U32ArithmeticGate::<F, D>::limb_bits();
|
let limb_base = 1 << U32ArithmeticGate::<F, D>::limb_bits();
|
||||||
let output_limbs_u64: Vec<_> = unfold((), move |_| {
|
let output_limbs_u64 = unfold((), move |_| {
|
||||||
let ret = output_u64 % limb_base;
|
let ret = output_u64 % limb_base;
|
||||||
output_u64 /= limb_base;
|
output_u64 /= limb_base;
|
||||||
Some(ret)
|
Some(ret)
|
||||||
})
|
})
|
||||||
.take(num_limbs)
|
.take(num_limbs);
|
||||||
.collect();
|
let output_limbs_f = output_limbs_u64.map(F::from_canonical_u64);
|
||||||
let output_limbs_f: Vec<_> = output_limbs_u64
|
|
||||||
.into_iter()
|
|
||||||
.map(F::from_canonical_u64)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
for j in 0..num_limbs {
|
for (j, output_limb) in output_limbs_f.enumerate() {
|
||||||
let wire = local_wire(U32ArithmeticGate::<F, D>::wire_ith_output_jth_limb(
|
let wire = local_wire(U32ArithmeticGate::<F, D>::wire_ith_output_jth_limb(
|
||||||
self.i, j,
|
self.i, j,
|
||||||
));
|
));
|
||||||
out_buffer.set_wire(wire, output_limbs_f[j]);
|
out_buffer.set_wire(wire, output_limb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -340,10 +340,10 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
let mut deps = Vec::new();
|
vec![
|
||||||
deps.push(local_target(self.gate.wire_first_input()));
|
local_target(self.gate.wire_first_input()),
|
||||||
deps.push(local_target(self.gate.wire_second_input()));
|
local_target(self.gate.wire_second_input()),
|
||||||
deps
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
@ -555,7 +555,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let max: u64 = 1 << num_bits - 1;
|
let max: u64 = 1 << (num_bits - 1);
|
||||||
let first_input_u64 = rng.gen_range(0..max);
|
let first_input_u64 = rng.gen_range(0..max);
|
||||||
let second_input_u64 = {
|
let second_input_u64 = {
|
||||||
let mut val = rng.gen_range(0..max);
|
let mut val = rng.gen_range(0..max);
|
||||||
|
|||||||
@ -151,10 +151,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Range-check the bits.
|
// Range-check the bits.
|
||||||
for i in 0..most_significant_diff_bits.len() {
|
for &bit in &most_significant_diff_bits {
|
||||||
constraints.push(
|
constraints.push(bit * (F::Extension::ONE - bit));
|
||||||
most_significant_diff_bits[i] * (F::Extension::ONE - most_significant_diff_bits[i]),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bits_combined = reduce_with_powers(&most_significant_diff_bits, F::Extension::TWO);
|
let bits_combined = reduce_with_powers(&most_significant_diff_bits, F::Extension::TWO);
|
||||||
@ -232,9 +230,8 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Range-check the bits.
|
// Range-check the bits.
|
||||||
for i in 0..most_significant_diff_bits.len() {
|
for &bit in &most_significant_diff_bits {
|
||||||
constraints
|
constraints.push(bit * (F::ONE - bit));
|
||||||
.push(most_significant_diff_bits[i] * (F::ONE - most_significant_diff_bits[i]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bits_combined = reduce_with_powers(&most_significant_diff_bits, F::TWO);
|
let bits_combined = reduce_with_powers(&most_significant_diff_bits, F::TWO);
|
||||||
@ -324,8 +321,7 @@ impl<F: RichField + Extendable<D>, const D: usize> Gate<F, D> for ComparisonGate
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// Range-check the bits.
|
// Range-check the bits.
|
||||||
for i in 0..most_significant_diff_bits.len() {
|
for &this_bit in &most_significant_diff_bits {
|
||||||
let this_bit = most_significant_diff_bits[i];
|
|
||||||
let inverse = builder.sub_extension(one, this_bit);
|
let inverse = builder.sub_extension(one, this_bit);
|
||||||
constraints.push(builder.mul_extension(this_bit, inverse));
|
constraints.push(builder.mul_extension(this_bit, inverse));
|
||||||
}
|
}
|
||||||
@ -388,10 +384,10 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
let mut deps = Vec::new();
|
vec![
|
||||||
deps.push(local_target(self.gate.wire_first_input()));
|
local_target(self.gate.wire_first_input()),
|
||||||
deps.push(local_target(self.gate.wire_second_input()));
|
local_target(self.gate.wire_second_input()),
|
||||||
deps
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
@ -638,7 +634,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let max: u64 = 1 << num_bits - 1;
|
let max: u64 = 1 << (num_bits - 1);
|
||||||
let first_input_u64 = rng.gen_range(0..max);
|
let first_input_u64 = rng.gen_range(0..max);
|
||||||
let second_input_u64 = {
|
let second_input_u64 = {
|
||||||
let mut val = rng.gen_range(0..max);
|
let mut val = rng.gen_range(0..max);
|
||||||
|
|||||||
@ -335,9 +335,8 @@ mod tests {
|
|||||||
.map(|b| F::from_canonical_u64(*b))
|
.map(|b| F::from_canonical_u64(*b))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut v = Vec::new();
|
let mut v = vec![base];
|
||||||
v.push(base);
|
v.extend(power_bits_f);
|
||||||
v.extend(power_bits_f.clone());
|
|
||||||
|
|
||||||
let mut intermediate_values = Vec::new();
|
let mut intermediate_values = Vec::new();
|
||||||
let mut current_intermediate_value = F::ONE;
|
let mut current_intermediate_value = F::ONE;
|
||||||
|
|||||||
@ -251,8 +251,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Insert
|
|||||||
|
|
||||||
let local_targets = |inputs: Range<usize>| inputs.map(local_target);
|
let local_targets = |inputs: Range<usize>| inputs.map(local_target);
|
||||||
|
|
||||||
let mut deps = Vec::new();
|
let mut deps = vec![local_target(self.gate.wires_insertion_index())];
|
||||||
deps.push(local_target(self.gate.wires_insertion_index()));
|
|
||||||
deps.extend(local_targets(self.gate.wires_element_to_insert()));
|
deps.extend(local_targets(self.gate.wires_element_to_insert()));
|
||||||
for i in 0..self.gate.vec_size {
|
for i in 0..self.gate.vec_size {
|
||||||
deps.extend(local_targets(self.gate.wires_original_list_item(i)));
|
deps.extend(local_targets(self.gate.wires_original_list_item(i)));
|
||||||
@ -291,7 +290,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F> for Insert
|
|||||||
vec_size
|
vec_size
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut new_vec = orig_vec.clone();
|
let mut new_vec = orig_vec;
|
||||||
new_vec.insert(insertion_index, to_insert);
|
new_vec.insert(insertion_index, to_insert);
|
||||||
|
|
||||||
let mut equality_dummy_vals = Vec::new();
|
let mut equality_dummy_vals = Vec::new();
|
||||||
@ -372,14 +371,13 @@ mod tests {
|
|||||||
fn get_wires(orig_vec: Vec<FF>, insertion_index: usize, element_to_insert: FF) -> Vec<FF> {
|
fn get_wires(orig_vec: Vec<FF>, insertion_index: usize, element_to_insert: FF) -> Vec<FF> {
|
||||||
let vec_size = orig_vec.len();
|
let vec_size = orig_vec.len();
|
||||||
|
|
||||||
let mut v = Vec::new();
|
let mut v = vec![F::from_canonical_usize(insertion_index)];
|
||||||
v.push(F::from_canonical_usize(insertion_index));
|
|
||||||
v.extend(element_to_insert.0);
|
v.extend(element_to_insert.0);
|
||||||
for j in 0..vec_size {
|
for j in 0..vec_size {
|
||||||
v.extend(orig_vec[j].0);
|
v.extend(orig_vec[j].0);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut new_vec = orig_vec.clone();
|
let mut new_vec = orig_vec;
|
||||||
new_vec.insert(insertion_index, element_to_insert);
|
new_vec.insert(insertion_index, element_to_insert);
|
||||||
let mut equality_dummy_vals = Vec::new();
|
let mut equality_dummy_vals = Vec::new();
|
||||||
for i in 0..=vec_size {
|
for i in 0..=vec_size {
|
||||||
|
|||||||
@ -72,7 +72,7 @@ impl<F: RichField + Extendable<D>, const D: usize> HighDegreeInterpolationGate<F
|
|||||||
g.powers()
|
g.powers()
|
||||||
.take(size)
|
.take(size)
|
||||||
.map(move |x| {
|
.map(move |x| {
|
||||||
let subgroup_element = builder.constant(x.into());
|
let subgroup_element = builder.constant(x);
|
||||||
builder.scalar_mul_ext(subgroup_element, shift)
|
builder.scalar_mul_ext(subgroup_element, shift)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|||||||
@ -157,7 +157,7 @@ where
|
|||||||
|
|
||||||
// Partial rounds.
|
// Partial rounds.
|
||||||
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
||||||
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&mut state);
|
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&state);
|
||||||
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
||||||
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
||||||
constraints.push(state[0] - sbox_in);
|
constraints.push(state[0] - sbox_in);
|
||||||
@ -243,7 +243,7 @@ where
|
|||||||
|
|
||||||
// Partial rounds.
|
// Partial rounds.
|
||||||
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
||||||
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&mut state);
|
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&state);
|
||||||
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
||||||
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
||||||
constraints.push(state[0] - sbox_in);
|
constraints.push(state[0] - sbox_in);
|
||||||
@ -345,7 +345,7 @@ where
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
<F as Poseidon<WIDTH>>::partial_first_constant_layer_recursive(builder, &mut state);
|
<F as Poseidon<WIDTH>>::partial_first_constant_layer_recursive(builder, &mut state);
|
||||||
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init_recursive(builder, &mut state);
|
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init_recursive(builder, &state);
|
||||||
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
||||||
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
let sbox_in = vars.local_wires[Self::wire_partial_sbox(r)];
|
||||||
constraints.push(builder.sub_extension(state[0], sbox_in));
|
constraints.push(builder.sub_extension(state[0], sbox_in));
|
||||||
@ -489,7 +489,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
<F as Poseidon<WIDTH>>::partial_first_constant_layer(&mut state);
|
||||||
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&mut state);
|
state = <F as Poseidon<WIDTH>>::mds_partial_layer_init(&state);
|
||||||
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
for r in 0..(poseidon::N_PARTIAL_ROUNDS - 1) {
|
||||||
out_buffer.set_wire(
|
out_buffer.set_wire(
|
||||||
local_wire(PoseidonGate::<F, D, WIDTH>::wire_partial_sbox(r)),
|
local_wire(PoseidonGate::<F, D, WIDTH>::wire_partial_sbox(r)),
|
||||||
|
|||||||
@ -263,8 +263,7 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
let mut deps = Vec::new();
|
let mut deps = vec![local_target(self.gate.wire_access_index(self.copy))];
|
||||||
deps.push(local_target(self.gate.wire_access_index(self.copy)));
|
|
||||||
for i in 0..self.gate.vec_size() {
|
for i in 0..self.gate.vec_size() {
|
||||||
deps.push(local_target(self.gate.wire_list_item(i, self.copy)));
|
deps.push(local_target(self.gate.wire_list_item(i, self.copy)));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -244,17 +244,11 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
|||||||
fn dependencies(&self) -> Vec<Target> {
|
fn dependencies(&self) -> Vec<Target> {
|
||||||
let local_target = |input| Target::wire(self.gate_index, input);
|
let local_target = |input| Target::wire(self.gate_index, input);
|
||||||
|
|
||||||
let mut deps = Vec::with_capacity(3);
|
vec![
|
||||||
deps.push(local_target(U32SubtractionGate::<F, D>::wire_ith_input_x(
|
local_target(U32SubtractionGate::<F, D>::wire_ith_input_x(self.i)),
|
||||||
self.i,
|
local_target(U32SubtractionGate::<F, D>::wire_ith_input_y(self.i)),
|
||||||
)));
|
local_target(U32SubtractionGate::<F, D>::wire_ith_input_borrow(self.i)),
|
||||||
deps.push(local_target(U32SubtractionGate::<F, D>::wire_ith_input_y(
|
]
|
||||||
self.i,
|
|
||||||
)));
|
|
||||||
deps.push(local_target(
|
|
||||||
U32SubtractionGate::<F, D>::wire_ith_input_borrow(self.i),
|
|
||||||
));
|
|
||||||
deps
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
fn run_once(&self, witness: &PartitionWitness<F>, out_buffer: &mut GeneratedValues<F>) {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::assertions_on_constants)]
|
||||||
|
|
||||||
use std::arch::aarch64::*;
|
use std::arch::aarch64::*;
|
||||||
|
|
||||||
use static_assertions::const_assert;
|
use static_assertions::const_assert;
|
||||||
@ -171,9 +173,7 @@ unsafe fn multiply(x: u64, y: u64) -> u64 {
|
|||||||
let xy_hi_lo_mul_epsilon = mul_epsilon(xy_hi);
|
let xy_hi_lo_mul_epsilon = mul_epsilon(xy_hi);
|
||||||
|
|
||||||
// add_with_wraparound is safe, as xy_hi_lo_mul_epsilon <= 0xfffffffe00000001 <= ORDER.
|
// add_with_wraparound is safe, as xy_hi_lo_mul_epsilon <= 0xfffffffe00000001 <= ORDER.
|
||||||
let res1 = add_with_wraparound(res0, xy_hi_lo_mul_epsilon);
|
add_with_wraparound(res0, xy_hi_lo_mul_epsilon)
|
||||||
|
|
||||||
res1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================================== STANDALONE CONST LAYER =====================================
|
// ==================================== STANDALONE CONST LAYER =====================================
|
||||||
@ -266,9 +266,7 @@ unsafe fn mds_reduce(
|
|||||||
// Multiply by EPSILON and accumulate.
|
// Multiply by EPSILON and accumulate.
|
||||||
let res_unadj = vmlal_laneq_u32::<0>(res_lo, res_hi_hi, mds_consts0);
|
let res_unadj = vmlal_laneq_u32::<0>(res_lo, res_hi_hi, mds_consts0);
|
||||||
let res_adj = vcgtq_u64(res_lo, res_unadj);
|
let res_adj = vcgtq_u64(res_lo, res_unadj);
|
||||||
let res = vsraq_n_u64::<32>(res_unadj, res_adj);
|
vsraq_n_u64::<32>(res_unadj, res_adj)
|
||||||
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -968,8 +966,7 @@ unsafe fn partial_round(
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn full_round(state: [u64; 12], round_constants: &[u64; WIDTH]) -> [u64; 12] {
|
unsafe fn full_round(state: [u64; 12], round_constants: &[u64; WIDTH]) -> [u64; 12] {
|
||||||
let state = sbox_layer_full(state);
|
let state = sbox_layer_full(state);
|
||||||
let state = mds_const_layers_full(state, round_constants);
|
mds_const_layers_full(state, round_constants)
|
||||||
state
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@ -110,9 +110,7 @@ pub fn hash_n_to_m<F: RichField>(mut inputs: Vec<F>, num_outputs: usize, pad: bo
|
|||||||
|
|
||||||
// Absorb all input chunks.
|
// Absorb all input chunks.
|
||||||
for input_chunk in inputs.chunks(SPONGE_RATE) {
|
for input_chunk in inputs.chunks(SPONGE_RATE) {
|
||||||
for i in 0..input_chunk.len() {
|
state[..input_chunk.len()].copy_from_slice(input_chunk);
|
||||||
state[i] = input_chunk[i];
|
|
||||||
}
|
|
||||||
state = permute(state);
|
state = permute(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ impl Target {
|
|||||||
|
|
||||||
/// A `Target` which has already been constrained such that it can only be 0 or 1.
|
/// A `Target` which has already been constrained such that it can only be 0 or 1.
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
#[allow(clippy::manual_non_exhaustive)]
|
||||||
pub struct BoolTarget {
|
pub struct BoolTarget {
|
||||||
pub target: Target,
|
pub target: Target,
|
||||||
/// This private field is here to force all instantiations to go through `new_unsafe`.
|
/// This private field is here to force all instantiations to go through `new_unsafe`.
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
#![allow(const_evaluatable_unchecked)]
|
#![allow(const_evaluatable_unchecked)]
|
||||||
|
#![allow(clippy::new_without_default)]
|
||||||
|
#![allow(clippy::too_many_arguments)]
|
||||||
|
#![allow(clippy::len_without_is_empty)]
|
||||||
|
#![allow(clippy::module_inception)]
|
||||||
|
#![allow(clippy::needless_range_loop)]
|
||||||
#![feature(asm)]
|
#![feature(asm)]
|
||||||
#![feature(asm_sym)]
|
#![feature(asm_sym)]
|
||||||
#![feature(destructuring_assignment)]
|
#![feature(destructuring_assignment)]
|
||||||
|
|||||||
@ -634,7 +634,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
|
|
||||||
// Precompute FFT roots.
|
// Precompute FFT roots.
|
||||||
let max_fft_points =
|
let max_fft_points =
|
||||||
1 << degree_bits + max(self.config.rate_bits, log2_ceil(quotient_degree_factor));
|
1 << (degree_bits + max(self.config.rate_bits, log2_ceil(quotient_degree_factor)));
|
||||||
let fft_root_table = fft_root_table(max_fft_points);
|
let fft_root_table = fft_root_table(max_fft_points);
|
||||||
|
|
||||||
let constants_sigmas_vecs = [constant_vecs, sigma_vecs.clone()].concat();
|
let constants_sigmas_vecs = [constant_vecs, sigma_vecs.clone()].concat();
|
||||||
@ -669,7 +669,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
|||||||
let watch_rep_index = forest.parents[watch_index];
|
let watch_rep_index = forest.parents[watch_index];
|
||||||
generator_indices_by_watches
|
generator_indices_by_watches
|
||||||
.entry(watch_rep_index)
|
.entry(watch_rep_index)
|
||||||
.or_insert(vec![])
|
.or_insert_with(Vec::new)
|
||||||
.push(i);
|
.push(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,11 +138,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CompressedProof<F, D> {
|
|||||||
plonk_zs_partial_products_cap,
|
plonk_zs_partial_products_cap,
|
||||||
quotient_polys_cap,
|
quotient_polys_cap,
|
||||||
openings,
|
openings,
|
||||||
opening_proof: opening_proof.decompress(
|
opening_proof: opening_proof.decompress(challenges, fri_inferred_elements, common_data),
|
||||||
&challenges,
|
|
||||||
fri_inferred_elements,
|
|
||||||
common_data,
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -527,7 +527,7 @@ mod tests {
|
|||||||
&inner_vd.constants_sigmas_cap,
|
&inner_vd.constants_sigmas_cap,
|
||||||
);
|
);
|
||||||
|
|
||||||
builder.add_recursive_verifier(pt, &inner_config, &inner_data, &inner_cd);
|
builder.add_recursive_verifier(pt, inner_config, &inner_data, &inner_cd);
|
||||||
|
|
||||||
if print_gate_counts {
|
if print_gate_counts {
|
||||||
builder.print_gate_counts(0);
|
builder.print_gate_counts(0);
|
||||||
@ -563,12 +563,12 @@ mod tests {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let proof_bytes = proof.to_bytes()?;
|
let proof_bytes = proof.to_bytes()?;
|
||||||
info!("Proof length: {} bytes", proof_bytes.len());
|
info!("Proof length: {} bytes", proof_bytes.len());
|
||||||
let proof_from_bytes = ProofWithPublicInputs::from_bytes(proof_bytes, &cd)?;
|
let proof_from_bytes = ProofWithPublicInputs::from_bytes(proof_bytes, cd)?;
|
||||||
assert_eq!(proof, &proof_from_bytes);
|
assert_eq!(proof, &proof_from_bytes);
|
||||||
|
|
||||||
let now = std::time::Instant::now();
|
let now = std::time::Instant::now();
|
||||||
let compressed_proof = proof.clone().compress(&cd)?;
|
let compressed_proof = proof.clone().compress(cd)?;
|
||||||
let decompressed_compressed_proof = compressed_proof.clone().decompress(&cd)?;
|
let decompressed_compressed_proof = compressed_proof.clone().decompress(cd)?;
|
||||||
info!("{:.4}s to compress proof", now.elapsed().as_secs_f64());
|
info!("{:.4}s to compress proof", now.elapsed().as_secs_f64());
|
||||||
assert_eq!(proof, &decompressed_compressed_proof);
|
assert_eq!(proof, &decompressed_compressed_proof);
|
||||||
|
|
||||||
@ -578,7 +578,7 @@ mod tests {
|
|||||||
compressed_proof_bytes.len()
|
compressed_proof_bytes.len()
|
||||||
);
|
);
|
||||||
let compressed_proof_from_bytes =
|
let compressed_proof_from_bytes =
|
||||||
CompressedProofWithPublicInputs::from_bytes(compressed_proof_bytes, &cd)?;
|
CompressedProofWithPublicInputs::from_bytes(compressed_proof_bytes, cd)?;
|
||||||
assert_eq!(compressed_proof, compressed_proof_from_bytes);
|
assert_eq!(compressed_proof, compressed_proof_from_bytes);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@ -441,7 +441,7 @@ mod tests {
|
|||||||
assert_eq!(coset_evals, naive_coset_evals);
|
assert_eq!(coset_evals, naive_coset_evals);
|
||||||
|
|
||||||
let ifft_coeffs = PolynomialValues::new(coset_evals).coset_ifft(shift);
|
let ifft_coeffs = PolynomialValues::new(coset_evals).coset_ifft(shift);
|
||||||
assert_eq!(poly, ifft_coeffs.into());
|
assert_eq!(poly, ifft_coeffs);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@ -13,7 +13,7 @@ pub(crate) fn quotient_chunk_products<F: Field>(
|
|||||||
max_degree: usize,
|
max_degree: usize,
|
||||||
) -> Vec<F> {
|
) -> Vec<F> {
|
||||||
debug_assert!(max_degree > 1);
|
debug_assert!(max_degree > 1);
|
||||||
assert!(quotient_values.len() > 0);
|
assert!(!quotient_values.is_empty());
|
||||||
let chunk_size = max_degree;
|
let chunk_size = max_degree;
|
||||||
quotient_values
|
quotient_values
|
||||||
.chunks(chunk_size)
|
.chunks(chunk_size)
|
||||||
@ -24,7 +24,7 @@ pub(crate) fn quotient_chunk_products<F: Field>(
|
|||||||
/// Compute partial products of the original vector `v` such that all products consist of `max_degree`
|
/// Compute partial products of the original vector `v` such that all products consist of `max_degree`
|
||||||
/// or less elements. This is done until we've computed the product `P` of all elements in the vector.
|
/// or less elements. This is done until we've computed the product `P` of all elements in the vector.
|
||||||
pub(crate) fn partial_products_and_z_gx<F: Field>(z_x: F, quotient_chunk_products: &[F]) -> Vec<F> {
|
pub(crate) fn partial_products_and_z_gx<F: Field>(z_x: F, quotient_chunk_products: &[F]) -> Vec<F> {
|
||||||
assert!(quotient_chunk_products.len() > 0);
|
assert!(!quotient_chunk_products.is_empty());
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
let mut acc = z_x;
|
let mut acc = z_x;
|
||||||
for "ient_chunk_product in quotient_chunk_products {
|
for "ient_chunk_product in quotient_chunk_products {
|
||||||
|
|||||||
@ -92,7 +92,7 @@ impl TimingTree {
|
|||||||
|
|
||||||
fn duration(&self) -> Duration {
|
fn duration(&self) -> Duration {
|
||||||
self.exit_time
|
self.exit_time
|
||||||
.unwrap_or(Instant::now())
|
.unwrap_or_else(Instant::now)
|
||||||
.duration_since(self.enter_time)
|
.duration_since(self.enter_time)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user