Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: feat: add commit scheme option #297

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/cli/src/app_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use clap::Command;
use clap::ValueHint;

use crate::args::HostMode;
use crate::args::Scheme;
use crate::command::DryRunArg;
use crate::command::ProveArg;
use crate::command::RunningArg;
Expand Down Expand Up @@ -197,6 +198,14 @@ fn setup_command() -> Command<'static> {
).takes_value(true)
.value_delimiter(',')
.required(false)
)
.arg(
arg!(
--scheme <SCHEME> "Specify polynomial commitment scheme"
)
.default_value("shplonk")
.value_parser(value_parser!(Scheme))
.required(false),
);

let command = if cfg!(not(feature = "uniform-circuit")) {
Expand Down Expand Up @@ -273,6 +282,7 @@ impl From<&ArgMatches> for SetupArg {
.map(|v| v.to_string())
.collect::<Vec<_>>(),
wasm_image: WasmImageArg::parse(val),
scheme: *val.get_one::<Scheme>("scheme").unwrap(),
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion crates/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
use circuits_batcher::args::OpenSchema;
use serde::Deserialize;
use serde::Serialize;

#[derive(clap::ArgEnum, Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub enum HostMode {
pub(crate) enum HostMode {
/// Trivial Wasm Host Environment
#[default]
Default,

/// Wasm Host Environment with more Zk plugins
Standard,
}

#[derive(clap::ArgEnum, Copy, Clone, Debug, Default, Serialize, Deserialize)]
pub(crate) enum Scheme {
Gwc,

#[default]
Shplonk,
}

impl From<Scheme> for OpenSchema {
fn from(val: Scheme) -> OpenSchema {
match val {
Scheme::Gwc => OpenSchema::GWC,
Scheme::Shplonk => OpenSchema::Shplonk,
}
}
}
4 changes: 4 additions & 0 deletions crates/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::io::Read;
use std::path::Path;
use std::path::PathBuf;

use crate::args::Scheme;
use crate::config::CircuitDataConfig;
use crate::config::CircuitDataMd5;
use crate::TRIVIAL_WASM;
Expand Down Expand Up @@ -38,6 +39,7 @@ pub(crate) struct SetupArg {
pub(crate) host_mode: HostMode,
pub(crate) phantom_functions: Vec<String>,
pub(crate) wasm_image: Option<PathBuf>,
pub(crate) scheme: Scheme,
}

impl SetupArg {
Expand Down Expand Up @@ -215,6 +217,8 @@ impl SetupArg {
checksum,
phantom_functions: self.phantom_functions.clone(),
host_mode: self.host_mode,

scheme: self.scheme,
};
config.write(&mut File::create(&config_path)?)?;

Expand Down
10 changes: 6 additions & 4 deletions crates/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::path::PathBuf;

use anyhow::Result;
use circuits_batcher::args::HashType;
use circuits_batcher::args::OpenSchema;
use circuits_batcher::proof::ProofGenerationInfo;
use circuits_batcher::proof::ProofInfo;
use circuits_batcher::proof::ProofPieceInfo;
Expand All @@ -31,6 +30,7 @@ use serde::Serialize;
use specs::slice_backend::SliceBackendBuilder;

use crate::args::HostMode;
use crate::args::Scheme;
use crate::names::name_of_circuit_data;
use crate::names::name_of_etable_slice;
use crate::names::name_of_external_host_call_table_slice;
Expand Down Expand Up @@ -74,6 +74,8 @@ pub(crate) struct Config {
pub(crate) checksum: (String, String),
pub(crate) phantom_functions: Vec<String>,
pub(crate) host_mode: HostMode,

pub(crate) scheme: Scheme,
}

impl Config {
Expand Down Expand Up @@ -413,7 +415,7 @@ impl Config {
&params,
&cached_proving_key.as_ref().unwrap().1,
proof_load_info.hashtype,
OpenSchema::Shplonk,
self.scheme.into(),
),
ZkWasmCircuit::LastSliceCircuit(circuit) => proof_piece_info
.create_proof::<Bn256, _>(
Expand All @@ -422,7 +424,7 @@ impl Config {
&params,
&cached_proving_key.as_ref().unwrap().1,
proof_load_info.hashtype,
OpenSchema::Shplonk,
self.scheme.into(),
),
};

Expand Down Expand Up @@ -509,7 +511,7 @@ impl Config {
};

proof
.verify_proof(&params_verifier, OpenSchema::Shplonk)
.verify_proof(&params_verifier, self.scheme.into())
.unwrap();

// TODO: handle checksum sanity check
Expand Down
7 changes: 4 additions & 3 deletions test_cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ set -e
set -x

CUDA="--features cuda"
SCHEME="--scheme shplonk"

test_default_cli() {
cargo build --release $CUDA
rm -rf params/*.data params/*.config output
$CLI --params ./params wasm_output setup --wasm ./crates/zkwasm/wasm/wasm_output.wasm
$CLI --params ./params wasm_output setup --wasm ./crates/zkwasm/wasm/wasm_output.wasm $SCHEME
$CLI --params ./params wasm_output dry-run --wasm crates/zkwasm/wasm/wasm_output.wasm --public 133:i64 --public 2:i64 --output ./output
$CLI --params ./params wasm_output prove --wasm crates/zkwasm/wasm/wasm_output.wasm --public 133:i64 --public 2:i64 --output ./output
$CLI --params ./params wasm_output verify --output ./output
Expand All @@ -19,7 +20,7 @@ test_default_cli() {
test_uniform_circuit_cli() {
cargo build --release --features uniform-circuit $CUDA
rm -rf params/*.data params/*.config output
$CLI --params ./params wasm_output setup
$CLI --params ./params wasm_output setup $SCHEME
$CLI --params ./params wasm_output dry-run --wasm crates/zkwasm/wasm/wasm_output.wasm --public 133:i64 --public 2:i64 --output ./output
$CLI --params ./params wasm_output prove --wasm crates/zkwasm/wasm/wasm_output.wasm --public 133:i64 --public 2:i64 --output ./output
$CLI --params ./params wasm_output verify --output ./output
Expand All @@ -28,7 +29,7 @@ test_uniform_circuit_cli() {
test_continuation_cli() {
cargo build --release --features continuation $CUDA
rm -rf params/*.data params/*.config output
$CLI --params ./params fibonacci setup
$CLI --params ./params fibonacci setup $SCHEME
$CLI --params ./params fibonacci dry-run --wasm crates/zkwasm/wasm/fibonacci.wasm --public 25:i64 --output ./output
$CLI --params ./params fibonacci prove --wasm crates/zkwasm/wasm/fibonacci.wasm --public 25:i64 --output ./output
$CLI --params ./params fibonacci verify --output ./output
Expand Down
Loading