mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 08:43:06 +00:00
ECDSA merge
This commit is contained in:
parent
82ce3ea8b2
commit
c561333c22
@ -204,7 +204,6 @@ impl<F: RichField + Extendable<D>, const D: usize> SimpleGenerator<F>
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use anyhow::Result;
|
||||
|
||||
use rand::{thread_rng, Rng};
|
||||
|
||||
use crate::field::goldilocks_field::GoldilocksField;
|
||||
@ -234,4 +233,4 @@ mod tests {
|
||||
let proof = data.prove(pw).unwrap();
|
||||
verify(proof, &data.verifier_only, &data.common)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let rem_u64 = rem.to_u64_digits()[0];
|
||||
limb_values.push(F::from_canonical_u64(rem_u64));
|
||||
}
|
||||
let limbs = limb_values.iter().map(|&l| self.constant_binary(l)).collect();
|
||||
let limbs = limb_values
|
||||
.iter()
|
||||
.map(|&l| self.constant_binary(l))
|
||||
.collect();
|
||||
|
||||
BigUintTarget { limbs }
|
||||
}
|
||||
|
||||
@ -3,8 +3,8 @@ use std::marker::PhantomData;
|
||||
use crate::curve::curve_types::Curve;
|
||||
use crate::field::extension_field::Extendable;
|
||||
use crate::field::field_types::RichField;
|
||||
use crate::gadgets::binary_arithmetic::BinaryTarget;
|
||||
use crate::gadgets::biguint::BigUintTarget;
|
||||
use crate::gadgets::binary_arithmetic::BinaryTarget;
|
||||
use crate::gadgets::curve::AffinePointTarget;
|
||||
use crate::gadgets::nonnative::NonNativeTarget;
|
||||
use crate::iop::target::{BoolTarget, Target};
|
||||
|
||||
@ -59,7 +59,11 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
|
||||
/// Helper function for comparing, specifically, lists of `U32Target`s.
|
||||
pub fn list_le_binary<const BITS: usize>(&mut self, a: Vec<BinaryTarget<BITS>>, b: Vec<BinaryTarget<BITS>>) -> BoolTarget {
|
||||
pub fn list_le_binary<const BITS: usize>(
|
||||
&mut self,
|
||||
a: Vec<BinaryTarget<BITS>>,
|
||||
b: Vec<BinaryTarget<BITS>>,
|
||||
) -> BoolTarget {
|
||||
let a_targets = a.iter().map(|&t| t.0).collect();
|
||||
let b_targets = b.iter().map(|&t| t.0).collect();
|
||||
self.list_le(a_targets, b_targets, BITS)
|
||||
|
||||
@ -139,7 +139,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
let num_limbs = x.value.num_limbs();
|
||||
let inv_biguint = self.add_virtual_biguint_target(num_limbs);
|
||||
let div = self.add_virtual_biguint_target(num_limbs);
|
||||
|
||||
|
||||
self.add_simple_generator(NonNativeInverseGenerator::<F, D, FF> {
|
||||
x: x.clone(),
|
||||
inv: inv_biguint.clone(),
|
||||
@ -148,7 +148,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
});
|
||||
|
||||
let product = self.mul_biguint(&x.value, &inv_biguint);
|
||||
|
||||
|
||||
let modulus = self.constant_biguint(&FF::order());
|
||||
let mod_times_div = self.mul_biguint(&modulus, &div);
|
||||
let one = self.constant_biguint(&BigUint::one());
|
||||
@ -460,11 +460,17 @@ mod tests {
|
||||
|
||||
let ffs: Vec<_> = (0..num).map(|_| FF::rand()).collect();
|
||||
|
||||
let op_targets: Vec<_> = ffs.iter().map(|&x| op_builder.constant_nonnative(x)).collect();
|
||||
let op_targets: Vec<_> = ffs
|
||||
.iter()
|
||||
.map(|&x| op_builder.constant_nonnative(x))
|
||||
.collect();
|
||||
op_builder.mul_many_nonnative(&op_targets);
|
||||
println!("OPTIMIZED GATE COUNT: {}", op_builder.num_gates());
|
||||
|
||||
let unop_targets: Vec<_> = ffs.iter().map(|&x| unop_builder.constant_nonnative(x)).collect();
|
||||
let unop_targets: Vec<_> = ffs
|
||||
.iter()
|
||||
.map(|&x| unop_builder.constant_nonnative(x))
|
||||
.collect();
|
||||
let mut result = unop_targets[0].clone();
|
||||
for i in 1..unop_targets.len() {
|
||||
result = unop_builder.mul_nonnative(&result, &unop_targets[i]);
|
||||
|
||||
@ -3,11 +3,11 @@
|
||||
|
||||
pub mod arithmetic_base;
|
||||
pub mod arithmetic_extension;
|
||||
pub mod binary_arithmetic;
|
||||
pub mod binary_subtraction;
|
||||
pub mod arithmetic_u32;
|
||||
pub mod assert_le;
|
||||
pub mod base_sum;
|
||||
pub mod binary_arithmetic;
|
||||
pub mod binary_subtraction;
|
||||
pub mod comparison;
|
||||
pub mod constant;
|
||||
pub mod exponentiation;
|
||||
|
||||
@ -1049,7 +1049,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
|
||||
(gate_index, copy)
|
||||
}
|
||||
|
||||
|
||||
/// Finds the last available binary arithmetic with the given `bits` or add one if there aren't any.
|
||||
/// Returns `(g,i)` such that there is a binary arithmetic for the given `bits` at index
|
||||
/// `g` and the gate's `i`-th copy is available.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user