Skip to content

Commit

Permalink
Merge pull request #17 from iosis-tech/npm
Browse files Browse the repository at this point in the history
Npm
  • Loading branch information
rkdud007 committed Jul 20, 2024
2 parents 89fcc15 + da2c622 commit eeb8f8e
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 283 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cairo-VM Verifier

![Version](https://img.shields.io/badge/v0.1.1-green?style=flat-square&logo=git&logoColor=white&label=version)
![Version](https://img.shields.io/badge/v0.0.3-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.
Expand Down Expand Up @@ -32,9 +32,9 @@ cargo test
- [x] starknet
- [x] starknet_with_keccak

- **WASM Support:**
- [ ] Wasm bindings for integration with web applications
- [ ] Example Cairo-VM STARK verifier web client
- **Web Support:**
- [x] Wasm Support
- [x] NPM package

## Contributing

Expand Down
6 changes: 3 additions & 3 deletions wasm-binding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "cairovm_verifier_wasm"
description.workspace = true
description = "CairoVM verifier - starknet_with_keccak & blake2s"
edition.workspace = true
homepage.workspace = true
license-file.workspace = true
license = "Apache-2.0"
readme.workspace = true
repository.workspace = true
version.workspace = true
Expand All @@ -23,7 +23,7 @@ crate-type = ["cdylib", "rlib"]
getrandom = { version = "0.2.15", features = ["js"] }

[features]
default = ["recursive", "keccak"]
default = ["starknet_with_keccak", "keccak"]
dex = []
recursive = []
recursive_with_poseidon = []
Expand Down
201 changes: 0 additions & 201 deletions wasm-binding/LICENSE

This file was deleted.

12 changes: 4 additions & 8 deletions wasm-binding/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cairo-VM Verifier WASM
# Cairo-VM Verifier

![Version](https://img.shields.io/badge/v0.1.1-green?style=flat-square&logo=git&logoColor=white&label=version)
![Version](https://img.shields.io/badge/v0.0.3-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.
Expand All @@ -13,9 +13,5 @@ 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.
wasm-pack build --target bundler --workspace --features starknet_with_keccak,blake2s --no-default-features
```
24 changes: 24 additions & 0 deletions wasm-binding/pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Cairo-VM Verifier

![Version](https://img.shields.io/badge/v0.0.3-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.

### Example usage
```js
import init, { cairovm_verify } from 'cairovm_verifier';

async function run(proof_json) {
await init(); // Initialize the Wasm module
try {
const [programHash, programOutput] = JSON.parse( await cairovm_verify(proof_json) );
} catch (err) {
console.error(`Verification failed: ${err}`);
}
}
```

## Contributing

Feel free to open issues or submit pull requests to help improve this project.
23 changes: 23 additions & 0 deletions wasm-binding/pkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "cairovm_verifier",
"type": "module",
"keywords": ["stark", "wasm", "verifier", "cairovm"],
"description": "CairoVM verifier - starknet_with_keccak & blake2s",
"version": "0.0.3",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/iosis-tech/cairovm-verifier"
},
"files": [
"cairovm_verifier_wasm_bg.wasm",
"cairovm_verifier_wasm.js",
"cairovm_verifier_wasm.d.ts"
],
"main": "cairovm_verifier_wasm.js",
"homepage": "",
"types": "cairovm_verifier_wasm.d.ts",
"sideEffects": [
"./snippets/*"
]
}
10 changes: 5 additions & 5 deletions wasm-binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ use cairovm_verifier_proof_parser::parse;
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn wasm_verify(proof: JsValue) -> Result<JsValue, JsValue> {
pub fn cairovm_verify(proof: JsValue) -> Result<JsValue, JsError> {
// Deserialize input from JsValue to Rust types
let proof_str: String = proof.as_string().ok_or_else(|| JsValue::from_str("Invalid input"))?;
let proof_str: String = proof.as_string().ok_or_else(|| JsError::new("Invalid input"))?;

// Parse the proof
let stark_proof = parse(proof_str).map_err(|e| JsValue::from_str(&e.to_string()))?;
let stark_proof = parse(proof_str).map_err(|e| JsError::new(&e.to_string()))?;

// Get security bits and verify
let security_bits = stark_proof.config.security_bits();
let (program_hash, output_hash) = stark_proof
.verify::<Layout>(security_bits)
.map_err(|e| JsValue::from_str(&e.to_string()))?;
.map_err(|e| JsError::new(&e.to_string()))?;

// Serialize result to JsValue
let result = serde_json::to_value((program_hash, output_hash))
.map_err(|e| JsValue::from_str(&e.to_string()))?;
.map_err(|e| JsError::new(&e.to_string()))?;
Ok(JsValue::from_str(&result.to_string()))
}
23 changes: 0 additions & 23 deletions wasm-binding/web/index.html

This file was deleted.

Loading

0 comments on commit eeb8f8e

Please sign in to comment.