diff --git a/Cargo.toml b/Cargo.toml index 4706a4b..0d30c9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,7 +48,7 @@ serde = "1.0" sha2 = "0.10.1" thiserror = "1.0.0" tiny-keccak = { version = "2.0.2" } -wasmer = "2.0" +wasmer = { version = "2.0", features = [ "dylib" ] } zkp-u256 = { version = "0.2", optional = true } # TODO: Remove # Use the same `ethers-core` version as ark-circom @@ -64,9 +64,6 @@ tempfile = "3.0" tiny-keccak = "2.0.2" tracing-test = "0.2" -# [patch.crates-io] -# wasmer = { git = 'https://github.com/philsippl/wasmer', rev = "e776616"} - [profile.release] codegen-units = 1 lto = true diff --git a/src/circuit.rs b/src/circuit.rs index 94e04d3..b83a9e5 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -5,9 +5,10 @@ use ark_relations::r1cs::ConstraintMatrices; use core::include_bytes; use once_cell::sync::Lazy; use std::{io::Cursor, sync::Mutex}; -use wasmer::{Module, Store}; +use wasmer::{Dylib, Module, Store}; const ZKEY_BYTES: &[u8] = include_bytes!("../semaphore/build/snark/semaphore_final.zkey"); + const WASM: &[u8] = include_bytes!("../semaphore/build/snark/semaphore.wasm"); pub static ZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(|| { @@ -17,8 +18,16 @@ pub static ZKEY: Lazy<(ProvingKey, ConstraintMatrices)> = Lazy::new(| pub static WITNESS_CALCULATOR: Lazy> = Lazy::new(|| { // Create Wasm module - let store = Store::default(); - let module = Module::from_binary(&store, WASM).expect("wasm should be valid"); + let module = if let Some(path) = option_env!("CIRCUIT_WASM_DYLIB") { + let store = Store::new(&Dylib::headless().engine()); + // The module must be exported using [`Module::serialize`]. + unsafe { + Module::deserialize_from_file(&store, path).expect("Failed to load wasm dylib module") + } + } else { + let store = Store::default(); + Module::from_binary(&store, WASM).expect("wasm should be valid") + }; // Create witness calculator let result =