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
9 changes: 5 additions & 4 deletions barretenberg/cpp/pil/vm2/bitwise.pil
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace bitwise;
// 1 1 0 1 0x52 0x42 0x52 0x42

// Selector for Bitwise Operation
pol commit sel;
pol commit sel; // @boolean
sel * (1 - sel) = 0;

// No relations will be checked if this identity is satisfied.
Expand All @@ -54,9 +54,10 @@ pol commit start; // Identifies when we want to capture the output to the main t
start * (1 - start) = 0;

// This is used to decouple generation of inverses of lookups into this trace.
pol commit start_keccak;
pol commit start_sha256;
pol commit start_keccak; // @boolean
pol commit start_sha256; // @boolean
start_keccak * (1 - start_keccak) = 0;
start_sha256 * (1 - start_sha256) = 0;
// If any of the above selectors is 1, then start must be 1.
(start_keccak + start_sha256) * (1 - start) = 0;

Expand Down Expand Up @@ -169,7 +170,7 @@ last * (acc_ic - ic_byte) = 0;

// If we encounter an error, we do not want to perform a lookup to retrieve ctr.
// In the case of an error, ctr is unconstrained (ideally set to 0).
pol commit sel_get_ctr;
pol commit sel_get_ctr; // @boolean
sel_get_ctr = start * (1 - err);

#[INTEGRAL_TAG_LENGTH]
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/pil/vm2/ecc_mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ include "gt.pil";
namespace ecc_add_mem;

pol commit sel;
sel * (1 - sel) = 0;

#[skippable_if]
sel = 0;
Expand Down
13 changes: 7 additions & 6 deletions barretenberg/cpp/pil/vm2/poseidon2_mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ include "gt.pil";

namespace poseidon2_perm_mem;

pol commit sel;
pol commit sel; // @boolean
sel * (1 - sel) = 0;

#[skippable_if]
sel = 0;
Expand All @@ -49,8 +50,8 @@ namespace poseidon2_perm_mem;
////////////////////////////////////////////////
// Error Handling - Out of Range Memory Access
////////////////////////////////////////////////
pol commit sel_src_out_of_range_err; // Constrained to be boolean by the lookup into gt. (provided that sel == 1).
pol commit sel_dst_out_of_range_err; // Constrained to be boolean by the lookup into gt. (provided that sel == 1).
pol commit sel_src_out_of_range_err; // @boolean - Constrained to be boolean by the lookup into gt. (provided that sel == 1).
pol commit sel_dst_out_of_range_err; // @boolean - Constrained to be boolean by the lookup into gt. (provided that sel == 1).

// Use the comparison gadget to check that the max addresses are within range
// The comparison gadget provides the ability to test GreaterThan so we check
Expand All @@ -73,7 +74,7 @@ namespace poseidon2_perm_mem;
////////////////////////////////////////////////
pol commit input[4];
pol commit input_tag[4];
pol commit sel_should_read_mem;
pol commit sel_should_read_mem; // @boolean
sel_should_read_mem = sel * (1 - sel_src_out_of_range_err) * (1 - sel_dst_out_of_range_err);

#[POS_READ_MEM_0]
Expand Down Expand Up @@ -127,7 +128,7 @@ namespace poseidon2_perm_mem;
////////////////////////////////////////////////
// Error Handling - Invalid Input Tag (not FF)
////////////////////////////////////////////////
pol commit sel_invalid_tag_err;
pol commit sel_invalid_tag_err; // @boolean
sel_invalid_tag_err * (1 - sel_invalid_tag_err) = 0;
pol INPUT_TAG_DIFF_0 = input_tag[0] - constants.MEM_TAG_FF;
pol INPUT_TAG_DIFF_1 = input_tag[1] - constants.MEM_TAG_FF;
Expand All @@ -150,7 +151,7 @@ namespace poseidon2_perm_mem;
// Dispatch inputs to poseidon2 permutation trace and retrieve outputs
///////////////////////////////////////////////////////////////////////
pol commit output[4];
pol commit sel_should_exec;
pol commit sel_should_exec; // @boolean
sel_should_exec = sel * (1 - err);

// TODO: Rename a's and b's to use array notation in poseidon2_perm.pil
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/pil/vm2/to_radix_mem.pil
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ include "precomputed.pil";
namespace to_radix_mem;

pol commit sel;
sel * (1 - sel) = 0;

#[skippable_if]
sel = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST_F(AvmRecursionConstraintTest, GateCountAndVKCheck)
using ProverInstance = ProverInstance_<UltraRollupFlavor>;

static constexpr FF EXPECTED_OUTER_VK_HASH =
FF("0x11d8fada6d2189627887f5c560ed4903798a35d0df4687e097622a47f4484b81");
FF("0x195059523571dbadeae1b213250567e17b4994568b736b73a1aae2b0c65fd2cd");

