Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avm): kernel output opcodes #6416

Merged
merged 80 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8853132
avm_logderivative
Maddiaa0 Apr 3, 2024
abc3cba
temp: chall line up
Maddiaa0 Apr 4, 2024
8b88dcd
fix: degree too low for lookup relations
Maddiaa0 Apr 5, 2024
c8d9601
chore: rename validate trace proof to check circuit, make another met…
Maddiaa0 Apr 5, 2024
c695905
chore: remove dangling code
Maddiaa0 Apr 5, 2024
40eeb8f
Merge branch 'master' into md/04-03-avm_logderivative
Maddiaa0 Apr 5, 2024
619175b
chore: further cleanup
Maddiaa0 Apr 5, 2024
65c3159
chore: from powdr codegen
Maddiaa0 Apr 8, 2024
61d10f6
temp
Maddiaa0 Apr 11, 2024
7e84550
feat: bb support for public input columns
Maddiaa0 Apr 11, 2024
c054aca
Merge branch 'master' into md/04-11-feat_bb_support_for_public_input_…
Maddiaa0 Apr 11, 2024
f38773f
merge fixy
Maddiaa0 Apr 11, 2024
a4262dc
chore: test structure
Maddiaa0 Apr 11, 2024
cf4bb86
🧹
Maddiaa0 Apr 11, 2024
12a9789
use pilgen
Maddiaa0 Apr 12, 2024
14d15cc
Merge branch 'master' into md/04-11-feat_bb_support_for_public_input_…
Maddiaa0 Apr 12, 2024
b0f8041
feat: example caller and address opcode
Maddiaa0 Apr 12, 2024
d5813a2
feat: generalise builder, move after review
Maddiaa0 Apr 15, 2024
6265c61
Merge branch 'master' into md/04-12-feat_example_caller_and_address_o…
Maddiaa0 Apr 17, 2024
59b221c
fix: add tests for all call context opcodes
Maddiaa0 Apr 18, 2024
b613cf5
Merge branch 'master' into md/04-11-feat_bb_support_for_public_input_…
Maddiaa0 Apr 18, 2024
81a2500
Merge branch 'md/04-11-feat_bb_support_for_public_input_columns' into…
Maddiaa0 Apr 18, 2024
c934c61
chore: update pil comments
Maddiaa0 Apr 18, 2024
a8ceaf8
fix: remove redundant comment
Maddiaa0 Apr 18, 2024
af343db
fix: some negative tests
Maddiaa0 Apr 21, 2024
9388ecc
temp
Maddiaa0 Apr 29, 2024
9e7aad0
Merge branch 'master' into md/04-12-feat_example_caller_and_address_o…
Maddiaa0 May 7, 2024
859a3df
chore: remove l1 gas - no longer exists
Maddiaa0 May 7, 2024
b4a47b3
chore: rearrange where relations live, based on review
Maddiaa0 May 7, 2024
79cf849
Merge branch 'master' into md/04-11-feat_bb_support_for_public_input_…
Maddiaa0 May 7, 2024
faac5b1
chore: update codegen
Maddiaa0 May 7, 2024
7e70e7d
Merge branch 'md/04-11-feat_bb_support_for_public_input_columns' into…
Maddiaa0 May 7, 2024
4bb42b8
feat: add cpp constants gen to calculate kernel offsets
Maddiaa0 May 8, 2024
bccfd67
feat: add global variable opcodes
Maddiaa0 May 8, 2024
2a74110
fix: transaction fee selector test
Maddiaa0 May 8, 2024
1285ccf
fix: update tags to line up with kernel
Maddiaa0 May 8, 2024
60836ca
Merge branch 'master' into md/04-12-feat_example_caller_and_address_o…
Maddiaa0 May 8, 2024
e2bcca8
feat: parallelise check circuit relations
Maddiaa0 May 8, 2024
7bff191
fix: forge fmt after constant gen
Maddiaa0 May 8, 2024
115f17c
fix: no futures for wasm builds
Maddiaa0 May 8, 2024
de663f1
feat: fix segfaults in parallel circuit checking
Maddiaa0 May 9, 2024
c910000
fix: missed log
Maddiaa0 May 9, 2024
fd728c7
fix: incorrect kernel tests
Maddiaa0 May 9, 2024
66f958e
Merge branch 'master' into md/04-11-feat_bb_support_for_public_input_…
Maddiaa0 May 9, 2024
ecdf742
🧹
Maddiaa0 May 9, 2024
3f31357
Merge branch 'md/04-11-feat_bb_support_for_public_input_columns' into…
Maddiaa0 May 9, 2024
d6aeda8
feat: use codegen, vector public inputs - pubs now misaligned
Maddiaa0 May 9, 2024
ea48aca
fix: update codegen
Maddiaa0 May 9, 2024
e1e2cb8
fix: remove legacy codegen files
Maddiaa0 May 10, 2024
3be1242
Merge branch 'master' into md/04-12-feat_example_caller_and_address_o…
Maddiaa0 May 10, 2024
bee84aa
fix: relation tags + removal of function opcode
Maddiaa0 May 10, 2024
449f3da
fmt fix
Maddiaa0 May 10, 2024
a6470d7
kernel_outputs
Maddiaa0 May 10, 2024
94269ae
feat: codegen cols
Maddiaa0 May 10, 2024
3d6633b
feat: first implementation of emit note hash
Maddiaa0 May 14, 2024
25e31bd
feat: add emit nullfier, l2 to l1 msg, unencrypted log
Maddiaa0 May 14, 2024
963dbf6
fix: mixup of emit l2 to l1 msg, l1 to l2 exists
Maddiaa0 May 15, 2024
d465a04
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 15, 2024
c45c666
feat: sload and sstore
Maddiaa0 May 15, 2024
036910e
merge master
Maddiaa0 May 15, 2024
9774d95
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 15, 2024
c1c4f21
fix: alter exists opcodes to all use fields
Maddiaa0 May 16, 2024
c88d5ef
fix: different in and out tags for exists opcodes
Maddiaa0 May 16, 2024
c5847b2
feat: use pil generated public input columns
Maddiaa0 May 16, 2024
70a6e86
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 16, 2024
f8e8349
fix: dirty merge
Maddiaa0 May 16, 2024
289c302
fix: annotate todos
Maddiaa0 May 16, 2024
17640ef
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 16, 2024
7e120ad
fix: incorrect offset in emitNoteHash test
Maddiaa0 May 17, 2024
0dc2c58
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 17, 2024
6b2bfd6
fix: review
Maddiaa0 May 23, 2024
3e85832
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 23, 2024
1922ccb
fix: add more constants to constant gen
Maddiaa0 May 23, 2024
9dca2e2
fix: add call_ptrs
Maddiaa0 May 23, 2024
f9cf428
fmt
Maddiaa0 May 23, 2024
cb1f006
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 27, 2024
1bdb64f
fix: share public inputs construction in executor
Maddiaa0 May 27, 2024
17c216b
fix: typo
Maddiaa0 May 27, 2024
c714d7f
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 27, 2024
b95b838
Merge branch 'master' into md/05-10-kernel_outputs
Maddiaa0 May 28, 2024
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
64 changes: 64 additions & 0 deletions barretenberg/cpp/pil/avm/avm_kernel.pil
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,72 @@ include "constants.pil";

