From dbcf07abc84d77d6d5a28917d67d067b878c7eeb Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Sat, 11 Nov 2023 10:58:40 +0000 Subject: [PATCH 1/4] feat: just pil --- bberg/src/circuit_builder.rs | 46 +++++++++---- bberg/src/trace_builder.rs | 122 +---------------------------------- compiler/src/lib.rs | 62 +++++++----------- 3 files changed, 60 insertions(+), 170 deletions(-) diff --git a/bberg/src/circuit_builder.rs b/bberg/src/circuit_builder.rs index dfc1492bf2..7102e4d49e 100644 --- a/bberg/src/circuit_builder.rs +++ b/bberg/src/circuit_builder.rs @@ -183,7 +183,7 @@ pub(crate) fn analyzed_to_cpp( fixed: &[(&str, Vec)], witness: &[(&str, Vec)], ) -> BBFiles { - let file_name: &str = "BrilligVM"; + let file_name: &str = "Fib"; let mut bb_files = BBFiles::default(file_name.to_owned()); // Collect all column names and determine if they need a shift or not @@ -198,10 +198,23 @@ pub(crate) fn analyzed_to_cpp( .map(|(name, _)| (*name).to_owned()) .collect::>(); + let first_col = fixed + .iter() + .find(|col_name| col_name.0.contains("FIRST")) + .expect("PIL file must contain a fixed column named FIRST") + .0; + + let last_col = fixed + .iter() + .find(|col_name| col_name.0.contains("LAST")) + .expect("PIL file must contain a fixed column named LAST") + .0; + // Inlining step to remove the intermediate poly definitions let analyzed_identities = inline_intermediate_polynomials(analyzed); - let (subrelations, identities, mut collected_shifts) = create_identities(&analyzed_identities); + let (subrelations, identities, mut collected_shifts) = + create_identities(first_col, last_col, &analyzed_identities); let shifted_polys: Vec = collected_shifts.drain().collect_vec(); dbg!(shifted_polys.clone()); @@ -232,7 +245,7 @@ pub(crate) fn analyzed_to_cpp( let flavor_hpp = flavor_builder::create_flavor_hpp( file_name, &subrelations, - &unshifted, + &all_cols, &to_be_shifted, // &shifted, ); @@ -493,13 +506,14 @@ fn get_cols_in_identity_macro(all_rows_and_shifts: &[String]) -> String { } fn create_identity( + last_col: &str, expression: &SelectedExpressions>, collected_shifts: &mut HashSet, ) -> Option { // We want to read the types of operators and then create the appropiate code if let Some(expr) = &expression.selector { - let x = craft_expression(expr, collected_shifts); + let x = craft_expression(last_col, expr, collected_shifts); println!("{:?}", x); Some(x) } else { @@ -508,7 +522,12 @@ fn create_identity( } // TODO: replace the preamble with a macro so the code looks nicer -fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity) -> String { +fn create_subrelation( + first_col: &str, + index: usize, + preamble: String, + identity: &mut BBIdentity, +) -> String { // \\\ let id = &identity.1; @@ -520,13 +539,14 @@ fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity) auto tmp = {id}; tmp *= scaling_factor; - tmp *= (-main_FIRST+ FF(1)); // Temp to switch off + tmp *= (-{first_col} + FF(1)); // Temp to switch off std::get<{index}>(evals) += tmp; }}", ) } fn craft_expression( + last_col: &str, expr: &Expression, collected_shifts: &mut HashSet, ) -> BBIdentity { @@ -543,14 +563,14 @@ fn craft_expression( poly_name = format!("{}_shift", poly_name); // TODO(HORRIBLE): TEMP, add in a relation that turns off shifts on the last row - poly_name = format!("{poly_name} * (-main_LAST + FF(1))"); + poly_name = format!("{poly_name} * (-{} + FF(1))", last_col); degree += 1; } (degree, poly_name) } Expression::BinaryOperation(lhe, op, rhe) => { - let (ld, lhs) = craft_expression(lhe, collected_shifts); - let (rd, rhs) = craft_expression(rhe, collected_shifts); + let (ld, lhs) = craft_expression(last_col, lhe, collected_shifts); + let (rd, rhs) = craft_expression(last_col, rhe, collected_shifts); // dbg!(&lhe); let degree = std::cmp::max(ld, rd); @@ -576,7 +596,7 @@ fn craft_expression( // } Expression::UnaryOperation(operator, expression) => match operator { AlgebraicUnaryOperator::Minus => { - let (d, e) = craft_expression(expression, collected_shifts); + let (d, e) = craft_expression(last_col, expression, collected_shifts); (d, format!("-{}", e)) } _ => unimplemented!("{:?}", expr), @@ -591,6 +611,8 @@ type BBIdentity = (DegreeType, String); /// Todo, eventually these will need to be siloed based on the file name they are in fn create_identities( + first_col: &str, + last_col: &str, identities: &Vec>>, ) -> (Vec, Vec, HashSet) { // We only want the expressions for now @@ -617,8 +639,8 @@ fn create_identities( ); // TODO: deal with unwrap - let mut identity = create_identity(expression, &mut collected_shifts).unwrap(); - let subrelation = create_subrelation(i, relation_boilerplate, &mut identity); + let mut identity = create_identity(last_col, expression, &mut collected_shifts).unwrap(); + let subrelation = create_subrelation(first_col, i, relation_boilerplate, &mut identity); identities.push(identity); diff --git a/bberg/src/trace_builder.rs b/bberg/src/trace_builder.rs index 8a60e91cda..32db2478e8 100644 --- a/bberg/src/trace_builder.rs +++ b/bberg/src/trace_builder.rs @@ -58,53 +58,6 @@ fn trace_hpp_includes(name: &str) -> String { ) } -fn build_shifts(fixed: &[String]) -> String { - let shift_assign: Vec = fixed - .iter() - .map(|name| format!("row.{name}_shift = rows[(i) % rows.size()].{name};")) - .collect(); - - format!( - " - for (size_t i = 1; i < rows.size(); ++i) {{ - Row& row = rows[i-1]; - {} - - }} - ", - shift_assign.join("\n") - ) -} - -fn build_empty_row(all_cols: &[String]) -> String { - // The empty row turns off all constraints when the ISLAST flag is set - // We must check that this column exists, and return an error to the user if it is not found - let is_last = all_cols.iter().find(|name| name.contains("ISLAST")); - if is_last.is_none() { - // TODO: make error - panic!("ISLAST column not found in witness"); - } - let is_last = is_last.unwrap(); - - let initialize = all_cols - .iter() - .filter(|name| !name.contains("ISLAST")) // filter out islast - .map(|name| format!("empty_row.{name} = fr(0);")) - .collect::>() - .join("\n"); - - format!( - " - auto empty_row = Row{{}}; - empty_row.{is_last} = fr(1); - {initialize} - rows.push_back(empty_row); - - - " - ) -} - impl TraceBuilder for BBFiles { // Create trace builder // Generate some code that can read a commits.bin and constants.bin into data structures that bberg understands @@ -113,7 +66,7 @@ impl TraceBuilder for BBFiles { name: &str, fixed: &[String], witness: &[String], - to_be_shifted: &[String], + _to_be_shifted: &[String], ) -> String { // We are assuming that the order of the columns in the trace file is the same as the order in the witness file let includes = trace_cpp_includes(&self.rel, name); @@ -157,28 +110,6 @@ impl TraceBuilder for BBFiles { .collect::>() .join("\n"); - let fixed_rows = fixed - .iter() - .map(|name| { - let n = name.replace('.', "_"); - format!("current_row.{n} = read_field(constant_file);") - }) - .collect::>() - .join("\n"); - - let wit_rows = &witness_name - .iter() - .map(|n| { - format!( - " - current_row.{n} = read_field(commited_file);" - ) - }) - .collect::>() - .join("\n"); - - let construct_shifts = build_shifts(to_be_shifted); - // NOTE: can we assume that the witness filename etc will stay the same? let read_from_file_boilerplate = format!( " @@ -190,57 +121,6 @@ using namespace barretenberg; namespace proof_system {{ {row_import} -inline fr read_field(std::ifstream& file) -{{ - uint8_t buffer[32]; - file.read(reinterpret_cast(buffer), 32); - - // swap it to big endian ???? TODO: create utility - for (int n = 0, m = 31; n < m; ++n, --m) {{ - std::swap(buffer[n], buffer[m]); - }} - - return fr::serialize_from_buffer(buffer); -}} - -inline std::vector read_both_file_into_cols( - std::string const& commited_filename, - std::string const& constants_filename -) {{ - std::vector rows; - - // open both files - std::ifstream commited_file(commited_filename, std::ios::binary); - if (!commited_file) {{ - std::cout << \"Error opening commited file\" << std::endl; - return {{}}; - }} - - std::ifstream constant_file(constants_filename, std::ios::binary); - if (!constant_file) {{ - std::cout << \"Error opening constant file\" << std::endl; - return {{}}; - }} - - // We are assuming that the two files are the same length - while (commited_file) {{ - Row current_row = {{}}; - - {fixed_rows} - {wit_rows} - - rows.push_back(current_row); - }} - - // remove the last row - TODO: BUG! - rows.pop_back(); - - // Build out shifts from collected rows - {construct_shifts} - - - return rows; -}} }} " diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 34b7f5d8f3..1a356c2996 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -20,6 +20,7 @@ pub use backend::{BackendType, Proof}; use executor::witgen::QueryCallback; use number::write_polys_file; use number::DegreeType; +use pil_analyzer::pil_analyzer::inline_intermediate_polynomials; pub use verify::{verify, verify_asm_string}; use ast::parsed::PILFile; @@ -209,40 +210,39 @@ fn compile>( analyzed: Analyzed, file_name: &OsStr, output_dir: &Path, - query_callback: Q, + _query_callback: Q, prove_with: Option, - external_witness_values: Vec<(&str, Vec)>, + _external_witness_values: Vec<(&str, Vec)>, ) -> CompilationResult { log::info!("Optimizing pil..."); // let analyzed = pilopt::optimize(analyzed); + + // md: we inline intermediate polynomials here, as honk does not have a notion of an intermediate + let mut mut_analyzed = analyzed; + mut_analyzed.identities = inline_intermediate_polynomials(&mut_analyzed); + let optimized_pil_file_name = output_dir.join(format!( "{}_opt.pil", Path::new(file_name).file_stem().unwrap().to_str().unwrap() )); - fs::write(optimized_pil_file_name.clone(), format!("{analyzed}")).unwrap(); + fs::write(optimized_pil_file_name.clone(), format!("{mut_analyzed}")).unwrap(); log::info!("Wrote {}.", optimized_pil_file_name.to_str().unwrap()); let start = Instant::now(); log::info!("Evaluating fixed columns..."); - let (constants, degree) = constant_evaluator::generate(&analyzed); + let (constants, degree) = constant_evaluator::generate(&mut_analyzed); log::info!("Took {}", start.elapsed().as_secs_f32()); - let witness = (analyzed.constant_count() == constants.len()).then(|| { - log::info!("Deducing witness columns..."); - let commits = - executor::witgen::WitnessGenerator::new(&analyzed, degree, &constants, query_callback) - .with_external_witness_values(external_witness_values) - .generate(); - - let witness = commits - .into_iter() - .map(|(name, c)| (name, c)) - .collect::>(); - - write_constants_to_fs(&constants, output_dir, degree); - write_commits_to_fs(&witness, output_dir, degree); + let witness_names = mut_analyzed + .committed_polys_in_source_order() + .into_iter() + .map(|(sym, _)| sym.absolute_name.clone()) + .collect::>(); - witness - }); + // NOTE: temporarily just append a vector to the end such that it is in the expected form for the backend + let witness_in_powdr_form: Vec<(&str, Vec)> = witness_names + .iter() + .map(|name| (name.as_str(), vec![])) + .collect(); // Even if we don't have all constants and witnesses, some backends will // still output the constraint serialization. @@ -250,16 +250,7 @@ fn compile>( let factory = backend.factory::(); let backend = factory.create(degree); - write_proving_results_to_fs( - false, - backend.prove( - &analyzed, - &constants, - witness.as_deref().unwrap_or_default(), - None, - ), - output_dir, - ); + backend.prove(&mut_analyzed, &constants, &witness_in_powdr_form, None); } let constants = constants @@ -267,13 +258,10 @@ fn compile>( .map(|(name, c)| (name.to_owned(), c)) .collect(); - let witness = witness.map(|v| { - v.into_iter() - .map(|(name, c)| (name.to_owned(), c)) - .collect() - }); - - CompilationResult { constants, witness } + CompilationResult { + constants, + witness: None, + } } pub fn write_proving_results_to_fs( From 9122869e1d4cc4a99f61dd550d281a69977e0d85 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:34:50 +0000 Subject: [PATCH 2/4] fix: do not generate trace builder .cpp --- bberg/src/circuit_builder.rs | 22 ++++++++++------------ bberg/src/lib.rs | 2 ++ bberg/src/trace_builder.rs | 10 +--------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/bberg/src/circuit_builder.rs b/bberg/src/circuit_builder.rs index 7102e4d49e..be436fb590 100644 --- a/bberg/src/circuit_builder.rs +++ b/bberg/src/circuit_builder.rs @@ -20,6 +20,7 @@ use pil_analyzer::pil_analyzer::inline_intermediate_polynomials; use crate::prover_builder::{prover_builder_cpp, prover_builder_hpp}; use crate::verifier_builder::{verifier_builder_cpp, verifier_builder_hpp}; +use crate::FILE_NAME; use crate::{ composer_builder::{composer_builder_cpp, composer_builder_hpp}, flavor_builder, @@ -32,7 +33,6 @@ pub struct BBFiles { pub flavor_hpp: Option, // trace pub trace_hpp: Option, - pub trace_cpp: Option, // composer pub composer_cpp: Option, pub composer_hpp: Option, @@ -85,7 +85,6 @@ impl BBFiles { arith_hpp: None, flavor_hpp: None, trace_hpp: None, - trace_cpp: None, composer_cpp: None, composer_hpp: None, prover_cpp: None, @@ -108,7 +107,6 @@ impl BBFiles { relation_hpp: String, arith_hpp: String, trace_hpp: String, - trace_cpp: String, flavor_hpp: String, composer_cpp: String, composer_hpp: String, @@ -124,7 +122,6 @@ impl BBFiles { self.composer_hpp = Some(composer_hpp); self.trace_hpp = Some(trace_hpp); - self.trace_cpp = Some(trace_cpp); self.verifier_cpp = Some(verifier_cpp); self.verifier_hpp = Some(verifier_hpp); @@ -149,7 +146,6 @@ impl BBFiles { // Trace write_file!(self.trace, "_trace.hpp", self.trace_hpp); - write_file!(self.trace, "_trace.cpp", self.trace_cpp); write_file!(self.flavor, "_flavor.hpp", self.flavor_hpp); @@ -183,7 +179,8 @@ pub(crate) fn analyzed_to_cpp( fixed: &[(&str, Vec)], witness: &[(&str, Vec)], ) -> BBFiles { - let file_name: &str = "Fib"; + let file_name: &str = FILE_NAME; + let mut bb_files = BBFiles::default(file_name.to_owned()); // Collect all column names and determine if they need a shift or not @@ -198,23 +195,27 @@ pub(crate) fn analyzed_to_cpp( .map(|(name, _)| (*name).to_owned()) .collect::>(); + println!("Fixed: {:?}", fixed_names); + println!("Witness: {:?}", witness_names); let first_col = fixed .iter() .find(|col_name| col_name.0.contains("FIRST")) .expect("PIL file must contain a fixed column named FIRST") - .0; + .0 + .replace(".", "_"); let last_col = fixed .iter() .find(|col_name| col_name.0.contains("LAST")) .expect("PIL file must contain a fixed column named LAST") - .0; + .0 + .replace(".", "_"); // Inlining step to remove the intermediate poly definitions let analyzed_identities = inline_intermediate_polynomials(analyzed); let (subrelations, identities, mut collected_shifts) = - create_identities(first_col, last_col, &analyzed_identities); + create_identities(&first_col, &last_col, &analyzed_identities); let shifted_polys: Vec = collected_shifts.drain().collect_vec(); dbg!(shifted_polys.clone()); @@ -237,8 +238,6 @@ pub(crate) fn analyzed_to_cpp( let arith_hpp = create_arith_boilerplate_file(file_name, num_cols); // ----------------------- Create the read from powdr columns file ----------------------- - let trace_cpp = - bb_files.create_trace_builder_cpp(file_name, &fixed_names, &witness_names, &to_be_shifted); let trace_hpp = bb_files.create_trace_builder_hpp(file_name, &all_cols, &to_be_shifted); // ----------------------- Create the flavor file ----------------------- @@ -266,7 +265,6 @@ pub(crate) fn analyzed_to_cpp( relation_hpp, arith_hpp, trace_hpp, - trace_cpp, flavor_hpp, composer_cpp, composer_hpp, diff --git a/bberg/src/lib.rs b/bberg/src/lib.rs index 28bf97567a..53b369f443 100644 --- a/bberg/src/lib.rs +++ b/bberg/src/lib.rs @@ -6,3 +6,5 @@ pub mod prover_builder; pub mod relation_builder; pub mod trace_builder; pub mod verifier_builder; + +const FILE_NAME: &str = "Fib"; diff --git a/bberg/src/trace_builder.rs b/bberg/src/trace_builder.rs index 32db2478e8..9c5f3551db 100644 --- a/bberg/src/trace_builder.rs +++ b/bberg/src/trace_builder.rs @@ -50,7 +50,6 @@ fn trace_hpp_includes(name: &str) -> String { #include \"barretenberg/proof_system/arithmetization/arithmetization.hpp\" #include \"barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp\" - #include \"./{name}_trace.cpp\" #include \"barretenberg/honk/flavor/generated/{name}_flavor.hpp\" #include \"barretenberg/proof_system/arithmetization/generated/{name}_arith.hpp\" #include \"barretenberg/proof_system/relations/generated/{name}.hpp\" @@ -174,11 +173,7 @@ class {name}TraceBuilder {{ static constexpr size_t num_polys = {num_polys}; std::vector rows; - - [[maybe_unused]] void build_circuit() {{ - rows = read_both_file_into_cols(\"../commits.bin\", \"../constants.bin\"); - }} - + [[maybe_unused]] void build_circuit(); AllPolynomials compute_polynomials() {{ const auto num_rows = get_circuit_subgroup_size(); @@ -199,9 +194,6 @@ class {name}TraceBuilder {{ }} [[maybe_unused]] bool check_circuit() {{ - // Get the rows from file - build_circuit(); - auto polys = compute_polynomials(); const size_t num_rows = polys[0].size(); From d2661ca27503180f2394dc027643a0cef41fb4d1 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:55:31 +0000 Subject: [PATCH 3/4] hack: allow specifying output name in pil cli --- backend/src/bberg_impl.rs | 4 +++- backend/src/lib.rs | 8 ++++++-- backend/src/pilstark/estark.rs | 1 + backend/src/pilstark/mod.rs | 1 + bberg/src/bberg_codegen.rs | 3 ++- bberg/src/circuit_builder.rs | 4 ++-- bberg/src/lib.rs | 2 -- compiler/src/lib.rs | 20 +++++++++++++++++++- compiler/src/verify.rs | 1 + powdr_cli/src/main.rs | 15 +++++++++++++-- 10 files changed, 48 insertions(+), 11 deletions(-) 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..9368d5e33e 100644 --- a/bberg/src/circuit_builder.rs +++ b/bberg/src/circuit_builder.rs @@ -20,7 +20,6 @@ use pil_analyzer::pil_analyzer::inline_intermediate_polynomials; use crate::prover_builder::{prover_builder_cpp, prover_builder_hpp}; use crate::verifier_builder::{verifier_builder_cpp, verifier_builder_hpp}; -use crate::FILE_NAME; use crate::{ composer_builder::{composer_builder_cpp, composer_builder_hpp}, flavor_builder, @@ -178,8 +177,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/bberg/src/lib.rs b/bberg/src/lib.rs index 53b369f443..28bf97567a 100644 --- a/bberg/src/lib.rs +++ b/bberg/src/lib.rs @@ -6,5 +6,3 @@ pub mod prover_builder; pub mod relation_builder; pub mod trace_builder; pub mod verifier_builder; - -const FILE_NAME: &str = "Fib"; diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 1a356c2996..10947a7db8 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, + bname, + ); } 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); From 7c7eae2e7999cb00a91c7ea588f72a6683a180a9 Mon Sep 17 00:00:00 2001 From: Maddiaa0 <47148561+Maddiaa0@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:58:21 +0000 Subject: [PATCH 4/4] merge fix --- compiler/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index e55d179ba6..4485d7b571 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -262,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