arkworks-rs / circom-compat

Arkworks bindings to Circom's R1CS, for Groth16 Proof and Witness generation in Rust.
Apache License 2.0
231 stars 111 forks source link

Compile to WASM + Bindings #4

Open gakonst opened 3 years ago

gakonst commented 3 years ago

We should make this lib compile to WASM and also provide bindings to it.

When using this library from the browser, the ideal JS API would be:

  1. readZKeyAndWasm
  2. prove with the inputs in JS as a k-v object
    1. Internally calls Circom's Witness Generator to generate the witness. (We cannot do this in Rust, because it requires calling WASM from WASM-compiled-Rust which is not possible.)
    2. Calls the ark-circom WASM with the inputs from the previous step
  3. Call verify
lsankar4033 commented 2 years ago

EDIT: realized that these issues are both issues with dependencies assuming os-specific stuff. figuring out if there's an obvious workaround


trying to compile proving with wasm-pack and running into issues compiling deps libloading and memmap2 (below)

am digging deeper, but lmk if the solution is obvious as i'm not v. familiar with rust

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
  --> /Users/lakshmansankar/.cargo/registry/src/github.com-1ecc6299db9ec823/libloading-0.7.0/src/lib.rs:63:20
   |
63 | pub struct Library(imp::Library);
   |                    ^^^ use of undeclared crate or module `imp`
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
   --> /Users/lakshmansankar/.cargo/registry/src/github.com-1ecc6299db9ec823/memmap2-0.2.3/src/lib.rs:229:9
    |
229 |         MmapInner::map(self.get_len(file)?, file, self.offset, self.populate)
    |         ^^^^^^^^^^^^^^ -------------------  ----  -----------  ------------- supplied 4 arguments
    |         |
    |         expected 3 arguments
    |
note: associated function defined here
   --> /Users/lakshmansankar/.cargo/registry/src/github.com-1ecc6299db9ec823/memmap2-0.2.3/src/stub.rs:18:12
    |
18  |     pub fn map(_: usize, _: &File, _: u64) -> io::Result<MmapInner> {
    |            ^^^ --------  --------  ------
lsankar4033 commented 2 years ago

approach I'm going with is extracting out all the wasm execution and just doing that in js. wasm-ing just the parts of this lib downstream of that

jinankjain commented 2 years ago

@gakonst We got a verifier working on Rust based chains (NEAR). We are following a slightly different approach but I think the same can be applied here to compile to wasm. We are also using arkwork as the base layer. https://github.com/Electron-Labs/electron-rs

gakonst commented 2 years ago

that's just for parsing the types, the main issue we have here is the wasm witness generator unfortunately :(

jinankjain commented 2 years ago

We were mostly interested in verifier on-chain and had no use case for witness generator on chain.