Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Wasm build first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
zemse committed Dec 16, 2023
1 parent 449d457 commit 91172b2
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 31 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 49 additions & 31 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,61 @@ path = "src/main.rs"

[dependencies]
# anvil
anvil = { git = "https://github.com/foundry-rs/foundry.git", package = "anvil", features = [ "default" ], rev = "dea5405" }
anvil-core = { git = "https://github.com/foundry-rs/foundry.git", package = "anvil-core", features = [ "default" ], rev = "dea5405" }
ethers = { git = "https://github.com/gakonst/ethers-rs", features = ["ws"] }
partial-mpt = { git = "https://github.com/zemse/partial-mpt", branch = "main" }
anvil = { git = "https://github.com/foundry-rs/foundry.git", package = "anvil", features = [ "default" ], rev = "dea5405", optional = true }
anvil-core = { git = "https://github.com/foundry-rs/foundry.git", package = "anvil-core", features = [ "default" ], rev = "dea5405", optional = true }
ethers = { git = "https://github.com/gakonst/ethers-rs", optional = true }
partial-mpt = { git = "https://github.com/zemse/partial-mpt", branch = "main", optional = true }

# zkevm
bus-mapping = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main", features = [ "test" ] }
eth-types = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main" }
zkevm-circuits = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main" }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20" }
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier.git", rev = "a440ff91" }
ethers-core = "2.0.7"
itertools = "0.10"
rand_chacha = "0.3"
bus-mapping = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main", features = [ "test" ], optional = true }
eth-types = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main", optional = true }
zkevm-circuits = { git = "https://github.com/privacy-scaling-explorations/zkevm-circuits", branch = "main", optional = true }
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_04_20", optional = true }
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier.git", rev = "a440ff91", optional = true }
ethers-core = { version = "2.0.7", optional = true }
itertools = { version = "0.10", optional = true }
rand_chacha = { version = "0.3", optional = true }

# misc
tokio = { version = "1.13", features = ["macros"] }
futures = { version = "0.3.*" }
dotenv = "0.15.0"
bytes = "1.1.0"
clap = { version = "4.0", features = ["derive", "cargo"] }
serde = "1.0.188"
serde_json = "1.0.107"
regex = "1.9.5"
reqwest = { version = "0.11" }
pinata-sdk = "1.1.0"
svm-rs = "0.3.3"
semver = { version = "1.0", features = ["serde"] }
home = "0.5.5"
tokio = { version = "1.13", features = ["macros"], optional = true }
futures = { version = "0.3.*", optional = true }
dotenv = { version = "0.15.0", optional = true }
bytes = { version = "1.1.0", optional = true }
clap = { version = "4.0", features = ["derive", "cargo"], optional = true }
serde = { version = "1.0.188", optional = true }
serde_json = { version = "1.0.107", optional = true }
regex = { version = "1.9.5", optional = true }
reqwest = { version = "0.11", optional = true }
pinata-sdk = { version = "1.1.0", optional = true }
svm-rs = { version = "0.3.3", optional = true }
semver = { version = "1.0", features = ["serde"], optional = true }
home = { version = "0.5.5", optional = true }

# [target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["js"], optional = true }
wasm-bindgen = { version = "0.2.81", features = ["serde-serialize"], optional = true }
rayon = { version = "1.5", optional = true }
wasm-bindgen-rayon = { version = "1.0", optional = true }
web-sys = { version = "0.3", features = ["Request", "Window", "Response"], optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
js-sys = { version = "0.3", optional = true }
# console_error_panic_hook = { version = "0.1.7", optional = true }

[patch."https://github.com/privacy-scaling-explorations/zkevm-circuits"]
bus-mapping = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230" }
eth-types = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230" }
zkevm-circuits = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230" }
bus-mapping = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230", optional = true }
eth-types = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230", optional = true }
zkevm-circuits = { git = "https://github.com/zemse/zkevm-circuits", rev = "fb284230", optional = true }

# for local development only
# [patch."https://github.com/privacy-scaling-explorations/zkevm-circuits"]
# bus-mapping = { path = "../zkevm-circuits/bus-mapping" }
# eth-types = { path = "../zkevm-circuits/eth-types" }
# zkevm-circuits = { path = "../zkevm-circuits/zkevm-circuits" }
# bus-mapping = { path = "../zkevm-circuits/bus-mapping", optional = true }
# eth-types = { path = "../zkevm-circuits/eth-types", optional = true }
# zkevm-circuits = { path = "../zkevm-circuits/zkevm-circuits", optional = true }

[features]
default = ["dep_wasm"]
dep_binary = ["dep_mainnet_fork", "dep_zkevm", "dep_misc"]
dep_mainnet_fork = ["anvil", "anvil-core", "ethers", "partial-mpt"]
dep_zkevm = ["bus-mapping", "eth-types", "zkevm-circuits", "halo2_proofs", "snark-verifier", "ethers-core", "itertools", "rand_chacha"]
dep_misc = ["tokio", "futures", "dotenv", "clap", "serde", "serde_json", "regex", "reqwest", "pinata-sdk", "svm-rs", "semver", "home"]
dep_wasm = ["getrandom", "wasm-bindgen", "rayon", "wasm-bindgen-rayon", "web-sys", "wasm-bindgen-futures", "js-sys"]
1 change: 1 addition & 0 deletions build_wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+mutable-globals' cargo build --lib --release --no-default-features --features dep_wasm --target wasm32-unknown-unknown -Z build-std=panic_abort,std
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
#![feature(let_chains)]
#![feature(slice_pattern)]

#[cfg(not(feature = "dep_wasm"))]
pub mod cli;
#[cfg(not(feature = "dep_wasm"))]
pub mod constants;
#[cfg(not(feature = "dep_wasm"))]
pub mod env;
#[cfg(not(feature = "dep_wasm"))]
pub mod error;
#[cfg(not(feature = "dep_wasm"))]
pub mod utils;
#[cfg(not(feature = "dep_wasm"))]
pub mod verification;
#[cfg(not(feature = "dep_wasm"))]
pub mod witness;

#[cfg(all(
feature = "dep_wasm",
not(target_arch = "wasm32"),
not(target_os = "unknown")
))]
compile_error!("compiling with dep_wasm feature requires wasm32-unknown-unknown target");
#[cfg(feature = "dep_wasm")]
pub mod wasm;
#[cfg(feature = "dep_wasm")]
pub use wasm::*;
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(feature = "dep_wasm"))]
use proof_of_exploit::{
cli::{
exploit_command, ProveArgs, PublishArgs, ScaffoldArgs, VerifyArgs, PROVE, PUBLISH,
Expand All @@ -9,6 +10,7 @@ use proof_of_exploit::{
witness::Witness,
};

#[cfg(not(feature = "dep_wasm"))]
#[tokio::main]
async fn main() {
let env = Env::load();
Expand Down Expand Up @@ -45,3 +47,8 @@ async fn main() {
_ => unreachable!("command not found"),
}
}

#[cfg(feature = "dep_wasm")]
fn main() {
unreachable!();
}
11 changes: 11 additions & 0 deletions src/wasm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
fn alert(s: &str);
}

#[wasm_bindgen]
pub fn temp_code() {
alert("Hello, myproject!");
}

0 comments on commit 91172b2

Please sign in to comment.