1

Update: created a small test app (react calling wasm rust code) but cant recreate rust exception, however this one liner is an extract from bit bigger function and I am still on to find what particular combo is leading to this exception

https://github.com/zkbitcoin/react-rust-wasm-vector-test

instructions:

a) clone b) rustup component add rust-src --toolchain nightly-2022-11-17-x86_64-apple-darwin c) yarn build:wasm d) yarn build e) yarn start

I compiled this sample rust code to WASM (note this one liner runs fine in standard non WASM environment)

let s = vec![vec![1usize; 131072]; 38];

This code fails in Chrome with:

rust_alloc_error_handler ... at alloc::vec::from_elem

Does anyone know how to overcome it? I tried both default and wee_alloc, both are failing.

Chayim Friedman
  • 47,971
  • 5
  • 48
  • 77
zkbitcoin.com
  • 39
  • 1
  • 7
  • 1
    You'll need to add more info cause your code runs fine here. Also check the [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) help section for more infos what to include. – cafce25 Nov 17 '22 at 17:30
  • its bit hard cause this would be in WASM environment (browser) assembled by wasm-pack (and code is one liner) let s = vec![vec![1usize; 131072]; 38]; – zkbitcoin.com Nov 17 '22 at 17:33
  • 1
    If you wan't us to be able to help you you'll have to provide more detail, wether it's hard or not. – cafce25 Nov 17 '22 at 18:05
  • fair enough will create small project with cargo and env details stand by – zkbitcoin.com Nov 17 '22 at 18:44
  • @cafce25 cant recreate problem with a bare bone code (updated main thread with it) issue originally came from me running much larger project this is the outliner of the problem in main program , https://github.com/SoraSuegami/halo2_rsa/issues/1 halo2_rsa calls https://github.com/privacy-scaling-explorations/halo2/blob/main/halo2_proofs/src/plonk/permutation/keygen.rs#L23 which does that vector allocation and fails (but there is "clone" of other objects going) and so its not easy could be web assembly created fault code which I know its rare... – zkbitcoin.com Nov 17 '22 at 21:23
  • and so I will try hard to find that faulty combination and update template app I have created (really minimal) but if @cafce25 others you see something that is a red flag in this please do let know (vector allocation faults in that function below) pub(crate) fn new(n: usize, p: &Argument) -> Self { ... – zkbitcoin.com Nov 17 '22 at 21:29

1 Answers1

0

In the original code I moved vec![vec![1usize; n]; p.columns.len()] size assignment to be first in the function, this got rid of mem alloc exception.

Resolved all my issues, this was also helpful (added --max-memory=4294967296 to RUSTFLAGS)

Only 1/4th of max memory available when rust wasm compiled with +atomics flag webassembly

Dharman
  • 30,962
  • 25
  • 85
  • 135
zkbitcoin.com
  • 39
  • 1
  • 7