Add dylib support with compile time env path
This commit is contained in:
parent
703fe282c1
commit
b84941f767
|
@ -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
|
||||
|
|
|
@ -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<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|| {
|
||||
|
@ -17,8 +18,16 @@ pub static ZKEY: Lazy<(ProvingKey<Bn254>, ConstraintMatrices<Fr>)> = Lazy::new(|
|
|||
|
||||
pub static WITNESS_CALCULATOR: Lazy<Mutex<WitnessCalculator>> = Lazy::new(|| {
|
||||
// Create Wasm module
|
||||
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();
|
||||
let module = Module::from_binary(&store, WASM).expect("wasm should be valid");
|
||||
Module::from_binary(&store, WASM).expect("wasm should be valid")
|
||||
};
|
||||
|
||||
// Create witness calculator
|
||||
let result =
|
||||
|
|
Loading…
Reference in New Issue