Skip to content

Commit

Permalink
wasm binding feature flags refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jul 19, 2024
1 parent 606ede1 commit ea4735e
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 34 deletions.
23 changes: 12 additions & 11 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ version = "0.0.3"

[workspace.dependencies]
bail-out = "0.2.0"
serde_json = "1.0.114"
serde = { version = "1.0", features = ["derive"] }
serde_with = "2.3.2"
sha3 = "0.10.8"
Expand Down
12 changes: 7 additions & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ version.workspace = true
clap = { version = "4.4.4", features = ["derive"] }
thiserror.workspace = true
starknet-crypto.workspace = true
cairovm_verifier_proof_parser.workspace = true
cairovm_verifier_stark.workspace = true
cairovm_verifier_air.workspace = true

cairovm_verifier_air = { workspace = true, default-features = false }
cairovm_verifier_stark = { workspace = true, default-features = false }
cairovm_verifier_proof_parser = { workspace = true, default-features = false }

[features]
default = ["recursive"]
default = ["recursive", "keccak"]
dex = []
recursive = []
recursive_with_poseidon = []
small = []
starknet = []
starknet_with_keccak = []
starknet_with_keccak = []
keccak = []
blake2s = []
2 changes: 1 addition & 1 deletion crates/air/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cairovm_verifier_commitment.workspace = true
cairovm_verifier_transcript.workspace = true

[features]
default = ["starknet_with_keccak"]
default = ["recursive"]
dex = []
recursive = []
recursive_with_poseidon = []
Expand Down
2 changes: 1 addition & 1 deletion crates/commitment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ blake2.workspace = true
cairovm_verifier_transcript.workspace = true

[features]
default = ["blake2s"]
default = ["keccak"]
keccak = []
blake2s = []
2 changes: 1 addition & 1 deletion crates/pow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ blake2.workspace = true
cairovm_verifier_transcript.workspace = true

[features]
default = ["blake2s"]
default = ["keccak"]
keccak = []
blake2s = []
2 changes: 1 addition & 1 deletion crates/stark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cairovm_verifier_pow.workspace = true
cairovm_verifier_transcript.workspace = true

[features]
default = ["starknet_with_keccak"]
default = ["recursive"]
dex = []
recursive = []
recursive_with_poseidon = []
Expand Down
12 changes: 5 additions & 7 deletions proof-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ clap = { version = "4.5.1", features = ["derive"] }
regex = "1.10.3"
serde_json = "1.0.114"

cairovm_verifier_stark = { workspace = true, features = [
"starknet_with_keccak",
] }
cairovm_verifier_commitment = { workspace = true, features = ["default"] }
cairovm_verifier_fri = { workspace = true }
cairovm_verifier_air = { workspace = true, features = ["starknet_with_keccak"] }
cairovm_verifier_pow = { workspace = true, features = ["default"] }
cairovm_verifier_stark.workspace = true
cairovm_verifier_commitment.workspace = true
cairovm_verifier_fri.workspace = true
cairovm_verifier_air.workspace = true
cairovm_verifier_pow.workspace = true
21 changes: 16 additions & 5 deletions wasm-binding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "wasm-binding"
name = "cairovm_verifier_wasm"
description.workspace = true
edition.workspace = true
homepage.workspace = true
Expand All @@ -9,15 +9,26 @@ repository.workspace = true
version.workspace = true

[dependencies]
serde_json.workspace = true
wasm-bindgen.workspace = true
getrandom = { version = "0.2.15", features = ["js"] }
serde_json = "1.0.114"

cairovm_verifier_air = { workspace = true, features = ["default"] }
cairovm_verifier_proof_parser = { workspace = true }
cairovm_verifier_air = { workspace = true, default-features = false }
cairovm_verifier_stark = { workspace = true, default-features = false }
cairovm_verifier_proof_parser = { workspace = true, default-features = false }

[lib]
crate-type = ["cdylib", "rlib"]

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2.15", features = ["js"] }

[features]
default = ["recursive", "keccak"]
dex = []
recursive = []
recursive_with_poseidon = []
small = []
starknet = []
starknet_with_keccak = []
keccak = []
blake2s = []
21 changes: 21 additions & 0 deletions wasm-binding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Cairo-VM Verifier WASM

![Version](https://img.shields.io/badge/v0.1.1-green?style=flat-square&logo=git&logoColor=white&label=version)
![Continuous Integration](https://img.shields.io/github/actions/workflow/status/iosis-tech/cairovm-verifier/ci.yml?style=flat-square&logo=githubactions&logoColor=white&label=Continuous%20Integration)

This is the Rust implementation of the Cairo-VM STARK verifier with layouts. The code is inspired by StarkWare's [Cairo-verifier](https://github.com/starkware-libs/cairo-lang) implementation in Cairo0.

### Install wasm-pack
```sh
cargo install wasm-pack
```

### Build WASM:

```sh
wasm-pack build --workspace --features starknet_with_keccak,blake2s --no-default-features --target wasm32-unknown-unknown
```

## Contributing

Feel free to open issues or submit pull requests to help improve this project.
16 changes: 14 additions & 2 deletions wasm-binding/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
use cairovm_verifier_air::layout::starknet_with_keccak;
#[cfg(feature = "dex")]
use cairovm_verifier_air::layout::dex::Layout;
#[cfg(feature = "recursive")]
use cairovm_verifier_air::layout::recursive::Layout;
#[cfg(feature = "recursive_with_poseidon")]
use cairovm_verifier_air::layout::recursive_with_poseidon::Layout;
#[cfg(feature = "small")]
use cairovm_verifier_air::layout::small::Layout;
#[cfg(feature = "starknet")]
use cairovm_verifier_air::layout::starknet::Layout;
#[cfg(feature = "starknet_with_keccak")]
use cairovm_verifier_air::layout::starknet_with_keccak::Layout;

use cairovm_verifier_proof_parser::parse;
use wasm_bindgen::prelude::*;

Expand All @@ -13,7 +25,7 @@ pub fn wasm_verify(proof: JsValue) -> Result<JsValue, JsValue> {
// Get security bits and verify
let security_bits = stark_proof.config.security_bits();
let (program_hash, output_hash) = stark_proof
.verify::<starknet_with_keccak::Layout>(security_bits)
.verify::<Layout>(security_bits)
.map_err(|e| JsValue::from_str(&e.to_string()))?;

// Serialize result to JsValue
Expand Down

0 comments on commit ea4735e

Please sign in to comment.