Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM compilation error due to loop unrolling #615

Closed
paberr opened this issue Mar 10, 2023 · 0 comments · Fixed by #794
Closed

WASM compilation error due to loop unrolling #615

paberr opened this issue Mar 10, 2023 · 0 comments · Fixed by #794

Comments

@paberr
Copy link
Contributor

paberr commented Mar 10, 2023

It seems that the loop unrolling on the Fp::into_bigint function results in an excessive number of local variables.

@ii-cruz and I have created a minimal example showcasing this problem: https://github.com/paberr/arkworks-example/blob/main/tests/test.rs

Steps to reproduce

  1. Checkout https://github.com/paberr/arkworks-example
  2. Install wasm-pack
  3. Run wasm-pack test --node

This will fail with the following error:

Error: failed to deserialize wasm module

Caused by:
    0: failed to parse code section
    1: locals exceed maximum (at offset 16377)

Troubleshooting

This error indicates that a function tries to allocate more than 50,000 local variables.
This problem initially occurred in a larger codebase and we traced it back to the into_bigint function.
Using the minimal example, the behaviour is reproducible.

We initially suspected that this happens due to excessive code inlining.
However, using a patched version of ark-ff, we found that the inlining does not trigger the error.
It is the loop unrolling, which deterministically creates the error.
Removing or reducing the unrolling will make the problem disappear.

hrxi added a commit to hrxi/ark-algebra that referenced this issue Feb 27, 2024
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 arkworks-rs#615.
hrxi added a commit to hrxi/ark-algebra that referenced this issue Feb 27, 2024
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 arkworks-rs#615.
@hrxi hrxi mentioned this issue Feb 27, 2024
6 tasks
hrxi added a commit to hrxi/ark-algebra that referenced this issue Feb 27, 2024
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 arkworks-rs#615.
github-merge-queue bot pushed a commit that referenced this issue Feb 27, 2024
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.

Co-authored-by: Pratyush Mishra <pratyushmishra@berkeley.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant