From 3e0ce6d32cf20e22e7219c5e76034f2385e298ea Mon Sep 17 00:00:00 2001 From: hrxi Date: Tue, 27 Feb 2024 17:24:23 +0100 Subject: [PATCH] Fix compilation on WASM Disable loop unrolling for `Fp::into_bigint` that led to WASM miscompilations with too many local variables: ``` Error: failed to deserialize wasm module Caused by: 0: failed to parse code section 1: locals exceed maximum (at offset 16977) ``` Issue diagnosed by @paberr and @ii-cruz. Fixes #615. --- CHANGELOG.md | 1 + ff/src/fields/models/fp/montgomery_backend.rs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9bfa6806..351953b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Pending - [\#772](https://github.com/arkworks-rs/algebra/pull/772) (`ark-ff`) Implementation of `mul` method for `BigInteger`. +- [\#794](https://github.com/arkworks-rs/algebra/pull/794) (`ark-ff`) Fix `wasm` compilation. ### Breaking changes diff --git a/ff/src/fields/models/fp/montgomery_backend.rs b/ff/src/fields/models/fp/montgomery_backend.rs index 125705399..98bc3a433 100644 --- a/ff/src/fields/models/fp/montgomery_backend.rs +++ b/ff/src/fields/models/fp/montgomery_backend.rs @@ -368,7 +368,8 @@ pub trait MontConfig: 'static + Sync + Send + Sized { } #[inline] - #[unroll_for_loops(12)] + #[cfg_attr(not(target_family = "wasm"), unroll_for_loops(12))] + #[cfg_attr(target_family = "wasm", unroll_for_loops(6))] #[allow(clippy::modulo_one)] fn into_bigint(a: Fp, N>) -> BigInt { let mut tmp = a.0;