Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion backend/src/bberg_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ impl<T: FieldElement> BackendImpl<T> for BBergCodegen {
fixed: &[(&str, Vec<T>)],
witness: &[(&str, Vec<T>)],
_prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
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
Expand Down Expand Up @@ -55,6 +56,7 @@ impl<T: FieldElement> BackendImpl<T> for BBergMock {
_fixed: &[(&str, Vec<T>)],
_witness: &[(&str, Vec<T>)],
prev_proof: Option<Proof>,
_bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
if prev_proof.is_some() {
unimplemented!("BBergMock backend does not support aggregation");
Expand Down
8 changes: 6 additions & 2 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ impl<F: FieldElement, B: BackendImpl<F>> Backend<F> for ConcreteBackendWithoutSe
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
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> {
Expand Down Expand Up @@ -117,8 +118,9 @@ impl<F: FieldElement, B: BackendImplWithSetup<F>> Backend<F> for ConcreteBackend
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
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> {
Expand Down Expand Up @@ -155,6 +157,7 @@ pub trait Backend<F: FieldElement> {
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>);

/// Write the prover setup to a file, so that it can be loaded later.
Expand Down Expand Up @@ -184,6 +187,7 @@ trait BackendImpl<F: FieldElement> {
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
prev_proof: Option<Proof>,
bname: Option<String>,
) -> (Option<Proof>, Option<String>);
}

Expand Down
1 change: 1 addition & 0 deletions backend/src/pilstark/estark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<F: FieldElement> BackendImpl<F> for EStark {
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
prev_proof: Option<crate::Proof>,
_bname: Option<String>,
) -> (Option<crate::Proof>, Option<String>) {
if prev_proof.is_some() {
unimplemented!("aggregration is not implemented");
Expand Down
1 change: 1 addition & 0 deletions backend/src/pilstark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl<T: FieldElement> BackendImpl<T> for PilStarkCli {
_fixed: &[(&str, Vec<T>)],
_witness: &[(&str, Vec<T>)],
prev_proof: Option<Proof>,
_bname: Option<String>,
) -> (Option<Proof>, Option<String>) {
if prev_proof.is_some() {
unimplemented!("Aggregration is not implemented for pil-stark CLI backend");
Expand Down
3 changes: 2 additions & 1 deletion bberg/src/bberg_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ impl BBergCodegen {
pil: &Analyzed<F>,
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
bname: Option<String>,
) -> Vec<u8> {
let bberg_files = analyzed_to_cpp(pil, fixed, witness);
let bberg_files = analyzed_to_cpp(pil, fixed, witness, bname);
bberg_files.write();

Vec::new()
Expand Down
3 changes: 2 additions & 1 deletion bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ pub(crate) fn analyzed_to_cpp<F: FieldElement>(
analyzed: &Analyzed<F>,
fixed: &[(&str, Vec<F>)],
witness: &[(&str, Vec<F>)],
bname: Option<String>,
) -> 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());

Expand Down
20 changes: 19 additions & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn compile_pil_or_asm<T: FieldElement>(
force_overwrite: bool,
prove_with: Option<BackendType>,
external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> Result<Option<CompilationResult<T>>, Vec<String>> {
if file_name.ends_with(".asm") {
compile_asm(
Expand All @@ -50,6 +51,7 @@ pub fn compile_pil_or_asm<T: FieldElement>(
force_overwrite,
prove_with,
external_witness_values,
bname,
)
} else {
Ok(Some(compile_pil(
Expand All @@ -58,6 +60,7 @@ pub fn compile_pil_or_asm<T: FieldElement>(
inputs_to_query_callback(inputs),
prove_with,
external_witness_values,
bname,
)))
}
}
Expand All @@ -76,6 +79,7 @@ pub fn compile_pil<T: FieldElement, Q: QueryCallback<T>>(
query_callback: Q,
prove_with: Option<BackendType>,
external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> CompilationResult<T> {
compile(
pil_analyzer::analyze(pil_file),
Expand All @@ -84,6 +88,7 @@ pub fn compile_pil<T: FieldElement, Q: QueryCallback<T>>(
query_callback,
prove_with,
external_witness_values,
bname,
)
}

Expand All @@ -96,6 +101,7 @@ pub fn compile_pil_ast<T: FieldElement, Q: QueryCallback<T>>(
query_callback: Q,
prove_with: Option<BackendType>,
external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> CompilationResult<T> {
// TODO exporting this to string as a hack because the parser
// is tied into the analyzer due to imports.
Expand All @@ -106,6 +112,7 @@ pub fn compile_pil_ast<T: FieldElement, Q: QueryCallback<T>>(
query_callback,
prove_with,
external_witness_values,
bname,
)
}

Expand All @@ -119,6 +126,7 @@ pub fn compile_asm<T: FieldElement>(
force_overwrite: bool,
prove_with: Option<BackendType>,
external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> Result<Option<CompilationResult<T>>, Vec<String>> {
let contents = fs::read_to_string(file_name).unwrap();
Ok(compile_asm_string(
Expand All @@ -129,6 +137,7 @@ pub fn compile_asm<T: FieldElement>(
force_overwrite,
prove_with,
external_witness_values,
bname,
)?
.1)
}
Expand All @@ -145,6 +154,7 @@ pub fn compile_asm_string<T: FieldElement>(
force_overwrite: bool,
prove_with: Option<BackendType>,
external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> Result<(PathBuf, Option<CompilationResult<T>>), Vec<String>> {
let parsed = parser::parse_asm(Some(file_name), contents).unwrap_or_else(|err| {
eprintln!("Error parsing .asm file:");
Expand Down Expand Up @@ -193,6 +203,7 @@ pub fn compile_asm_string<T: FieldElement>(
inputs_to_query_callback(inputs),
prove_with,
external_witness_values,
bname,
)),
))
}
Expand All @@ -213,6 +224,7 @@ fn compile<T: FieldElement, Q: QueryCallback<T>>(
_query_callback: Q,
prove_with: Option<BackendType>,
_external_witness_values: Vec<(&str, Vec<T>)>,
bname: Option<String>,
) -> CompilationResult<T> {
log::info!("Optimizing pil...");
// let analyzed = pilopt::optimize(analyzed);
Expand Down Expand Up @@ -250,7 +262,13 @@ fn compile<T: FieldElement, Q: QueryCallback<T>>(
let factory = backend.factory::<T>();
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
Expand Down
1 change: 1 addition & 0 deletions compiler/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn verify_asm_string<T: FieldElement>(file_name: &str, contents: &str, input
true,
Some(BackendType::PilStarkCli),
vec![],
None,
)
.unwrap();
verify(&temp_dir);
Expand Down
15 changes: 13 additions & 2 deletions powdr_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
},
/// Compiles (no-std) rust code to riscv assembly, then to powdr assembly
/// and finally to PIL and generates fixed and witness columns.
Expand Down Expand Up @@ -377,6 +381,7 @@ fn run_command(command: Commands) {
prove_with,
export_csv,
csv_mode,
bname,
} => {
match call_with_field!(compile_with_csv_export::<field>(
file,
Expand All @@ -386,7 +391,8 @@ fn run_command(command: Commands) {
force,
prove_with,
export_csv,
csv_mode
csv_mode,
bname
)) {
Ok(()) => {}
Err(errors) => {
Expand Down Expand Up @@ -455,6 +461,7 @@ fn run_rust<F: FieldElement>(
force_overwrite,
prove_with,
vec![],
None,
)?;
Ok(())
}
Expand Down Expand Up @@ -485,6 +492,7 @@ fn run_riscv_asm<F: FieldElement>(
force_overwrite,
prove_with,
vec![],
None,
)?;
Ok(())
}
Expand All @@ -499,6 +507,7 @@ fn compile_with_csv_export<T: FieldElement>(
prove_with: Option<BackendType>,
export_csv: bool,
csv_mode: CsvRenderModeCLI,
bname: Option<String>,
) -> Result<(), Vec<String>> {
let external_witness_values = witness_values
.map(|csv_path| {
Expand All @@ -519,6 +528,7 @@ fn compile_with_csv_export<T: FieldElement>(
force,
prove_with,
external_witness_values,
bname,
)?;

if export_csv {
Expand Down Expand Up @@ -593,7 +603,7 @@ fn read_and_prove<T: FieldElement>(

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,
);
}
Expand Down Expand Up @@ -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);

Expand Down