Skip to content

Commit

Permalink
Merge pull request #2 from zkmopro/refactor-2
Browse files Browse the repository at this point in the history
refactor: use tests and crates folders
  • Loading branch information
vivianjeng authored Feb 5, 2025
2 parents 1d32c92 + d4a4c65 commit da8cba1
Show file tree
Hide file tree
Showing 77 changed files with 341 additions and 241 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

95 changes: 9 additions & 86 deletions Cargo.lock

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

21 changes: 3 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
[package]
name = "rust-rapidsnark"
version = "0.1.0"
edition = "2021"

[lib]

[dependencies]
anyhow = "1.0.95"
num-bigint = "0.4.6"
rust-witness = "0.1.2"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
num-traits = "0.2.19"

[build-dependencies]
cc = "1.0"
rust-witness = "0.1.2"
[workspace]
members = ["crates", "tests"]
resolver = "2"
89 changes: 87 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,88 @@
# rust-rapidsnark
# Rust Rapidsnark

Rust bindings for the [rapidsnark](https://github.com/iden3/rapidsnark/) prover.
<!-- [![Crates.io](https://img.shields.io/crates/v/witnesscalc-adapter?label=witnesscalc-adapter)](https://crates.io/crates/witnesscalc-adapter) -->

This project provides a Rust adapter for compiling and linking [Rapidsnark](https://github.com/iden3/rapidsnark) into a native library for target platforms (e.g., mobile devices). It includes macros and functions to facilitate the integration of proof generation into Rust codebases.

## Usage

Include the crate in your `Cargo.toml`:

```toml
[dependencies]
rust-rapidsnark = "0.1.0"

[build-dependencies]
rust-rapidsnark = "0.1.0"
```

It doesn't include the witness generation functions, you need to use one of the following crates to generate the witness:

- [rust-witness](https://github.com/chancehudson/rust-witness)
- [witnesscalc-adapter](https://github.com/zkmopro/witnesscalc_adapter)
- [circom-witnesscalc](https://github.com/iden3/circom-witnesscalc)
- [wasmer](https://github.com/wasmerio/wasmer)

For example, building witness with `witnesscalc-adapter`:

```rust
witnesscalc_adapter::witness!(multiplier2);
let json_input_string = "{\"a\": [\"2\"], \"b\": [\"3\"]}";;
let wtns_buffer = multiplier2_witness(json_input_string).unwrap();
```

### Calculate the proof

Calculate the proof by using the `groth16_prover_zkey_file_wrapper` function.
It will take a `wtns` bytes array like the output of [witnesscalc](https://github.com/0xPolygonID/witnesscalc) or [snarkjs](https://github.com/iden3/snarkjs).

```rust
let zkey_path = "./test-vectors/multiplier2_final.zkey".to_string();
let proof = rust_rapidsnark::groth16_prover_zkey_file_wrapper(&zkey_path, wtns_buffer).unwrap();
```

### Verify the proof

Verify the proof by using the `groth16_verifier_zkey_file_wrapper` function.

```rust
let vkey = std::fs::read_to_string("./test-vectors/keccak256_256_test.vkey.json")?;
let valid = rust_rapidsnark::groth16_verify_wrapper(
&proof.proof,
&proof.public_signals,
&vkey,
)?;
```

## Supported platforms

### Linux

- x86_64 linux
- arm64 linux

### MacOS

- aarch64-apple-darwin
- x86_64-apple-darwin

### iOS

- aarch64-apple-ios
- aarch64-apple-ios-sim
- x86_64-apple-ios

### Android

- aarch64-linux-android
- x86_64-linux-android

## Community

- Website: [zkmopro.com](https://zkmopro.com)
- X account: <a href="https://twitter.com/zkmopro"><img src="https://img.shields.io/twitter/follow/zkmopro?style=flat-square&logo=x&label=zkmopro"></a>
- Telegram group: <a href="https://t.me/zkmopro"><img src="https://img.shields.io/badge/telegram-@zkmopro-blue.svg?style=flat-square&logo=telegram"></a>

## Acknowledgements

- The project is sponsored by [PSE](https://pse.dev/).
18 changes: 18 additions & 0 deletions crates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "rust-rapidsnark"
version = "0.1.0"
edition = "2021"
license = "MIT OR Apache-2.0"
repository = "https://github.com/zkmopro/rust-rapidsnark"
documentation = "https://zkmopro.org/"
homepage = "https://zkmopro.org/"

[lib]

[dependencies]
anyhow = "1.0.95"
num-bigint = "0.4.6"
num-traits = "0.2.19"

[build-dependencies]
cc = "1.0"
88 changes: 88 additions & 0 deletions crates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Rust Rapidsnark

<!-- [![Crates.io](https://img.shields.io/crates/v/witnesscalc-adapter?label=witnesscalc-adapter)](https://crates.io/crates/witnesscalc-adapter) -->

This project provides a Rust adapter for compiling and linking [Rapidsnark](https://github.com/iden3/rapidsnark) into a native library for target platforms (e.g., mobile devices). It includes macros and functions to facilitate the integration of proof generation into Rust codebases.

## Usage

Include the crate in your `Cargo.toml`:

```toml
[dependencies]
rust-rapidsnark = "0.1.0"

[build-dependencies]
rust-rapidsnark = "0.1.0"
```

It doesn't include the witness generation functions, you need to use one of the following crates to generate the witness:

- [rust-witness](https://github.com/chancehudson/rust-witness)
- [witnesscalc-adapter](https://github.com/zkmopro/witnesscalc_adapter)
- [circom-witnesscalc](https://github.com/iden3/circom-witnesscalc)
- [wasmer](https://github.com/wasmerio/wasmer)

For example, building witness with `witnesscalc-adapter`:

```rust
witnesscalc_adapter::witness!(multiplier2);
let json_input_string = "{\"a\": [\"2\"], \"b\": [\"3\"]}";;
let wtns_buffer = multiplier2_witness(json_input_string).unwrap();
```

### Calculate the proof

Calculate the proof by using the `groth16_prover_zkey_file_wrapper` function.
It will take a `wtns` bytes array like the output of [witnesscalc](https://github.com/0xPolygonID/witnesscalc) or [snarkjs](https://github.com/iden3/snarkjs).

```rust
let zkey_path = "./test-vectors/multiplier2_final.zkey".to_string();
let proof = rust_rapidsnark::groth16_prover_zkey_file_wrapper(&zkey_path, wtns_buffer).unwrap();
```

### Verify the proof

Verify the proof by using the `groth16_verifier_zkey_file_wrapper` function.

```rust
let vkey = std::fs::read_to_string("./test-vectors/keccak256_256_test.vkey.json")?;
let valid = rust_rapidsnark::groth16_verify_wrapper(
&proof.proof,
&proof.public_signals,
&vkey,
)?;
```

## Supported platforms

### Linux

- x86_64 linux
- arm64 linux

### MacOS

- aarch64-apple-darwin
- x86_64-apple-darwin

### iOS

- aarch64-apple-ios
- aarch64-apple-ios-sim
- x86_64-apple-ios

### Android

- aarch64-linux-android
- x86_64-linux-android

## Community

- Website: [zkmopro.com](https://zkmopro.com)
- X account: <a href="https://twitter.com/zkmopro"><img src="https://img.shields.io/twitter/follow/zkmopro?style=flat-square&logo=x&label=zkmopro"></a>
- Telegram group: <a href="https://t.me/zkmopro"><img src="https://img.shields.io/badge/telegram-@zkmopro-blue.svg?style=flat-square&logo=telegram"></a>

## Acknowledgements

- The project is sponsored by [PSE](https://pse.dev/).
4 changes: 0 additions & 4 deletions build.rs → crates/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use std::path::Path;
use std::path::PathBuf;

fn main() {
if std::env::var("RUST_RAPIDSNARK_LINK_TEST_WITNESS").is_ok() {
rust_witness::transpile::transpile_wasm("./test-vectors".to_string());
}

let target = std::env::var("TARGET").unwrap();
let arch = target.split('-').next().unwrap();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit da8cba1

Please sign in to comment.