Skip to content
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
3 changes: 2 additions & 1 deletion barretenberg/cpp/pil/vm2/calldata.pil
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ namespace calldata;
#[skippable_if]
sel = 0;

pol commit sel;
pol commit sel; // @boolean
sel * (1 - sel) = 0;
pol commit value;
pol commit context_id;
// **NOTE** The index starts at one in this trace (see above comment for special case of empty calldata and index = 0):
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/pil/vm2/calldata_hashing.pil
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ namespace calldata_hashing;
#[skippable_if]
sel = 0;

pol commit sel;
pol commit sel; // @boolean
sel * (1 - sel) = 0;
// If sel = 0, sel' != 1
#[TRACE_CONTINUITY]
(1 - precomputed.first_row) * (1 - sel) * sel' = 0;
Expand Down
5 changes: 4 additions & 1 deletion barretenberg/cpp/pil/vm2/sha256_mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ namespace sha256;
////////////////////////////////////////////////
// Control flow
////////////////////////////////////////////////
pol commit start;
pol commit start; // @boolean (by definition)
// start * (1 - sel) = 0; means that start != 0 ==> sel == 1 or equivalently sel == 0 ==> start == 0
// And from #[START_AFTER_LAST], we have sel == 1 ==> start is boolean.
// Together, we have the guarantee that start is boolean.
start * (1 - sel) = 0;

