Skip to content

Commit

Permalink
feat: codegen for multiple public input columns (#61)
Browse files Browse the repository at this point in the history
* feat: support public columns

* feat: codegen public input columns

* chore: cleanup

* fix: public input cols check

* fix: make rendering evaluate conditional

* temp

* opt: convert relation checks to futures

* fix: wasm compatible futures gen

* fix: remove single public input column limit

* feat: generate multiple public input column checks

* fmt

* fixes
  • Loading branch information
Maddiaa0 authored May 28, 2024
1 parent 46a6500 commit 9b10946
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
25 changes: 17 additions & 8 deletions bberg/src/verifier_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,29 @@ impl VerifierBuilder for BBFiles {
};

let verify_proof_function_declaration: String = if has_public_input_columns {
format!("bool {name}Verifier::verify_proof(const HonkProof& proof, const std::vector<FF>& public_inputs)")
format!("bool {name}Verifier::verify_proof(const HonkProof& proof, const std::vector<std::vector<FF>>& public_inputs)")
} else {
format!("bool {name}Verifier::verify_proof(const HonkProof& proof)")
};

let (public_inputs_check, evaluate_public_inputs) = if has_public_input_columns {
let public_inputs_column = public_cols[0].clone(); // asserted to be 1 for the meantime, this will be generalized when required
let inputs_check = format!(
let public_inputs_column_transformation = |public_inputs_column_name: &String, i: usize| {
format!(
"
FF public_column_evaluation = evaluate_public_input_column(public_inputs, circuit_size, multivariate_challenge);
if (public_column_evaluation != claimed_evaluations.{public_inputs_column}) {{
FF {public_inputs_column_name}_evaluation = evaluate_public_input_column(public_inputs[{i}], circuit_size, multivariate_challenge);
if ({public_inputs_column_name}_evaluation != claimed_evaluations.{public_inputs_column_name}) {{
return false;
}}
"
);
)
};

let (public_inputs_check, evaluate_public_inputs) = if has_public_input_columns {
let inputs_check = public_cols
.iter()
.enumerate()
.map(|(i, col_name)| public_inputs_column_transformation(col_name, i))
.collect::<String>();

let evaluate_public_inputs = format!(
"
Expand Down Expand Up @@ -172,6 +180,7 @@ impl VerifierBuilder for BBFiles {
return false;
}}
// Public columns evaluation checks
{public_inputs_check}
// Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the
Expand Down Expand Up @@ -207,7 +216,7 @@ impl VerifierBuilder for BBFiles {

// If there are public input columns, then the generated verifier must take them in as an argument for the verify_proof
let verify_proof = if !public_cols.is_empty() {
"bool verify_proof(const HonkProof& proof, const std::vector<FF>& public_inputs);"
"bool verify_proof(const HonkProof& proof, const std::vector<std::vector<FF>>& public_inputs);"
.to_string()
} else {
"bool verify_proof(const HonkProof& proof);".to_owned()
Expand Down
5 changes: 0 additions & 5 deletions bberg/src/vm_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ast::analyzed::Analyzed;

use itertools::Itertools;
use number::FieldElement;

use crate::circuit_builder::CircuitBuilder;
Expand Down Expand Up @@ -217,9 +216,5 @@ pub fn extract_public_input_columns(witness_columns: Vec<String>) -> (Vec<String
.filter(|name| name.ends_with("__is_public"))
.collect();

assert!(
public_input_column_names.len() <= 1,
"There should only be one public input column (for now)"
);
(witness_names, public_input_column_names)
}

0 comments on commit 9b10946

Please sign in to comment.