Skip to content

Commit

Permalink
fix: use u64 in BaseSplitGenerator
Browse files Browse the repository at this point in the history
The BaseSplitGenerator was casting fields (which fit in u64) into usize.
This doesn't work in 32-bit architectures where usize is 32 bits, like
wasm32.  Keeping the value at u64 allows it to work in 32-bit
architectures.
  • Loading branch information
ed255 committed Jan 10, 2025
1 parent 02e80e9 commit 7c14c79
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions plonky2/src/gates/base_sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ impl<F: RichField + Extendable<D>, const B: usize, const D: usize> SimpleGenerat
) -> Result<()> {
let sum_value = witness
.get_target(Target::wire(self.row, BaseSumGate::<B>::WIRE_SUM))
.to_canonical_u64() as usize;
.to_canonical_u64();
debug_assert_eq!(
(0..self.num_limbs).fold(sum_value, |acc, _| acc / B),
(0..self.num_limbs).fold(sum_value, |acc, _| acc / (B as u64)),
0,
"Integer too large to fit in given number of limbs"
);
Expand All @@ -205,9 +205,9 @@ impl<F: RichField + Extendable<D>, const B: usize, const D: usize> SimpleGenerat
.map(|i| Target::wire(self.row, i));
let limbs_value = (0..self.num_limbs)
.scan(sum_value, |acc, _| {
let tmp = *acc % B;
*acc /= B;
Some(F::from_canonical_usize(tmp))
let tmp: u64 = *acc % (B as u64);
*acc /= B as u64;
Some(F::from_canonical_u64(tmp))
})
.collect::<Vec<_>>();

Expand Down

0 comments on commit 7c14c79

Please sign in to comment.