-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathsubmit.rs
More file actions
72 lines (59 loc) · 2.2 KB
/
submit.rs
File metadata and controls
72 lines (59 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use agg_mode_sdk::{gateway::provider::AggregationModeGatewayProvider, types::Network};
use clap::{command, Args, Subcommand};
use sp1_sdk::{SP1ProofWithPublicValues, SP1VerifyingKey};
use std::path::PathBuf;
use crate::commands::helpers::{parse_network, PrivateKeyType};
#[derive(Debug, Subcommand)]
pub enum SubmitCommand {
#[command(name = "sp1")]
SP1(SubmitSP1Args),
}
#[derive(Debug, Clone, Args)]
pub struct SubmitSP1Args {
#[arg(short = 'p', long = "proof")]
proof_path: PathBuf,
#[arg(long = "vk")]
verifying_key_path: PathBuf,
#[command(flatten)]
private_key_type: PrivateKeyType,
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
network: Network,
}
pub async fn run(args: SubmitSP1Args) {
tracing::info!("Submitting SP1 proof to {:?} ", args.network);
let proof = load_proof(&args.proof_path).expect("Valid proof");
let vk = load_vk(&args.verifying_key_path).expect("Valid vk");
let signer = match args.private_key_type.into_signer() {
Ok(s) => s,
Err(e) => {
tracing::error!("{e}");
return;
}
};
let provider = AggregationModeGatewayProvider::new_with_signer(args.network.clone(), signer)
.expect("failed to initialize gateway client: {e:?}");
let response = provider
.submit_sp1_proof(&proof, &vk)
.await
.expect("failed to submit proof: {e:?}");
tracing::info!(
"Proof submitted successfully. Task ID: {}",
response.data.task_id
);
}
fn load_proof(path: &PathBuf) -> Result<SP1ProofWithPublicValues, String> {
let bytes = std::fs::read(path)
.map_err(|e| format!("failed to read proof from {}: {e}", path.display()))?;
bincode::deserialize(&bytes)
.map_err(|e| format!("failed to deserialize proof {}: {e}", path.display()))
}
fn load_vk(path: &PathBuf) -> Result<SP1VerifyingKey, String> {
let bytes = std::fs::read(path)
.map_err(|e| format!("failed to read verifying key from {}: {e}", path.display()))?;
bincode::deserialize(&bytes).map_err(|e| {
format!(
"failed to deserialize verifying key {}: {e}",
path.display()
)
})
}