Skip to content

Conversation

@HarryR
Copy link

@HarryR HarryR commented Sep 24, 2025

This is a small patch to import the two prove & verify functions from my ark-circom-witnesscalc, as a quick demo.

The reason behind this patch is:

  • I wanted to use MoPro on mobile web, not native
  • snarkjs was hanging when doing the groth16 setup for a complex circuit, so I used arkworks for trusted setup (runs almost instantly)
  • arkworks circom-prover used wasix to run the snarkjs WASM witness calculator, which made building for WASM complicated & slow
  • circom-witnesscalc used bindgen, which made WASM compilation difficult/annoying (no C headers for wasm32-unknown, C bindings were unnecessary when linking directly against it from Rust)
  • zkey loading isn't zero-copy for arkworks, requires filesystem access (not available on browser WASM)
  • wanted to use rayon for multithreading with browser WASM

To fix this I:

  • Made a small patch to circom-witnesscalc, to make building for browser WASM possible
  • Made a small repo combining arkworks & my circom-witnesscalc branch
    • https://github.com/HarryR/ark-circom-witnesscalc
    • Accepts JSON, responds with a JSON proof
    • Pass data (proving key, r1cs, witnesscalc graph) directly as bytes instead of loading from filesystem
    • Some small utilities, and library functions e.g. proof_to_json, verifying_key_from_json and so on which input/output in Circom JSON format.

This is a work in progress, and I would like feedback on how best to integrate this properly with MoPro, as it stands I can produce a single .wasm file containing the proving key, the witness generation runs quickly, and with rayon it can use all CPU cores while proving.

Unfortunately I ran into a small bug with circom-witnesscalc, where if the optimizer is enabled (anything aside form -O0) the wires/signals get confused, I will need to fix this. I also noticed that I had to disable the additional 'optimizer' stage in wasm-pack, as that resulted in nearly an order of magnitude increase in proving time, e.g. 47s vs 10s for a 100k constraint circuit on a single thread.

@vivianjeng
Copy link
Member

This is amazing!
I think it can be another feature in circom-prover
e.g. ark-circom-witnesscalc or wasm-circom-witnesscalc if it can be used for wasm
and enable this feature when user chooses to use it

and I hope if it is more stable, please publish the crate
Since we can only publish package on crates.io if all dependencies are published

and even if it is slower, we can still merge the PR
make the witness generation in browser working first, then improve the speed (with updating the version of ark-circom-witnesscalc)

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 this pull request may close these issues.

2 participants