mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-03-03 19:23:06 +00:00
addressed comments
This commit is contained in:
parent
9043a47e1b
commit
dd945ef5b7
@ -61,7 +61,6 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
(a.clone(), padded_b)
|
||||
} else {
|
||||
let mut padded_a = a.clone();
|
||||
let to_extend = b.num_limbs() - a.num_limbs();
|
||||
for _ in a.num_limbs()..b.num_limbs() {
|
||||
padded_a.limbs.push(self.zero_u32());
|
||||
}
|
||||
@ -266,10 +265,10 @@ mod tests {
|
||||
fn test_biguint_sub() -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
let mut y_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
while y_value > x_value {
|
||||
y_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
if y_value > x_value {
|
||||
(x_value, y_value) = (y_value, x_value);
|
||||
}
|
||||
let expected_z_value = &x_value - &y_value;
|
||||
|
||||
@ -343,10 +342,10 @@ mod tests {
|
||||
fn test_biguint_div_rem() -> Result<()> {
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
let mut x_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
let mut y_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
while y_value > x_value {
|
||||
y_value = BigUint::from_u128(rng.gen()).unwrap();
|
||||
if y_value > x_value {
|
||||
(x_value, y_value) = (y_value, x_value);
|
||||
}
|
||||
let (expected_div_value, expected_rem_value) = x_value.div_rem(&y_value);
|
||||
|
||||
|
||||
@ -44,9 +44,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
a: &ForeignFieldTarget<FF>,
|
||||
b: &ForeignFieldTarget<FF>,
|
||||
) -> ForeignFieldTarget<FF> {
|
||||
let a_biguint = self.nonnative_to_biguint(a);
|
||||
let b_biguint = self.nonnative_to_biguint(b);
|
||||
let result = self.add_biguint(&a_biguint, &b_biguint);
|
||||
let result = self.add_biguint(&a.value, &b.value);
|
||||
|
||||
self.reduce(&result)
|
||||
}
|
||||
@ -58,10 +56,8 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
b: &ForeignFieldTarget<FF>,
|
||||
) -> ForeignFieldTarget<FF> {
|
||||
let order = self.constant_biguint(&FF::order());
|
||||
let a_biguint = self.nonnative_to_biguint(a);
|
||||
let a_plus_order = self.add_biguint(&order, &a_biguint);
|
||||
let b_biguint = self.nonnative_to_biguint(b);
|
||||
let result = self.sub_biguint(&a_plus_order, &b_biguint);
|
||||
let a_plus_order = self.add_biguint(&order, &a.value);
|
||||
let result = self.sub_biguint(&a_plus_order, &b.value);
|
||||
|
||||
// TODO: reduce sub result with only one conditional addition?
|
||||
self.reduce(&result)
|
||||
@ -72,9 +68,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
a: &ForeignFieldTarget<FF>,
|
||||
b: &ForeignFieldTarget<FF>,
|
||||
) -> ForeignFieldTarget<FF> {
|
||||
let a_biguint = self.nonnative_to_biguint(a);
|
||||
let b_biguint = self.nonnative_to_biguint(b);
|
||||
let result = self.mul_biguint(&a_biguint, &b_biguint);
|
||||
let result = self.mul_biguint(&a.value, &b.value);
|
||||
|
||||
self.reduce(&result)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user