AcirConstraint constraint;
WitnessVector witness;
Expand Down Expand Up @@ -165,7 +165,7 @@ class AvmRecursionInnerCircuitTests : public ::testing::Test {
using FF = Builder::FF;

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

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,8 +14,8 @@ template <typename FF_> class bitwiseImpl {
public:
using FF = FF_;

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

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

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_LAST_ON_ERROR = 8;
static constexpr size_t SR_RES_TAG_SHOULD_MATCH_INPUT = 9;
static constexpr size_t SR_INPUT_TAG_CANNOT_BE_FF = 10;
static constexpr size_t SR_INPUT_TAGS_SHOULD_MATCH = 11;
static constexpr size_t SR_BITW_OP_ID_REL = 12;
static constexpr size_t SR_BITW_CTR_DECREMENT = 13;
static constexpr size_t SR_BITW_SEL_CTR_NON_ZERO = 14;
static constexpr size_t SR_BITW_LAST_FOR_CTR_ONE = 15;
static constexpr size_t SR_BITW_INIT_A = 16;
static constexpr size_t SR_BITW_INIT_B = 17;
static constexpr size_t SR_BITW_INIT_C = 18;
static constexpr size_t SR_BITW_ACC_REL_A = 19;
static constexpr size_t SR_BITW_ACC_REL_B = 20;
static constexpr size_t SR_BITW_ACC_REL_C = 21;
static constexpr size_t SR_LAST_ON_ERROR = 9;
static constexpr size_t SR_RES_TAG_SHOULD_MATCH_INPUT = 10;
static constexpr size_t SR_INPUT_TAG_CANNOT_BE_FF = 11;
static constexpr size_t SR_INPUT_TAGS_SHOULD_MATCH = 12;
static constexpr size_t SR_BITW_OP_ID_REL = 13;
static constexpr size_t SR_BITW_CTR_DECREMENT = 14;
static constexpr size_t SR_BITW_SEL_CTR_NON_ZERO = 15;
static constexpr size_t SR_BITW_LAST_FOR_CTR_ONE = 16;
static constexpr size_t SR_BITW_INIT_A = 17;
static constexpr size_t SR_BITW_INIT_B = 18;
static constexpr size_t SR_BITW_INIT_C = 19;
static constexpr size_t SR_BITW_ACC_REL_A = 20;
static constexpr size_t SR_BITW_ACC_REL_B = 21;
static constexpr size_t SR_BITW_ACC_REL_C = 22;

static std::string get_subrelation_label(size_t index)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,143 +37,149 @@ void bitwiseImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
}
{
using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_start_sha256)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_start_sha256)));
std::get<3>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
auto tmp =
(static_cast<View>(in.get(C::bitwise_start_keccak)) + static_cast<View>(in.get(C::bitwise_start_sha256))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_start)));
std::get<3>(evals) += (tmp * scaling_factor);
std::get<4>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)));
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::bitwise_sel_tag_mismatch_err)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err)));
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::bitwise_err)) -
(FF(1) - (FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)))));
std::get<6>(evals) += (tmp * scaling_factor);
std::get<7>(evals) += (tmp * scaling_factor);
}
{
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::bitwise_last)) * (FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<7>(evals) += (tmp * scaling_factor);
std::get<8>(evals) += (tmp * scaling_factor);
}
{ // LAST_ON_ERROR
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::bitwise_err)) * (static_cast<View>(in.get(C::bitwise_last)) - FF(1));
std::get<8>(evals) += (tmp * scaling_factor);
std::get<9>(evals) += (tmp * scaling_factor);
}
{ // RES_TAG_SHOULD_MATCH_INPUT
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
auto tmp = (FF(1) - static_cast<View>(in.get(C::bitwise_err))) * static_cast<View>(in.get(C::bitwise_start)) *
(static_cast<View>(in.get(C::bitwise_tag_c)) - static_cast<View>(in.get(C::bitwise_tag_a)));
std::get<9>(evals) += (tmp * scaling_factor);
std::get<10>(evals) += (tmp * scaling_factor);
}
{ // INPUT_TAG_CANNOT_BE_FF
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::bitwise_start)) *
((CView(bitwise_TAG_A_DIFF) * (static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_tag_a_inv))) +
static_cast<View>(in.get(C::bitwise_tag_a_inv))) -
FF(1)) +
static_cast<View>(in.get(C::bitwise_sel_tag_ff_err)));
std::get<10>(evals) += (tmp * scaling_factor);
std::get<11>(evals) += (tmp * scaling_factor);
}
{ // INPUT_TAGS_SHOULD_MATCH
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::bitwise_start)) *
(CView(bitwise_TAG_AB_DIFF) * ((FF(1) - static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_tag_ab_diff_inv))) +
static_cast<View>(in.get(C::bitwise_tag_ab_diff_inv))) -
static_cast<View>(in.get(C::bitwise_sel_tag_mismatch_err)));
std::get<11>(evals) += (tmp * scaling_factor);
std::get<12>(evals) += (tmp * scaling_factor);
}
{ // BITW_OP_ID_REL
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::bitwise_op_id_shift)) - static_cast<View>(in.get(C::bitwise_op_id))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<12>(evals) += (tmp * scaling_factor);
std::get<13>(evals) += (tmp * scaling_factor);
}
{ // BITW_CTR_DECREMENT
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::bitwise_sel)) *
((static_cast<View>(in.get(C::bitwise_ctr_shift)) - static_cast<View>(in.get(C::bitwise_ctr))) + FF(1)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<13>(evals) += (tmp * scaling_factor);
std::get<14>(evals) += (tmp * scaling_factor);
}
{ // BITW_SEL_CTR_NON_ZERO
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::bitwise_ctr)) * ((FF(1) - static_cast<View>(in.get(C::bitwise_sel))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_ctr_inv))) +
static_cast<View>(in.get(C::bitwise_ctr_inv))) -
static_cast<View>(in.get(C::bitwise_sel)));
std::get<14>(evals) += (tmp * scaling_factor);
std::get<15>(evals) += (tmp * scaling_factor);
}
{ // BITW_LAST_FOR_CTR_ONE
using View = typename std::tuple_element_t<15, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_sel)) *
(((static_cast<View>(in.get(C::bitwise_ctr)) - FF(1)) *
(static_cast<View>(in.get(C::bitwise_last)) *
(FF(1) - static_cast<View>(in.get(C::bitwise_ctr_min_one_inv))) +
static_cast<View>(in.get(C::bitwise_ctr_min_one_inv))) +
static_cast<View>(in.get(C::bitwise_last))) -
FF(1));
std::get<15>(evals) += (tmp * scaling_factor);
std::get<16>(evals) += (tmp * scaling_factor);
}
{ // BITW_INIT_A
using View = typename std::tuple_element_t<16, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
(static_cast<View>(in.get(C::bitwise_acc_ia)) - static_cast<View>(in.get(C::bitwise_ia_byte)));
std::get<16>(evals) += (tmp * scaling_factor);
std::get<17>(evals) += (tmp * scaling_factor);
}
{ // BITW_INIT_B
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
(static_cast<View>(in.get(C::bitwise_acc_ib)) - static_cast<View>(in.get(C::bitwise_ib_byte)));
std::get<17>(evals) += (tmp * scaling_factor);
std::get<18>(evals) += (tmp * scaling_factor);
}
{ // BITW_INIT_C
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<19, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::bitwise_last)) *
(static_cast<View>(in.get(C::bitwise_acc_ic)) - static_cast<View>(in.get(C::bitwise_ic_byte)));
std::get<18>(evals) += (tmp * scaling_factor);
std::get<19>(evals) += (tmp * scaling_factor);
}
{ // BITW_ACC_REL_A
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::bitwise_acc_ia)) - static_cast<View>(in.get(C::bitwise_ia_byte))) -
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ia_shift))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<19>(evals) += (tmp * scaling_factor);
std::get<20>(evals) += (tmp * scaling_factor);
}
{ // BITW_ACC_REL_B
using View = typename std::tuple_element_t<20, ContainerOverSubrelations>::View;
using View = typename std::tuple_element_t<21, ContainerOverSubrelations>::View;
auto tmp = ((static_cast<View>(in.get(C::bitwise_acc_ib)) - static_cast<View>(in.get(C::bitwise_ib_byte))) -
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ib_shift))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<20>(evals) += (tmp * scaling_factor);
std::get<21>(evals) += (tmp * scaling_factor);
}
{ // BITW_ACC_REL_C
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::bitwise_acc_ic)) - static_cast<View>(in.get(C::bitwise_ic_byte))) -
FF(256) * static_cast<View>(in.get(C::bitwise_acc_ic_shift))) *
(FF(1) - static_cast<View>(in.get(C::bitwise_last)));
std::get<21>(evals) += (tmp * scaling_factor);
std::get<22>(evals) += (tmp * scaling_factor);
}
{
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::bitwise_sel_get_ctr)) -
static_cast<View>(in.get(C::bitwise_start)) * (FF(1) - static_cast<View>(in.get(C::bitwise_err))));
std::get<22>(evals) += (tmp * scaling_factor);
std::get<23>(evals) += (tmp * scaling_factor);
}
}

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

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

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

// Subrelation indices constants, to be used in tests.
static constexpr size_t SR_WRITE_INCR_DST_ADDR = 0;
static constexpr size_t SR_P_CURVE_EQN = 5;
static constexpr size_t SR_P_ON_CURVE_CHECK = 6;
static constexpr size_t SR_Q_CURVE_EQN = 7;
static constexpr size_t SR_Q_ON_CURVE_CHECK = 8;
static constexpr size_t SR_WRITE_INCR_DST_ADDR = 1;
static constexpr size_t SR_P_CURVE_EQN = 6;
static constexpr size_t SR_P_ON_CURVE_CHECK = 7;
static constexpr size_t SR_Q_CURVE_EQN = 8;
static constexpr size_t SR_Q_ON_CURVE_CHECK = 9;

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