Skip to content

Commit

Permalink
chore: reorganize cli params and rename some types
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Aug 12, 2024
1 parent 5905cf7 commit eb7ed92
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 168 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions proof_gen/src/proof_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use plonky2::{

use crate::{
proof_types::{
GeneratedBlockProof, GeneratedSegmentAggProof, GeneratedSegmentProof, GeneratedTxnAggProof,
SegmentAggregatableProof, TxnAggregatableProof,
BatchAggregatableProof, GeneratedBlockProof, GeneratedSegmentAggProof,
GeneratedSegmentProof, GeneratedTxnAggProof, SegmentAggregatableProof,
},
prover_state::ProverState,
types::{Field, PlonkyProofIntern, EXTENSION_DEGREE},
Expand Down Expand Up @@ -121,8 +121,8 @@ pub fn generate_segment_agg_proof(
/// Note that the child proofs may be either transaction or aggregation proofs.
pub fn generate_transaction_agg_proof(
p_state: &ProverState,
lhs_child: &TxnAggregatableProof,
rhs_child: &TxnAggregatableProof,
lhs_child: &BatchAggregatableProof,
rhs_child: &BatchAggregatableProof,
) -> ProofGenResult<GeneratedTxnAggProof> {
let (b_proof_intern, p_vals) = p_state
.state
Expand Down
32 changes: 16 additions & 16 deletions proof_gen/src/proof_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub enum SegmentAggregatableProof {
/// we can combine it into an agg proof. For these cases, we want to abstract
/// away whether or not the proof was a txn or agg proof.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum TxnAggregatableProof {
pub enum BatchAggregatableProof {
/// The underlying proof is a segment proof. It first needs to be aggregated
/// with another segment proof, or a dummy one.
Segment(GeneratedSegmentProof),
Expand Down Expand Up @@ -100,28 +100,28 @@ impl SegmentAggregatableProof {
}
}

impl TxnAggregatableProof {
impl BatchAggregatableProof {
pub(crate) fn public_values(&self) -> PublicValues {
match self {
TxnAggregatableProof::Segment(info) => info.p_vals.clone(),
TxnAggregatableProof::Txn(info) => info.p_vals.clone(),
TxnAggregatableProof::Agg(info) => info.p_vals.clone(),
BatchAggregatableProof::Segment(info) => info.p_vals.clone(),
BatchAggregatableProof::Txn(info) => info.p_vals.clone(),
BatchAggregatableProof::Agg(info) => info.p_vals.clone(),
}
}

pub(crate) fn is_agg(&self) -> bool {
match self {
TxnAggregatableProof::Segment(_) => false,
TxnAggregatableProof::Txn(_) => false,
TxnAggregatableProof::Agg(_) => true,
BatchAggregatableProof::Segment(_) => false,
BatchAggregatableProof::Txn(_) => false,
BatchAggregatableProof::Agg(_) => true,
}
}

pub(crate) fn intern(&self) -> &PlonkyProofIntern {
match self {
TxnAggregatableProof::Segment(info) => &info.intern,
TxnAggregatableProof::Txn(info) => &info.intern,
TxnAggregatableProof::Agg(info) => &info.intern,
BatchAggregatableProof::Segment(info) => &info.intern,
BatchAggregatableProof::Txn(info) => &info.intern,
BatchAggregatableProof::Agg(info) => &info.intern,
}
}
}
Expand All @@ -138,23 +138,23 @@ impl From<GeneratedSegmentAggProof> for SegmentAggregatableProof {
}
}

impl From<GeneratedSegmentAggProof> for TxnAggregatableProof {
impl From<GeneratedSegmentAggProof> for BatchAggregatableProof {
fn from(v: GeneratedSegmentAggProof) -> Self {
Self::Txn(v)
}
}

impl From<GeneratedTxnAggProof> for TxnAggregatableProof {
impl From<GeneratedTxnAggProof> for BatchAggregatableProof {
fn from(v: GeneratedTxnAggProof) -> Self {
Self::Agg(v)
}
}

impl From<SegmentAggregatableProof> for TxnAggregatableProof {
impl From<SegmentAggregatableProof> for BatchAggregatableProof {
fn from(v: SegmentAggregatableProof) -> Self {
match v {
SegmentAggregatableProof::Agg(agg) => TxnAggregatableProof::Txn(agg),
SegmentAggregatableProof::Seg(seg) => TxnAggregatableProof::Segment(seg),
SegmentAggregatableProof::Agg(agg) => BatchAggregatableProof::Txn(agg),
SegmentAggregatableProof::Seg(seg) => BatchAggregatableProof::Segment(seg),
}
}
}
26 changes: 4 additions & 22 deletions zero_bin/leader/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::PathBuf;

use alloy::transports::http::reqwest::Url;
use clap::{Parser, Subcommand, ValueHint};
use prover::cli::CliProverConfig;
use rpc::RpcType;
use zero_bin_common::prover_state::cli::CliProverStateConfig;

Expand All @@ -14,6 +15,9 @@ pub(crate) struct Cli {
#[clap(flatten)]
pub(crate) paladin: paladin::config::Config,

#[clap(flatten)]
pub(crate) prover_config: CliProverConfig,

// Note this is only relevant for the leader when running in in-memory
// mode.
#[clap(flatten)]
Expand All @@ -27,13 +31,6 @@ pub(crate) enum Command {
/// The previous proof output.
#[arg(long, short = 'f', value_hint = ValueHint::FilePath)]
previous_proof: Option<PathBuf>,
#[arg(short, long, default_value_t = 20)]
max_cpu_len_log: usize,
#[arg(short, long, default_value_t = 1)]
batch_size: usize,
/// If true, save the public inputs to disk on error.
#[arg(short, long, default_value_t = false)]
save_inputs_on_error: bool,
},
/// Reads input from a node rpc and writes output to stdout.
Rpc {
Expand All @@ -56,14 +53,6 @@ pub(crate) enum Command {
/// stdout.
#[arg(long, short = 'o', value_hint = ValueHint::FilePath)]
proof_output_dir: Option<PathBuf>,
/// The log of the max number of CPU cycles per proof.
#[arg(short, long, default_value_t = 20)]
max_cpu_len_log: usize,
#[arg(short, long, default_value_t = 1)]
batch_size: usize,
/// If true, save the public inputs to disk on error.
#[arg(short, long, default_value_t = false)]
save_inputs_on_error: bool,
/// Network block time in milliseconds. This value is used
/// to determine the blockchain node polling interval.
#[arg(short, long, env = "ZERO_BIN_BLOCK_TIME", default_value_t = 2000)]
Expand Down Expand Up @@ -92,12 +81,5 @@ pub(crate) enum Command {
/// The directory to which output should be written.
#[arg(short, long, value_hint = ValueHint::DirPath)]
output_dir: PathBuf,
#[arg(short, long, default_value_t = 20)]
max_cpu_len_log: usize,
#[arg(short, long, default_value_t = 1)]
batch_size: usize,
/// If true, save the public inputs to disk on error.
#[arg(short, long, default_value_t = false)]
save_inputs_on_error: bool,
},
}
11 changes: 4 additions & 7 deletions zero_bin/leader/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use alloy::transports::http::reqwest::Url;
use anyhow::Result;
use paladin::runtime::Runtime;
use proof_gen::proof_types::GeneratedBlockProof;
use prover::ProverConfig;
use rpc::{retry::build_http_retry_provider, RpcType};
use tracing::{error, info, warn};
use zero_bin_common::block_interval::BlockInterval;
Expand All @@ -18,14 +19,12 @@ pub struct RpcParams {
pub max_retries: u32,
}

#[derive(Debug, Default)]
#[derive(Debug)]
pub struct ProofParams {
pub checkpoint_block_number: u64,
pub previous_proof: Option<GeneratedBlockProof>,
pub proof_output_dir: Option<PathBuf>,
pub max_cpu_len_log: usize,
pub batch_size: usize,
pub save_inputs_on_error: bool,
pub prover_config: ProverConfig,
pub keep_intermediate_proofs: bool,
}

Expand Down Expand Up @@ -56,10 +55,8 @@ pub(crate) async fn client_main(
let proved_blocks = prover_input
.prove(
&runtime,
params.max_cpu_len_log,
params.previous_proof.take(),
params.batch_size,
params.save_inputs_on_error,
params.prover_config,
params.proof_output_dir.clone(),
)
.await;
Expand Down
25 changes: 5 additions & 20 deletions zero_bin/leader/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anyhow::{bail, Result};
use axum::{http::StatusCode, routing::post, Json, Router};
use paladin::runtime::Runtime;
use proof_gen::proof_types::GeneratedBlockProof;
use prover::BlockProverInput;
use prover::{BlockProverInput, ProverConfig};
use serde::{Deserialize, Serialize};
use serde_json::to_writer;
use tracing::{debug, error, info};
Expand All @@ -15,9 +15,7 @@ pub(crate) async fn http_main(
runtime: Runtime,
port: u16,
output_dir: PathBuf,
max_cpu_len_log: usize,
batch_size: usize,
save_inputs_on_error: bool,
prover_config: ProverConfig,
) -> Result<()> {
let addr = SocketAddr::from(([0, 0, 0, 0], port));
debug!("listening on {}", addr);
Expand All @@ -27,16 +25,7 @@ pub(crate) async fn http_main(
"/prove",
post({
let runtime = runtime.clone();
move |body| {
prove(
body,
runtime,
output_dir.clone(),
max_cpu_len_log,
batch_size,
save_inputs_on_error,
)
}
move |body| prove(body, runtime, output_dir.clone(), prover_config)
}),
);
let listener = tokio::net::TcpListener::bind(&addr).await?;
Expand Down Expand Up @@ -76,9 +65,7 @@ async fn prove(
Json(payload): Json<HttpProverInput>,
runtime: Arc<Runtime>,
output_dir: PathBuf,
max_cpu_len_log: usize,
batch_size: usize,
save_inputs_on_error: bool,
prover_config: ProverConfig,
) -> StatusCode {
debug!("Received payload: {:#?}", payload);

Expand All @@ -88,10 +75,8 @@ async fn prove(
.prover_input
.prove(
&runtime,
max_cpu_len_log,
payload.previous.map(futures::future::ok),
batch_size,
save_inputs_on_error,
prover_config,
)
.await
{
Expand Down
43 changes: 7 additions & 36 deletions zero_bin/leader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,14 @@ async fn main() -> Result<()> {

let runtime = Runtime::from_config(&args.paladin, register()).await?;

let cli_prover_config = args.prover_config;

match args.command {
Command::Stdio {
previous_proof,
max_cpu_len_log,
batch_size,
save_inputs_on_error,
} => {
Command::Stdio { previous_proof } => {
let previous_proof = get_previous_proof(previous_proof)?;
stdio::stdio_main(
runtime,
max_cpu_len_log,
previous_proof,
batch_size,
save_inputs_on_error,
)
.await?;
stdio::stdio_main(runtime, previous_proof, cli_prover_config.into()).await?;
}
Command::Http {
port,
output_dir,
max_cpu_len_log,
batch_size,
save_inputs_on_error,
} => {
Command::Http { port, output_dir } => {
// check if output_dir exists, is a directory, and is writable
let output_dir_metadata = std::fs::metadata(&output_dir);
if output_dir_metadata.is_err() {
Expand All @@ -95,15 +79,7 @@ async fn main() -> Result<()> {
panic!("output-dir is not a writable directory");
}

http::http_main(
runtime,
port,
output_dir,
max_cpu_len_log,
batch_size,
save_inputs_on_error,
)
.await?;
http::http_main(runtime, port, output_dir, cli_prover_config.into()).await?;
}
Command::Rpc {
rpc_url,
Expand All @@ -112,9 +88,6 @@ async fn main() -> Result<()> {
checkpoint_block_number,
previous_proof,
proof_output_dir,
max_cpu_len_log,
batch_size,
save_inputs_on_error,
block_time,
keep_intermediate_proofs,
backoff,
Expand Down Expand Up @@ -145,9 +118,7 @@ async fn main() -> Result<()> {
checkpoint_block_number,
previous_proof,
proof_output_dir,
max_cpu_len_log,
batch_size,
save_inputs_on_error,
prover_config: cli_prover_config.into(),
keep_intermediate_proofs,
},
)
Expand Down
15 changes: 3 additions & 12 deletions zero_bin/leader/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ use std::io::{Read, Write};
use anyhow::Result;
use paladin::runtime::Runtime;
use proof_gen::proof_types::GeneratedBlockProof;
use prover::ProverInput;
use prover::{ProverConfig, ProverInput};
use tracing::info;

/// The main function for the stdio mode.
pub(crate) async fn stdio_main(
runtime: Runtime,
max_cpu_len_log: usize,
previous: Option<GeneratedBlockProof>,
batch_size: usize,
save_inputs_on_error: bool,
prover_config: ProverConfig,
) -> Result<()> {
let mut buffer = String::new();
std::io::stdin().read_to_string(&mut buffer)?;
Expand All @@ -23,14 +21,7 @@ pub(crate) async fn stdio_main(
};

let proved_blocks = prover_input
.prove(
&runtime,
max_cpu_len_log,
previous,
batch_size,
save_inputs_on_error,
None,
)
.prove(&runtime, previous, prover_config, None)
.await;
runtime.close().await?;
let proved_blocks = proved_blocks?;
Expand Down
Loading

0 comments on commit eb7ed92

Please sign in to comment.