Skip to content

Commit 4481bad

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/spartan
2 parents 3b04a40 + 72c125c commit 4481bad

15 files changed

Lines changed: 116 additions & 190 deletions

File tree

barretenberg/cpp/pil/vm2/precomputed.pil

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pol constant sel_mem_tag_out_of_range;
209209
// - instruction size (in bytes): instr_size
210210
// - Selector on whether the instruction has a tag: sel_has_tag
211211
// - Selector on whether operand op2 is a tag: sel_tag_is_op2
212-
//
212+
//
213213
// Used by the instruction fetching subtrace to decode raw bytecode.
214214
// Selectors for operands decomposition into bytes (required by instr_fetching.pil)
215215
// This table is populated by a map generated by a cpp test defined in op_decomposition.test.cpp.
@@ -361,22 +361,23 @@ pol constant addressing_gas;
361361
// properties: which tree operations are allowed, public-input offsets, revert behavior.
362362
// Used by the transaction trace to enforce phase-based constraints.
363363
//
364-
// Example trace (idx encodes the TransactionPhase enum; abbreviated column names):
365-
// idx | sel_phase | is_call | is_teardown | is_collect_fee | is_tree_padding | is_cleanup | is_revertible | nr_null | nr_note | nr_l2l1 | r_null | r_note | r_l2l1 | next_on_revert
366-
// ----+-----------+---------+-------------+----------------+-----------------+------------+---------------+---------+---------+---------+--------+--------+--------+---------------
367-
// 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 (NR_NULLIFIER_INSERTION)
368-
// 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 (NR_NOTE_INSERTION)
369-
// 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 (NR_L2_TO_L1_MESSAGE)
370-
// 3 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (SETUP)
371-
// 4 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 8 (R_NULLIFIER_INSERTION)
372-
// 5 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 8 (R_NOTE_INSERTION)
373-
// 6 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 8 (R_L2_TO_L1_MESSAGE)
374-
// 7 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 8 (APP_LOGIC)
375-
// 8 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 9 (TEARDOWN)
376-
// 9 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (COLLECT_GAS_FEES)
377-
// 10 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (TREE_PADDING)
378-
// 11 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (CLEANUP)
379-
// 12 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (beyond phase range)
364+
// Example trace (idx encodes the TransactionPhase enum; abbreviated column names).
365+
// Whether an append is revertible or not is determined by `is_revertible`.
366+
// idx | sel_phase | is_call | is_teardown | is_collect_fee | is_tree_padding | is_cleanup | is_revertible | append_null | append_note | append_l2l1 | next_on_revert
367+
// ----+-----------+---------+-------------+----------------+-----------------+------------+---------------+-------------+-------------+-------------+---------------
368+
// 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 (NR_NULLIFIER_INSERTION)
369+
// 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 (NR_NOTE_INSERTION)
370+
// 2 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 (NR_L2_TO_L1_MESSAGE)
371+
// 3 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (SETUP)
372+
// 4 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 8 (R_NULLIFIER_INSERTION)
373+
// 5 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 8 (R_NOTE_INSERTION)
374+
// 6 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 8 (R_L2_TO_L1_MESSAGE)
375+
// 7 | 1 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 8 (APP_LOGIC)
376+
// 8 | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 9 (TEARDOWN)
377+
// 9 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (COLLECT_GAS_FEES)
378+
// 10 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 (TREE_PADDING)
379+
// 11 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 (CLEANUP)
380+
// 12 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 (beyond phase range)
380381

381382
// Phase Table for Tx Trace
382383
pol constant sel_phase; // Selector for phase table
@@ -389,12 +390,9 @@ pol constant is_cleanup;
389390
pol constant is_revertible;
390391
pol constant read_pi_start_offset;
391392
pol constant read_pi_length_offset;
392-
pol constant sel_non_revertible_append_note_hash;
393-
pol constant sel_non_revertible_append_nullifier;
394-
pol constant sel_non_revertible_append_l2_l1_msg;
395-
pol constant sel_revertible_append_note_hash;
396-
pol constant sel_revertible_append_nullifier;
397-
pol constant sel_revertible_append_l2_l1_msg;
393+
pol constant sel_append_note_hash;
394+
pol constant sel_append_nullifier;
395+
pol constant sel_append_l2_l1_msg;
398396
pol constant next_phase_on_revert;
399397

400398
// ===== Section 12: Keccak round constants =====