namespace avm_kernel(256);
pol public kernel_inputs;

pol public kernel_value_out;
pol public kernel_side_effect_out;
pol public kernel_metadata_out;

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6463): just use one col for both of these
pol commit kernel_sel;
pol commit kernel_out_sel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suffix "sel" makes us think it is a boolean. I think "offset" suffix might be better,


// Note: in the future, with some codegen adjustments, this column will not be needed
// as we can just add every entry in the public kernel_inputs to the lookup table
pol commit q_public_input_kernel_add_to_table;
pol commit q_public_input_kernel_out_add_to_table;

// Kernel Outputs
//
// The current implementation of kernel outputs is described within https://hackmd.io/zP1oMXF6Rf-L-ZZLXWmfHg

// Global side effect counter; incremented after each side effect is produced.
pol commit side_effect_counter;

// FIXED INDEXES
pol START_NOTE_HASH_EXISTS_WRITE_OFFSET = 0;
pol START_EMIT_NOTE_HASH_WRITE_OFFSET = 4;
pol START_NULLIFIER_EXISTS_OFFSET = 8;
pol START_EMIT_NULLIFIER_WRITE_OFFSET = 12;
pol START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET = 16;
pol START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET = 20;
pol START_EMIT_L2_TO_l1_MSG = 24;

