Skip to content

Commit f0ee298

Browse files
committed
feat: submit and verify zisk proofs commands in cli
1 parent e360ec3 commit f0ee298

6 files changed

Lines changed: 154 additions & 64 deletions

File tree

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
use clap::{self, ValueEnum};
21
use std::str::FromStr;
32

43
use agg_mode_sdk::types::Network;
54

65
pub fn parse_network(value: &str) -> Result<Network, String> {
76
Network::from_str(value).map_err(|_| format!("unsupported network supplied: {value}"))
87
}
9-
10-
#[derive(Debug, Clone, ValueEnum)]
11-
pub enum ProvingSystemArg {
12-
#[clap(name = "SP1")]
13-
SP1,
14-
#[clap(name = "Risc0")]
15-
Risc0,
16-
}

aggregation_mode/cli/src/commands/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::commands::{deposit::SendPaymentArgs, submit::SubmitCommand, verify::VerifyOnChainArgs};
1+
use crate::commands::{deposit::SendPaymentArgs, submit::SubmitCommand, verify::VerifyCommand};
22
use clap::{Parser, Subcommand};
33

44
pub mod deposit;
@@ -17,8 +17,8 @@ pub enum Command {
1717
#[command(subcommand)]
1818
Submit(SubmitCommand),
1919
/// Check whether a proof has been verified on AlignedProofAggregationService contract
20-
#[command(name = "verify-on-chain")]
21-
VerifyOnChain(VerifyOnChainArgs),
20+
#[command(subcommand, name = "verify-on-chain")]
21+
VerifyOnChain(VerifyCommand),
2222
/// Send 1 ether to the aggregation mode payment service
2323
#[command(name = "deposit")]
2424
Deposit(SendPaymentArgs),

aggregation_mode/cli/src/commands/submit.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use crate::commands::helpers::parse_network;
1010
pub enum SubmitCommand {
1111
#[command(name = "sp1")]
1212
SP1(SubmitSP1Args),
13+
#[command(name = "zisk")]
14+
Zisk(SubmitZiskArgs),
1315
}
1416

1517
#[derive(Debug, Clone, Args)]
@@ -24,11 +26,21 @@ pub struct SubmitSP1Args {
2426
network: Network,
2527
}
2628

27-
pub async fn run(args: SubmitSP1Args) {
29+
#[derive(Debug, Clone, Args)]
30+
pub struct SubmitZiskArgs {
31+
#[arg(short = 'p', long = "proof")]
32+
proof_path: PathBuf,
33+
#[arg(long = "private-key")]
34+
private_key: String,
35+
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
36+
network: Network,
37+
}
38+
39+
pub async fn run_sp1(args: SubmitSP1Args) {
2840
tracing::info!("Submitting SP1 proof to {:?} ", args.network);
2941

30-
let proof = load_proof(&args.proof_path).expect("Valid proof");
31-
let vk = load_vk(&args.verifying_key_path).expect("Valid vk");
42+
let proof = load_sp1_proof(&args.proof_path).expect("Valid proof");
43+
let vk = load_sp1_vk(&args.verifying_key_path).expect("Valid vk");
3244

3345
let signer =
3446
LocalSigner::from_str(args.private_key.trim()).expect("failed to parse private key: {e}");
@@ -47,15 +59,38 @@ pub async fn run(args: SubmitSP1Args) {
4759
);
4860
}
4961

50-
fn load_proof(path: &PathBuf) -> Result<SP1ProofWithPublicValues, String> {
62+
pub async fn run_zisk(args: SubmitZiskArgs) {
63+
tracing::info!("Submitting Zisk proof to {:?} ", args.network);
64+
65+
let proof = std::fs::read(&args.proof_path)
66+
.expect(&format!("failed to read proof from {}", args.proof_path.display()));
67+
68+
let signer =
69+
LocalSigner::from_str(args.private_key.trim()).expect("failed to parse private key: {e}");
70+
71+
let provider = AggregationModeGatewayProvider::new_with_signer(args.network.clone(), signer)
72+
.expect("failed to initialize gateway client: {e:?}");
73+
74+
let response = provider
75+
.submit_zisk_proof(&proof)
76+
.await
77+
.expect("failed to submit proof: {e:?}");
78+
79+
tracing::info!(
80+
"Proof submitted successfully. Task ID: {}",
81+
response.data.task_id
82+
);
83+
}
84+
85+
fn load_sp1_proof(path: &PathBuf) -> Result<SP1ProofWithPublicValues, String> {
5186
let bytes = std::fs::read(path)
5287
.map_err(|e| format!("failed to read proof from {}: {e}", path.display()))?;
5388

5489
bincode::deserialize(&bytes)
5590
.map_err(|e| format!("failed to deserialize proof {}: {e}", path.display()))
5691
}
5792

58-
fn load_vk(path: &PathBuf) -> Result<SP1VerifyingKey, String> {
93+
fn load_sp1_vk(path: &PathBuf) -> Result<SP1VerifyingKey, String> {
5994
let bytes = std::fs::read(path)
6095
.map_err(|e| format!("failed to read verifying key from {}: {e}", path.display()))?;
6196

aggregation_mode/cli/src/commands/verify.rs

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ use agg_mode_sdk::{
55
types::Network,
66
};
77
use alloy::hex;
8-
use clap::{self, Args};
8+
use clap::{command, Args, Subcommand};
99
use std::path::PathBuf;
1010

11-
use crate::commands::helpers::{parse_network, ProvingSystemArg};
11+
use crate::commands::helpers::parse_network;
12+
13+
#[derive(Debug, Subcommand)]
14+
pub enum VerifyCommand {
15+
#[command(name = "sp1")]
16+
SP1(VerifySP1Args),
17+
#[command(name = "risc0")]
18+
Risc0(VerifyRisc0Args),
19+
#[command(name = "zisk")]
20+
Zisk(VerifyZiskArgs),
21+
}
1222

1323
#[derive(Debug, Clone, Args)]
14-
pub struct VerifyOnChainArgs {
24+
pub struct VerifySP1Args {
1525
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
1626
network: Network,
1727
#[arg(long = "rpc-url")]
@@ -20,41 +30,93 @@ pub struct VerifyOnChainArgs {
2030
beacon_url: String,
2131
#[arg(long = "from-block")]
2232
from_block: Option<u64>,
23-
#[arg(long = "proving-system")]
24-
proving_system: ProvingSystemArg,
25-
#[arg(
26-
name = "Program verification key hash",
27-
long = "vk-hash",
28-
required = true
29-
)]
30-
program_vk: PathBuf,
31-
#[arg(name = "Public input file name", long = "public-inputs")]
32-
pub_input_file_name: Option<PathBuf>,
33+
#[arg(long = "vk-hash")]
34+
vk_hash: PathBuf,
35+
#[arg(long = "public-inputs")]
36+
public_inputs: PathBuf,
3337
}
3438

35-
pub async fn run(args: VerifyOnChainArgs) {
36-
let program_id_key: [u8; 32] = std::fs::read(&args.program_vk)
37-
.expect("to read program vk file")
39+
#[derive(Debug, Clone, Args)]
40+
pub struct VerifyRisc0Args {
41+
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
42+
network: Network,
43+
#[arg(long = "rpc-url")]
44+
rpc_url: String,
45+
#[arg(long = "beacon-url")]
46+
beacon_url: String,
47+
#[arg(long = "from-block")]
48+
from_block: Option<u64>,
49+
#[arg(long = "image-id")]
50+
image_id: PathBuf,
51+
#[arg(long = "public-inputs")]
52+
public_inputs: PathBuf,
53+
}
54+
55+
#[derive(Debug, Clone, Args)]
56+
pub struct VerifyZiskArgs {
57+
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
58+
network: Network,
59+
#[arg(long = "rpc-url")]
60+
rpc_url: String,
61+
#[arg(long = "beacon-url")]
62+
beacon_url: String,
63+
#[arg(long = "from-block")]
64+
from_block: Option<u64>,
65+
#[arg(short = 'p', long = "proof")]
66+
proof: PathBuf,
67+
}
68+
69+
pub async fn run_sp1(args: VerifySP1Args) {
70+
tracing::info!("Verifying SP1 proof on {:?}...", args.network);
71+
72+
let vk: [u8; 32] = std::fs::read(&args.vk_hash)
73+
.expect("to read vk hash file")
3874
.try_into()
39-
.expect("Invalid hexadecimal encoded vk hash");
75+
.expect("Invalid vk hash (expected 32 bytes)");
4076

41-
let Some(pub_inputs_file_name) = args.pub_input_file_name else {
42-
tracing::error!("Public input file not provided");
43-
return;
44-
};
45-
let public_inputs =
46-
std::fs::read(&pub_inputs_file_name).expect("to read program public inputs file");
77+
let public_inputs = std::fs::read(&args.public_inputs).expect("to read public inputs file");
4778

48-
let provider =
49-
ProofAggregationServiceProvider::new(args.network, args.rpc_url, args.beacon_url);
79+
let verification_data = AggregationModeVerificationData::SP1 { vk, public_inputs };
5080

51-
let verification_data = AggregationModeVerificationData::SP1 {
52-
vk: program_id_key,
53-
public_inputs,
54-
};
81+
verify_proof(args.network, args.rpc_url, args.beacon_url, args.from_block, verification_data).await;
82+
}
83+
84+
pub async fn run_risc0(args: VerifyRisc0Args) {
85+
tracing::info!("Verifying Risc0 proof on {:?}...", args.network);
86+
87+
let image_id: [u8; 32] = std::fs::read(&args.image_id)
88+
.expect("to read image id file")
89+
.try_into()
90+
.expect("Invalid image id (expected 32 bytes)");
91+
92+
let public_inputs = std::fs::read(&args.public_inputs).expect("to read public inputs file");
93+
94+
let verification_data = AggregationModeVerificationData::Risc0 { image_id, public_inputs };
95+
96+
verify_proof(args.network, args.rpc_url, args.beacon_url, args.from_block, verification_data).await;
97+
}
98+
99+
pub async fn run_zisk(args: VerifyZiskArgs) {
100+
tracing::info!("Verifying Zisk proof on {:?}...", args.network);
101+
102+
let proof = std::fs::read(&args.proof).expect("to read proof file");
103+
104+
let verification_data = AggregationModeVerificationData::Zisk { proof };
105+
106+
verify_proof(args.network, args.rpc_url, args.beacon_url, args.from_block, verification_data).await;
107+
}
108+
109+
async fn verify_proof(
110+
network: Network,
111+
rpc_url: String,
112+
beacon_url: String,
113+
from_block: Option<u64>,
114+
verification_data: AggregationModeVerificationData,
115+
) {
116+
let provider = ProofAggregationServiceProvider::new(network, rpc_url, beacon_url);
55117

56118
let proof_status = match provider
57-
.check_proof_verification(args.from_block, verification_data)
119+
.check_proof_verification(from_block, verification_data)
58120
.await
59121
{
60122
Ok(res) => res,

aggregation_mode/cli/src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use agg_mode_cli::commands::{self, submit::SubmitCommand, Cli, Command};
1+
use agg_mode_cli::commands::{self, submit::SubmitCommand, verify::VerifyCommand, Cli, Command};
22
use clap::Parser;
33
use tracing_subscriber::{EnvFilter, FmtSubscriber};
44

@@ -12,9 +12,14 @@ async fn main() {
1212

1313
match cli.command {
1414
Command::Submit(subcommand) => match subcommand {
15-
SubmitCommand::SP1(args) => commands::submit::run(args).await,
15+
SubmitCommand::SP1(args) => commands::submit::run_sp1(args).await,
16+
SubmitCommand::Zisk(args) => commands::submit::run_zisk(args).await,
17+
},
18+
Command::VerifyOnChain(subcommand) => match subcommand {
19+
VerifyCommand::SP1(args) => commands::verify::run_sp1(args).await,
20+
VerifyCommand::Risc0(args) => commands::verify::run_risc0(args).await,
21+
VerifyCommand::Zisk(args) => commands::verify::run_zisk(args).await,
1622
},
17-
Command::VerifyOnChain(args) => commands::verify::run(args).await,
1823
Command::Deposit(args) => commands::deposit::run(args).await,
1924
};
2025
}

aggregation_mode/sdk/src/blockchain/types.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,25 @@ pub enum AggregationModeVerificationData {
9191
image_id: [u8; 32],
9292
public_inputs: Vec<u8>,
9393
},
94+
Zisk {
95+
proof: Vec<u8>,
96+
},
9497
}
9598

9699
impl AggregationModeVerificationData {
97-
pub fn program_id(&self) -> [u8; 32] {
98-
match self {
99-
Self::Risc0 { image_id, .. } => *image_id,
100-
Self::SP1 { vk, .. } => *vk,
101-
}
102-
}
103-
104-
pub fn public_inputs(&self) -> &Vec<u8> {
105-
match self {
106-
Self::Risc0 { public_inputs, .. } => public_inputs,
107-
Self::SP1 { public_inputs, .. } => public_inputs,
108-
}
109-
}
110-
111100
pub fn proving_system_id(&self) -> u16 {
112101
match self {
113102
Self::SP1 { .. } => AggregationModeProvingSystem::SP1.id(),
114103
Self::Risc0 { .. } => AggregationModeProvingSystem::RISC0.id(),
104+
Self::Zisk { .. } => AggregationModeProvingSystem::ZISK.id(),
115105
}
116106
}
117107

118108
pub fn proving_system_id_bytes(&self) -> [u8; 2] {
119109
match self {
120110
Self::SP1 { .. } => AggregationModeProvingSystem::SP1.id_bytes(),
121111
Self::Risc0 { .. } => AggregationModeProvingSystem::RISC0.id_bytes(),
112+
Self::Zisk { .. } => AggregationModeProvingSystem::ZISK.id_bytes(),
122113
}
123114
}
124115

@@ -141,6 +132,12 @@ impl AggregationModeVerificationData {
141132
hasher.update(public_inputs);
142133
hasher.finalize().into()
143134
}
135+
AggregationModeVerificationData::Zisk { proof } => {
136+
let mut hasher = Keccak256::new();
137+
hasher.update(self.proving_system_id_bytes());
138+
hasher.update(proof);
139+
hasher.finalize().into()
140+
}
144141
}
145142
}
146143
}

0 commit comments

Comments
 (0)