From 7c14c79702d872976743f3399be021ae3c6471f8 Mon Sep 17 00:00:00 2001 From: "Eduard S." Date: Fri, 10 Jan 2025 17:06:17 +0100 Subject: [PATCH] fix: use u64 in BaseSplitGenerator 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. --- plonky2/src/gates/base_sum.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plonky2/src/gates/base_sum.rs b/plonky2/src/gates/base_sum.rs index 1101bd967a..01e3dabd97 100644 --- a/plonky2/src/gates/base_sum.rs +++ b/plonky2/src/gates/base_sum.rs @@ -194,9 +194,9 @@ impl, const B: usize, const D: usize> SimpleGenerat ) -> Result<()> { let sum_value = witness .get_target(Target::wire(self.row, BaseSumGate::::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" ); @@ -205,9 +205,9 @@ impl, 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::>();