pol START_SLOAD_WRITE_OFFSET = 28;
pol START_SSTORE_WRITE_OFFSET = 32;

// TODO(https://github.com/AztecProtocol/aztec-packages/issues/6465): Must constrain write_offset counters to be less than side effect MAX
// Current write offsets for each opcode
pol commit note_hash_exist_write_offset;
pol commit emit_note_hash_write_offset;
pol commit nullifier_exists_write_offset;
pol commit emit_nullifier_write_offset;
pol commit l1_to_l2_msg_exists_write_offset;
pol commit emit_unencrypted_log_write_offset;
pol commit emit_l2_to_l1_msg_write_offset;

pol commit sload_write_offset;
pol commit sstore_write_offset;

pol NOT_LAST = (1 - avm_main.last);

// Constraints to increase the offsets when the opcodes are found
#[NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK]
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;
#[NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK]
NOT_LAST * (nullifier_exists_write_offset' - (nullifier_exists_write_offset + avm_main.sel_op_nullifier_exists)) = 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]
NOT_LAST * (l1_to_l2_msg_exists_write_offset' - (l1_to_l2_msg_exists_write_offset + avm_main.sel_op_l1_to_l2_msg_exists)) = 0;
#[EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK]
NOT_LAST * (emit_unencrypted_log_write_offset' - (emit_unencrypted_log_write_offset + avm_main.sel_op_emit_unencrypted_log)) = 0;
#[EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK]
NOT_LAST * (emit_l2_to_l1_msg_write_offset' - (emit_l2_to_l1_msg_write_offset + avm_main.sel_op_emit_l2_to_l1_msg)) = 0;


#[SLOAD_INC_CONSISTENCY_CHECK]
NOT_LAST * (sload_write_offset' - (sload_write_offset + avm_main.sel_op_sload)) = 0;
#[SSTORE_INC_CONSISTENCY_CHECK]
NOT_LAST * (sstore_write_offset' - (sstore_write_offset + avm_main.sel_op_sstore)) = 0;
91 changes: 80 additions & 11 deletions barretenberg/cpp/pil/avm/avm_main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ include "avm_kernel.pil";
include "gadgets/avm_conversion.pil";

namespace avm_main(256);
//===== CONSTANT POLYNOMIALS ==================================================
pol constant clk(i) { i };
pol constant first = [1] + [0]*; // Used mostly to toggle off the first row consisting
// only in first element of shifted polynomials.

//===== KERNEL INPUTS =========================================================
// Kernel lookup selector opcodes
pol commit q_kernel_lookup;

Expand All @@ -26,14 +32,23 @@ namespace avm_main(256);
pol commit sel_op_coinbase;
pol commit sel_op_timestamp;

//===== KERNEL OUTPUTS ========================================================
pol commit q_kernel_output_lookup;

pol commit sel_op_note_hash_exists;
pol commit sel_op_emit_note_hash;
pol commit sel_op_nullifier_exists;
pol commit sel_op_emit_nullifier;
pol commit sel_op_l1_to_l2_msg_exists;
pol commit sel_op_emit_unencrypted_log;
pol commit sel_op_emit_l2_to_l1_msg;

pol commit sel_op_sload;
pol commit sel_op_sstore;

//===== Gadget Selectors ======================================================
pol commit sel_op_radix_le;

//===== CONSTANT POLYNOMIALS ==================================================
pol constant clk(i) { i };
pol constant first = [1] + [0]*; // Used mostly to toggle off the first row consisting
// only in first element of shifted polynomials.

//===== Fix Range Checks Selectors=============================================
// We re-use the clk column for the lookup values of 8-bit resp. 16-bit range check.
pol commit sel_rng_8; // Boolean selector for the 8-bit range check lookup
Expand Down Expand Up @@ -171,6 +186,17 @@ namespace avm_main(256);
sel_op_fee_per_da_gas * (1 - sel_op_fee_per_da_gas) = 0;
sel_op_transaction_fee * (1 - sel_op_transaction_fee) = 0;

sel_op_note_hash_exists * (1 - sel_op_note_hash_exists) = 0;
sel_op_emit_note_hash * (1 - sel_op_emit_note_hash) = 0;
sel_op_nullifier_exists * (1 - sel_op_nullifier_exists) = 0;
sel_op_emit_nullifier * (1 - sel_op_emit_nullifier) = 0;
sel_op_l1_to_l2_msg_exists * (1 - sel_op_l1_to_l2_msg_exists) = 0;
sel_op_emit_unencrypted_log * (1 - sel_op_emit_unencrypted_log) = 0;
sel_op_emit_l2_to_l1_msg * (1 - sel_op_emit_l2_to_l1_msg) = 0;

sel_op_sload * (1 - sel_op_sload) = 0;
sel_op_sstore * (1 - sel_op_sstore) = 0;

sel_op_radix_le * (1 - sel_op_radix_le) = 0;

sel_op_add * (1 - sel_op_add) = 0;
Expand Down Expand Up @@ -275,13 +301,20 @@ namespace avm_main(256);
// Drawback is the need to paralllelize the latter.

//===== KERNEL LOOKUPS =======================================================
pol KERNEL_SELECTORS = (
sel_op_sender + sel_op_address + sel_op_portal + sel_op_chain_id + sel_op_version + sel_op_block_number +
sel_op_coinbase + sel_op_timestamp + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas + sel_op_transaction_fee
pol KERNEL_INPUT_SELECTORS = (
sel_op_sender + sel_op_address + sel_op_portal + sel_op_chain_id + sel_op_version + sel_op_block_number + sel_op_coinbase +
sel_op_timestamp + sel_op_fee_per_l2_gas + sel_op_fee_per_da_gas + sel_op_transaction_fee
);
// Ensure that only one kernel lookup is active when the kernel_sel is active
#[KERNEL_ACTIVE_CHECK]
KERNEL_SELECTORS * (1 - q_kernel_lookup) = 0;
#[KERNEL_INPUT_ACTIVE_CHECK]
KERNEL_INPUT_SELECTORS * (1 - q_kernel_lookup) = 0;

pol KERNEL_OUTPUT_SELECTORS = (
sel_op_note_hash_exists + sel_op_emit_note_hash + sel_op_nullifier_exists + sel_op_emit_nullifier + sel_op_l1_to_l2_msg_exists +
sel_op_emit_unencrypted_log + sel_op_emit_l2_to_l1_msg + sel_op_sload + sel_op_sstore
);
#[KERNEL_OUTPUT_ACTIVE_CHECK]
KERNEL_OUTPUT_SELECTORS * (1 - q_kernel_output_lookup) = 0;

//===== CONTROL FLOW =======================================================
//===== JUMP ===============================================================
Expand Down Expand Up @@ -318,7 +351,7 @@ namespace avm_main(256);
//===== CONTROL_FLOW_CONSISTENCY ============================================
pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt);
pol OPCODE_SELECTORS = (sel_op_add + sel_op_sub + sel_op_div + sel_op_fdiv + sel_op_mul + sel_op_not
+ sel_op_eq + sel_op_and + sel_op_or + sel_op_xor + sel_op_cast + KERNEL_SELECTORS);
+ sel_op_eq + sel_op_and + sel_op_or + sel_op_xor + sel_op_cast + KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS);

// Program counter must increment if not jumping or returning
#[PC_INCREMENT]
Expand Down Expand Up @@ -419,6 +452,42 @@ namespace avm_main(256);
#[TIMESTAMP_KERNEL]
sel_op_timestamp * (avm_kernel.kernel_sel - constants.TIMESTAMP_SELECTOR) = 0;

// OUTPUTS LOOKUPS
// Constrain the value of kernel_out_sel to be the correct offset for the operation being performed
#[NOTE_HASH_KERNEL_OUTPUT]
sel_op_note_hash_exists * (avm_kernel.kernel_out_sel - (avm_kernel.START_NOTE_HASH_EXISTS_WRITE_OFFSET + avm_kernel.note_hash_exist_write_offset)) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avm_kernel.note_hash_exist_write_offset should be constrained to be initialized to zero. (maybe on first line?)

Same holds for all other offsets.


#[EMIT_NOTE_HASH_KERNEL_OUTPUT]
sel_op_emit_note_hash * (avm_kernel.kernel_out_sel - (avm_kernel.START_EMIT_NOTE_HASH_WRITE_OFFSET + avm_kernel.emit_note_hash_write_offset)) = 0;

#[NULLIFIER_EXISTS_KERNEL_OUTPUT]
sel_op_nullifier_exists * (avm_kernel.kernel_out_sel - (avm_kernel.START_NULLIFIER_EXISTS_OFFSET + avm_kernel.nullifier_exists_write_offset)) = 0;

#[EMIT_NULLIFIER_KERNEL_OUTPUT]
sel_op_emit_nullifier * (avm_kernel.kernel_out_sel - (avm_kernel.START_EMIT_NULLIFIER_WRITE_OFFSET + avm_kernel.emit_nullifier_write_offset)) = 0;

#[L1_TO_L2_MSG_EXISTS_KERNEL_OUTPUT]
sel_op_l1_to_l2_msg_exists * (avm_kernel.kernel_out_sel - (avm_kernel.START_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET + avm_kernel.l1_to_l2_msg_exists_write_offset)) = 0;

#[EMIT_UNENCRYPTED_LOG_KERNEL_OUTPUT]
sel_op_emit_unencrypted_log * (avm_kernel.kernel_out_sel - (avm_kernel.START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET + avm_kernel.emit_unencrypted_log_write_offset)) = 0;

#[EMIT_L2_TO_L1_MSGS_KERNEL_OUTPUT]
sel_op_emit_l2_to_l1_msg * (avm_kernel.kernel_out_sel - (avm_kernel.START_EMIT_L2_TO_l1_MSG + avm_kernel.emit_l2_to_l1_msg_write_offset)) = 0;

#[SLOAD_KERNEL_OUTPUT]
sel_op_sload * (avm_kernel.kernel_out_sel - (avm_kernel.START_SLOAD_WRITE_OFFSET + avm_kernel.sload_write_offset)) = 0;

#[SSTORE_KERNEL_OUTPUT]
sel_op_sstore * (avm_kernel.kernel_out_sel - (avm_kernel.START_SSTORE_WRITE_OFFSET + avm_kernel.sstore_write_offset)) = 0;

// When we encounter a state writing opcode
// We increment the side effect counter by 1
KERNEL_OUTPUT_SELECTORS * (avm_kernel.side_effect_counter' - (avm_kernel.side_effect_counter + 1)) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this crucial to start at zero? (Probably, otherwise a malicious prover might choose a huge value and then you get overflow/wraparound. Not sure about what the kernel is expecting.)

If yes, then we should have a constraint to enforce the initial value to be zero. (maybe sthg like: first * avm_kernel.side_effect_counter =0 )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side effect counter will be required to be constrained to the value of the start_side_effect_counter in the public inputs - this can be done with a copy constraint or via a lookup


#[KERNEL_OUTPUT_LOOKUP]
q_kernel_output_lookup {avm_kernel.kernel_out_sel, ia, avm_kernel.side_effect_counter, ib} in avm_kernel.q_public_input_kernel_out_add_to_table {clk, avm_kernel.kernel_value_out__is_public, avm_kernel.kernel_side_effect_out__is_public, avm_kernel.kernel_metadata_out__is_public};

#[LOOKUP_INTO_KERNEL]
// TODO: FIX not having the trailing is_public breaking compilation :(
q_kernel_lookup { avm_main.ia, avm_kernel.kernel_sel } in avm_kernel.q_public_input_kernel_add_to_table { avm_kernel.kernel_inputs__is_public, clk };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

namespace bb::Avm_vm {

template <typename FF> struct Avm_kernelRow {
FF avm_kernel_emit_l2_to_l1_msg_write_offset{};
FF avm_kernel_emit_l2_to_l1_msg_write_offset_shift{};
FF avm_kernel_emit_note_hash_write_offset{};
FF avm_kernel_emit_note_hash_write_offset_shift{};
FF avm_kernel_emit_nullifier_write_offset{};
FF avm_kernel_emit_nullifier_write_offset_shift{};
FF avm_kernel_emit_unencrypted_log_write_offset{};
FF avm_kernel_emit_unencrypted_log_write_offset_shift{};
FF avm_kernel_l1_to_l2_msg_exists_write_offset{};
FF avm_kernel_l1_to_l2_msg_exists_write_offset_shift{};
FF avm_kernel_note_hash_exist_write_offset{};
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_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_last{};
FF avm_main_sel_op_emit_l2_to_l1_msg{};
FF avm_main_sel_op_emit_note_hash{};
FF avm_main_sel_op_emit_nullifier{};
FF avm_main_sel_op_emit_unencrypted_log{};
FF avm_main_sel_op_l1_to_l2_msg_exists{};
FF avm_main_sel_op_note_hash_exists{};
FF avm_main_sel_op_nullifier_exists{};
FF avm_main_sel_op_sload{};
FF avm_main_sel_op_sstore{};
};

inline std::string get_relation_label_avm_kernel(int index)
{
switch (index) {
case 0:
return "NOTE_HASH_EXISTS_INC_CONSISTENCY_CHECK";

case 1:
return "EMIT_NOTE_HASH_INC_CONSISTENCY_CHECK";

case 2:
return "NULLIFIER_EXISTS_INC_CONSISTENCY_CHECK";

case 3:
return "EMIT_NULLIFIER_INC_CONSISTENCY_CHECK";

case 4:
return "L1_TO_L2_MSG_EXISTS_INC_CONSISTENCY_CHECK";

case 5:
return "EMIT_UNENCRYPTED_LOG_INC_CONSISTENCY_CHECK";

case 6:
return "EMIT_L2_TO_L1_MSG_INC_CONSISTENCY_CHECK";

case 7:
return "SLOAD_INC_CONSISTENCY_CHECK";

case 8:
return "SSTORE_INC_CONSISTENCY_CHECK";
}
return std::to_string(index);
}

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,
};

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_note_hash_exist_write_offset_shift -
(avm_kernel_note_hash_exist_write_offset + avm_main_sel_op_note_hash_exists)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
}
// Contribution 1
{
Avm_DECLARE_VIEWS(1);

auto tmp = ((-avm_main_last + FF(1)) *
(avm_kernel_emit_note_hash_write_offset_shift -
(avm_kernel_emit_note_hash_write_offset + avm_main_sel_op_emit_note_hash)));
tmp *= scaling_factor;
std::get<1>(evals) += tmp;
}
// Contribution 2
{
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)));
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)));
tmp *= scaling_factor;
std::get<3>(evals) += tmp;
}
// Contribution 4
{
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)));
tmp *= scaling_factor;
std::get<4>(evals) += tmp;
}
// Contribution 5
{
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)));
tmp *= scaling_factor;
std::get<5>(evals) += tmp;
}
// Contribution 6
{
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)));
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)));
tmp *= scaling_factor;
std::get<7>(evals) += tmp;
}
// Contribution 8
{
Avm_DECLARE_VIEWS(8);

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;
}
}
};

template <typename FF> using avm_kernel = Relation<avm_kernelImpl<FF>>;

} // namespace bb::Avm_vm
Loading
Loading