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

fix(dsl): Assume block constraint is only using new witness #525

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 8 additions & 13 deletions cpp/src/barretenberg/dsl/acir_format/block_constraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
using namespace proof_system::plonk;

namespace acir_format {

// Returns a field_ct representing the poly_triple
// This function only works for constant or single witness poly_triple
// Supporting more general poly_triple for block constraints yield to complications when we have no witness assignment
// (e.g during verification or getting the circuit size)
field_ct poly_to_field_ct(const poly_triple poly, Builder& builder)
{
ASSERT(poly.q_m == 0);
Expand All @@ -14,6 +19,8 @@ field_ct poly_to_field_ct(const poly_triple poly, Builder& builder)
return field_ct(poly.q_c);
}
field_ct x = field_ct::from_witness_index(&builder, poly.a);
ASSERT(poly.q_c == 0);
ASSERT(poly.q_l == 1);
x.additive_constant = poly.q_c;
x.multiplicative_constant = poly.q_l;
return x;
Expand All @@ -37,26 +44,14 @@ void create_block_constraints(Builder& builder, const BlockConstraint constraint
// For a ROM table, constant read should be optimised out:
// The rom_table won't work with a constant read because the table may not be initialised
ASSERT(op.index.q_l != 0);
// We create a new witness w to avoid issues with non-valid witness assignements:
// if witness are not assigned, then w will be zero and table[w] will work
fr w_value = 0;
if (has_valid_witness_assignments) {
// If witness are assigned, we use the correct value for w
w_value = index.get_value();
}
field_ct w = field_ct::from_witness(&builder, w_value);
value.assert_equal(table[w]);
w.assert_equal(index);
value.assert_equal(table[index]);
}
} break;
case BlockType::RAM: {
ram_table_ct table(init);
for (auto& op : constraint.trace) {
field_ct value = poly_to_field_ct(op.value, builder);
field_ct index = poly_to_field_ct(op.index, builder);
if (has_valid_witness_assignments == false) {
index = field_ct(0);
}
if (op.access_type == 0) {
value.assert_equal(table.read(index));
} else {
Expand Down