mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-02-24 07:43:11 +00:00
fix
This commit is contained in:
parent
e8c2813cc7
commit
557456ddd9
@ -32,16 +32,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
self.connect(x.0, y.0)
|
||||
}
|
||||
|
||||
pub fn assert_zero_u32(&self, x: U32Target) {
|
||||
pub fn assert_zero_u32(&mut self, x: U32Target) {
|
||||
self.assert_zero(x.0)
|
||||
}
|
||||
|
||||
fn get_u32_target(&self, target: U32Target) -> F {
|
||||
let result = self.get_target(target.0);
|
||||
debug_assert!(result.to_canonical_u64() < 1 << 32u64);
|
||||
result
|
||||
}
|
||||
|
||||
// Returns x * y + z.
|
||||
pub fn mul_add_u32(
|
||||
&mut self,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Neg;
|
||||
|
||||
use num::BigUint;
|
||||
use num::{BigUint, Zero};
|
||||
|
||||
use crate::field::field_types::RichField;
|
||||
use crate::field::{extension_field::Extendable, field_types::Field};
|
||||
@ -27,7 +27,7 @@ impl BigUintTarget {
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
fn connect_biguint(&self, lhs: BigUintTarget, rhs: BigUintTarget) {
|
||||
fn connect_biguint(&mut self, lhs: BigUintTarget, rhs: BigUintTarget) {
|
||||
let min_limbs = lhs.num_limbs().min(rhs.num_limbs());
|
||||
for i in 0..min_limbs {
|
||||
self.connect_u32(lhs.get_limb(i), rhs.get_limb(i));
|
||||
@ -41,17 +41,6 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_biguint_target(&self, target: BigUintTarget) -> BigUint {
|
||||
let mut result = BigUint::zero();
|
||||
let base = BigUint::from_u64(1 << 32u64);
|
||||
for &limb in target.limbs.iter().rev() {
|
||||
let limb_value = self.get_target(limb.0);
|
||||
result += BigUint::from_u64(limb_value.to_canonical_u64());
|
||||
result *= base;
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn pad_biguints(
|
||||
&mut self,
|
||||
a: BigUintTarget,
|
||||
@ -75,10 +64,10 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
|
||||
fn cmp_biguint(&mut self, a: BigUintTarget, b: BigUintTarget) -> BoolTarget {
|
||||
let (padded_a, padded_b) = self.pad_biguints(a, b);
|
||||
let (padded_a, padded_b) = self.pad_biguints(a.clone(), b.clone());
|
||||
|
||||
let a_vec = a.limbs.iter().map(|&x| x.0).collect();
|
||||
let b_vec = b.limbs.iter().map(|&x| x.0).collect();
|
||||
let a_vec = padded_a.limbs.iter().map(|&x| x.0).collect();
|
||||
let b_vec = padded_b.limbs.iter().map(|&x| x.0).collect();
|
||||
|
||||
self.list_le(a_vec, b_vec, 32)
|
||||
}
|
||||
@ -176,11 +165,11 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
|
||||
let div_b = self.mul_biguint(div, b);
|
||||
let div_b_plus_rem = self.add_biguint(div_b, rem);
|
||||
let div_b = self.mul_biguint(div.clone(), b.clone());
|
||||
let div_b_plus_rem = self.add_biguint(div_b, rem.clone());
|
||||
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.clone(), b);
|
||||
self.assert_one(cmp_rem_b.target);
|
||||
|
||||
(div, rem)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user