From d818e5e15e165cec7a3f43deea8a6a7edb10a4b3 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Tue, 9 Jul 2024 14:04:45 +0200 Subject: [PATCH 01/15] fix: failed to send proof --- zero_bin/prover/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index aa5367dc0..3738c8682 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -125,7 +125,7 @@ impl BlockProverInput { self, _runtime: &Runtime, max_cpu_len_log: usize, - _previous: Option>>, + previous: Option>>, batch_size: usize, _save_inputs_on_error: bool, ) -> Result { @@ -147,6 +147,12 @@ impl BlockProverInput { simulate_all_segments_interpreter::(txn, max_cpu_len_log)?; } + // Wait for previous block proof + let _prev = match previous { + Some(it) => Some(it.await?), + None => None, + }; + info!("Successfully generated witness for block {block_number}."); // Dummy proof to match expected output type. From f7e37b2a5c9ee9d9c91229cd30a478ce57be10fa Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 19 Jul 2024 12:11:57 +0200 Subject: [PATCH 02/15] fix: optimize segment proof aggregation --- zero_bin/prover/src/lib.rs | 66 ++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 3738c8682..43ebcbc54 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -18,6 +18,8 @@ use trace_decoder::{ use tracing::info; use zero_bin_common::fs::generate_block_proof_file_name; +const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 2; + #[derive(Debug, Deserialize, Serialize)] pub struct BlockProverInput { pub block_trace: BlockTrace, @@ -56,41 +58,63 @@ impl BlockProverInput { batch_size, )?; + // Create segment proof + let seg_ops = ops::SegmentProof { + save_inputs_on_error, + }; + // Generate segment data. let agg_ops = ops::SegmentAggProof { save_inputs_on_error, }; - let seg_ops = ops::SegmentProof { + // Aggregate transaction proofs + let txn_agg_proof = ops::TxnAggProof { save_inputs_on_error, }; // Map the transactions to a stream of transaction proofs. - let tx_proof_futs: FuturesUnordered<_> = txs - .iter() + let tx_proof_futs : FuturesUnordered<_> = txs.chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE) .enumerate() - .map(|(idx, txn)| { - let data_iterator = SegmentDataIterator { - partial_next_data: None, - inputs: txn, - max_cpu_len_log: Some(max_cpu_len_log), - }; - - Directive::map(IndexedStream::from(data_iterator), &seg_ops) - .fold(&agg_ops) - .run(runtime) - .map(move |e| { - e.map(|p| (idx, proof_gen::proof_types::TxnAggregatableProof::from(p))) - }) - }) + .map(|(idy, chunk)| + { + let chunk_tx_proof_futs: FuturesUnordered<_> = chunk + .iter() + .enumerate() + .map(|(idx, txn)| { + let data_iterator = SegmentDataIterator { + partial_next_data: None, + inputs: txn, + max_cpu_len_log: Some(max_cpu_len_log), + }; + + Directive::map(IndexedStream::from(data_iterator), &seg_ops) + .fold(&agg_ops) + .run(runtime) + .map(move |e| { + e.map(|p| (idx, proof_gen::proof_types::TxnAggregatableProof::from(p))) + }) + }) + .collect(); + + let result = Directive::fold( + IndexedStream::new(chunk_tx_proof_futs), + &txn_agg_proof, + ).run(runtime); + result.map(move |p| (idy, p)) + }) .collect(); + let mut txn_aggregatable_proofs = Vec::new(); + for fut in tx_proof_futs { + let (_idx, txn_aggregatable_proof) = fut.await; + txn_aggregatable_proofs.push(txn_aggregatable_proof?); + } + // Fold the transaction proof stream into a single transaction proof. let final_txn_proof = Directive::fold( - IndexedStream::new(tx_proof_futs), - &ops::TxnAggProof { - save_inputs_on_error, - }, + IndexedStream::from(txn_aggregatable_proofs.into_iter()), + &txn_agg_proof, ) .run(runtime) .await?; From 8009310938e65cc231276678bab7e6c983762e3c Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 19 Jul 2024 12:17:25 +0200 Subject: [PATCH 03/15] fix: optimize --- zero_bin/prover/src/lib.rs | 81 ++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 35 deletions(-) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 43ebcbc54..d102a3040 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -18,7 +18,10 @@ use trace_decoder::{ use tracing::info; use zero_bin_common::fs::generate_block_proof_file_name; -const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 2; +// Limit the number of segments that are proven in parallel +// to prevent excessive memory consumption +const GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER: usize = 2; +const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 5; #[derive(Debug, Deserialize, Serialize)] pub struct BlockProverInput { @@ -69,51 +72,58 @@ impl BlockProverInput { }; // Aggregate transaction proofs - let txn_agg_proof = ops::TxnAggProof { + let txn_agg_proof = ops::TxnAggProof { save_inputs_on_error, }; - // Map the transactions to a stream of transaction proofs. - let tx_proof_futs : FuturesUnordered<_> = txs.chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE) - .enumerate() - .map(|(idy, chunk)| - { + // Tweak inner and outer chunk size if needed for memory/utilization balance + let mut all_txn_aggregatable_proofs = Vec::new(); + for chunk in txs.chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE) { + // Map the chunk of transactions to transaction proofs. let chunk_tx_proof_futs: FuturesUnordered<_> = chunk - .iter() - .enumerate() - .map(|(idx, txn)| { - let data_iterator = SegmentDataIterator { - partial_next_data: None, - inputs: txn, - max_cpu_len_log: Some(max_cpu_len_log), - }; - - Directive::map(IndexedStream::from(data_iterator), &seg_ops) - .fold(&agg_ops) - .run(runtime) - .map(move |e| { - e.map(|p| (idx, proof_gen::proof_types::TxnAggregatableProof::from(p))) + .chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER) + .map(|generation_inputs| { + let chunk_tx_proof_futs: FuturesUnordered<_> = generation_inputs + .iter() + .enumerate() + .map(|(idx, generation_inputs)| { + let data_iterator = SegmentDataIterator { + partial_next_data: None, + inputs: generation_inputs, + max_cpu_len_log: Some(max_cpu_len_log), + }; + + // Create segment aggregatable proofs from generation segment data + // and aggregate them into single txn aggregatable proof + Directive::map(IndexedStream::from(data_iterator), &seg_ops) + .fold(&agg_ops) + .run(runtime) + .map(move |e| { + e.map(|p| { + (idx, proof_gen::proof_types::TxnAggregatableProof::from(p)) + }) + }) }) + .collect(); + + // Aggregate txn aggregatable proofs for this chunk + Directive::fold(IndexedStream::new(chunk_tx_proof_futs), &txn_agg_proof) + .run(runtime) }) .collect(); - let result = Directive::fold( - IndexedStream::new(chunk_tx_proof_futs), - &txn_agg_proof, - ).run(runtime); - result.map(move |p| (idy, p)) - }) - .collect(); - - let mut txn_aggregatable_proofs = Vec::new(); - for fut in tx_proof_futs { - let (_idx, txn_aggregatable_proof) = fut.await; - txn_aggregatable_proofs.push(txn_aggregatable_proof?); + // Await for the chunk to be computed + all_txn_aggregatable_proofs.extend( + futures::future::join_all(chunk_tx_proof_futs) + .await + .into_iter() + .collect::, _>>()?, + ); } - // Fold the transaction proof stream into a single transaction proof. + // Fold all the agg transaction proofs into a single transaction proof let final_txn_proof = Directive::fold( - IndexedStream::from(txn_aggregatable_proofs.into_iter()), + IndexedStream::from(all_txn_aggregatable_proofs.into_iter()), &txn_agg_proof, ) .run(runtime) @@ -128,6 +138,7 @@ impl BlockProverInput { None => None, }; + // Generate the block proof let block_proof = paladin::directive::Literal(proof) .map(&ops::BlockProof { prev, From daf0e59439c54a4529612d33fd206bd388c9b1a3 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 19 Jul 2024 16:30:59 +0200 Subject: [PATCH 04/15] fix: clippy --- zero_bin/prover/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index d102a3040..494367aed 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -20,7 +20,9 @@ use zero_bin_common::fs::generate_block_proof_file_name; // Limit the number of segments that are proven in parallel // to prevent excessive memory consumption +#[cfg(not(feature = "test_only"))] const GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER: usize = 2; +#[cfg(not(feature = "test_only"))] const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 5; #[derive(Debug, Deserialize, Serialize)] From 1a44121559bc28fc28be176cd46e6f409c7855ff Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 19 Jul 2024 17:16:10 +0200 Subject: [PATCH 05/15] fix: ordered --- zero_bin/prover/src/lib.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 494367aed..97891cac7 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; use alloy::primitives::{BlockNumber, U256}; use anyhow::{Context, Result}; -use futures::{future::BoxFuture, stream::FuturesOrdered, FutureExt, TryFutureExt, TryStreamExt}; +use futures::stream::FuturesOrdered; +use futures::{future::BoxFuture, FutureExt, TryFutureExt, TryStreamExt}; use num_traits::ToPrimitive as _; use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; @@ -50,7 +51,7 @@ impl BlockProverInput { ) -> Result { use anyhow::Context as _; use evm_arithmetization::prover::SegmentDataIterator; - use futures::{stream::FuturesUnordered, FutureExt}; + use futures::{stream::FuturesOrdered, FutureExt, StreamExt}; use paladin::directive::{Directive, IndexedStream}; let block_number = self.get_block_number(); @@ -82,10 +83,10 @@ impl BlockProverInput { let mut all_txn_aggregatable_proofs = Vec::new(); for chunk in txs.chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE) { // Map the chunk of transactions to transaction proofs. - let chunk_tx_proof_futs: FuturesUnordered<_> = chunk + let chunk_tx_proof_futs = chunk .chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER) .map(|generation_inputs| { - let chunk_tx_proof_futs: FuturesUnordered<_> = generation_inputs + let chunk_tx_proof_futs: FuturesOrdered<_> = generation_inputs .iter() .enumerate() .map(|(idx, generation_inputs)| { @@ -112,12 +113,13 @@ impl BlockProverInput { Directive::fold(IndexedStream::new(chunk_tx_proof_futs), &txn_agg_proof) .run(runtime) }) - .collect(); + .collect::>() + .collect::>() + .await; - // Await for the chunk to be computed + // Keep the chunk computation result all_txn_aggregatable_proofs.extend( - futures::future::join_all(chunk_tx_proof_futs) - .await + chunk_tx_proof_futs .into_iter() .collect::, _>>()?, ); From a8324f014dea155eef2ffc458b8c58706680cd24 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 19 Jul 2024 17:48:40 +0200 Subject: [PATCH 06/15] fix: increase the chunk size --- zero_bin/prover/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 97891cac7..efa37cab5 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -22,9 +22,9 @@ use zero_bin_common::fs::generate_block_proof_file_name; // Limit the number of segments that are proven in parallel // to prevent excessive memory consumption #[cfg(not(feature = "test_only"))] -const GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER: usize = 2; +const GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER: usize = 4; #[cfg(not(feature = "test_only"))] -const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 5; +const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 4; #[derive(Debug, Deserialize, Serialize)] pub struct BlockProverInput { From 3d47ee410bb1b41f64152c6481c5719ae16063f4 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Tue, 23 Jul 2024 15:38:39 +0200 Subject: [PATCH 07/15] feat: introduce segments chunk proving --- evm_arithmetization/src/prover.rs | 37 +++++++++ zero_bin/leader/src/cli.rs | 13 ++++ zero_bin/leader/src/client.rs | 7 +- zero_bin/leader/src/http.rs | 10 +-- zero_bin/leader/src/main.rs | 14 +++- zero_bin/leader/src/stdio.rs | 6 +- zero_bin/prover/src/lib.rs | 122 +++++++++++++++--------------- 7 files changed, 135 insertions(+), 74 deletions(-) diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index 6ab08896f..e71188052 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -550,6 +550,43 @@ impl<'a> Iterator for SegmentDataIterator<'a> { } } +pub struct SegmentDataChunkIterator<'a> { + segment_data_iter: &'a mut SegmentDataIterator<'a>, + chunk_size: usize, +} + +impl<'a> SegmentDataChunkIterator<'a> { + pub fn new(segment_data_iter: &'a mut SegmentDataIterator<'a>, chunk_size: usize) -> Self { + Self { + segment_data_iter, + chunk_size, + } + } +} + +impl<'a> Iterator for SegmentDataChunkIterator<'a> { + type Item = Vec<(GenerationInputs, GenerationSegmentData)>; + + fn next(&mut self) -> Option { + let mut chunk_empty_space = self.chunk_size as isize; + let mut chunk = Vec::with_capacity(self.chunk_size); + while chunk_empty_space > 0 { + chunk_empty_space -= 1; + if let Some(it) = self.segment_data_iter.next() { + chunk.push(it); + } else { + break; + } + } + + if chunk.is_empty() { + None + } else { + Some(chunk) + } + } +} + /// Returns the data for the current segment, as well as the data -- except /// registers_after -- for the next segment. pub(crate) fn generate_next_segment( diff --git a/zero_bin/leader/src/cli.rs b/zero_bin/leader/src/cli.rs index 9ec32a420..0c83a94f1 100644 --- a/zero_bin/leader/src/cli.rs +++ b/zero_bin/leader/src/cli.rs @@ -22,6 +22,7 @@ pub(crate) struct Cli { #[derive(Subcommand)] pub(crate) enum Command { + //TODO unify parameters for all use cases /// Reads input from stdin and writes output to stdout. Stdio { /// The previous proof output. @@ -29,8 +30,12 @@ pub(crate) enum Command { previous_proof: Option, #[arg(short, long, default_value_t = 20)] max_cpu_len_log: usize, + /// Number of transactions in a batch to process at once #[arg(short, long, default_value_t = 1)] batch_size: usize, + /// Number of segments to keep in memory and prove in parallel + #[arg(long, default_value_t = 64)] + segment_chunk_size: usize, /// If true, save the public inputs to disk on error. #[arg(short, long, default_value_t = false)] save_inputs_on_error: bool, @@ -59,8 +64,12 @@ pub(crate) enum Command { /// The log of the max number of CPU cycles per proof. #[arg(short, long, default_value_t = 20)] max_cpu_len_log: usize, + /// Number of transactions in a batch to process at once #[arg(short, long, default_value_t = 1)] batch_size: usize, + /// Number of segments to keep in memory and prove in parallel + #[arg(long, default_value_t = 64)] + segment_chunk_size: usize, /// If true, save the public inputs to disk on error. #[arg(short, long, default_value_t = false)] save_inputs_on_error: bool, @@ -94,8 +103,12 @@ pub(crate) enum Command { output_dir: PathBuf, #[arg(short, long, default_value_t = 20)] max_cpu_len_log: usize, + /// Number of transactions in a batch to process at once #[arg(short, long, default_value_t = 1)] batch_size: usize, + /// Number of segments to keep in memory and prove in parallel + #[arg(long, default_value_t = 64)] + segment_chunk_size: usize, /// If true, save the public inputs to disk on error. #[arg(short, long, default_value_t = false)] save_inputs_on_error: bool, diff --git a/zero_bin/leader/src/client.rs b/zero_bin/leader/src/client.rs index 50993d4a3..0ec5e48a0 100644 --- a/zero_bin/leader/src/client.rs +++ b/zero_bin/leader/src/client.rs @@ -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::ProverParams; use rpc::{retry::build_http_retry_provider, RpcType}; use tracing::{error, info, warn}; use zero_bin_common::block_interval::BlockInterval; @@ -25,6 +26,7 @@ pub struct ProofParams { pub proof_output_dir: Option, pub max_cpu_len_log: usize, pub batch_size: usize, + pub segment_chunk_size: usize, pub save_inputs_on_error: bool, pub keep_intermediate_proofs: bool, } @@ -58,7 +60,10 @@ pub(crate) async fn client_main( &runtime, params.max_cpu_len_log, params.previous_proof.take(), - params.batch_size, + ProverParams { + batch_size: params.batch_size, + segment_chunk_size: params.segment_chunk_size, + }, params.save_inputs_on_error, params.proof_output_dir.clone(), ) diff --git a/zero_bin/leader/src/http.rs b/zero_bin/leader/src/http.rs index 971192384..a20b26e3c 100644 --- a/zero_bin/leader/src/http.rs +++ b/zero_bin/leader/src/http.rs @@ -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, ProverParams}; use serde::{Deserialize, Serialize}; use serde_json::to_writer; use tracing::{debug, error, info}; @@ -16,7 +16,7 @@ pub(crate) async fn http_main( port: u16, output_dir: PathBuf, max_cpu_len_log: usize, - batch_size: usize, + prover_params: ProverParams, save_inputs_on_error: bool, ) -> Result<()> { let addr = SocketAddr::from(([0, 0, 0, 0], port)); @@ -33,7 +33,7 @@ pub(crate) async fn http_main( runtime, output_dir.clone(), max_cpu_len_log, - batch_size, + prover_params, save_inputs_on_error, ) } @@ -77,7 +77,7 @@ async fn prove( runtime: Arc, output_dir: PathBuf, max_cpu_len_log: usize, - batch_size: usize, + prover_params: ProverParams, save_inputs_on_error: bool, ) -> StatusCode { debug!("Received payload: {:#?}", payload); @@ -90,7 +90,7 @@ async fn prove( &runtime, max_cpu_len_log, payload.previous.map(futures::future::ok), - batch_size, + prover_params, save_inputs_on_error, ) .await diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index f76e94300..275e7c552 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -67,6 +67,7 @@ async fn main() -> Result<()> { previous_proof, max_cpu_len_log, batch_size, + segment_chunk_size, save_inputs_on_error, } => { let previous_proof = get_previous_proof(previous_proof)?; @@ -74,7 +75,10 @@ async fn main() -> Result<()> { runtime, max_cpu_len_log, previous_proof, - batch_size, + prover::ProverParams { + batch_size, + segment_chunk_size, + }, save_inputs_on_error, ) .await?; @@ -84,6 +88,7 @@ async fn main() -> Result<()> { output_dir, max_cpu_len_log, batch_size, + segment_chunk_size, save_inputs_on_error, } => { // check if output_dir exists, is a directory, and is writable @@ -100,7 +105,10 @@ async fn main() -> Result<()> { port, output_dir, max_cpu_len_log, - batch_size, + prover::ProverParams { + batch_size, + segment_chunk_size, + }, save_inputs_on_error, ) .await?; @@ -114,6 +122,7 @@ async fn main() -> Result<()> { proof_output_dir, max_cpu_len_log, batch_size, + segment_chunk_size, save_inputs_on_error, block_time, keep_intermediate_proofs, @@ -147,6 +156,7 @@ async fn main() -> Result<()> { proof_output_dir, max_cpu_len_log, batch_size, + segment_chunk_size, save_inputs_on_error, keep_intermediate_proofs, }, diff --git a/zero_bin/leader/src/stdio.rs b/zero_bin/leader/src/stdio.rs index 3b8bc2660..7bca2301a 100644 --- a/zero_bin/leader/src/stdio.rs +++ b/zero_bin/leader/src/stdio.rs @@ -3,7 +3,7 @@ use std::io::{Read, Write}; use anyhow::Result; use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; -use prover::ProverInput; +use prover::{ProverInput, ProverParams}; use tracing::info; /// The main function for the stdio mode. @@ -11,7 +11,7 @@ pub(crate) async fn stdio_main( runtime: Runtime, max_cpu_len_log: usize, previous: Option, - batch_size: usize, + prover_params: ProverParams, save_inputs_on_error: bool, ) -> Result<()> { let mut buffer = String::new(); @@ -27,7 +27,7 @@ pub(crate) async fn stdio_main( &runtime, max_cpu_len_log, previous, - batch_size, + prover_params, save_inputs_on_error, None, ) diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index efa37cab5..4d7025b9d 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -19,12 +19,11 @@ use trace_decoder::{ use tracing::info; use zero_bin_common::fs::generate_block_proof_file_name; -// Limit the number of segments that are proven in parallel -// to prevent excessive memory consumption -#[cfg(not(feature = "test_only"))] -const GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER: usize = 4; -#[cfg(not(feature = "test_only"))] -const GENERATION_INPUTS_AGG_CHUNK_SIZE: usize = 4; +#[derive(Debug, Clone, Copy)] +pub struct ProverParams { + pub batch_size: usize, + pub segment_chunk_size: usize, +} #[derive(Debug, Deserialize, Serialize)] pub struct BlockProverInput { @@ -46,23 +45,27 @@ impl BlockProverInput { runtime: &Runtime, max_cpu_len_log: usize, previous: Option>>, - batch_size: usize, + prover_params: ProverParams, save_inputs_on_error: bool, ) -> Result { use anyhow::Context as _; - use evm_arithmetization::prover::SegmentDataIterator; - use futures::{stream::FuturesOrdered, FutureExt, StreamExt}; + use evm_arithmetization::prover::{SegmentDataChunkIterator, SegmentDataIterator}; use paladin::directive::{Directive, IndexedStream}; let block_number = self.get_block_number(); - info!("Proving block {block_number}"); - let other_data = self.other_data; - let txs = self.block_trace.into_txn_proof_gen_ir( + let block_generation_inputs = self.block_trace.into_txn_proof_gen_ir( &ProcessingMeta::new(resolve_code_hash_fn), other_data.clone(), - batch_size, + prover_params.batch_size, )?; + info!( + "Proving block {}, generation inputs count: {}, batch size: {}, segment chunk size: {}", + block_number, + block_generation_inputs.len(), + prover_params.batch_size, + prover_params.segment_chunk_size + ); // Create segment proof let seg_ops = ops::SegmentProof { @@ -79,55 +82,51 @@ impl BlockProverInput { save_inputs_on_error, }; - // Tweak inner and outer chunk size if needed for memory/utilization balance - let mut all_txn_aggregatable_proofs = Vec::new(); - for chunk in txs.chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE) { - // Map the chunk of transactions to transaction proofs. - let chunk_tx_proof_futs = chunk - .chunks(GENERATION_INPUTS_AGG_CHUNK_SIZE_INNER) - .map(|generation_inputs| { - let chunk_tx_proof_futs: FuturesOrdered<_> = generation_inputs - .iter() - .enumerate() - .map(|(idx, generation_inputs)| { - let data_iterator = SegmentDataIterator { - partial_next_data: None, - inputs: generation_inputs, - max_cpu_len_log: Some(max_cpu_len_log), - }; + let mut all_block_txn_aggregatable_proofs = Vec::new(); + // Loop for all generation inputs in the block + for generation_inputs in block_generation_inputs { + let mut segment_data_iter = SegmentDataIterator { + partial_next_data: None, + inputs: &generation_inputs, + max_cpu_len_log: Some(max_cpu_len_log), + }; + let mut chunk_segment_iter = SegmentDataChunkIterator::new( + &mut segment_data_iter, + prover_params.segment_chunk_size, + ); - // Create segment aggregatable proofs from generation segment data - // and aggregate them into single txn aggregatable proof - Directive::map(IndexedStream::from(data_iterator), &seg_ops) - .fold(&agg_ops) - .run(runtime) - .map(move |e| { - e.map(|p| { - (idx, proof_gen::proof_types::TxnAggregatableProof::from(p)) - }) - }) + let mut chunk_txn_aggregatable_proofs = Vec::new(); + // We take one chunk of segments, perform proving and + // aggregate it to `TxnAggregatableProof` + while let Some(chunk) = chunk_segment_iter.next() { + chunk_txn_aggregatable_proofs.push( + Directive::map(IndexedStream::from(chunk.into_iter()), &seg_ops) + .fold(&agg_ops) + .run(runtime) + .map(move |e| { + e.map(|p| proof_gen::proof_types::TxnAggregatableProof::from(p)) }) - .collect(); + .await, + ); + } - // Aggregate txn aggregatable proofs for this chunk - Directive::fold(IndexedStream::new(chunk_tx_proof_futs), &txn_agg_proof) - .run(runtime) - }) - .collect::>() - .collect::>() - .await; - - // Keep the chunk computation result - all_txn_aggregatable_proofs.extend( - chunk_tx_proof_futs - .into_iter() - .collect::, _>>()?, - ); + // Fold all the generation input transaction proofs + // into a single transaction proof + let generation_input_txn_proof = Directive::fold( + IndexedStream::from(chunk_txn_aggregatable_proofs.into_iter().collect::, + anyhow::Error, + >>( + )?), + &txn_agg_proof, + ) + .run(runtime) + .await?; + all_block_txn_aggregatable_proofs.push(generation_input_txn_proof); } - // Fold all the agg transaction proofs into a single transaction proof let final_txn_proof = Directive::fold( - IndexedStream::from(all_txn_aggregatable_proofs.into_iter()), + IndexedStream::from(all_block_txn_aggregatable_proofs.into_iter()), &txn_agg_proof, ) .run(runtime) @@ -165,7 +164,7 @@ impl BlockProverInput { _runtime: &Runtime, max_cpu_len_log: usize, previous: Option>>, - batch_size: usize, + prover_params: ProverParams, _save_inputs_on_error: bool, ) -> Result { use evm_arithmetization::prover::testing::simulate_all_segments_interpreter; @@ -178,7 +177,7 @@ impl BlockProverInput { let txs = self.block_trace.into_txn_proof_gen_ir( &ProcessingMeta::new(resolve_code_hash_fn), other_data.clone(), - batch_size, + prover_params.batch_size, )?; type F = GoldilocksField; @@ -218,7 +217,7 @@ impl ProverInput { runtime: &Runtime, max_cpu_len_log: usize, previous_proof: Option, - batch_size: usize, + prover_params: ProverParams, save_inputs_on_error: bool, proof_output_dir: Option, ) -> Result)>> { @@ -229,9 +228,6 @@ impl ProverInput { .blocks .into_iter() .map(|block| { - let block_number = block.get_block_number(); - info!("Proving block {block_number}"); - let (tx, rx) = oneshot::channel::(); // Prove the block @@ -241,7 +237,7 @@ impl ProverInput { runtime, max_cpu_len_log, prev.take(), - batch_size, + prover_params, save_inputs_on_error, ) .then(move |proof| async move { From 616598bd75a7c2b2c7f251504808deff21db34a7 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Tue, 23 Jul 2024 16:23:48 +0200 Subject: [PATCH 08/15] fix: cli conflict --- zero_bin/leader/src/cli.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zero_bin/leader/src/cli.rs b/zero_bin/leader/src/cli.rs index 0c83a94f1..14ced2e6b 100644 --- a/zero_bin/leader/src/cli.rs +++ b/zero_bin/leader/src/cli.rs @@ -75,7 +75,7 @@ pub(crate) enum Command { 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)] + #[arg(long, env = "ZERO_BIN_BLOCK_TIME", default_value_t = 2000)] block_time: u64, /// Keep intermediate proofs. Default action is to /// delete them after the final proof is generated. From 4952b04b302819fdaf0b1b327a019e51b7f6f263 Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Tue, 23 Jul 2024 17:22:21 +0200 Subject: [PATCH 09/15] fix: remove cloning --- evm_arithmetization/src/prover.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index e71188052..43401c596 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -537,7 +537,7 @@ impl<'a> Iterator for SegmentDataIterator<'a> { let cur_and_next_data = generate_next_segment::( self.max_cpu_len_log, self.inputs, - self.partial_next_data.clone(), + self.partial_next_data.take(), ); if cur_and_next_data.is_some() { From e09916f4915320b56c9a803d22928e884ec9a06b Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Tue, 23 Jul 2024 17:53:30 +0200 Subject: [PATCH 10/15] feat: reorganize cli params (#432) * feat: reorganize cli params * fix: conficts * fix: review * fix: review 2 --- Cargo.lock | 1 + zero_bin/leader/src/cli.rs | 40 ++++---------------------- zero_bin/leader/src/client.rs | 16 +++-------- zero_bin/leader/src/http.rs | 25 ++++------------- zero_bin/leader/src/main.rs | 53 +++++------------------------------ zero_bin/leader/src/stdio.rs | 15 ++-------- zero_bin/prover/Cargo.toml | 1 + zero_bin/prover/src/cli.rs | 31 ++++++++++++++++++++ zero_bin/prover/src/lib.rs | 49 +++++++++++++++----------------- 9 files changed, 80 insertions(+), 151 deletions(-) create mode 100644 zero_bin/prover/src/cli.rs diff --git a/Cargo.lock b/Cargo.lock index 4c1f122b0..c074a45fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3848,6 +3848,7 @@ version = "0.1.0" dependencies = [ "alloy", "anyhow", + "clap", "evm_arithmetization", "futures", "num-traits", diff --git a/zero_bin/leader/src/cli.rs b/zero_bin/leader/src/cli.rs index 14ced2e6b..36dc977df 100644 --- a/zero_bin/leader/src/cli.rs +++ b/zero_bin/leader/src/cli.rs @@ -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; @@ -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)] @@ -28,17 +32,6 @@ pub(crate) enum Command { /// The previous proof output. #[arg(long, short = 'f', value_hint = ValueHint::FilePath)] previous_proof: Option, - #[arg(short, long, default_value_t = 20)] - max_cpu_len_log: usize, - /// Number of transactions in a batch to process at once - #[arg(short, long, default_value_t = 1)] - batch_size: usize, - /// Number of segments to keep in memory and prove in parallel - #[arg(long, default_value_t = 64)] - segment_chunk_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 { @@ -61,21 +54,9 @@ pub(crate) enum Command { /// stdout. #[arg(long, short = 'o', value_hint = ValueHint::FilePath)] proof_output_dir: Option, - /// The log of the max number of CPU cycles per proof. - #[arg(short, long, default_value_t = 20)] - max_cpu_len_log: usize, - /// Number of transactions in a batch to process at once - #[arg(short, long, default_value_t = 1)] - batch_size: usize, - /// Number of segments to keep in memory and prove in parallel - #[arg(long, default_value_t = 64)] - segment_chunk_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(long, env = "ZERO_BIN_BLOCK_TIME", default_value_t = 2000)] + #[arg(short, long, env = "ZERO_BIN_BLOCK_TIME", default_value_t = 2000)] block_time: u64, /// Keep intermediate proofs. Default action is to /// delete them after the final proof is generated. @@ -101,16 +82,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, - /// Number of transactions in a batch to process at once - #[arg(short, long, default_value_t = 1)] - batch_size: usize, - /// Number of segments to keep in memory and prove in parallel - #[arg(long, default_value_t = 64)] - segment_chunk_size: usize, - /// If true, save the public inputs to disk on error. - #[arg(short, long, default_value_t = false)] - save_inputs_on_error: bool, }, } diff --git a/zero_bin/leader/src/client.rs b/zero_bin/leader/src/client.rs index 0ec5e48a0..74910f621 100644 --- a/zero_bin/leader/src/client.rs +++ b/zero_bin/leader/src/client.rs @@ -5,7 +5,7 @@ use alloy::transports::http::reqwest::Url; use anyhow::Result; use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; -use prover::ProverParams; +use prover::ProverConfig; use rpc::{retry::build_http_retry_provider, RpcType}; use tracing::{error, info, warn}; use zero_bin_common::block_interval::BlockInterval; @@ -19,15 +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, pub proof_output_dir: Option, - pub max_cpu_len_log: usize, - pub batch_size: usize, - pub segment_chunk_size: usize, - pub save_inputs_on_error: bool, + pub prover_config: ProverConfig, pub keep_intermediate_proofs: bool, } @@ -58,13 +55,8 @@ pub(crate) async fn client_main( let proved_blocks = prover_input .prove( &runtime, - params.max_cpu_len_log, params.previous_proof.take(), - ProverParams { - batch_size: params.batch_size, - segment_chunk_size: params.segment_chunk_size, - }, - params.save_inputs_on_error, + params.prover_config, params.proof_output_dir.clone(), ) .await; diff --git a/zero_bin/leader/src/http.rs b/zero_bin/leader/src/http.rs index a20b26e3c..9137622be 100644 --- a/zero_bin/leader/src/http.rs +++ b/zero_bin/leader/src/http.rs @@ -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, ProverParams}; +use prover::{BlockProverInput, ProverConfig}; use serde::{Deserialize, Serialize}; use serde_json::to_writer; use tracing::{debug, error, info}; @@ -15,9 +15,7 @@ pub(crate) async fn http_main( runtime: Runtime, port: u16, output_dir: PathBuf, - max_cpu_len_log: usize, - prover_params: ProverParams, - save_inputs_on_error: bool, + prover_config: ProverConfig, ) -> Result<()> { let addr = SocketAddr::from(([0, 0, 0, 0], port)); debug!("listening on {}", addr); @@ -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, - prover_params, - save_inputs_on_error, - ) - } + move |body| prove(body, runtime, output_dir.clone(), prover_config) }), ); let listener = tokio::net::TcpListener::bind(&addr).await?; @@ -76,9 +65,7 @@ async fn prove( Json(payload): Json, runtime: Arc, output_dir: PathBuf, - max_cpu_len_log: usize, - prover_params: ProverParams, - save_inputs_on_error: bool, + prover_config: ProverConfig, ) -> StatusCode { debug!("Received payload: {:#?}", payload); @@ -88,10 +75,8 @@ async fn prove( .prover_input .prove( &runtime, - max_cpu_len_log, payload.previous.map(futures::future::ok), - prover_params, - save_inputs_on_error, + prover_config, ) .await { diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 275e7c552..5886e264f 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -62,35 +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, - segment_chunk_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, - prover::ProverParams { - batch_size, - segment_chunk_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, - segment_chunk_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() { @@ -100,18 +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, - prover::ProverParams { - batch_size, - segment_chunk_size, - }, - save_inputs_on_error, - ) - .await?; + http::http_main(runtime, port, output_dir, cli_prover_config.into()).await?; } Command::Rpc { rpc_url, @@ -120,10 +88,6 @@ async fn main() -> Result<()> { checkpoint_block_number, previous_proof, proof_output_dir, - max_cpu_len_log, - batch_size, - segment_chunk_size, - save_inputs_on_error, block_time, keep_intermediate_proofs, backoff, @@ -154,10 +118,7 @@ async fn main() -> Result<()> { checkpoint_block_number, previous_proof, proof_output_dir, - max_cpu_len_log, - batch_size, - segment_chunk_size, - save_inputs_on_error, + prover_config: cli_prover_config.into(), keep_intermediate_proofs, }, ) diff --git a/zero_bin/leader/src/stdio.rs b/zero_bin/leader/src/stdio.rs index 7bca2301a..d74f4dce6 100644 --- a/zero_bin/leader/src/stdio.rs +++ b/zero_bin/leader/src/stdio.rs @@ -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, ProverParams}; +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, - prover_params: ProverParams, - save_inputs_on_error: bool, + prover_config: ProverConfig, ) -> Result<()> { let mut buffer = String::new(); std::io::stdin().read_to_string(&mut buffer)?; @@ -23,14 +21,7 @@ pub(crate) async fn stdio_main( }; let proved_blocks = prover_input - .prove( - &runtime, - max_cpu_len_log, - previous, - prover_params, - save_inputs_on_error, - None, - ) + .prove(&runtime, previous, prover_config, None) .await; runtime.close().await?; let proved_blocks = proved_blocks?; diff --git a/zero_bin/prover/Cargo.toml b/zero_bin/prover/Cargo.toml index 3c2d9e131..d750f5bb1 100644 --- a/zero_bin/prover/Cargo.toml +++ b/zero_bin/prover/Cargo.toml @@ -25,6 +25,7 @@ ruint = { workspace = true, features = ["num-traits", "primitive-types"] } ops = { workspace = true } zero_bin_common ={ workspace = true } num-traits = { workspace = true } +clap = {workspace = true} [features] default = [] diff --git a/zero_bin/prover/src/cli.rs b/zero_bin/prover/src/cli.rs new file mode 100644 index 000000000..7c3425c16 --- /dev/null +++ b/zero_bin/prover/src/cli.rs @@ -0,0 +1,31 @@ +use clap::Args; + +const HELP_HEADING: &str = "Prover options"; + +/// Represents the main configuration structure for the runtime. +#[derive(Args, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Default)] +pub struct CliProverConfig { + /// The log of the max number of CPU cycles per proof. + #[arg(short, long, help_heading = HELP_HEADING, default_value_t = 20)] + max_cpu_len_log: usize, + /// Number of transactions in a batch to process at once. + #[arg(short, long, help_heading = HELP_HEADING, default_value_t = 1)] + batch_size: usize, + /// Number of segments to keep in memory and prove in parallel. + #[arg(short='c', long, help_heading = HELP_HEADING, default_value_t = 64)] + segment_chunk_size: usize, + /// If true, save the public inputs to disk on error. + #[arg(short='i', long, help_heading = HELP_HEADING, default_value_t = false)] + save_inputs_on_error: bool, +} + +impl From for crate::ProverConfig { + fn from(cli: CliProverConfig) -> Self { + Self { + segment_chunk_size: cli.segment_chunk_size, + batch_size: cli.batch_size, + max_cpu_len_log: cli.max_cpu_len_log, + save_inputs_on_error: cli.save_inputs_on_error, + } + } +} diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 4d7025b9d..42141cf0e 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -1,3 +1,5 @@ +pub mod cli; + use std::future::Future; use std::path::PathBuf; @@ -20,9 +22,11 @@ use tracing::info; use zero_bin_common::fs::generate_block_proof_file_name; #[derive(Debug, Clone, Copy)] -pub struct ProverParams { +pub struct ProverConfig { pub batch_size: usize, pub segment_chunk_size: usize, + pub max_cpu_len_log: usize, + pub save_inputs_on_error: bool, } #[derive(Debug, Deserialize, Serialize)] @@ -43,28 +47,33 @@ impl BlockProverInput { pub async fn prove( self, runtime: &Runtime, - max_cpu_len_log: usize, previous: Option>>, - prover_params: ProverParams, - save_inputs_on_error: bool, + prover_config: ProverConfig, ) -> Result { use anyhow::Context as _; use evm_arithmetization::prover::{SegmentDataChunkIterator, SegmentDataIterator}; use paladin::directive::{Directive, IndexedStream}; + let ProverConfig { + max_cpu_len_log, + batch_size, + segment_chunk_size, + save_inputs_on_error, + } = prover_config; + let block_number = self.get_block_number(); let other_data = self.other_data; let block_generation_inputs = self.block_trace.into_txn_proof_gen_ir( &ProcessingMeta::new(resolve_code_hash_fn), other_data.clone(), - prover_params.batch_size, + batch_size, )?; info!( "Proving block {}, generation inputs count: {}, batch size: {}, segment chunk size: {}", block_number, block_generation_inputs.len(), - prover_params.batch_size, - prover_params.segment_chunk_size + batch_size, + segment_chunk_size ); // Create segment proof @@ -90,10 +99,8 @@ impl BlockProverInput { inputs: &generation_inputs, max_cpu_len_log: Some(max_cpu_len_log), }; - let mut chunk_segment_iter = SegmentDataChunkIterator::new( - &mut segment_data_iter, - prover_params.segment_chunk_size, - ); + let mut chunk_segment_iter = + SegmentDataChunkIterator::new(&mut segment_data_iter, segment_chunk_size); let mut chunk_txn_aggregatable_proofs = Vec::new(); // We take one chunk of segments, perform proving and @@ -162,10 +169,8 @@ impl BlockProverInput { pub async fn prove( self, _runtime: &Runtime, - max_cpu_len_log: usize, previous: Option>>, - prover_params: ProverParams, - _save_inputs_on_error: bool, + prover_config: ProverConfig, ) -> Result { use evm_arithmetization::prover::testing::simulate_all_segments_interpreter; use plonky2::field::goldilocks_field::GoldilocksField; @@ -177,12 +182,12 @@ impl BlockProverInput { let txs = self.block_trace.into_txn_proof_gen_ir( &ProcessingMeta::new(resolve_code_hash_fn), other_data.clone(), - prover_params.batch_size, + prover_config.batch_size, )?; type F = GoldilocksField; for txn in txs.into_iter() { - simulate_all_segments_interpreter::(txn, max_cpu_len_log)?; + simulate_all_segments_interpreter::(txn, prover_config.max_cpu_len_log)?; } // Wait for previous block proof @@ -215,10 +220,8 @@ impl ProverInput { pub async fn prove( self, runtime: &Runtime, - max_cpu_len_log: usize, previous_proof: Option, - prover_params: ProverParams, - save_inputs_on_error: bool, + prover_config: ProverConfig, proof_output_dir: Option, ) -> Result)>> { let mut prev: Option>> = @@ -233,13 +236,7 @@ impl ProverInput { // Prove the block let proof_output_dir = proof_output_dir.clone(); let fut = block - .prove( - runtime, - max_cpu_len_log, - prev.take(), - prover_params, - save_inputs_on_error, - ) + .prove(runtime, prev.take(), prover_config) .then(move |proof| async move { let proof = proof?; let block_number = proof.b_height; From 134cbe988ccacb0473a3781ca73997bb80c9da3c Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Wed, 24 Jul 2024 12:55:04 +0200 Subject: [PATCH 11/15] fix: remove cloning --- evm_arithmetization/src/prover.rs | 2 +- zero_bin/common/src/prover_state/mod.rs | 4 ++-- zero_bin/prover/src/lib.rs | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/evm_arithmetization/src/prover.rs b/evm_arithmetization/src/prover.rs index 43401c596..e71188052 100644 --- a/evm_arithmetization/src/prover.rs +++ b/evm_arithmetization/src/prover.rs @@ -537,7 +537,7 @@ impl<'a> Iterator for SegmentDataIterator<'a> { let cur_and_next_data = generate_next_segment::( self.max_cpu_len_log, self.inputs, - self.partial_next_data.take(), + self.partial_next_data.clone(), ); if cur_and_next_data.is_some() { diff --git a/zero_bin/common/src/prover_state/mod.rs b/zero_bin/common/src/prover_state/mod.rs index 575af06e7..e6631d703 100644 --- a/zero_bin/common/src/prover_state/mod.rs +++ b/zero_bin/common/src/prover_state/mod.rs @@ -261,11 +261,11 @@ impl ProverStateManager { match self.persistence { CircuitPersistence::None | CircuitPersistence::Disk(TableLoadStrategy::Monolithic) => { info!("using monolithic circuit {:?}", self); - self.segment_proof_monolithic(generation_inputs.clone(), &mut segment_data) + self.segment_proof_monolithic(generation_inputs, &mut segment_data) } CircuitPersistence::Disk(TableLoadStrategy::OnDemand) => { info!("using on demand circuit {:?}", self); - self.segment_proof_on_demand(generation_inputs.clone(), &mut segment_data) + self.segment_proof_on_demand(generation_inputs, &mut segment_data) } } } diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index 42141cf0e..e40c4ff2a 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -110,9 +110,7 @@ impl BlockProverInput { Directive::map(IndexedStream::from(chunk.into_iter()), &seg_ops) .fold(&agg_ops) .run(runtime) - .map(move |e| { - e.map(|p| proof_gen::proof_types::TxnAggregatableProof::from(p)) - }) + .map(move |e| e.map(proof_gen::proof_types::TxnAggregatableProof::from)) .await, ); } From 8060288ed0703be5ad8ad297ac852e001d95a90c Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Wed, 24 Jul 2024 13:59:33 +0200 Subject: [PATCH 12/15] feat: add prover config argumetns to scripts --- zero_bin/tools/prove_rpc.sh | 12 +++++++++++- zero_bin/tools/prove_stdio.sh | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/zero_bin/tools/prove_rpc.sh b/zero_bin/tools/prove_rpc.sh index 6da293b4f..477698301 100755 --- a/zero_bin/tools/prove_rpc.sh +++ b/zero_bin/tools/prove_rpc.sh @@ -64,6 +64,16 @@ OUTPUT_TO_TERMINAL="${OUTPUT_TO_TERMINAL:-false}" # Only generate proof by default RUN_VERIFICATION="${RUN_VERIFICATION:-false}" +# Prover config. Override the defaults if needed by setting the env variables. +PROVER_BATCH_SIZE="${PROVER_BATCH_SIZE:-1}" +PROVER_SEGMENT_CHUNK_SIZE="${PROVER_SEGMENT_CHUNK_SIZE:-64}" +PROVER_MAC_CPU_LEN_LOG="${PROVER_MAC_CPU_LEN_LOG:-20}" +if [[ $PROVER_SAVE_INPUTS_ON_ERROR == "true" ]]; then + PROVER_SAVE_INPUTS_ON_ERROR="--save-inputs-on-error" +else + PROVER_SAVE_INPUTS_ON_ERROR="" +fi + mkdir -p $PROOF_OUTPUT_DIR if [ $IGNORE_PREVIOUS_PROOFS ]; then @@ -122,7 +132,7 @@ if [[ $8 == "test_only" ]]; then else # normal run echo "Proving blocks ${BLOCK_INTERVAL} now... (Total: ${TOT_BLOCKS})" - command='cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" ' + command='cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand --batch-size $PROVER_BATCH_SIZE --max-cpu-len-log $PROVER_MAC_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE $PROVER_SAVE_INPUTS_ON_ERROR rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" ' if [ "$OUTPUT_TO_TERMINAL" = true ]; then eval $command echo -e "Proof generation finished with result: $?" diff --git a/zero_bin/tools/prove_stdio.sh b/zero_bin/tools/prove_stdio.sh index 0ae4e72a6..86b4d8bf8 100755 --- a/zero_bin/tools/prove_stdio.sh +++ b/zero_bin/tools/prove_stdio.sh @@ -91,6 +91,18 @@ else fi +# Prover config. Override the defaults if needed by setting the env variables. +PROVER_BATCH_SIZE="${PROVER_BATCH_SIZE:-1}" +PROVER_SEGMENT_CHUNK_SIZE="${PROVER_SEGMENT_CHUNK_SIZE:-64}" +PROVER_MAC_CPU_LEN_LOG="${PROVER_MAC_CPU_LEN_LOG:-20}" +if [[ $PROVER_SAVE_INPUTS_ON_ERROR == "true" ]]; then + PROVER_SAVE_INPUTS_ON_ERROR="--save-inputs-on-error" +else + PROVER_SAVE_INPUTS_ON_ERROR="" +fi + + + # If we run ./prove_stdio.sh test_only, we'll generate a dummy # proof. This is useful for quickly testing decoding and all of the # other non-proving code. @@ -108,7 +120,9 @@ fi cargo build --release --jobs "$num_procs" start_time=$(date +%s%N) -"${TOOLS_DIR}/../../target/release/leader" --runtime in-memory --load-strategy on-demand stdio < $INPUT_FILE | tee $LEADER_OUT_PATH +"${TOOLS_DIR}/../../target/release/leader" --runtime in-memory --load-strategy on-demand --batch-size $PROVER_BATCH_SIZE \ + --max-cpu-len-log $PROVER_MAC_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE \ + $PROVER_SAVE_INPUTS_ON_ERROR stdio < $INPUT_FILE | tee $LEADER_OUT_PATH end_time=$(date +%s%N) tail -n 1 $LEADER_OUT_PATH > $PROOFS_JSON_PATH From 5b92df14a0ac5d7059d9451220522ae83741328d Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Thu, 25 Jul 2024 15:14:26 +0200 Subject: [PATCH 13/15] feat: fix aggregation add segmentation ci test --- .github/workflows/ci.yml | 21 +++++++++++++++--- proof_gen/src/proof_gen.rs | 8 +++---- proof_gen/src/proof_types.rs | 32 +++++++++++++------------- zero_bin/ops/src/lib.rs | 20 ++++++++--------- zero_bin/prover/src/lib.rs | 42 +++++++++++++++++------------------ zero_bin/tools/prove_rpc.sh | 8 ++++++- zero_bin/tools/prove_stdio.sh | 28 ++++++++++++++--------- 7 files changed, 93 insertions(+), 66 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da2a3d615..f9bd28607 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -176,6 +176,20 @@ jobs: CARGO_INCREMENTAL: 1 RUST_BACKTRACE: 1 + simple_proof_witness_only: + name: Execute bash script to generate the proof witness for a small block. + runs-on: zero-ci + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Run the script + run: | + pushd zero_bin/tools + ./prove_stdio.sh artifacts/witness_b19240705.json test_only + + simple_proof_regular: name: Execute bash script to generate and verify a proof for a small block. runs-on: zero-ci @@ -189,8 +203,8 @@ jobs: pushd zero_bin/tools ./prove_stdio.sh artifacts/witness_b19240705.json - simple_proof_witness_only: - name: Execute bash script to generate the proof witness for a small block. + simple_proof_using_continuations: + name: Execute bash script to generate and verify a proof for a small block utilizing custom batch and segment chunk size runs-on: zero-ci steps: @@ -200,7 +214,8 @@ jobs: - name: Run the script run: | pushd zero_bin/tools - ./prove_stdio.sh artifacts/witness_b19240705.json test_only + time PROVER_BATCH_SIZE=5 PROVER_SEGMENT_CHUNK_SIZE=4 PROVER_MAX_CPU_LEN_LOG=17 ./prove_stdio.sh ./artifacts/witness_b19240705.json + multi_blocks_proof_regular: name: Execute bash script to generate and verify a proof for multiple blocks using parallel proving. diff --git a/proof_gen/src/proof_gen.rs b/proof_gen/src/proof_gen.rs index cd6d48a52..c387460d6 100644 --- a/proof_gen/src/proof_gen.rs +++ b/proof_gen/src/proof_gen.rs @@ -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}, @@ -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 { let (b_proof_intern, p_vals) = p_state .state diff --git a/proof_gen/src/proof_types.rs b/proof_gen/src/proof_types.rs index fea8f845f..9807f0b25 100644 --- a/proof_gen/src/proof_types.rs +++ b/proof_gen/src/proof_types.rs @@ -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), @@ -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, } } } @@ -138,23 +138,23 @@ impl From for SegmentAggregatableProof { } } -impl From for TxnAggregatableProof { +impl From for BatchAggregatableProof { fn from(v: GeneratedSegmentAggProof) -> Self { Self::Txn(v) } } -impl From for TxnAggregatableProof { +impl From for BatchAggregatableProof { fn from(v: GeneratedTxnAggProof) -> Self { Self::Agg(v) } } -impl From for TxnAggregatableProof { +impl From 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), } } } diff --git a/zero_bin/ops/src/lib.rs b/zero_bin/ops/src/lib.rs index f2c025913..4ff93a93f 100644 --- a/zero_bin/ops/src/lib.rs +++ b/zero_bin/ops/src/lib.rs @@ -9,7 +9,7 @@ use paladin::{ use proof_gen::{ proof_gen::{generate_block_proof, generate_segment_agg_proof, generate_transaction_agg_proof}, proof_types::{ - GeneratedBlockProof, GeneratedTxnAggProof, SegmentAggregatableProof, TxnAggregatableProof, + BatchAggregatableProof, GeneratedBlockProof, GeneratedTxnAggProof, SegmentAggregatableProof, }, }; use serde::{Deserialize, Serialize}; @@ -234,23 +234,23 @@ impl Monoid for SegmentAggProof { } #[derive(Deserialize, Serialize, RemoteExecute)] -pub struct TxnAggProof { +pub struct BatchAggProof { pub save_inputs_on_error: bool, } -fn get_agg_proof_public_values(elem: TxnAggregatableProof) -> PublicValues { +fn get_agg_proof_public_values(elem: BatchAggregatableProof) -> PublicValues { match elem { - TxnAggregatableProof::Segment(info) => info.p_vals, - TxnAggregatableProof::Txn(info) => info.p_vals, - TxnAggregatableProof::Agg(info) => info.p_vals, + BatchAggregatableProof::Segment(info) => info.p_vals, + BatchAggregatableProof::Txn(info) => info.p_vals, + BatchAggregatableProof::Agg(info) => info.p_vals, } } -impl Monoid for TxnAggProof { - type Elem = TxnAggregatableProof; +impl Monoid for BatchAggProof { + type Elem = BatchAggregatableProof; fn combine(&self, a: Self::Elem, b: Self::Elem) -> Result { let lhs = match a { - TxnAggregatableProof::Segment(segment) => TxnAggregatableProof::from( + BatchAggregatableProof::Segment(segment) => BatchAggregatableProof::from( generate_segment_agg_proof( p_state(), &SegmentAggregatableProof::from(segment.clone()), @@ -263,7 +263,7 @@ impl Monoid for TxnAggProof { }; let rhs = match b { - TxnAggregatableProof::Segment(segment) => TxnAggregatableProof::from( + BatchAggregatableProof::Segment(segment) => BatchAggregatableProof::from( generate_segment_agg_proof( p_state(), &SegmentAggregatableProof::from(segment.clone()), diff --git a/zero_bin/prover/src/lib.rs b/zero_bin/prover/src/lib.rs index e40c4ff2a..bc109ec35 100644 --- a/zero_bin/prover/src/lib.rs +++ b/zero_bin/prover/src/lib.rs @@ -77,21 +77,21 @@ impl BlockProverInput { ); // Create segment proof - let seg_ops = ops::SegmentProof { + let seg_prove_ops = ops::SegmentProof { save_inputs_on_error, }; // Generate segment data. - let agg_ops = ops::SegmentAggProof { + let seg_agg_ops = ops::SegmentAggProof { save_inputs_on_error, }; - // Aggregate transaction proofs - let txn_agg_proof = ops::TxnAggProof { + // Aggregate batch proofs to a single proof + let batch_agg_ops = ops::BatchAggProof { save_inputs_on_error, }; - let mut all_block_txn_aggregatable_proofs = Vec::new(); + let mut all_block_batch_proofs = Vec::new(); // Loop for all generation inputs in the block for generation_inputs in block_generation_inputs { let mut segment_data_iter = SegmentDataIterator { @@ -102,42 +102,42 @@ impl BlockProverInput { let mut chunk_segment_iter = SegmentDataChunkIterator::new(&mut segment_data_iter, segment_chunk_size); - let mut chunk_txn_aggregatable_proofs = Vec::new(); + let mut chunk_seg_aggregatable_proofs = Vec::new(); // We take one chunk of segments, perform proving and - // aggregate it to `TxnAggregatableProof` + // aggregate it into a single chunk proof while let Some(chunk) = chunk_segment_iter.next() { - chunk_txn_aggregatable_proofs.push( - Directive::map(IndexedStream::from(chunk.into_iter()), &seg_ops) - .fold(&agg_ops) + chunk_seg_aggregatable_proofs.push( + Directive::map(IndexedStream::from(chunk.into_iter()), &seg_prove_ops) + .fold(&seg_agg_ops) .run(runtime) - .map(move |e| e.map(proof_gen::proof_types::TxnAggregatableProof::from)) .await, ); } - // Fold all the generation input transaction proofs - // into a single transaction proof - let generation_input_txn_proof = Directive::fold( - IndexedStream::from(chunk_txn_aggregatable_proofs.into_iter().collect::, anyhow::Error, >>( )?), - &txn_agg_proof, + &seg_agg_ops, ) .run(runtime) + .map(move |e| e.map(proof_gen::proof_types::BatchAggregatableProof::from)) .await?; - all_block_txn_aggregatable_proofs.push(generation_input_txn_proof); + all_block_batch_proofs.push(batch_aggregated_proof); } - // Fold all the agg transaction proofs into a single transaction proof + // Fold all the aggregated batch proofs into a single batch proof let final_txn_proof = Directive::fold( - IndexedStream::from(all_block_txn_aggregatable_proofs.into_iter()), - &txn_agg_proof, + IndexedStream::from(all_block_batch_proofs.into_iter()), + &batch_agg_ops, ) .run(runtime) .await?; - if let proof_gen::proof_types::TxnAggregatableProof::Agg(proof) = final_txn_proof { + if let proof_gen::proof_types::BatchAggregatableProof::Agg(proof) = final_txn_proof { let block_number = block_number .to_u64() .context("block number overflows u64")?; diff --git a/zero_bin/tools/prove_rpc.sh b/zero_bin/tools/prove_rpc.sh index 477698301..40aebc4f4 100755 --- a/zero_bin/tools/prove_rpc.sh +++ b/zero_bin/tools/prove_rpc.sh @@ -74,6 +74,12 @@ else PROVER_SAVE_INPUTS_ON_ERROR="" fi +if [ -n "$NUM_WORKERS" ]; then + SET_NUM_WORKERS="--num-workers $NUM_WORKERS" +else + SET_NUM_WORKERS="" +fi + mkdir -p $PROOF_OUTPUT_DIR if [ $IGNORE_PREVIOUS_PROOFS ]; then @@ -132,7 +138,7 @@ if [[ $8 == "test_only" ]]; then else # normal run echo "Proving blocks ${BLOCK_INTERVAL} now... (Total: ${TOT_BLOCKS})" - command='cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand --batch-size $PROVER_BATCH_SIZE --max-cpu-len-log $PROVER_MAC_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE $PROVER_SAVE_INPUTS_ON_ERROR rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" ' + command='cargo r --release --bin leader -- --runtime in-memory --load-strategy on-demand --batch-size $PROVER_BATCH_SIZE --max-cpu-len-log $PROVER_MAC_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE $SET_NUM_WORKERS $PROVER_SAVE_INPUTS_ON_ERROR rpc --rpc-type "$NODE_RPC_TYPE" --rpc-url "$3" --block-interval $BLOCK_INTERVAL --proof-output-dir $PROOF_OUTPUT_DIR $PREV_PROOF_EXTRA_ARG --backoff "$BACKOFF" --max-retries "$RETRIES" ' if [ "$OUTPUT_TO_TERMINAL" = true ]; then eval $command echo -e "Proof generation finished with result: $?" diff --git a/zero_bin/tools/prove_stdio.sh b/zero_bin/tools/prove_stdio.sh index 86b4d8bf8..ce61a9a4d 100755 --- a/zero_bin/tools/prove_stdio.sh +++ b/zero_bin/tools/prove_stdio.sh @@ -57,14 +57,14 @@ else # These sizes are configured specifically for block 19240705. Don't use this in other scenarios. echo "Using specific circuit sizes for witness_b19240705.json" export ARITHMETIC_CIRCUIT_SIZE="16..19" - export BYTE_PACKING_CIRCUIT_SIZE="11..15" - export CPU_CIRCUIT_SIZE="18..21" - export KECCAK_CIRCUIT_SIZE="14..18" - export KECCAK_SPONGE_CIRCUIT_SIZE="9..13" - export LOGIC_CIRCUIT_SIZE="12..17" - export MEMORY_CIRCUIT_SIZE="20..23" - export MEMORY_BEFORE_CIRCUIT_SIZE="16..17" - export MEMORY_AFTER_CIRCUIT_SIZE="7..8" + export BYTE_PACKING_CIRCUIT_SIZE="10..15" + export CPU_CIRCUIT_SIZE="17..21" + export KECCAK_CIRCUIT_SIZE="12..18" + export KECCAK_SPONGE_CIRCUIT_SIZE="7..13" + export LOGIC_CIRCUIT_SIZE="10..17" + export MEMORY_CIRCUIT_SIZE="19..23" + export MEMORY_BEFORE_CIRCUIT_SIZE="15..19" + export MEMORY_AFTER_CIRCUIT_SIZE="7..19" elif [[ $INPUT_FILE == *"witness_b2_b7"* ]]; then # These sizes are configured specifically for custom small blocks. Don't use this in other scenarios. echo "Using specific circuit sizes for witness_b2_b7.json" @@ -94,13 +94,19 @@ fi # Prover config. Override the defaults if needed by setting the env variables. PROVER_BATCH_SIZE="${PROVER_BATCH_SIZE:-1}" PROVER_SEGMENT_CHUNK_SIZE="${PROVER_SEGMENT_CHUNK_SIZE:-64}" -PROVER_MAC_CPU_LEN_LOG="${PROVER_MAC_CPU_LEN_LOG:-20}" +PROVER_MAX_CPU_LEN_LOG="${PROVER_MAX_CPU_LEN_LOG:-20}" if [[ $PROVER_SAVE_INPUTS_ON_ERROR == "true" ]]; then PROVER_SAVE_INPUTS_ON_ERROR="--save-inputs-on-error" else PROVER_SAVE_INPUTS_ON_ERROR="" fi +if [ -n "$NUM_WORKERS" ]; then + SET_NUM_WORKERS="--num-workers $NUM_WORKERS" +else + SET_NUM_WORKERS="" +fi + # If we run ./prove_stdio.sh test_only, we'll generate a dummy @@ -121,8 +127,8 @@ cargo build --release --jobs "$num_procs" start_time=$(date +%s%N) "${TOOLS_DIR}/../../target/release/leader" --runtime in-memory --load-strategy on-demand --batch-size $PROVER_BATCH_SIZE \ - --max-cpu-len-log $PROVER_MAC_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE \ - $PROVER_SAVE_INPUTS_ON_ERROR stdio < $INPUT_FILE | tee $LEADER_OUT_PATH + --max-cpu-len-log $PROVER_MAX_CPU_LEN_LOG --segment-chunk-size $PROVER_SEGMENT_CHUNK_SIZE \ + $SET_NUM_WORKERS $PROVER_SAVE_INPUTS_ON_ERROR stdio < $INPUT_FILE | tee $LEADER_OUT_PATH end_time=$(date +%s%N) tail -n 1 $LEADER_OUT_PATH > $PROOFS_JSON_PATH From 50c5d2143c557edd31b10257038fead2c5afb4fa Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Thu, 25 Jul 2024 19:15:37 +0200 Subject: [PATCH 14/15] fix: rename ci tests --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9bd28607..f954d2760 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -177,7 +177,7 @@ jobs: RUST_BACKTRACE: 1 simple_proof_witness_only: - name: Execute bash script to generate the proof witness for a small block. + name: Test witness for a small block. runs-on: zero-ci steps: @@ -191,7 +191,7 @@ jobs: simple_proof_regular: - name: Execute bash script to generate and verify a proof for a small block. + name: Test real proof for a small block. runs-on: zero-ci steps: @@ -204,7 +204,7 @@ jobs: ./prove_stdio.sh artifacts/witness_b19240705.json simple_proof_using_continuations: - name: Execute bash script to generate and verify a proof for a small block utilizing custom batch and segment chunk size + name: Test proof for a small block with custom batch and segment chunk size runs-on: zero-ci steps: @@ -218,7 +218,7 @@ jobs: multi_blocks_proof_regular: - name: Execute bash script to generate and verify a proof for multiple blocks using parallel proving. + name: Test proof for multiple blocks using parallel proving. runs-on: zero-ci steps: From e45be0b97db395af0aa1e1bf8c56b6d0c3fee43f Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Fri, 26 Jul 2024 00:35:12 +0200 Subject: [PATCH 15/15] fix: test --- .github/workflows/ci.yml | 2 +- zero_bin/tools/prove_stdio.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f954d2760..aa1ba4fbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -214,7 +214,7 @@ jobs: - name: Run the script run: | pushd zero_bin/tools - time PROVER_BATCH_SIZE=5 PROVER_SEGMENT_CHUNK_SIZE=4 PROVER_MAX_CPU_LEN_LOG=17 ./prove_stdio.sh ./artifacts/witness_b19240705.json + PROVER_BATCH_SIZE=3 PROVER_SEGMENT_CHUNK_SIZE=4 PROVER_MAX_CPU_LEN_LOG=17 ./prove_stdio.sh ./artifacts/witness_b19240705.json multi_blocks_proof_regular: diff --git a/zero_bin/tools/prove_stdio.sh b/zero_bin/tools/prove_stdio.sh index ce61a9a4d..d27957e21 100755 --- a/zero_bin/tools/prove_stdio.sh +++ b/zero_bin/tools/prove_stdio.sh @@ -57,12 +57,12 @@ else # These sizes are configured specifically for block 19240705. Don't use this in other scenarios. echo "Using specific circuit sizes for witness_b19240705.json" export ARITHMETIC_CIRCUIT_SIZE="16..19" - export BYTE_PACKING_CIRCUIT_SIZE="10..15" - export CPU_CIRCUIT_SIZE="17..21" - export KECCAK_CIRCUIT_SIZE="12..18" + export BYTE_PACKING_CIRCUIT_SIZE="9..15" + export CPU_CIRCUIT_SIZE="14..21" + export KECCAK_CIRCUIT_SIZE="10..18" export KECCAK_SPONGE_CIRCUIT_SIZE="7..13" - export LOGIC_CIRCUIT_SIZE="10..17" - export MEMORY_CIRCUIT_SIZE="19..23" + export LOGIC_CIRCUIT_SIZE="8..17" + export MEMORY_CIRCUIT_SIZE="18..23" export MEMORY_BEFORE_CIRCUIT_SIZE="15..19" export MEMORY_AFTER_CIRCUIT_SIZE="7..19" elif [[ $INPUT_FILE == *"witness_b2_b7"* ]]; then