Skip to content

Commit

Permalink
feat(avm): nullifier non exist (#6877)
Browse files Browse the repository at this point in the history
Please read [contributing guidelines](CONTRIBUTING.md) and remove this
line.

---------

Co-authored-by: dbanks12 <[email protected]>
Co-authored-by: David Banks <[email protected]>
  • Loading branch information
3 people authored Jun 5, 2024
1 parent 315c46e commit 05697f2
Show file tree
Hide file tree
Showing 18 changed files with 308 additions and 97 deletions.
15 changes: 10 additions & 5 deletions barretenberg/cpp/pil/avm/avm_kernel.pil
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ namespace avm_kernel(256);
// FIXED INDEXES
// Exists checks
pol START_NOTE_HASH_EXISTS_WRITE_OFFSET = 0;
pol START_NULLIFIER_EXISTS_OFFSET = 32; // START_NOTE_HASH_EXISTS_WRITE_OFFSET + MAX_NOTE_HASH_READ_REQUESTS_PER_CALL TODO: exists and non exists
pol START_NULLIFIER_EXISTS_OFFSET = 32; // START_NOTE_HASH_EXISTS_WRITE_OFFSET + MAX_NOTE_HASH_READ_REQUESTS_PER_CALL
pol START_NULLIFIER_NON_EXISTS_OFFSET = 64; // START_NULLIFIER_EXISTS_OFFSET + MAX_NULLIFIER_READ_REQUESTS_PER_CALL
pol START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = 96; // START_NULLIFIER_EXISTS_OFFET + (MAX_NULLIFIER_READ_REQUESTS_PER_CALL + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL)

// Public storage requests
pol START_SLOAD_WRITE_OFFSET = 112; // START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL
pol START_SSTORE_WRITE_OFFSET = 144; // START_SSTORE_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL
pol START_SSTORE_WRITE_OFFSET = 128; // START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL
pol START_SLOAD_WRITE_OFFSET = 144; // START_SSTORE_WRITE_OFFSET + MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL

// Emit data
pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 160; // START_SLOAD_WRITE_OFFSET + MAX_PUBLIC_DATA_READS_PER_CALL
pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 160; // START_SSTORE_WRITE_OFFSET + MAX_PUBLIC_DATA_READS_PER_CALL
pol START_EMIT_NULLIFIER_WRITE_OFFSET = 176; // START_EMIT_NOTE_HASH_WRITE_OFFSET + MAX_NEW_NOTE_HASHES_PER_CALL
pol START_EMIT_L2_TO_l1_MSG = 192; // START_EMIT_NULLIFIER_WRITE_OFFSET + MAX_NEW_NULLIFIERS_PER_CALL
pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 194; // START_EMIT_L2_TO_L1_MSG + MAX_NEW_L2_TO_L1_MSGS_PER_CALL
Expand All @@ -45,6 +46,7 @@ namespace avm_kernel(256);
// Current write offsets for each opcode
pol commit note_hash_exist_write_offset;
pol commit nullifier_exists_write_offset;
pol commit nullifier_non_exists_write_offset;
pol commit l1_to_l2_msg_exists_write_offset;

pol commit sload_write_offset;
Expand All @@ -63,8 +65,11 @@ namespace avm_kernel(256);
NOT_LAST * (note_hash_exist_write_offset' - (note_hash_exist_write_offset + avm_main.sel_op_note_hash_exists)) = 0;
#[EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK]
NOT_LAST * (emit_note_hash_write_offset' - (emit_note_hash_write_offset + avm_main.sel_op_emit_note_hash)) = 0;
// if avm_main.ib is set on op_nullifier_exists, then the nullifier_exists_write_offset will be incremented by 1, otherwise non_exists will be incremented
#[NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK]
NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + avm_main.sel_op_nullifier_exists)) = 0;
NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + (avm_main.sel_op_nullifier_exists * avm_main.ib))) = 0;
#[NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK]
NOT_LAST * (nullifier_non_exists_write_offset' - (nullifier_non_exists_write_offset + (avm_main.sel_op_nullifier_exists * (1 - avm_main.ib)))) = 0;
#[EMIT_NULLIFIER_INC_CONSISTENCY_CHECK]
NOT_LAST * (emit_nullifier_write_offset' - (emit_nullifier_write_offset + avm_main.sel_op_emit_nullifier)) = 0;
#[L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK]
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/pil/avm/avm_main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,9 @@ namespace avm_main(256);
first * avm_kernel.emit_note_hash_write_offset = 0;

#[NULLIFIER_EXISTS_KERNEL_OUTPUT]
sel_op_nullifier_exists * (avm_kernel.kernel_out_offset - (avm_kernel.START_NULLIFIER_EXISTS_OFFSET + avm_kernel.nullifier_exists_write_offset)) = 0;
sel_op_nullifier_exists * (avm_kernel.kernel_out_offset - ((ib * (avm_kernel.START_NULLIFIER_EXISTS_OFFSET + avm_kernel.nullifier_exists_write_offset)) + ((1 - ib) * (avm_kernel.START_NULLIFIER_NON_EXISTS_OFFSET + avm_kernel.nullifier_non_exists_write_offset)))) = 0;
first * avm_kernel.nullifier_exists_write_offset = 0;
first * avm_kernel.nullifier_non_exists_write_offset = 0;

#[EMIT_NULLIFIER_KERNEL_OUTPUT]
sel_op_emit_nullifier * (avm_kernel.kernel_out_offset - (avm_kernel.START_EMIT_NULLIFIER_WRITE_OFFSET + avm_kernel.emit_nullifier_write_offset)) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ template <typename FF> struct Avm_kernelRow {
FF avm_kernel_note_hash_exist_write_offset_shift{};
FF avm_kernel_nullifier_exists_write_offset{};
FF avm_kernel_nullifier_exists_write_offset_shift{};
FF avm_kernel_nullifier_non_exists_write_offset{};
FF avm_kernel_nullifier_non_exists_write_offset_shift{};
FF avm_kernel_sload_write_offset{};
FF avm_kernel_sload_write_offset_shift{};
FF avm_kernel_sstore_write_offset{};
FF avm_kernel_sstore_write_offset_shift{};
FF avm_main_ib{};
FF avm_main_last{};
FF avm_main_sel_op_emit_l2_to_l1_msg{};
FF avm_main_sel_op_emit_note_hash{};
Expand All @@ -50,21 +53,24 @@ inline std::string get_relation_label_avm_kernel(int index)
return "NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK";

case 3:
return "EMIT_NULLIFIER_INC_CONSISTENCY_CHECK";
return "NULLIFIER_NON_EXISTS_INC_CONSISTENCY_CHECK";

case 4:
return "L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK";
return "EMIT_NULLIFIER_INC_CONSISTENCY_CHECK";

case 5:
return "EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK";
return "L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK";

case 6:
return "EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK";
return "EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK";

case 7:
return "SLOAD_INC_CONSISTENCY_CHECK";
return "EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK";

case 8:
return "SLOAD_INC_CONSISTENCY_CHECK";

case 9:
return "SSTORE_INC_CONSISTENCY_CHECK";
}
return std::to_string(index);
Expand All @@ -74,8 +80,8 @@ template <typename FF_> class avm_kernelImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 9> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 3, 3, 3, 3, 3, 3, 3,
static constexpr std::array<size_t, 10> SUBRELATION_PARTIAL_LENGTHS{
3, 3, 4, 4, 3, 3, 3, 3, 3, 3,
};

template <typename ContainerOverSubrelations, typename AllEntities>
Expand Down Expand Up @@ -109,19 +115,20 @@ template <typename FF_> class avm_kernelImpl {
{
Avm_DECLARE_VIEWS(2);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_nullifier_exists_write_offset_shift -
(avm_kernel_nullifier_exists_write_offset + avm_main_sel_op_nullifier_exists)));
auto tmp =
((-avm_main_last + FF(1)) *
(avm_kernel_nullifier_exists_write_offset_shift -
(avm_kernel_nullifier_exists_write_offset + (avm_main_sel_op_nullifier_exists * avm_main_ib))));
tmp *= scaling_factor;
std::get<2>(evals) += tmp;
}
// Contribution 3
{
Avm_DECLARE_VIEWS(3);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_emit_nullifier_write_offset_shift -
(avm_kernel_emit_nullifier_write_offset + avm_main_sel_op_emit_nullifier)));
auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_nullifier_non_exists_write_offset_shift -
(avm_kernel_nullifier_non_exists_write_offset +
(avm_main_sel_op_nullifier_exists * (-avm_main_ib + FF(1))))));
tmp *= scaling_factor;
std::get<3>(evals) += tmp;
}
Expand All @@ -130,8 +137,8 @@ template <typename FF_> class avm_kernelImpl {
Avm_DECLARE_VIEWS(4);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_l1_to_l2_msg_exists_write_offset_shift -
(avm_kernel_l1_to_l2_msg_exists_write_offset + avm_main_sel_op_l1_to_l2_msg_exists)));
(avm_kernel_emit_nullifier_write_offset_shift -
(avm_kernel_emit_nullifier_write_offset + avm_main_sel_op_emit_nullifier)));
tmp *= scaling_factor;
std::get<4>(evals) += tmp;
}
Expand All @@ -140,8 +147,8 @@ template <typename FF_> class avm_kernelImpl {
Avm_DECLARE_VIEWS(5);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_emit_unencrypted_log_write_offset_shift -
(avm_kernel_emit_unencrypted_log_write_offset + avm_main_sel_op_emit_unencrypted_log)));
(avm_kernel_l1_to_l2_msg_exists_write_offset_shift -
(avm_kernel_l1_to_l2_msg_exists_write_offset + avm_main_sel_op_l1_to_l2_msg_exists)));
tmp *= scaling_factor;
std::get<5>(evals) += tmp;
}
Expand All @@ -150,28 +157,38 @@ template <typename FF_> class avm_kernelImpl {
Avm_DECLARE_VIEWS(6);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_emit_l2_to_l1_msg_write_offset_shift -
(avm_kernel_emit_l2_to_l1_msg_write_offset + avm_main_sel_op_emit_l2_to_l1_msg)));
(avm_kernel_emit_unencrypted_log_write_offset_shift -
(avm_kernel_emit_unencrypted_log_write_offset + avm_main_sel_op_emit_unencrypted_log)));
tmp *= scaling_factor;
std::get<6>(evals) += tmp;
}
// Contribution 7
{
Avm_DECLARE_VIEWS(7);

auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_sload_write_offset_shift -
(avm_kernel_sload_write_offset + avm_main_sel_op_sload)));
auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_emit_l2_to_l1_msg_write_offset_shift -
(avm_kernel_emit_l2_to_l1_msg_write_offset + avm_main_sel_op_emit_l2_to_l1_msg)));
tmp *= scaling_factor;
std::get<7>(evals) += tmp;
}
// Contribution 8
{
Avm_DECLARE_VIEWS(8);

auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_sload_write_offset_shift -
(avm_kernel_sload_write_offset + avm_main_sel_op_sload)));
tmp *= scaling_factor;
std::get<8>(evals) += tmp;
}
// Contribution 9
{
Avm_DECLARE_VIEWS(9);

auto tmp = ((-avm_main_last + FF(1)) * (avm_kernel_sstore_write_offset_shift -
(avm_kernel_sstore_write_offset + avm_main_sel_op_sstore)));
tmp *= scaling_factor;
std::get<8>(evals) += tmp;
std::get<9>(evals) += tmp;
}
}
};
Expand Down
Loading

0 comments on commit 05697f2

Please sign in to comment.