// Selector to indicate end of this chunk of sha256
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class AvmRecursionInnerCircuitTests : public ::testing::Test {
using FF = Builder::FF;

static constexpr FF EXPECTED_INNER_VK_HASH =
FF("0x16e8f3172e5f14636bd7d73f695d734c326c31a78cb460d389e4555447cc69db");
FF("0x01caba77a068a59190885beaf6c30240dcd92b0515064b36dd4a3035b39154ea");

static void SetUpTestSuite() { bb::srs::init_file_crs_factory(bb::srs::bb_crs_path()); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template <typename FF_> class calldataImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 6> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 4, 4, 3, 4 };
static constexpr std::array<size_t, 7> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 4, 4, 3, 4 };

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
Expand All @@ -35,9 +35,9 @@ template <typename FF> class calldata : public Relation<calldataImpl<FF>> {
static constexpr const std::string_view NAME = "calldata";

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_SEL_TOGGLED_AT_LATCH = 1;
static constexpr size_t SR_TRACE_CONTINUITY = 3;
static constexpr size_t SR_CONTEXT_ID_CONTINUITY = 4;
static constexpr size_t SR_SEL_TOGGLED_AT_LATCH = 2;
static constexpr size_t SR_TRACE_CONTINUITY = 4;
static constexpr size_t SR_CONTEXT_ID_CONTINUITY = 5;

static std::string get_subrelation_label(size_t index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ template <typename FF_> class calldata_hashingImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 23> SUBRELATION_PARTIAL_LENGTHS = { 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 3,
3, 3, 3, 4, 4, 4, 4, 5, 3, 3, 4 };
static constexpr std::array<size_t, 24> SUBRELATION_PARTIAL_LENGTHS = { 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4,
3, 3, 3, 3, 4, 4, 4, 4, 5, 3, 3, 4 };

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
Expand All @@ -36,24 +36,24 @@ template <typename FF> class calldata_hashing : public Relation<calldata_hashing
static constexpr const std::string_view NAME = "calldata_hashing";

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_TRACE_CONTINUITY = 0;
static constexpr size_t SR_SEL_TOGGLED_AT_LATCH = 2;
static constexpr size_t SR_ID_CONSISTENCY = 3;
static constexpr size_t SR_SIZE_CONSISTENCY = 4;
static constexpr size_t SR_START_AFTER_LATCH = 7;
static constexpr size_t SR_START_INDEX_IS_ZERO = 8;
static constexpr size_t SR_START_IS_SEPARATOR = 9;
static constexpr size_t SR_INDEX_INCREMENTS = 10;
static constexpr size_t SR_INDEX_INCREMENTS_1 = 11;
static constexpr size_t SR_INDEX_INCREMENTS_2 = 12;
static constexpr size_t SR_PADDED_BY_ZERO_1 = 15;
static constexpr size_t SR_PADDED_BY_ZERO_2 = 16;
static constexpr size_t SR_PADDING_CONSISTENCY = 17;
static constexpr size_t SR_PADDING_END = 18;
static constexpr size_t SR_CHECK_FINAL_INDEX = 19;
static constexpr size_t SR_HASH_CONSISTENCY = 20;
static constexpr size_t SR_CALLDATA_HASH_INPUT_LENGTH_FIELDS = 21;
static constexpr size_t SR_ROUNDS_DECREMENT = 22;
static constexpr size_t SR_TRACE_CONTINUITY = 1;
static constexpr size_t SR_SEL_TOGGLED_AT_LATCH = 3;
static constexpr size_t SR_ID_CONSISTENCY = 4;
static constexpr size_t SR_SIZE_CONSISTENCY = 5;
static constexpr size_t SR_START_AFTER_LATCH = 8;
static constexpr size_t SR_START_INDEX_IS_ZERO = 9;
static constexpr size_t SR_START_IS_SEPARATOR = 10;
static constexpr size_t SR_INDEX_INCREMENTS = 11;
static constexpr size_t SR_INDEX_INCREMENTS_1 = 12;
static constexpr size_t SR_INDEX_INCREMENTS_2 = 13;
static constexpr size_t SR_PADDED_BY_ZERO_1 = 16;
static constexpr size_t SR_PADDED_BY_ZERO_2 = 17;
static constexpr size_t SR_PADDING_CONSISTENCY = 18;
static constexpr size_t SR_PADDING_END = 19;
static constexpr size_t SR_CHECK_FINAL_INDEX = 20;
static constexpr size_t SR_HASH_CONSISTENCY = 21;
static constexpr size_t SR_CALLDATA_HASH_INPUT_LENGTH_FIELDS = 22;
static constexpr size_t SR_ROUNDS_DECREMENT = 23;

static std::string get_subrelation_label(size_t index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,161 +22,167 @@ void calldata_hashingImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
const auto calldata_hashing_PADDING_2 =
in.get(C::calldata_hashing_sel) * (FF(1) - in.get(C::calldata_hashing_sel_not_padding_2));

{ // TRACE_CONTINUITY
{
using View = typename std::tuple_element_t<0, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_sel)));
std::get<0>(evals) += (tmp * scaling_factor);
}
{ // TRACE_CONTINUITY
using View = typename std::tuple_element_t<1, ContainerOverSubrelations>::View;
auto tmp = (FF(1) - static_cast<View>(in.get(C::precomputed_first_row))) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_sel))) *
static_cast<View>(in.get(C::calldata_hashing_sel_shift));
std::get<0>(evals) += (tmp * scaling_factor);
std::get<1>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<1, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<2, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_latch)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_latch)));
std::get<1>(evals) += (tmp * scaling_factor);
std::get<2>(evals) += (tmp * scaling_factor);
}
{ // SEL_TOGGLED_AT_LATCH
using View = typename std::tuple_element_t<2, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_latch)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_sel)));
std::get<2>(evals) += (tmp * scaling_factor);
std::get<3>(evals) += (tmp * scaling_factor);
}
{ // ID_CONSISTENCY
using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
auto tmp = (FF(1) - CView(calldata_hashing_LATCH_CONDITION)) *
(static_cast<View>(in.get(C::calldata_hashing_context_id_shift)) -
static_cast<View>(in.get(C::calldata_hashing_context_id)));
std::get<3>(evals) += (tmp * scaling_factor);
std::get<4>(evals) += (tmp * scaling_factor);
}
{ // SIZE_CONSISTENCY
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
auto tmp = (FF(1) - CView(calldata_hashing_LATCH_CONDITION)) *
(static_cast<View>(in.get(C::calldata_hashing_calldata_size_shift)) -
static_cast<View>(in.get(C::calldata_hashing_calldata_size)));
std::get<4>(evals) += (tmp * scaling_factor);
std::get<5>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_start)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_start)));
std::get<5>(evals) += (tmp * scaling_factor);
std::get<6>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
auto tmp = (static_cast<View>(in.get(C::calldata_hashing_sel_not_start)) -
static_cast<View>(in.get(C::calldata_hashing_sel)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_start))));
std::get<6>(evals) += (tmp * scaling_factor);
std::get<7>(evals) += (tmp * scaling_factor);
}
{ // START_AFTER_LATCH
using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
auto tmp =
static_cast<View>(in.get(C::calldata_hashing_sel_shift)) *
(static_cast<View>(in.get(C::calldata_hashing_start_shift)) - CView(calldata_hashing_LATCH_CONDITION));
std::get<7>(evals) += (tmp * scaling_factor);
std::get<8>(evals) += (tmp * scaling_factor);
}
{ // START_INDEX_IS_ZERO
using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_start)) *
static_cast<View>(in.get(C::calldata_hashing_index_0_));
std::get<8>(evals) += (tmp * scaling_factor);
std::get<9>(evals) += (tmp * scaling_factor);
}
{ // START_IS_SEPARATOR
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
auto tmp =
static_cast<View>(in.get(C::calldata_hashing_start)) *
(static_cast<View>(in.get(C::calldata_hashing_input_0_)) - CView(constants_DOM_SEP__PUBLIC_CALLDATA));
std::get<9>(evals) += (tmp * scaling_factor);
std::get<10>(evals) += (tmp * scaling_factor);
}
{ // INDEX_INCREMENTS
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<11, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
(FF(1) - CView(calldata_hashing_LATCH_CONDITION)) *
(static_cast<View>(in.get(C::calldata_hashing_index_0__shift)) -
(static_cast<View>(in.get(C::calldata_hashing_index_0_)) + FF(3)));
std::get<10>(evals) += (tmp * scaling_factor);
std::get<11>(evals) += (tmp * scaling_factor);
}
{ // INDEX_INCREMENTS_1
using View = typename std::tuple_element_t<11, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<12, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
(static_cast<View>(in.get(C::calldata_hashing_index_1_)) -
(static_cast<View>(in.get(C::calldata_hashing_index_0_)) + FF(1)));
std::get<11>(evals) += (tmp * scaling_factor);
std::get<12>(evals) += (tmp * scaling_factor);
}
{ // INDEX_INCREMENTS_2
using View = typename std::tuple_element_t<12, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<13, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
(static_cast<View>(in.get(C::calldata_hashing_index_2_)) -
(static_cast<View>(in.get(C::calldata_hashing_index_1_)) + FF(1)));
std::get<12>(evals) += (tmp * scaling_factor);
std::get<13>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<13, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<14, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_1)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_1)));
std::get<13>(evals) += (tmp * scaling_factor);
std::get<14>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<14, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_2)) *
(FF(1) - static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_2)));
std::get<14>(evals) += (tmp * scaling_factor);
std::get<15>(evals) += (tmp * scaling_factor);
}
{ // PADDED_BY_ZERO_1
using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
auto tmp = CView(calldata_hashing_PADDING_1) * static_cast<View>(in.get(C::calldata_hashing_input_1_));
std::get<15>(evals) += (tmp * scaling_factor);
std::get<16>(evals) += (tmp * scaling_factor);
}
{ // PADDED_BY_ZERO_2
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
auto tmp = CView(calldata_hashing_PADDING_2) * static_cast<View>(in.get(C::calldata_hashing_input_2_));
std::get<16>(evals) += (tmp * scaling_factor);
std::get<17>(evals) += (tmp * scaling_factor);
}
{ // PADDING_CONSISTENCY
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
auto tmp = CView(calldata_hashing_PADDING_1) * static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_2));
std::get<17>(evals) += (tmp * scaling_factor);
std::get<18>(evals) += (tmp * scaling_factor);
}
{ // PADDING_END
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
auto tmp = CView(calldata_hashing_PADDING_2) * (FF(1) - static_cast<View>(in.get(C::calldata_hashing_latch)));
std::get<18>(evals) += (tmp * scaling_factor);
std::get<19>(evals) += (tmp * scaling_factor);
}
{ // CHECK_FINAL_INDEX
using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_latch)) *
(static_cast<View>(in.get(C::calldata_hashing_calldata_size)) -
(CView(calldata_hashing_PADDING_1) * static_cast<View>(in.get(C::calldata_hashing_index_0_)) +
(CView(calldata_hashing_PADDING_2) - CView(calldata_hashing_PADDING_1)) *
static_cast<View>(in.get(C::calldata_hashing_index_1_)) +
static_cast<View>(in.get(C::calldata_hashing_sel_not_padding_2)) *
static_cast<View>(in.get(C::calldata_hashing_index_2_))));
std::get<19>(evals) += (tmp * scaling_factor);
std::get<20>(evals) += (tmp * scaling_factor);
}
{ // HASH_CONSISTENCY
using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
auto tmp = (FF(1) - CView(calldata_hashing_LATCH_CONDITION)) *
(static_cast<View>(in.get(C::calldata_hashing_output_hash_shift)) -
static_cast<View>(in.get(C::calldata_hashing_output_hash)));
std::get<20>(evals) += (tmp * scaling_factor);
std::get<21>(evals) += (tmp * scaling_factor);
}
{ // CALLDATA_HASH_INPUT_LENGTH_FIELDS
using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<22, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
(static_cast<View>(in.get(C::calldata_hashing_input_len)) -
(static_cast<View>(in.get(C::calldata_hashing_calldata_size)) + FF(1)));
std::get<21>(evals) += (tmp * scaling_factor);
std::get<22>(evals) += (tmp * scaling_factor);
}
{ // ROUNDS_DECREMENT
using View = typename std::tuple_element_t<22, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<23, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::calldata_hashing_sel)) *
((FF(1) - CView(calldata_hashing_LATCH_CONDITION)) *
((static_cast<View>(in.get(C::calldata_hashing_rounds_rem_shift)) -
static_cast<View>(in.get(C::calldata_hashing_rounds_rem))) +
FF(1)) +
static_cast<View>(in.get(C::calldata_hashing_latch)) *
(static_cast<View>(in.get(C::calldata_hashing_rounds_rem)) - FF(1)));
std::get<22>(evals) += (tmp * scaling_factor);
std::get<23>(evals) += (tmp * scaling_factor);
}
}

Expand Down
Loading
Loading