barretenberg/cpp/pil/vm2/tx.pil

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,9 @@ namespace tx;
209209
is_revertible,
210210
read_pi_start_offset,
211211
read_pi_length_offset,
212-
sel_non_revertible_append_note_hash,
213-
sel_non_revertible_append_nullifier,
214-
sel_non_revertible_append_l2_l1_msg,
215-
sel_revertible_append_note_hash,
216-
sel_revertible_append_nullifier,
217-
sel_revertible_append_l2_l1_msg,
212+
sel_append_note_hash,
213+
sel_append_nullifier,
214+
sel_append_l2_l1_msg,
218215
next_phase_on_revert
219216
}
220217
in
@@ -228,12 +225,9 @@ namespace tx;
228225
precomputed.is_revertible,
229226
precomputed.read_pi_start_offset,
230227
precomputed.read_pi_length_offset,
231-
precomputed.sel_non_revertible_append_note_hash,
232-
precomputed.sel_non_revertible_append_nullifier,
233-
precomputed.sel_non_revertible_append_l2_l1_msg,
234-
precomputed.sel_revertible_append_note_hash,
235-
precomputed.sel_revertible_append_nullifier,
236-
precomputed.sel_revertible_append_l2_l1_msg,
228+
precomputed.sel_append_note_hash,
229+
precomputed.sel_append_nullifier,
230+
precomputed.sel_append_l2_l1_msg,
237231
precomputed.next_phase_on_revert
238232
};
239233

@@ -465,18 +459,16 @@ namespace tx;
465459
/***************************************************************************
466460
* Private Side Effect Insertions
467461
**************************************************************************/
468-
pol commit sel_revertible_append_note_hash; // @boolean
469-
pol commit sel_non_revertible_append_note_hash; // @boolean
470-
pol commit sel_revertible_append_nullifier; // @boolean
471-
pol commit sel_non_revertible_append_nullifier; // @boolean
472-
pol commit sel_revertible_append_l2_l1_msg; // @boolean
473-
pol commit sel_non_revertible_append_l2_l1_msg; // @boolean
474-
// The 6 above selectors are booleans thanks to #[READ_PHASE_SPEC] on active rows.
462+
pol commit sel_append_note_hash; // @boolean
463+
pol commit sel_append_nullifier; // @boolean
464+
pol commit sel_append_l2_l1_msg; // @boolean
465+
// The 3 above selectors are booleans thanks to #[READ_PHASE_SPEC] on active rows.
475466
// Furthermore, phase spec guarantees that they are mutually exclusive.
467+
// Whether such an append is revertible or not is determined by `is_revertible`.
476468

477469
// A tree selector means we need to get the tree value
478-
pol commit is_tree_insert_phase; // @boolean on active rows (follows from mutual exclusivity of the 6 above selectors)
479-
is_tree_insert_phase = sel_revertible_append_note_hash + sel_non_revertible_append_note_hash + sel_revertible_append_nullifier + sel_non_revertible_append_nullifier;
470+
pol commit is_tree_insert_phase; // @boolean on active rows (follows from mutual exclusivity of the above selectors)
471+
is_tree_insert_phase = sel_append_note_hash + sel_append_nullifier;
480472
pol commit leaf_value;
481473
// Shared column to track the inverse of the remaining side effects for note hashes, nullifiers, and L2 to L1 messages
482474
pol commit remaining_side_effects_inv;
@@ -491,7 +483,7 @@ namespace tx;
491483

492484
// ===== NOTE HASHES =====
493485
pol commit sel_try_note_hash_append; // @boolean (follows from definition)
494-
sel_try_note_hash_append = (sel - is_padded) * (sel_revertible_append_note_hash + sel_non_revertible_append_note_hash);
486+
sel_try_note_hash_append = (sel - is_padded) * sel_append_note_hash;
495487

496488
// If we are at the maximum emitted note hashes, we must revert
497489
pol REMAINING_NOTE_HASH_WRITES = constants.MAX_NOTE_HASHES_PER_TX - prev_num_note_hashes_emitted;
@@ -509,7 +501,9 @@ namespace tx;
509501
prev_note_hash_tree_size,
510502
prev_note_hash_tree_root,
511503
precomputed.zero, // Already siloed. (No need to pass address.)
512-
sel_revertible_append_note_hash, // Not unique for revertible note hashes.
504+
is_revertible, // Used as `sel_unique`: revertible note hashes need to be made unique with a nonce.
505+
// On rows where sel_note_hash_append == 1 (NR_NOTE_INSERTION or R_NOTE_INSERTION),
506+
// is_revertible is exactly the discriminator we want.
513507
prev_num_note_hashes_emitted,
514508
discard, // from tx_discard.pil virtual trace
515509
next_note_hash_tree_root
@@ -532,7 +526,7 @@ namespace tx;
532526

