Skip to content

Commit

Permalink
Add Plonky2 example
Browse files Browse the repository at this point in the history
  • Loading branch information
alxkzmn committed Feb 5, 2025
1 parent 7c441b2 commit 327322c
Show file tree
Hide file tree
Showing 18 changed files with 606 additions and 7 deletions.
143 changes: 141 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[workspace]
members = ["mopro-ffi", "test-e2e", "cli", "mopro-wasm", "test-e2e/mopro-wasm-lib"]
members = ["mopro-ffi", "test-e2e", "cli", "mopro-wasm", "test-e2e/mopro-wasm-lib", "plonky2-fibonacci"]
resolver = "2"
exclude = ["mopro-example-app"]

[workspace.dependencies]
plonk-fibonacci = { package = "plonk-fibonacci", git = "https://github.com/sifnoc/plonkish-fibonacci-sample.git" }
hyperplonk-fibonacci = { package = "hyperplonk-fibonacci", git = "https://github.com/sifnoc/plonkish-fibonacci-sample.git" }
gemini-fibonacci = { package = "gemini-fibonacci", git = "https://github.com/sifnoc/plonkish-fibonacci-sample.git" }
plonky2-fibonacci = { package = "plonky2-fibonacci", path = "./plonky2-fibonacci" }
4 changes: 4 additions & 0 deletions mopro-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ circom = [
"num-traits",
"byteorder",
]
plonky2 = []

[dependencies]
uniffi = { version = "=0.28.0", features = ["cli", "build"] }
Expand Down Expand Up @@ -86,3 +87,6 @@ serde_derive = "1.0"
plonk-fibonacci = { workspace = true }
hyperplonk-fibonacci = { workspace = true }
gemini-fibonacci = { workspace = true }

# Plonky2 dependencies
plonky2-fibonacci = { workspace = true }
29 changes: 29 additions & 0 deletions mopro-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod ashlang;
mod circom;
#[cfg(feature = "halo2")]
mod halo2;
#[cfg(feature = "plonky2")]
mod plonky2;

#[cfg(feature = "circom")]
pub use circom::{
Expand Down Expand Up @@ -89,6 +91,29 @@ macro_rules! halo2_app {
};
}

#[cfg(feature = "plonky2")]
pub use plonky2::{Plonky2ProveFn, Plonky2VerifyFn};

#[cfg(not(feature = "plonky2"))]
#[macro_export]
macro_rules! plonky2_app {
() => {
fn generate_plonky2_proof(
in0: String,
in1: std::collections::HashMap<String, Vec<String>>,
) -> Result<Vec<u8>, MoproError> {
panic!("Plonky2 is not enabled in this build. Please pass `plonky2` feature to `mopro-ffi` to enable Halo2.")
}

fn verify_plonky2_proof(
in0: String,
in1: Vec<u8>,
) -> Result<bool, MoproError> {
panic!("Plonky2 is not enabled in this build. Please pass `plonky2` feature to `mopro-ffi` to enable Halo2.")
}
};
}

use thiserror::Error;

#[derive(Debug, Error)]
Expand All @@ -99,6 +124,8 @@ pub enum MoproError {
Halo2Error(String),
#[error("AshlangError: {0}")]
AshlangError(String),
#[error("Plonky2Error: {0}")]
Plonky2Error(String),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -172,6 +199,8 @@ macro_rules! app {

mopro_ffi::halo2_app!();

mopro_ffi::plonky2_app!();

mopro_ffi::ashlang_spartan_app!();

uniffi::include_scaffolding!("mopro");
Expand Down
7 changes: 7 additions & 0 deletions mopro-ffi/src/mopro.udl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ namespace mopro {
[Throws=MoproError]
boolean verify_halo2_proof(string srs_path, string vk_path, bytes proof, bytes public_input);

[Throws=MoproError]
bytes generate_plonky2_proof(string pk_path, record<string, sequence<string>> circuit_inputs);

[Throws=MoproError]
boolean verify_plonky2_proof( string vk_path, bytes proof);

[Throws=MoproError]
GenerateProofResult generate_circom_proof(string zkey_path, record<string, sequence<string>> circuit_inputs);

Expand Down Expand Up @@ -47,4 +53,5 @@ enum MoproError {
"CircomError",
"Halo2Error",
"AshlangError",
"Plonky2Error"
};
Loading

0 comments on commit 327322c

Please sign in to comment.