Skip to content

Commit

Permalink
fix(ssa refactor): BigUint for radix (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
joss-aztec authored Jun 15, 2023
1 parent a2108d7 commit 00cf462
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,19 +271,26 @@ impl GeneratedAcir {
limb_count: u32,
) -> Result<Vec<Witness>, AcirGenError> {
let bit_size = u32::BITS - (radix - 1).leading_zeros();
assert_eq!(2_u32.pow(bit_size), radix, "ICE: Radix must be a power of 2");
let radix_big = BigUint::from(radix);
assert_eq!(
BigUint::from(2u128).pow(bit_size),
radix_big,
"ICE: Radix must be a power of 2"
);

let mut composed_limbs = Expression::default();

let mut radix_pow: u128 = 1;
let mut radix_pow = BigUint::from(1u128);
let limb_witnesses = try_vecmap(0..limb_count, |_| {
let limb_witness = self.next_witness_index();
self.range_constraint(limb_witness, bit_size)?;

composed_limbs = composed_limbs
.add_mul(FieldElement::from(radix_pow), &Expression::from(limb_witness));
composed_limbs = composed_limbs.add_mul(
FieldElement::from_be_bytes_reduce(&radix_pow.to_bytes_be()),
&Expression::from(limb_witness),
);

radix_pow *= radix as u128;
radix_pow *= &radix_big;
Ok(limb_witness)
})?;

Expand Down

0 comments on commit 00cf462

Please sign in to comment.