Skip to content
Merged
181 changes: 101 additions & 80 deletions barretenberg/cpp/pil/vm2/merkle_check.pil

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions barretenberg/cpp/src/barretenberg/vm2/generated/flavor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ class AvmFlavor {
static constexpr bool HasZK = false;

static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 47;
static constexpr size_t NUM_WITNESS_ENTITIES = 936;
static constexpr size_t NUM_SHIFTED_ENTITIES = 134;
static constexpr size_t NUM_WITNESS_ENTITIES = 942;
static constexpr size_t NUM_SHIFTED_ENTITIES = 135;
static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES;
// We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for
// the unshifted and one for the shifted
static constexpr size_t NUM_ALL_ENTITIES = 1117;
static constexpr size_t NUM_ALL_ENTITIES = 1124;

// In the sumcheck univariate computation, we divide the trace in chunks and each chunk is
// evenly processed by all the threads. This constant defines the maximum number of rows
Expand Down Expand Up @@ -175,7 +175,8 @@ class AvmFlavor {
lookup_instr_fetching_pc_abs_diff_positive_relation<FF_>,
lookup_instr_fetching_tag_value_validation_relation<FF_>,
lookup_instr_fetching_wire_instruction_info_relation<FF_>,
lookup_merkle_check_merkle_poseidon2_relation<FF_>,
lookup_merkle_check_merkle_poseidon2_read_relation<FF_>,
lookup_merkle_check_merkle_poseidon2_write_relation<FF_>,
lookup_poseidon2_hash_poseidon2_perm_relation<FF_>,
lookup_range_check_dyn_diff_is_u16_relation<FF_>,
lookup_range_check_dyn_rng_chk_pow_2_relation<FF_>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

namespace bb::avm2 {

/////////////////// lookup_merkle_check_merkle_poseidon2 ///////////////////
/////////////////// lookup_merkle_check_merkle_poseidon2_read ///////////////////

class lookup_merkle_check_merkle_poseidon2_settings {
class lookup_merkle_check_merkle_poseidon2_read_settings {
public:
static constexpr std::string_view NAME = "LOOKUP_MERKLE_CHECK_MERKLE_POSEIDON2";
static constexpr std::string_view NAME = "LOOKUP_MERKLE_CHECK_MERKLE_POSEIDON2_READ";
static constexpr std::string_view RELATION_NAME = "merkle_check";

static constexpr size_t READ_TERMS = 1;
Expand All @@ -29,14 +29,14 @@ class lookup_merkle_check_merkle_poseidon2_settings {
// Columns using the Column enum.
static constexpr Column SRC_SELECTOR = Column::merkle_check_sel;
static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end;
static constexpr Column COUNTS = Column::lookup_merkle_check_merkle_poseidon2_counts;
static constexpr Column INVERSES = Column::lookup_merkle_check_merkle_poseidon2_inv;
static constexpr Column COUNTS = Column::lookup_merkle_check_merkle_poseidon2_read_counts;
static constexpr Column INVERSES = Column::lookup_merkle_check_merkle_poseidon2_read_inv;
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
ColumnAndShifts::merkle_check_left_node,
ColumnAndShifts::merkle_check_right_node,
ColumnAndShifts::merkle_check_read_left_node,
ColumnAndShifts::merkle_check_read_right_node,
ColumnAndShifts::precomputed_zero,
ColumnAndShifts::merkle_check_constant_2,
ColumnAndShifts::merkle_check_output_hash
ColumnAndShifts::merkle_check_read_output_hash
};
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> DST_COLUMNS = {
ColumnAndShifts::poseidon2_hash_input_0,
Expand Down Expand Up @@ -72,15 +72,15 @@ class lookup_merkle_check_merkle_poseidon2_settings {

template <typename AllEntities> static inline auto get_entities(AllEntities&& in)
{
return std::forward_as_tuple(in._lookup_merkle_check_merkle_poseidon2_inv(),
in._lookup_merkle_check_merkle_poseidon2_counts(),
return std::forward_as_tuple(in._lookup_merkle_check_merkle_poseidon2_read_inv(),
in._lookup_merkle_check_merkle_poseidon2_read_counts(),
in._merkle_check_sel(),
in._poseidon2_hash_end(),
in._merkle_check_left_node(),
in._merkle_check_right_node(),
in._merkle_check_read_left_node(),
in._merkle_check_read_right_node(),
in._precomputed_zero(),
in._merkle_check_constant_2(),
in._merkle_check_output_hash(),
in._merkle_check_read_output_hash(),
in._poseidon2_hash_input_0(),
in._poseidon2_hash_input_1(),
in._poseidon2_hash_input_2(),
Expand All @@ -90,16 +90,120 @@ class lookup_merkle_check_merkle_poseidon2_settings {
};

template <typename FF_>
class lookup_merkle_check_merkle_poseidon2_relation
: public GenericLookupRelation<lookup_merkle_check_merkle_poseidon2_settings, FF_> {
class lookup_merkle_check_merkle_poseidon2_read_relation
: public GenericLookupRelation<lookup_merkle_check_merkle_poseidon2_read_settings, FF_> {
public:
using Settings = lookup_merkle_check_merkle_poseidon2_settings;
static constexpr std::string_view NAME = lookup_merkle_check_merkle_poseidon2_settings::NAME;
static constexpr std::string_view RELATION_NAME = lookup_merkle_check_merkle_poseidon2_settings::RELATION_NAME;
using Settings = lookup_merkle_check_merkle_poseidon2_read_settings;
static constexpr std::string_view NAME = lookup_merkle_check_merkle_poseidon2_read_settings::NAME;
static constexpr std::string_view RELATION_NAME = lookup_merkle_check_merkle_poseidon2_read_settings::RELATION_NAME;

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
return in.lookup_merkle_check_merkle_poseidon2_inv.is_zero();
return in.lookup_merkle_check_merkle_poseidon2_read_inv.is_zero();
}

static std::string get_subrelation_label(size_t index)
{
if (index == 0) {
return "INVERSES_ARE_CORRECT";
} else if (index == 1) {
return "ACCUMULATION_IS_CORRECT";
}
return std::to_string(index);
}
};

/////////////////// lookup_merkle_check_merkle_poseidon2_write ///////////////////

class lookup_merkle_check_merkle_poseidon2_write_settings {
public:
static constexpr std::string_view NAME = "LOOKUP_MERKLE_CHECK_MERKLE_POSEIDON2_WRITE";
static constexpr std::string_view RELATION_NAME = "merkle_check";

static constexpr size_t READ_TERMS = 1;
static constexpr size_t WRITE_TERMS = 1;
static constexpr size_t READ_TERM_TYPES[READ_TERMS] = { 0 };
static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = { 0 };
static constexpr size_t LOOKUP_TUPLE_SIZE = 5;
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = 4;
static constexpr size_t READ_TERM_DEGREE = 0;
static constexpr size_t WRITE_TERM_DEGREE = 0;

// Columns using the Column enum.
static constexpr Column SRC_SELECTOR = Column::merkle_check_write;
static constexpr Column DST_SELECTOR = Column::poseidon2_hash_end;
static constexpr Column COUNTS = Column::lookup_merkle_check_merkle_poseidon2_write_counts;
static constexpr Column INVERSES = Column::lookup_merkle_check_merkle_poseidon2_write_inv;
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
ColumnAndShifts::merkle_check_write_left_node,
ColumnAndShifts::merkle_check_write_right_node,
ColumnAndShifts::precomputed_zero,
ColumnAndShifts::merkle_check_constant_2,
ColumnAndShifts::merkle_check_write_output_hash
};
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> DST_COLUMNS = {
ColumnAndShifts::poseidon2_hash_input_0,
ColumnAndShifts::poseidon2_hash_input_1,
ColumnAndShifts::poseidon2_hash_input_2,
ColumnAndShifts::poseidon2_hash_input_len,
ColumnAndShifts::poseidon2_hash_output
};

template <typename AllEntities> static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in)
{
return (in._merkle_check_write() == 1 || in._poseidon2_hash_end() == 1);
}

template <typename Accumulator, typename AllEntities>
static inline auto compute_inverse_exists(const AllEntities& in)
{
using View = typename Accumulator::View;
const auto is_operation = View(in._merkle_check_write());
const auto is_table_entry = View(in._poseidon2_hash_end());
return (is_operation + is_table_entry - is_operation * is_table_entry);
}

template <typename AllEntities> static inline auto get_const_entities(const AllEntities& in)
{
return get_entities(in);
}

template <typename AllEntities> static inline auto get_nonconst_entities(AllEntities& in)
{
return get_entities(in);
}

template <typename AllEntities> static inline auto get_entities(AllEntities&& in)
{
return std::forward_as_tuple(in._lookup_merkle_check_merkle_poseidon2_write_inv(),
in._lookup_merkle_check_merkle_poseidon2_write_counts(),
in._merkle_check_write(),
in._poseidon2_hash_end(),
in._merkle_check_write_left_node(),
in._merkle_check_write_right_node(),
in._precomputed_zero(),
in._merkle_check_constant_2(),
in._merkle_check_write_output_hash(),
in._poseidon2_hash_input_0(),
in._poseidon2_hash_input_1(),
in._poseidon2_hash_input_2(),
in._poseidon2_hash_input_len(),
in._poseidon2_hash_output());
}
};

template <typename FF_>
class lookup_merkle_check_merkle_poseidon2_write_relation
: public GenericLookupRelation<lookup_merkle_check_merkle_poseidon2_write_settings, FF_> {
public:
using Settings = lookup_merkle_check_merkle_poseidon2_write_settings;
static constexpr std::string_view NAME = lookup_merkle_check_merkle_poseidon2_write_settings::NAME;
static constexpr std::string_view RELATION_NAME =
lookup_merkle_check_merkle_poseidon2_write_settings::RELATION_NAME;

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
return in.lookup_merkle_check_merkle_poseidon2_write_inv.is_zero();
}

static std::string get_subrelation_label(size_t index)
Expand Down
Loading