533527
// ===== NULLIFIERS =====
534528
pol commit sel_try_nullifier_append; // @boolean (follows from definition)
535-
sel_try_nullifier_append = (sel - is_padded) * (sel_revertible_append_nullifier + sel_non_revertible_append_nullifier);
529+
sel_try_nullifier_append = (sel - is_padded) * sel_append_nullifier;
536530

537531
pol commit nullifier_limit_error; // @boolean
538532
nullifier_limit_error * (1 - nullifier_limit_error) = 0;
@@ -594,7 +588,7 @@ namespace tx;
594588

595589
// ===== L2 - L1 Messages =====
596590
pol commit sel_try_l2_l1_msg_append; // @boolean (follows from definition)
597-
sel_try_l2_l1_msg_append = (sel - is_padded) * (sel_revertible_append_l2_l1_msg + sel_non_revertible_append_l2_l1_msg);
591+
sel_try_l2_l1_msg_append = (sel - is_padded) * sel_append_l2_l1_msg;
598592

599593
pol commit l2_l1_msg_contract_address;
600594
pol commit l2_l1_msg_recipient;

barretenberg/cpp/pil/vm2/tx_context.pil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,12 @@ namespace tx;
330330
NOT_LAST_ROW * (1 - is_teardown') * (da_gas_limit - da_gas_limit') = 0;
331331

332332
// Selectors to allow prev => next state changes in the different phases
333-
pol SEL_CAN_EMIT_NOTE_HASH = is_public_call_request + sel_non_revertible_append_note_hash + sel_revertible_append_note_hash;
334-
pol SEL_CAN_EMIT_NULLIFIER = is_public_call_request + sel_non_revertible_append_nullifier + sel_revertible_append_nullifier;
333+
pol SEL_CAN_EMIT_NOTE_HASH = is_public_call_request + sel_append_note_hash;
334+
pol SEL_CAN_EMIT_NULLIFIER = is_public_call_request + sel_append_nullifier;
335335
pol SEL_CAN_WRITE_PUBLIC_DATA = is_public_call_request + is_collect_fee;
336336
pol SEL_CAN_WRITE_WRITTEN_PUBLIC_DATA_SLOTS = is_public_call_request;
337337
pol SEL_CAN_EMIT_PUBLIC_LOG = is_public_call_request;
338-
pol SEL_CAN_EMIT_L2_L1_MSG = is_public_call_request + sel_non_revertible_append_l2_l1_msg + sel_revertible_append_l2_l1_msg;
338+
pol SEL_CAN_EMIT_L2_L1_MSG = is_public_call_request + sel_append_l2_l1_msg;
339339
// The 6 above selectors are booleans on active rows due to #[READ_PHASE_SPEC] and
340340
// mutual exclusivity of the selectors on the right-hand side.
341341

barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AvmHardCodedVKAndHash {
1717
using FF = bb::curve::BN254::ScalarField;
1818

1919
// Precomputed VK hash (hash of all commitments below).
20-
static FF vk_hash() { return FF(uint256_t("0x183783fd7c3f269b595307224be99cf3773b781f8d1d59a305ce711101d43a60")); }
20+
static FF vk_hash() { return FF(uint256_t("0x23a03c6f87c465dbecc386b091e8123a8936597b5b0749f276d042a8964bd390")); }
2121

2222
static constexpr std::array<Commitment, NUM_PRECOMPUTED_ENTITIES> get_all()
2323
{
@@ -232,6 +232,18 @@ class AvmHardCodedVKAndHash {
232232
uint256_t("0x0752e216f6398f2dc16b86cd762f9bd9f961964f9c6a354530c45b04920f06ab"),
233233
uint256_t(
234234
"0x062522db0dc283ad1d328147904f0fdc0e44add870aa0b099cf16c3d73352a9e")), // precomputed_sel_addressing_gas
235+
Commitment(
236+
uint256_t("0x095419f3dc475e499012c5d001c266643669a19173217b51fd5f2a86b3e1a8b2"),
237+
uint256_t(
238+
"0x0f9bf4c4f62da52213998f25ab3eca754175cf4580e070f1abb251e2d8a8e64a")), // precomputed_sel_append_l2_l1_msg
239+
Commitment(
240+
uint256_t("0x2932e8961b4b905fe11c2f93092e57d7e541a9bb00aca69af2a6d213577670ea"),
241+
uint256_t(
242+
"0x20b57b640b0186c53727c6f4724dc71b51387a34d8db51af06b1f9ad3a92d467")), // precomputed_sel_append_note_hash
243+
Commitment(
244+
uint256_t("0x1eba8da14083ce2c1b307a5493006a232c89e55fa657f9c193f5654990f06544"),
245+
uint256_t(
246+
"0x07b64d628ee70ee71e89aaabb91abd9005096a24e8c4cd3543cbf1b9344e108f")), // precomputed_sel_append_nullifier
235247
Commitment(
236248
uint256_t("0x2059be69211e5ea9bb365ab69c1132eb7b7c6814925453953f62bf731e5e42f9"),
237249
uint256_t(
@@ -280,18 +292,6 @@ class AvmHardCodedVKAndHash {
280292
uint256_t("0x089cdab4e8e8381977b093cb267a1b7c8c60f4466c39a99af1247e37fe56ebfe"),
281293
uint256_t(
282294
"0x1144347d2bfe5c1f4a6d44418562facb9a5c9c7bf2b6b463424e8b0915254710")), // precomputed_sel_mem_tag_out_of_range
283-
Commitment(
284-
uint256_t("0x020ad6e43ccd48a6a39e43897cc85187bd364919be8a3b82d4809715cfe489db"),
285-
uint256_t(
286-
"0x21a79ebae2ea3d92b49c521407d2600ac061146f2c188c6c6a33c598179e4543")), // precomputed_sel_non_revertible_append_l2_l1_msg
287-
Commitment(
288-
uint256_t("0x2d360628289ff943ff6bd1a87bbe4e62abe7fb61ba83effd266f22bdcf31e6f9"),
289-
uint256_t(
290-
"0x26b92a79e563c3f48252cce7feeca2f0f8d33dcb4ef7b0643bf07bd405700aaa")), // precomputed_sel_non_revertible_append_note_hash
291-
Commitment(
292-
uint256_t("0x0000000000000000000000000000000000000000000000000000000000000001"),
293-
uint256_t(
294-
"0x0000000000000000000000000000000000000000000000000000000000000002")), // precomputed_sel_non_revertible_append_nullifier
295295
Commitment(
296296
uint256_t("0x0bf1970c2e92fee577ba15d063fa78fdd17752cafd19261ff0f176a1d3348769"),
297297
uint256_t(
@@ -404,18 +404,6 @@ class AvmHardCodedVKAndHash {
404404
uint256_t("0x2e51e57417ece86800e7afa2ac53cfffcf35343cfb4bad1f6016a5b657fc3bfe"),
405405
uint256_t(
406406
"0x2c8617a36d1bbb5e7bf06c192e8ffc9aa90c714d222f8c8c29ed6a8a7e5eb717")), // precomputed_sel_range_8
407-
Commitment(
408-
uint256_t("0x262d212add82bcbcf96d0773c59926e1b8e68e45c662f9348f2e4f64770595b3"),
409-
uint256_t(
410-
"0x2fe4de705da2b7bfb03cb3baa199ed4cc97e6ce620d0e939b603493223e88703")), // precomputed_sel_revertible_append_l2_l1_msg
411-
Commitment(
412-
uint256_t("0x041008987db8f55ded689b589133da9860150ed8c97b6bb5e87f0a31f78582b8"),
413-
uint256_t(
414-
"0x113ecb4f4d07b4efb19a22b59e5634d58e5f1d5a433b08a32f1ac2bdd0e7c01a")), // precomputed_sel_revertible_append_note_hash
415-
Commitment(
416-
uint256_t("0x2a56ce41f6b0be13b9c26747621b821eee81b23a887f299049b14c11e98460d6"),
417-
uint256_t(
418-
"0x1aa98f2de3ddda547d8f6de4e725ded5827d6338c78656c0d12ca1aea6ef2c7c")), // precomputed_sel_revertible_append_nullifier
419407
Commitment(
420408
uint256_t("0x2db8d548af3efd182047c9081ce2870f3c2e7a96b4a6469aca26167209285d9b"),
421409
uint256_t(

0 commit comments

Comments
 (0)