diff --git a/backend/src/bberg_impl.rs b/backend/src/bberg_impl.rs index 8792fa5855..0999dee8ad 100644 --- a/backend/src/bberg_impl.rs +++ b/backend/src/bberg_impl.rs @@ -20,8 +20,9 @@ impl BackendImpl for BBergCodegen { fixed: &[(&str, Vec)], witness: &[(&str, Vec)], _prev_proof: Option, + bname: Option, ) -> (Option, Option) { - self.build_ast(pil, fixed, witness); + self.build_ast(pil, fixed, witness, bname); // Note(md): In the current bberg impl we do not produce proofs here // as we do cpp code generation, and then create proofs with bberg @@ -55,6 +56,7 @@ impl BackendImpl for BBergMock { _fixed: &[(&str, Vec)], _witness: &[(&str, Vec)], prev_proof: Option, + _bname: Option, ) -> (Option, Option) { if prev_proof.is_some() { unimplemented!("BBergMock backend does not support aggregation"); diff --git a/backend/src/lib.rs b/backend/src/lib.rs index 36a4724ed4..8b33e1a13b 100644 --- a/backend/src/lib.rs +++ b/backend/src/lib.rs @@ -79,8 +79,9 @@ impl> Backend for ConcreteBackendWithoutSe fixed: &[(&str, Vec)], witness: &[(&str, Vec)], prev_proof: Option, + bname: Option, ) -> (Option, Option) { - self.0.prove(pil, fixed, witness, prev_proof) + self.0.prove(pil, fixed, witness, prev_proof, bname) } fn write_setup(&self, _output: &mut dyn io::Write) -> Result<(), Error> { @@ -117,8 +118,9 @@ impl> Backend for ConcreteBackend fixed: &[(&str, Vec)], witness: &[(&str, Vec)], prev_proof: Option, + bname: Option, ) -> (Option, Option) { - self.0.prove(pil, fixed, witness, prev_proof) + self.0.prove(pil, fixed, witness, prev_proof, bname) } fn write_setup(&self, output: &mut dyn io::Write) -> Result<(), Error> { @@ -155,6 +157,7 @@ pub trait Backend { fixed: &[(&str, Vec)], witness: &[(&str, Vec)], prev_proof: Option, + bname: Option, ) -> (Option, Option); /// Write the prover setup to a file, so that it can be loaded later. @@ -184,6 +187,7 @@ trait BackendImpl { fixed: &[(&str, Vec)], witness: &[(&str, Vec)], prev_proof: Option, + bname: Option, ) -> (Option, Option); } diff --git a/backend/src/pilstark/estark.rs b/backend/src/pilstark/estark.rs index cb27e48473..5ebbc7968c 100644 --- a/backend/src/pilstark/estark.rs +++ b/backend/src/pilstark/estark.rs @@ -51,6 +51,7 @@ impl BackendImpl for EStark { fixed: &[(&str, Vec)], witness: &[(&str, Vec)], prev_proof: Option, + _bname: Option, ) -> (Option, Option) { if prev_proof.is_some() { unimplemented!("aggregration is not implemented"); diff --git a/backend/src/pilstark/mod.rs b/backend/src/pilstark/mod.rs index 75b1653c84..687a9daa92 100644 --- a/backend/src/pilstark/mod.rs +++ b/backend/src/pilstark/mod.rs @@ -18,6 +18,7 @@ impl BackendImpl for PilStarkCli { _fixed: &[(&str, Vec)], _witness: &[(&str, Vec)], prev_proof: Option, + _bname: Option, ) -> (Option, Option) { if prev_proof.is_some() { unimplemented!("Aggregration is not implemented for pil-stark CLI backend"); diff --git a/bberg/src/bberg_codegen.rs b/bberg/src/bberg_codegen.rs index 943247a536..9d9aa86e37 100644 --- a/bberg/src/bberg_codegen.rs +++ b/bberg/src/bberg_codegen.rs @@ -32,8 +32,9 @@ impl BBergCodegen { pil: &Analyzed, fixed: &[(&str, Vec)], witness: &[(&str, Vec)], + bname: Option, ) -> Vec { - let bberg_files = analyzed_to_cpp(pil, fixed, witness); + let bberg_files = analyzed_to_cpp(pil, fixed, witness, bname); bberg_files.write(); Vec::new() diff --git a/bberg/src/circuit_builder.rs b/bberg/src/circuit_builder.rs index be436fb590..357ab692ce 100644 --- a/bberg/src/circuit_builder.rs +++ b/bberg/src/circuit_builder.rs @@ -178,8 +178,9 @@ pub(crate) fn analyzed_to_cpp( analyzed: &Analyzed, fixed: &[(&str, Vec)], witness: &[(&str, Vec)], + bname: Option, ) -> BBFiles { - let file_name: &str = FILE_NAME; + let file_name: &str = &bname.unwrap_or("Example".to_owned()); let mut bb_files = BBFiles::default(file_name.to_owned()); diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 1a356c2996..4485d7b571 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -41,6 +41,7 @@ pub fn compile_pil_or_asm( force_overwrite: bool, prove_with: Option, external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> Result>, Vec> { if file_name.ends_with(".asm") { compile_asm( @@ -50,6 +51,7 @@ pub fn compile_pil_or_asm( force_overwrite, prove_with, external_witness_values, + bname, ) } else { Ok(Some(compile_pil( @@ -58,6 +60,7 @@ pub fn compile_pil_or_asm( inputs_to_query_callback(inputs), prove_with, external_witness_values, + bname, ))) } } @@ -76,6 +79,7 @@ pub fn compile_pil>( query_callback: Q, prove_with: Option, external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> CompilationResult { compile( pil_analyzer::analyze(pil_file), @@ -84,6 +88,7 @@ pub fn compile_pil>( query_callback, prove_with, external_witness_values, + bname, ) } @@ -96,6 +101,7 @@ pub fn compile_pil_ast>( query_callback: Q, prove_with: Option, external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> CompilationResult { // TODO exporting this to string as a hack because the parser // is tied into the analyzer due to imports. @@ -106,6 +112,7 @@ pub fn compile_pil_ast>( query_callback, prove_with, external_witness_values, + bname, ) } @@ -119,6 +126,7 @@ pub fn compile_asm( force_overwrite: bool, prove_with: Option, external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> Result>, Vec> { let contents = fs::read_to_string(file_name).unwrap(); Ok(compile_asm_string( @@ -129,6 +137,7 @@ pub fn compile_asm( force_overwrite, prove_with, external_witness_values, + bname, )? .1) } @@ -145,6 +154,7 @@ pub fn compile_asm_string( force_overwrite: bool, prove_with: Option, external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> Result<(PathBuf, Option>), Vec> { let parsed = parser::parse_asm(Some(file_name), contents).unwrap_or_else(|err| { eprintln!("Error parsing .asm file:"); @@ -193,6 +203,7 @@ pub fn compile_asm_string( inputs_to_query_callback(inputs), prove_with, external_witness_values, + bname, )), )) } @@ -213,6 +224,7 @@ fn compile>( _query_callback: Q, prove_with: Option, _external_witness_values: Vec<(&str, Vec)>, + bname: Option, ) -> CompilationResult { log::info!("Optimizing pil..."); // let analyzed = pilopt::optimize(analyzed); @@ -250,7 +262,13 @@ fn compile>( let factory = backend.factory::(); let backend = factory.create(degree); - backend.prove(&mut_analyzed, &constants, &witness_in_powdr_form, None); + backend.prove( + &mut_analyzed, + &constants, + &witness_in_powdr_form, + None, + None, + ); } let constants = constants diff --git a/compiler/src/verify.rs b/compiler/src/verify.rs index a3272e1c49..13090414bb 100644 --- a/compiler/src/verify.rs +++ b/compiler/src/verify.rs @@ -14,6 +14,7 @@ pub fn verify_asm_string(file_name: &str, contents: &str, input true, Some(BackendType::PilStarkCli), vec![], + None, ) .unwrap(); verify(&temp_dir); diff --git a/powdr_cli/src/main.rs b/powdr_cli/src/main.rs index b75bad3e5d..19ebac179d 100644 --- a/powdr_cli/src/main.rs +++ b/powdr_cli/src/main.rs @@ -94,6 +94,10 @@ enum Commands { #[arg(default_value_t = CsvRenderModeCLI::Hex)] #[arg(value_parser = clap_enum_variants!(CsvRenderModeCLI))] csv_mode: CsvRenderModeCLI, + + /// BBerg: Name of the output file for bberg + #[arg(long)] + bname: Option, }, /// Compiles (no-std) rust code to riscv assembly, then to powdr assembly /// and finally to PIL and generates fixed and witness columns. @@ -377,6 +381,7 @@ fn run_command(command: Commands) { prove_with, export_csv, csv_mode, + bname, } => { match call_with_field!(compile_with_csv_export::( file, @@ -386,7 +391,8 @@ fn run_command(command: Commands) { force, prove_with, export_csv, - csv_mode + csv_mode, + bname )) { Ok(()) => {} Err(errors) => { @@ -455,6 +461,7 @@ fn run_rust( force_overwrite, prove_with, vec![], + None, )?; Ok(()) } @@ -485,6 +492,7 @@ fn run_riscv_asm( force_overwrite, prove_with, vec![], + None, )?; Ok(()) } @@ -499,6 +507,7 @@ fn compile_with_csv_export( prove_with: Option, export_csv: bool, csv_mode: CsvRenderModeCLI, + bname: Option, ) -> Result<(), Vec> { let external_witness_values = witness_values .map(|csv_path| { @@ -519,6 +528,7 @@ fn compile_with_csv_export( force, prove_with, external_witness_values, + bname, )?; if export_csv { @@ -593,7 +603,7 @@ fn read_and_prove( write_proving_results_to_fs( proof.is_some(), - backend.prove(&pil, &fixed.0, &witness.0, proof), + backend.prove(&pil, &fixed.0, &witness.0, proof, None), dir, ); } @@ -629,6 +639,7 @@ mod test { prove_with: Some(BackendType::PilStarkCli), export_csv: true, csv_mode: CsvRenderModeCLI::Hex, + bname: "Example".into(), }; run_command(pil_command);