Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: codegen for multiple public input columns #61

Merged
merged 14 commits into from
May 28, 2024
8 changes: 8 additions & 0 deletions bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ impl CircuitBuilder for BBFiles {
let serial_relations = map_with_newline(relations, execute_serial_transformation);
let serial_lookups = map_with_newline(permutations, execute_serial_transformation);

// With futures
Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
let emplace_future_relations = map_with_newline(relations, emplace_future_transformation);
let emplace_future_lookups = map_with_newline(permutations, emplace_future_transformation);

// With threads
let serial_relations = map_with_newline(relations, execute_serial_transformation);
let serial_lookups = map_with_newline(permutations, execute_serial_transformation);

let (params, lookup_check_closure) = if !permutations.is_empty() {
(get_params(), get_lookup_check_closure())
} else {
Expand Down
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>();

Maddiaa0 marked this conversation as resolved.
Show resolved Hide resolved
let evaluate_public_inputs = format!(
"

Expand Down Expand Up @@ -168,6 +176,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 @@ -203,7 +212,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
2 changes: 1 addition & 1 deletion parser/src/powdr.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ConstantDefinition: PilStatement<T> = {
}

PolynomialDefinition: PilStatement<T> = {
<@L> PolCol <Identifier> "=" <Expression> => PilStatement::PolynomialDefinition(<>)
<loc:@L> PolCol <id:Identifier> "=" <expr:Expression> => PilStatement::PolynomialDefinition(<>)
}


Expand Down
Loading