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: support bberg lookups #37

Merged
merged 8 commits into from
Jan 9, 2024
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
5 changes: 3 additions & 2 deletions asm_to_pil/src/vm_to_constrained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl<T: FieldElement> ASMPILConverter<T> {

self.pil.push(PilStatement::PlookupIdentity(
0,
None,
SelectedExpressions {
selector: None,
expressions: self
Expand Down Expand Up @@ -417,8 +418,8 @@ impl<T: FieldElement> ASMPILConverter<T> {
}
} else {
match &mut statement {
PilStatement::PermutationIdentity(_, _, left, _)
| PilStatement::PlookupIdentity(_, left, _) => {
PilStatement::PermutationIdentity(_, _attr, left, _)
| PilStatement::PlookupIdentity(_, _attr, left, _) => {
assert!(
left.selector.is_none(),
"LHS selector not supported, could and-combine with instruction flag later."
Expand Down
2 changes: 1 addition & 1 deletion ast/src/parsed/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ impl<T: Display> Display for PilStatement<T> {
write!(f, "{expression} = 0;")
}
}
PilStatement::PlookupIdentity(_, left, right) => write!(f, "{left} in {right};"),
PilStatement::PlookupIdentity(_, _, left, right) => write!(f, "{left} in {right};"),
PilStatement::PermutationIdentity(
_, //
_, //
Expand Down
1 change: 1 addition & 0 deletions ast/src/parsed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum PilStatement<T> {
PolynomialIdentity(usize, Option<String>, Expression<T>),
PlookupIdentity(
usize,
Option<String>,
SelectedExpressions<Expression<T>>,
SelectedExpressions<Expression<T>>,
),
Expand Down
4 changes: 2 additions & 2 deletions ast/src/parsed/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
{
match self {
PilStatement::Expression(_, e) => e.visit_expressions_mut(f, o),
PilStatement::PlookupIdentity(_, left, right)
PilStatement::PlookupIdentity(_, _, left, right)
| PilStatement::PermutationIdentity(
_, //
_, //
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<T> ExpressionVisitable<Expression<T, NamespacedPolynomialReference>> for Pi
{
match self {
PilStatement::Expression(_, e) => e.visit_expressions(f, o),
PilStatement::PlookupIdentity(_, left, right)
PilStatement::PlookupIdentity(_, _, left, right)
| PilStatement::PermutationIdentity(
_, //
_, //
Expand Down
40 changes: 20 additions & 20 deletions bberg/src/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fn circuit_hpp_includes(name: &str, relations: &[String], permutations: &[String
#include \"barretenberg/ecc/curves/bn254/fr.hpp\"
#include \"barretenberg/proof_system/circuit_builder/circuit_builder_base.hpp\"
#include \"barretenberg/relations/generic_permutation/generic_permutation_relation.hpp\"
#include \"barretenberg/relations/generic_lookup/generic_lookup_relation.hpp\"
#include \"barretenberg/honk/proof_system/logderivative_library.hpp\"

#include \"barretenberg/flavor/generated/{name}_flavor.hpp\"
Expand Down Expand Up @@ -86,12 +87,11 @@ impl CircuitBuilder for BBFiles {
relation_name = relation_name
)
};
let check_permutation_transformation = |permutation_name: &String| {
let check_lookup_transformation = |lookup_name: &String| {
format!(
"if (!evaluate_permutation.template operator()<honk::sumcheck::{permutation_name}_relation<FF>>(\"{permutation_name}\")) {{
"if (!evaluate_logderivative.template operator()<honk::sumcheck::{lookup_name}_relation<FF>>(\"{lookup_name}\")) {{
return false;
}}",
permutation_name = permutation_name
}}"
)
};

Expand All @@ -100,11 +100,11 @@ impl CircuitBuilder for BBFiles {
let all_poly_shifts = map_with_newline(to_be_shifted, all_polys_transformation);
let check_circuit_for_each_relation =
map_with_newline(relations, check_circuit_transformation);
let check_circuit_for_each_permutation =
map_with_newline(permutations, check_permutation_transformation);
let check_circuit_for_each_lookup =
map_with_newline(permutations, check_lookup_transformation);

let (params, permutation_check_closure) = if !permutations.is_empty() {
(get_params(), get_permutation_check_closure())
let (params, lookup_check_closure) = if !permutations.is_empty() {
(get_params(), get_lookup_check_closure())
} else {
("", "".to_owned())
};
Expand Down Expand Up @@ -166,11 +166,11 @@ class {name}CircuitBuilder {{

{relation_check_closure}

{permutation_check_closure}
{lookup_check_closure}

{check_circuit_for_each_relation}

{check_circuit_for_each_permutation}
{check_circuit_for_each_lookup}

return true;
}}
Expand Down Expand Up @@ -199,28 +199,28 @@ class {name}CircuitBuilder {{
}
}

fn get_permutation_check_closure() -> String {
fn get_lookup_check_closure() -> String {
"
const auto evaluate_permutation = [&]<typename PermutationSettings>(const std::string& permutation_name) {
const auto evaluate_logderivative = [&]<typename LogDerivativeSettings>(const std::string& lookup_name) {

// Check the tuple permutation relation
// Check the logderivative relation
proof_system::honk::logderivative_library::compute_logderivative_inverse<
Flavor,
PermutationSettings>(
LogDerivativeSettings>(
polys, params, num_rows);

typename PermutationSettings::SumcheckArrayOfValuesOverSubrelations
permutation_result;
typename LogDerivativeSettings::SumcheckArrayOfValuesOverSubrelations
lookup_result;

for (auto& r : permutation_result) {
for (auto& r : lookup_result) {
r = 0;
}
for (size_t i = 0; i < num_rows; ++i) {
PermutationSettings::accumulate(permutation_result, polys.get_row(i), params, 1);
LogDerivativeSettings::accumulate(lookup_result, polys.get_row(i), params, 1);
}
for (auto r : permutation_result) {
for (auto r : lookup_result) {
if (r != 0) {
info(\"Tuple \", permutation_name, \" failed.\");
info(\"Lookup \", lookup_name, \" failed.\");
return false;
}
}
Expand Down
1 change: 1 addition & 0 deletions bberg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod circuit_builder;
mod composer_builder;
mod file_writer;
mod flavor_builder;
pub mod lookup_builder;
pub mod permutation_builder;
mod prover_builder;
mod relation_builder;
Expand Down
Loading
Loading