Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
206 commits
Select commit Hold shift + click to select a range
941476d
[empty] Start merge-train. Choo choo.
ludamad Jul 1, 2025
4058f84
Merge branch 'next' into merge-train/avm [skip ci]
Jul 1, 2025
516db36
Merge branch 'next' into merge-train/avm [skip ci]
Jul 1, 2025
c5a4475
Merge branch 'next' into merge-train/avm [skip ci]
Jul 1, 2025
3873b54
Merge branch 'next' into merge-train/avm [skip ci]
Jul 1, 2025
1e73b50
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
fe9c753
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
947ccb6
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
d496fb0
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
493ca69
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
7e839e6
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
8d417b8
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
0a164af
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
f250c84
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
7680f65
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
995194a
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
c1b16d6
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
fa05651
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
6bcf444
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
541df85
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
d382a45
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
534b507
Merge branch 'next' into merge-train/avm [skip ci]
Jul 2, 2025
ab063b3
Merge branch 'next' into merge-train/avm
Jul 2, 2025
bbfb8aa
Merge branch 'next' into merge-train/avm
Jul 2, 2025
cdf15ab
Merge branch 'next' into merge-train/avm
Jul 2, 2025
0e0b744
Merge branch 'next' into merge-train/avm
Jul 2, 2025
dc338fb
Merge branch 'next' into merge-train/avm
Jul 2, 2025
cea4bb3
Merge branch 'next' into merge-train/avm
Jul 2, 2025
2f56079
Merge branch 'next' into merge-train/avm
Jul 2, 2025
f93f9b5
Merge branch 'next' into merge-train/avm
Jul 2, 2025
f179d16
Merge branch 'next' into merge-train/avm
Jul 2, 2025
65ebe5e
Merge branch 'next' into merge-train/avm
Jul 2, 2025
5ed2929
Merge branch 'next' into merge-train/avm
Jul 3, 2025
4b9295a
Merge branch 'next' into merge-train/avm
Jul 3, 2025
fd7009b
Merge branch 'next' into merge-train/avm
Jul 3, 2025
b955460
Merge branch 'next' into merge-train/avm
Jul 3, 2025
785de6b
Merge branch 'next' into merge-train/avm
Jul 3, 2025
a0521e4
Merge branch 'next' into merge-train/avm
Jul 3, 2025
9a74076
Merge branch 'next' into merge-train/avm
Jul 3, 2025
dd7e8de
Merge branch 'next' into merge-train/avm
Jul 3, 2025
426abbf
Merge branch 'next' into merge-train/avm
Jul 3, 2025
4c99994
Merge branch 'next' into merge-train/avm
Jul 3, 2025
4fdcd66
Merge branch 'next' into merge-train/avm
Jul 3, 2025
7c25eb6
Merge branch 'next' into merge-train/avm
Jul 3, 2025
4d36c44
Merge branch 'next' into merge-train/avm
Jul 4, 2025
6bd1944
Merge branch 'next' into merge-train/avm
Jul 4, 2025
da20fe4
Merge branch 'next' into merge-train/avm
Jul 4, 2025
e0819a1
Merge branch 'next' into merge-train/avm
Jul 4, 2025
d3c5544
Merge branch 'next' into merge-train/avm
Jul 4, 2025
31106eb
Merge branch 'next' into merge-train/avm
Jul 4, 2025
968f635
Merge branch 'next' into merge-train/avm
Jul 4, 2025
b99caa8
Merge branch 'next' into merge-train/avm
Jul 4, 2025
3a4faa4
Merge branch 'next' into merge-train/avm
Jul 4, 2025
c3a55f0
Merge branch 'next' into merge-train/avm
Jul 5, 2025
ff0b193
Merge branch 'next' into merge-train/avm
Jul 5, 2025
59cf8bb
Merge branch 'next' into merge-train/avm
Jul 5, 2025
837d7d7
Merge branch 'next' into merge-train/avm
Jul 7, 2025
204d752
Merge branch 'next' into merge-train/avm
Jul 7, 2025
c7a4e15
Merge branch 'next' into merge-train/avm
Jul 7, 2025
a7c2831
Merge branch 'next' into merge-train/avm
Jul 7, 2025
4271f6c
Merge branch 'next' into merge-train/avm
Jul 7, 2025
f475065
Merge branch 'next' into merge-train/avm
Jul 7, 2025
d263125
Merge branch 'next' into merge-train/avm
Jul 7, 2025
2891657
Merge branch 'next' into merge-train/avm
Jul 7, 2025
8abf7af
Merge branch 'next' into merge-train/avm
Jul 7, 2025
2711c7d
Merge branch 'next' into merge-train/avm
Jul 7, 2025
16bc9ce
Merge branch 'next' into merge-train/avm
Jul 8, 2025
320fdc0
Merge branch 'next' into merge-train/avm
Jul 8, 2025
4977747
Merge branch 'next' into merge-train/avm
Jul 8, 2025
aa6f874
Merge branch 'next' into merge-train/avm
Jul 8, 2025
c69ad24
Merge branch 'next' into merge-train/avm
Jul 8, 2025
99130a7
Merge branch 'next' into merge-train/avm
Jul 8, 2025
d77ca08
Merge branch 'next' into merge-train/avm
Jul 8, 2025
4426ed3
Merge branch 'next' into merge-train/avm
Jul 8, 2025
18574bb
Merge branch 'next' into merge-train/avm
Jul 8, 2025
6502cac
Merge branch 'next' into merge-train/avm
Jul 8, 2025
f3cbab3
Merge branch 'next' into merge-train/avm
Jul 8, 2025
95f07cd
Merge branch 'next' into merge-train/avm
Jul 8, 2025
911b10c
Merge branch 'next' into merge-train/avm
Jul 8, 2025
28a41bb
Merge branch 'next' into merge-train/avm
Jul 8, 2025
50c5a78
Merge branch 'next' into merge-train/avm
Jul 8, 2025
f620dbe
Merge branch 'next' into merge-train/avm
Jul 8, 2025
83d7da0
Merge branch 'next' into merge-train/avm
Jul 9, 2025
e926d7f
Merge branch 'next' into merge-train/avm
Jul 9, 2025
91fa56c
Merge branch 'next' into merge-train/avm
Jul 9, 2025
bea6837
Merge branch 'next' into merge-train/avm
Jul 9, 2025
323c8ba
Merge branch 'next' into merge-train/avm
Jul 9, 2025
f7ddd3b
Merge branch 'next' into merge-train/avm
Jul 9, 2025
506adb5
Merge branch 'next' into merge-train/avm
Jul 9, 2025
ab0e900
Merge branch 'next' into merge-train/avm
Jul 9, 2025
f03f227
Merge branch 'next' into merge-train/avm
Jul 9, 2025
6bf8eaf
Merge branch 'next' into merge-train/avm
Jul 9, 2025
446b0b1
Merge branch 'next' into merge-train/avm
Jul 9, 2025
d61209c
Merge branch 'next' into merge-train/avm
Jul 10, 2025
77ec5d7
Merge branch 'next' into merge-train/avm
Jul 10, 2025
5d87f47
Merge branch 'next' into merge-train/avm
Jul 10, 2025
761c00e
Merge branch 'next' into merge-train/avm
Jul 10, 2025
35540d1
Merge branch 'next' into merge-train/avm
Jul 10, 2025
742c3c9
Merge branch 'next' into merge-train/avm
Jul 10, 2025
d9f8a71
Merge branch 'next' into merge-train/avm
Jul 10, 2025
b5bafef
Merge branch 'next' into merge-train/avm
Jul 10, 2025
c2ab19a
Merge branch 'next' into merge-train/avm
Jul 10, 2025
dff5634
Merge branch 'next' into merge-train/avm
Jul 10, 2025
834d547
Merge branch 'next' into merge-train/avm
Jul 11, 2025
ac0d1d3
Merge branch 'next' into merge-train/avm
Jul 11, 2025
59b97b7
Merge branch 'next' into merge-train/avm
Jul 11, 2025
cb66a49
Merge branch 'next' into merge-train/avm
Jul 11, 2025
b3ea2be
Merge branch 'next' into merge-train/avm
Jul 11, 2025
e615970
Merge branch 'next' into merge-train/avm
Jul 11, 2025
f53e12c
Merge branch 'next' into merge-train/avm
Jul 14, 2025
748865c
Merge branch 'next' into merge-train/avm
Jul 14, 2025
e12c0d9
Merge branch 'next' into merge-train/avm
Jul 14, 2025
e5f9043
Merge branch 'next' into merge-train/avm
Jul 14, 2025
9a9c5dd
Merge branch 'next' into merge-train/avm
Jul 14, 2025
7b692ff
Merge branch 'next' into merge-train/avm
Jul 14, 2025
69520fe
Merge branch 'next' into merge-train/avm
Jul 14, 2025
c8c8018
Merge branch 'next' into merge-train/avm
Jul 14, 2025
f1d66c5
Merge branch 'next' into merge-train/avm
Jul 14, 2025
4e29266
Merge branch 'next' into merge-train/avm
Jul 14, 2025
89b8c29
Merge branch 'next' into merge-train/avm
Jul 14, 2025
1eff017
Merge branch 'next' into merge-train/avm
Jul 14, 2025
86a134e
Merge branch 'next' into merge-train/avm
Jul 14, 2025
7b181af
Merge branch 'next' into merge-train/avm
Jul 14, 2025
cc99c3a
Merge branch 'next' into merge-train/avm
Jul 14, 2025
a8bfae0
Merge branch 'next' into merge-train/avm
Jul 14, 2025
3a4a587
Merge branch 'next' into merge-train/avm
Jul 14, 2025
fd9a20f
Merge branch 'next' into merge-train/avm
Jul 14, 2025
d01b4b9
Merge branch 'next' into merge-train/avm
Jul 14, 2025
dd4b598
Merge branch 'next' into merge-train/avm
Jul 15, 2025
501cddd
Merge branch 'next' into merge-train/avm
Jul 15, 2025
ca3a19d
Merge branch 'next' into merge-train/avm
Jul 15, 2025
cc176f4
Merge branch 'next' into merge-train/avm
Jul 15, 2025
1f69c31
Merge branch 'next' into merge-train/avm
Jul 15, 2025
efa0c1b
Merge branch 'next' into merge-train/avm
Jul 15, 2025
7e39321
Merge branch 'next' into merge-train/avm
Jul 15, 2025
8271f0c
Merge branch 'next' into merge-train/avm
Jul 15, 2025
e359a2a
Merge branch 'next' into merge-train/avm
Jul 15, 2025
05db1cb
Merge branch 'next' into merge-train/avm
Jul 15, 2025
0afd12e
Merge branch 'next' into merge-train/avm
Jul 15, 2025
00d8a95
Merge branch 'next' into merge-train/avm
Jul 15, 2025
9c6c38a
Merge branch 'next' into merge-train/avm
Jul 15, 2025
f77bc62
Merge branch 'next' into merge-train/avm
Jul 15, 2025
b2a0670
Merge branch 'next' into merge-train/avm
Jul 15, 2025
311049f
Merge branch 'next' into merge-train/avm
Jul 15, 2025
36592b0
Merge branch 'next' into merge-train/avm
Jul 16, 2025
b0ac12a
Merge branch 'next' into merge-train/avm
Jul 16, 2025
dd6d81f
Merge branch 'next' into merge-train/avm
Jul 16, 2025
999d17e
Merge branch 'next' into merge-train/avm
Jul 16, 2025
ce98a2c
Merge branch 'next' into merge-train/avm
Jul 16, 2025
2739a25
Merge branch 'next' into merge-train/avm
Jul 16, 2025
88af965
Merge branch 'next' into merge-train/avm
Jul 16, 2025
941c029
Merge branch 'next' into merge-train/avm
Jul 16, 2025
ec3417c
Merge branch 'next' into merge-train/avm
Jul 16, 2025
a329667
Merge branch 'next' into merge-train/avm
Jul 16, 2025
a042c35
Merge branch 'next' into merge-train/avm
Jul 16, 2025
4f94d30
Merge branch 'next' into merge-train/avm
Jul 16, 2025
e68f080
Merge branch 'next' into merge-train/avm
Jul 16, 2025
7d18b9a
Merge branch 'next' into merge-train/avm
Jul 16, 2025
5b0b85f
Merge branch 'next' into merge-train/avm
Jul 16, 2025
f4d72fa
Merge branch 'next' into merge-train/avm
Jul 16, 2025
3636d08
Merge branch 'next' into merge-train/avm
Jul 16, 2025
d229f87
Merge branch 'next' into merge-train/avm
Jul 17, 2025
2cd6f70
Merge branch 'next' into merge-train/avm
Jul 17, 2025
ba74aa7
Merge branch 'next' into merge-train/avm
Jul 17, 2025
ec4b51d
Merge branch 'next' into merge-train/avm
Jul 17, 2025
5e33736
Merge branch 'next' into merge-train/avm
Jul 17, 2025
c098c3e
Merge branch 'next' into merge-train/avm
Jul 17, 2025
5df3602
Merge branch 'next' into merge-train/avm
Jul 17, 2025
d1f02be
Merge branch 'next' into merge-train/avm
Jul 17, 2025
8ab3f96
Merge branch 'next' into merge-train/avm
Jul 18, 2025
d570adb
Merge branch 'next' into merge-train/avm
Jul 18, 2025
b512a87
Merge branch 'next' into merge-train/avm
Jul 18, 2025
95bd40d
Merge branch 'next' into merge-train/avm
Jul 18, 2025
0e5f7af
Merge branch 'next' into merge-train/avm
Jul 18, 2025
6423cab
Merge branch 'next' into merge-train/avm
Jul 18, 2025
d7dd515
Merge branch 'next' into merge-train/avm
Jul 18, 2025
5ea5aa1
Merge branch 'next' into merge-train/avm
Jul 18, 2025
718a600
Merge branch 'next' into merge-train/avm
Jul 18, 2025
a843da1
Merge branch 'next' into merge-train/avm
Jul 18, 2025
03c7869
Merge branch 'next' into merge-train/avm
Jul 19, 2025
438f433
Merge branch 'next' into merge-train/avm
Jul 19, 2025
2556dac
Merge branch 'next' into merge-train/avm
Jul 21, 2025
8e10388
Merge branch 'next' into merge-train/avm
Jul 21, 2025
e94edb1
Merge branch 'next' into merge-train/avm
Jul 21, 2025
43b6bbf
Merge branch 'next' into merge-train/avm
Jul 21, 2025
e7133c9
feat!: constrain NullifierExists AVM opcode (#15636)
dbanks12 Jul 21, 2025
73616a6
Merge branch 'next' into merge-train/avm
Jul 21, 2025
a1c40c2
Merge branch 'next' into merge-train/avm
Jul 21, 2025
795f993
Merge branch 'next' into merge-train/avm
Jul 21, 2025
abfd8ce
Merge branch 'next' into merge-train/avm
Jul 21, 2025
66ee06d
feat(avm)!: memory aware ecc add (#15780)
Jul 21, 2025
7a5a63b
Merge branch 'next' into merge-train/avm
Jul 21, 2025
18edf5a
Merge branch 'next' into merge-train/avm
Jul 21, 2025
af3972f
Merge branch 'next' into merge-train/avm
Jul 21, 2025
8d0f070
Merge branch 'next' into merge-train/avm
Jul 21, 2025
37f59ba
Merge branch 'next' into merge-train/avm
Jul 21, 2025
e7063f1
Merge branch 'next' into merge-train/avm
Jul 21, 2025
f06e4ea
Merge branch 'next' into merge-train/avm
Jul 22, 2025
2fb25d9
Merge branch 'next' into merge-train/avm
Jul 22, 2025
8c2cffa
Merge branch 'next' into merge-train/avm
Jul 22, 2025
7126eb3
Merge branch 'next' into merge-train/avm
Jul 22, 2025
90054b6
Merge branch 'next' into merge-train/avm
Jul 22, 2025
083f59f
Merge branch 'next' into merge-train/avm
Jul 22, 2025
f942316
Merge branch 'next' into merge-train/avm
Jul 22, 2025
06956c3
Merge branch 'next' into merge-train/avm
Jul 22, 2025
851f8be
Merge branch 'next' into merge-train/avm
Jul 22, 2025
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
7 changes: 7 additions & 0 deletions barretenberg/cpp/pil/vm2/constants_gen.pil
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ namespace constants;
pol NOTE_HASH_TREE_LEAF_COUNT = 1099511627776;
pol L1_TO_L2_MSG_TREE_LEAF_COUNT = 549755813888;
pol MAX_NOTE_HASHES_PER_TX = 64;
pol MAX_NULLIFIERS_PER_TX = 64;
pol MAX_ENQUEUED_CALLS_PER_TX = 32;
pol MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 64;
pol MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX = 63;
pol MAX_L2_TO_L1_MSGS_PER_TX = 8;
pol MAX_PUBLIC_LOGS_PER_TX = 8;
pol MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 3000;
pol CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS = 2;
pol FEE_JUICE_ADDRESS = 5;
pol FEE_JUICE_BALANCES_SLOT = 1;
pol UPDATED_CLASS_IDS_SLOT = 1;
pol MAX_PUBLIC_CALLS_TO_UNIQUE_CONTRACT_CLASS_IDS = 21;
pol MEM_TAG_FF = 0;
pol MEM_TAG_U1 = 1;
pol MEM_TAG_U8 = 2;
Expand Down Expand Up @@ -62,6 +68,7 @@ namespace constants;
pol AVM_EXEC_OP_ID_NOTEHASH_EXISTS = 32768;
pol AVM_EXEC_OP_ID_EMIT_NOTEHASH = 65536;
pol AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS = 131072;
pol AVM_EXEC_OP_ID_NULLIFIEREXISTS = 262144;
pol AVM_EXEC_OP_ID_ALU_ADD = 1;
pol AVM_EXEC_OP_ID_ALU_SUB = 2;
pol AVM_EXEC_OP_ID_ALU_MUL = 4;
Expand Down
182 changes: 182 additions & 0 deletions barretenberg/cpp/pil/vm2/ecc_mem.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
include "ecc.pil";
include "gt.pil";
include "execution.pil";

/**
* This handles the memory writes when the ECCADD opcode is executed by user code.
* The reads are handled by the registers in the execution trace.
* This trace writes the resulting embedded curve point to the addresses {dst,
* dst + 1, and dst + 2 }. Embedded curve points consist of the tuple of types
* {x: FF, y: FF, is_inf: U1 }.
*
* Opcode operands (relevant in EXECUTION when interacting with this gadget):
* - rop[0]: p_x_addr
* - rop[1]: p_y_addr
* - rop[2]: p_is_inf_addr
* - rop[3]: q_x_addr
* - rop[4]: q_y_addr
* - rop[5]: q_is_inf_addr
* - rop[6]: dst_addr
*
* Memory I/O:
* - register[0]: M[p_x_addr] aka p_x (x coordinate of point P - read from memory by EXECUTION)
* - p_x is tagged-checked by execution/registers to be FF based on instruction spec.
* - register[1]: M[p_y_addr] aka p_y (y coordinate of point P - read from memory by EXECUTION)
* - p_y is tagged-checked by execution/registers to be FF based on instruction spec.
* - register[2]: M[p_is_inf_addr] aka p_is_inf (boolean flag if P is the point at infinity - read from memory by EXECUTION)
* - p_is_inf is tagged-checked by execution/registers to be U1 based on instruction spec.
* - register[3]: M[q_x_addr] aka q_x (x coordinate of point Q - read from memory by EXECUTION)
* - q_x is tagged-checked by execution/registers to be FF based on instruction spec.
* - register[4]: M[q_y_addr] aka q_y (y coordinate of point Q - read from memory by EXECUTION)
* - q_y is tagged-checked by execution/registers to be FF based on instruction spec.
* - register[5]: M[q_is_inf_addr] aka q_is_inf (boolean flag if Q is the point at infinity - read from memory by EXECUTION)
* - q_is_inf is tagged-checked by execution/registers to be U1 based on instruction spec.
* - M[rop[6]]: M[dst_addr] aka res_x (x coordinate of the resulting point RES - written by this gadget)
* - guaranteed by this gadget to be FF.
* - M[rop[6]+1]: M[dst_offset+1] aka res_y (y coordinate of the resulting point RES - written by this gadget)
* - guaranteed by this gadget to be FF.
* - M[rop[6]+2]: M[dst_offset+2] aka res_is_inf (boolean flag if RES is the point at infinity - written by this gadget)
* - guaranteed by this gadget to be U1.
*
* ERROR HANDLING:
* A single error needs to be handled as part of this trace
* (1) DST_OUT_OF_BOUNDS_ACCESS: If the writes would access a memory address outside
* of the max AVM memory address (AVM_HIGHEST_MEM_ADDRESS).
*
* N.B This subtrace writes the values within a single row (i.e. 3 output columns)
*
* This subtrace is connected to the ECC subtrace via a lookup. ECC is used by
* other subtraces internally (e.g., address derivation)
*/

namespace ecc_add_mem;

pol commit sel;

#[skippable_if]
sel = 0;

pol commit execution_clk;
pol commit space_id;
pol commit dst_addr[3];

// dst_addr[0] constrained by the permutation to execution
#[WRITE_INCR_DST_ADDR]
dst_addr[1] = sel * (dst_addr[0] + 1);
dst_addr[2] = sel * (dst_addr[0] + 2);

pol commit p_x, p_y, p_is_inf;
pol commit q_x, q_y, q_is_inf;

////////////////////////////////////////////////
// Error Handling - Out of Range Memory Access
////////////////////////////////////////////////
pol commit sel_dst_out_of_range_err;
sel_dst_out_of_range_err * (1 - sel_dst_out_of_range_err) = 0;

// 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
// dst_addr[2] > max_mem_addr
pol commit max_mem_addr; // Column needed until we support constants in lookups
sel * (max_mem_addr - constants.AVM_HIGHEST_MEM_ADDRESS) = 0;

#[CHECK_DST_ADDR_IN_RANGE]
sel { dst_addr[2], max_mem_addr, sel_dst_out_of_range_err }
in
gt.sel { gt.input_a, gt.input_b, gt.res };

////////////////////////////////////////////////
// Dispatch from execution trace to ECC Add
////////////////////////////////////////////////
#[DISPATCH_EXEC_ECC_ADD]
execution.sel_execute_ecc_add {
precomputed.clk,
execution.context_id,
// Point P
execution.register[0],
execution.register[1],
execution.register[2],
// Point Q
execution.register[3],
execution.register[4],
execution.register[5],
// Dst address
execution.rop[6],
// Error
execution.sel_opcode_error
} is
sel {
execution_clk,
space_id,
// Point P
p_x,
p_y,
p_is_inf,
// Point Q
q_x,
q_y,
q_is_inf,
// Dst address
dst_addr[0],
// Error
sel_dst_out_of_range_err
};

///////////////////////////////////////////////////////////////////////
// Dispatch inputs to ecc add and retrieve outputs
///////////////////////////////////////////////////////////////////////
pol commit res_x, res_y, res_is_inf;
pol commit sel_should_exec;
sel_should_exec = sel * (1 - sel_dst_out_of_range_err);

#[INPUT_OUTPUT_ECC_ADD]
sel_should_exec {
p_x, p_y, p_is_inf,
q_x, q_y, q_is_inf,
res_x, res_y, res_is_inf
} in
ecc.sel {
ecc.p_x, ecc.p_y, ecc.p_is_inf,
ecc.q_x, ecc.q_y, ecc.q_is_inf,
ecc.r_x, ecc.r_y, ecc.r_is_inf
};

////////////////////////////////////////////////
// Write output to memory
////////////////////////////////////////////////
// TODO: These need to be changed to permutations once we have the custom permutation selectors impl
#[WRITE_MEM_0]
sel_should_exec {
execution_clk, dst_addr[0],
res_x, /*FF_mem_tag*/ precomputed.zero,
space_id, /*rw=1*/ sel_should_exec
} in
memory.sel {
memory.clk, memory.address,
memory.value, memory.tag,
memory.space_id, memory.rw
};

#[WRITE_MEM_1]
sel_should_exec {
execution_clk, dst_addr[1],
res_y, /*FF_mem_tag*/ precomputed.zero,
space_id, /*rw=1*/ sel_should_exec
} in
memory.sel {
memory.clk, memory.address,
memory.value, memory.tag,
memory.space_id, memory.rw
};

#[WRITE_MEM_2]
sel_should_exec {
execution_clk, dst_addr[2],
res_is_inf, /*U1_mem_tag=1*/ sel_should_exec,
space_id, /*rw=1*/ sel_should_exec
} in
memory.sel {
memory.clk, memory.address,
memory.value, memory.tag,
memory.space_id, memory.rw
};
8 changes: 6 additions & 2 deletions barretenberg/cpp/pil/vm2/execution.pil
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include "memory.pil";
include "keccakf1600.pil";
include "precomputed.pil";
include "sha256.pil";
include "ecc.pil";
include "ecc_mem.pil";
include "poseidon2_mem.pil";
include "scalar_mul.pil";
include "to_radix.pil";
Expand Down Expand Up @@ -46,6 +46,7 @@ include "opcodes/sstore.pil";
include "opcodes/notehash_exists.pil";
include "opcodes/emit_notehash.pil";
include "opcodes/l1_to_l2_message_exists.pil";
include "opcodes/nullifier_exists.pil";

namespace execution;

Expand Down Expand Up @@ -395,6 +396,7 @@ pol commit sel_execute_sstore;
pol commit sel_execute_notehash_exists;
pol commit sel_execute_emit_notehash;
pol commit sel_execute_l1_to_l2_message_exists;
pol commit sel_execute_nullifier_exists;
sel_execute_get_env_var * (1 - sel_execute_get_env_var) = 0;
sel_execute_mov * (1 - sel_execute_mov) = 0;
sel_execute_jump * (1 - sel_execute_jump) = 0;
Expand All @@ -413,6 +415,7 @@ sel_execute_sstore * (1 - sel_execute_sstore) = 0;
sel_execute_notehash_exists * (1 - sel_execute_notehash_exists) = 0;
sel_execute_emit_notehash * (1 - sel_execute_emit_notehash) = 0;
sel_execute_l1_to_l2_message_exists * (1 - sel_execute_l1_to_l2_message_exists) = 0;
sel_execute_nullifier_exists * (1 - sel_execute_nullifier_exists) = 0;

#[EXEC_OP_ID_DECOMPOSITION]
sel_execute_get_env_var * constants.AVM_EXEC_OP_ID_GETENVVAR +
Expand All @@ -432,7 +435,8 @@ sel_execute_sload * constants.AVM_EXEC_OP_ID_SLOAD +
sel_execute_sstore * constants.AVM_EXEC_OP_ID_SSTORE +
sel_execute_notehash_exists * constants.AVM_EXEC_OP_ID_NOTEHASH_EXISTS +
sel_execute_emit_notehash * constants.AVM_EXEC_OP_ID_EMIT_NOTEHASH +
sel_execute_l1_to_l2_message_exists * constants.AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS
sel_execute_l1_to_l2_message_exists * constants.AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS +
sel_execute_nullifier_exists * constants.AVM_EXEC_OP_ID_NULLIFIEREXISTS
// We force the selectors to be 0 if we are not executing an opcode
// or when we are not in the execution subtrace.
= sel_should_execute_opcode * sel_execute_execution * subtrace_operation_id;
Expand Down
56 changes: 56 additions & 0 deletions barretenberg/cpp/pil/vm2/opcodes/nullifier_exists.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* This virtual gadget implements the NullifierExists opcode, which checks if a nullifier exists
* in the nullifier tree for a given contract address.
*
* The opcode is gated by the `sel_execute_nullifier_exists` selector, which is set to 1 if the
* NullifierExists opcode has reached dispatch (there are no earlier errors).
*
* This opcode uses:
* - register[0] as the nullifier input register (FF)
* - register[1] as the contract address input register (FF)
* - register[2] as the output register (boolean result to be tagged as u1)
*
* Memory reads and writes are handled by standard execution logic.
*
* The gadget performs a lookup into the nullifier_check gadget to determine if the nullifier
* exists for the specified contract address. The result is written to the output register.
*
* If there are errors in earlier temporality groups (e.g. address resolution or out-of-gas errors),
* all selectors should be 0 and output register & intermediate values should be 0.
*/

namespace execution; // this is a virtual gadget that shares rows with the execution trace

// No relations will be checked if this identity is satisfied.
#[skippable_if]
sel_execute_nullifier_exists = 0; // from execution.pil.


// Lookup into nullifier tree check to determine existence
#[NULLIFIER_EXISTS_CHECK]
sel_execute_nullifier_exists {
// Outputs
/*exists=*/ register[2], // output: whether nullifier exists
// Inputs
/*nullifier=*/ register[0], // input: nullifier to check
prev_nullifier_tree_root, // input: tree root from context
/*should_silo=1*/ sel_execute_nullifier_exists, // input: should_silo = 1 (always silo for contract nullifiers)
/*contract_address=*/ register[1] // input: contract address for siloing
} in nullifier_check.sel {
// Outputs
nullifier_check.exists,
// Inputs
nullifier_check.nullifier,
nullifier_check.root,
nullifier_check.should_silo,
nullifier_check.address
};

// Tag result (`exists`) as u1 (via mem_tag_reg[2]).
#[NULLIFIER_EXISTS_U1_OUTPUT_TAG]
sel_execute_nullifier_exists * (constants.MEM_TAG_U1 - mem_tag_reg[2]) = 0;

// NullifierExists opcode has no errors!
// (other than of those handled by standard execution logic)
#[NULLIFIER_EXISTS_SUCCESS]
sel_opcode_error * sel_execute_nullifier_exists = 0;
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#define AVM_EXEC_OP_ID_NOTEHASH_EXISTS 32768
#define AVM_EXEC_OP_ID_EMIT_NOTEHASH 65536
#define AVM_EXEC_OP_ID_L1_TO_L2_MESSAGE_EXISTS 131072
#define AVM_EXEC_OP_ID_NULLIFIEREXISTS 262144
#define AVM_EXEC_OP_ID_ALU_ADD 1
#define AVM_EXEC_OP_ID_ALU_SUB 2
#define AVM_EXEC_OP_ID_ALU_MUL 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,13 @@ const std::unordered_map<ExecutionOpCode, ExecInstructionSpec> EXEC_INSTRUCTION_
.register_info = RegisterInfo()
.add_inputs({ /*unique_note_hash*/ ValueTag::FF, /*leaf_index*/ ValueTag::U64 })
.add_output(/*exists*/) } },
{ ExecutionOpCode::NULLIFIEREXISTS,
{ .num_addresses = 3,
.gas_cost = { .opcode_gas = AVM_NULLIFIEREXISTS_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
.register_info = RegisterInfo()
.add_inputs({ /*nullifier*/ ValueTag::FF,
/*address*/ ValueTag::FF })
.add_output(/*exists*/) } },
{ ExecutionOpCode::GETCONTRACTINSTANCE,
{ .num_addresses = 2,
.gas_cost = { .opcode_gas = AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
Expand All @@ -599,6 +606,16 @@ const std::unordered_map<ExecutionOpCode, ExecInstructionSpec> EXEC_INSTRUCTION_
{ ExecutionOpCode::POSEIDON2PERM,
{ .num_addresses = 2,
.gas_cost = { .opcode_gas = AVM_POSEIDON2_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 } } },
{ ExecutionOpCode::ECADD,
{ .num_addresses = 7,
.gas_cost = { .opcode_gas = AVM_ECADD_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
.register_info = RegisterInfo().add_inputs({ /*p_x=*/ValueTag::FF,
/*p_y=*/ValueTag::FF,
/*p_inf*/ ValueTag::U1,
/*q_x*/ ValueTag::FF,
/*q_y*/ ValueTag::FF,
/*q_inf*/ ValueTag::U1 }) } },

};

} // namespace bb::avm2
Loading
Loading