Skip to content

Commit

Permalink
assume block constraint is only using new witness (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic authored Jun 13, 2023
1 parent f7aa13a commit 65e651d
Showing 1 changed file with 8 additions and 13 deletions.
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, Composer& composer)
{
ASSERT(poly.q_m == 0);
Expand All @@ -14,6 +19,8 @@ field_ct poly_to_field_ct(const poly_triple poly, Composer& composer)
return field_ct(poly.q_c);
}
field_ct x = field_ct::from_witness_index(&composer, 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(Composer& composer, const BlockConstraint constrai
// 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(&composer, 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, composer);
field_ct index = poly_to_field_ct(op.index, composer);
if (has_valid_witness_assignments == false) {
index = field_ct(0);
}
if (op.access_type == 0) {
value.assert_equal(table.read(index));
} else {
Expand Down

0 comments on commit 65e651d

Please sign in to comment.