Skip to content

Commit d903029

Browse files
authored
feat!: allow consuming l1-to-l2 message in the same block (#16704)
We now feed the new l1-to-l2 message tree root to the avm, allowing the public functions to consume the messages that are going to be inserted to the tree in the block root rollup.
1 parent 7bfeae4 commit d903029

31 files changed

+199
-135
lines changed

noir-projects/noir-protocol-circuits/crates/rollup-base-private/Prover.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8358,7 +8358,7 @@ next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000
83588358
root = "0x04522891b206ed43de89ad1f2bf6701ff8589b78893ee32d43a231522f99bfa3"
83598359
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000009"
83608360

8361-
[inputs.constants.last_l1_to_l2]
8361+
[inputs.constants.new_l1_to_l2]
83628362
root = "0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"
83638363
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000080"
83648364

noir-projects/noir-protocol-circuits/crates/rollup-block-root/Prover.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ accumulated_mana_used = "0x00000000000000000000000000000000000000000000000000000
1313
root = "0x11ec690ae2d1a79033acbde89cb053a6bfeb7713fdc47a18b28fde85057afb4d"
1414
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000008"
1515

16-
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.last_l1_to_l2]
16+
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.new_l1_to_l2]
1717
root = "0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"
18-
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000070"
18+
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000080"
1919

2020
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.global_variables]
2121
chain_id = "0x0000000000000000000000000000000000000000000000000000000000007a69"
@@ -781,9 +781,9 @@ accumulated_mana_used = "0x00000000000000000000000000000000000000000000000000000
781781
root = "0x11ec690ae2d1a79033acbde89cb053a6bfeb7713fdc47a18b28fde85057afb4d"
782782
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000008"
783783

784-
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.last_l1_to_l2]
784+
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.new_l1_to_l2]
785785
root = "0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"
786-
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000070"
786+
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000080"
787787

788788
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.global_variables]
789789
chain_id = "0x0000000000000000000000000000000000000000000000000000000000007a69"

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/base/public_base_rollup.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl PublicBaseRollupInputs {
8989

9090
BlockConstantData {
9191
last_archive: self.last_archive,
92-
last_l1_to_l2: avm_data.start_tree_snapshots.l1_to_l2_message_tree,
92+
new_l1_to_l2: avm_data.start_tree_snapshots.l1_to_l2_message_tree,
9393
global_variables: avm_data.global_variables,
9494
vk_tree_root: tube_data.constants.vk_tree_root,
9595
protocol_contract_tree_root: tube_data.constants.protocol_contract_tree_root,

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/block_root_rollup_inputs.nr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,13 @@ pub(crate) mod tests {
372372
let _ = builder.execute();
373373
}
374374

375-
#[test(should_fail_with = "last_l1_to_l2 in constants does not match the value in the previous block header")]
376-
unconstrained fn mismatch_last_l1_to_l2_snapshot_fails() {
375+
#[test(should_fail_with = "new_l1_to_l2 in constants does not match the computed value")]
376+
unconstrained fn mismatch_new_l1_to_l2_snapshot_fails() {
377377
let mut builder = TestBuilder::new();
378378

379-
builder.inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.last_l1_to_l2.root +=
379+
builder.inputs.previous_rollup_data[0].base_or_merge_rollup_public_inputs.constants.new_l1_to_l2.root +=
380380
1;
381-
builder.inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.last_l1_to_l2.root +=
381+
builder.inputs.previous_rollup_data[1].base_or_merge_rollup_public_inputs.constants.new_l1_to_l2.root +=
382382
1;
383383

384384
let _ = builder.execute();

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/components/block_root_rollup_inputs_validator.nr

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,5 @@ impl<let NUM_ROLLUPS: u32, let N: u32> BlockRootRollupInputsValidator<NUM_ROLLUP
107107
),
108108
"hash of the previous block header is not the last leaf in the archive tree",
109109
);
110-
111-
// Validate last_l1_to_l2.
112-
assert_eq(
113-
constants.last_l1_to_l2,
114-
previous_block_header.state.l1_to_l2_message_tree,
115-
"last_l1_to_l2 in constants does not match the value in the previous block header",
116-
);
117110
}
118111
}

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/block_root/components/block_root_rollup_output_composer.nr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ impl BlockRootRollupOutputComposer {
178178
self.data.l1_to_l2_roots.public_inputs.converted_root,
179179
L1_TO_L2_MSG_SUBTREE_HEIGHT as u8,
180180
);
181+
182+
// Check that the `new_l1_to_l2` tree snapshot in the constants matches the computed value.
183+
// This snapshot is used in the avm to validate the l1 to l2 message read requests
184+
assert_eq(
185+
constants.new_l1_to_l2,
186+
new_l1_to_l2_message_tree_snapshot,
187+
"new_l1_to_l2 in constants does not match the computed value",
188+
);
189+
181190
let state = StateReference {
182191
l1_to_l2_message_tree: new_l1_to_l2_message_tree_snapshot,
183192
partial: end_partial_state,

noir-projects/noir-protocol-circuits/crates/rollup-lib/src/tests/rollup_fixture_builder.nr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use types::{
1919
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, L1_TO_L2_MSG_TREE_HEIGHT,
2020
PUBLIC_BASE_ROLLUP_VK_INDEX, ROOT_PARITY_INDEX,
2121
},
22-
merkle_tree::MerkleTree,
22+
merkle_tree::{append_only_tree, calculate_empty_tree_root, MerkleTree},
2323
proof::vk_data::VkData,
2424
tests::{fixtures, merkle_tree_utils::{compute_zero_hashes, NonEmptyMerkleTree}},
2525
traits::{Empty, Hash, Serialize},
@@ -31,6 +31,7 @@ pub struct RollupFixtureBuilder {
3131
pub previous_block_hash: Field,
3232
pub last_l1_to_l2: AppendOnlyTreeSnapshot,
3333
pub last_l1_to_l2_subtree_sibling_path: [Field; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH],
34+
pub new_l1_to_l2: AppendOnlyTreeSnapshot,
3435
pub last_archive: AppendOnlyTreeSnapshot,
3536
pub last_archive_sibling_path: [Field; ARCHIVE_HEIGHT],
3637
pub new_archive: AppendOnlyTreeSnapshot,
@@ -61,6 +62,7 @@ impl RollupFixtureBuilder {
6162
previous_block_hash: 0,
6263
last_l1_to_l2: AppendOnlyTreeSnapshot::empty(),
6364
last_l1_to_l2_subtree_sibling_path: [0; L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH],
65+
new_l1_to_l2: AppendOnlyTreeSnapshot::empty(),
6466
last_archive: AppendOnlyTreeSnapshot::empty(),
6567
last_archive_sibling_path: [0; ARCHIVE_HEIGHT],
6668
new_archive: AppendOnlyTreeSnapshot::empty(),
@@ -201,6 +203,16 @@ impl RollupFixtureBuilder {
201203
self.last_l1_to_l2 = snapshot;
202204
self.last_l1_to_l2_subtree_sibling_path = sibling_path;
203205

206+
let converted_root = self.to_root_rollup_parity_input().public_inputs.converted_root;
207+
let empty_l1_to_l2_subtree_root = calculate_empty_tree_root(L1_TO_L2_MSG_SUBTREE_HEIGHT);
208+
self.new_l1_to_l2 = append_only_tree::insert_subtree_to_snapshot_tree(
209+
snapshot,
210+
sibling_path,
211+
empty_l1_to_l2_subtree_root,
212+
converted_root,
213+
L1_TO_L2_MSG_SUBTREE_HEIGHT as u8,
214+
);
215+
204216
*self
205217
}
206218

@@ -237,7 +249,7 @@ impl RollupFixtureBuilder {
237249
pub fn to_block_constant_data(self) -> BlockConstantData {
238250
BlockConstantData {
239251
last_archive: self.last_archive,
240-
last_l1_to_l2: self.last_l1_to_l2,
252+
new_l1_to_l2: self.new_l1_to_l2,
241253
vk_tree_root: self.vk_tree_root,
242254
protocol_contract_tree_root: self.protocol_contract_tree_root,
243255
global_variables: self.global_variables,

noir-projects/noir-protocol-circuits/crates/rollup-merge/Prover.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ accumulated_mana_used = "0x00000000000000000000000000000000000000000000000000000
1313
root = "0x11ec690ae2d1a79033acbde89cb053a6bfeb7713fdc47a18b28fde85057afb4d"
1414
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000008"
1515

16-
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.last_l1_to_l2]
16+
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.new_l1_to_l2]
1717
root = "0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"
1818
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000070"
1919

@@ -781,7 +781,7 @@ accumulated_mana_used = "0x00000000000000000000000000000000000000000000000000000
781781
root = "0x11ec690ae2d1a79033acbde89cb053a6bfeb7713fdc47a18b28fde85057afb4d"
782782
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000008"
783783

784-
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.last_l1_to_l2]
784+
[inputs.previous_rollup_data.base_or_merge_rollup_public_inputs.constants.new_l1_to_l2]
785785
root = "0x2e33ee2008411c04b99c24b313513d097a0d21a5040b6193d1f978b8226892d6"
786786
next_available_leaf_index = "0x0000000000000000000000000000000000000000000000000000000000000070"
787787

noir-projects/noir-protocol-circuits/crates/types/src/abis/block_constant_data.nr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::meta::derive;
88
pub struct BlockConstantData {
99
// Archive tree snapshot at the very beginning of the entire block.
1010
pub last_archive: AppendOnlyTreeSnapshot,
11-
// L1toL2Message tree snapshot at the very beginning of the entire block.
12-
pub last_l1_to_l2: AppendOnlyTreeSnapshot,
11+
// L1toL2Message tree snapshot after this block lands.
12+
pub new_l1_to_l2: AppendOnlyTreeSnapshot,
1313
pub vk_tree_root: Field,
1414
pub protocol_contract_tree_root: Field,
1515
pub global_variables: GlobalVariables,
@@ -19,7 +19,7 @@ impl Empty for BlockConstantData {
1919
fn empty() -> Self {
2020
BlockConstantData {
2121
last_archive: AppendOnlyTreeSnapshot::empty(),
22-
last_l1_to_l2: AppendOnlyTreeSnapshot::empty(),
22+
new_l1_to_l2: AppendOnlyTreeSnapshot::empty(),
2323
vk_tree_root: 0,
2424
protocol_contract_tree_root: 0,
2525
global_variables: GlobalVariables::empty(),
@@ -43,7 +43,7 @@ mod test {
4343
fn serialization_of_block_constant_data() {
4444
let item = BlockConstantData {
4545
last_archive: AppendOnlyTreeSnapshot { root: 123, next_available_leaf_index: 456 },
46-
last_l1_to_l2: AppendOnlyTreeSnapshot { root: 789, next_available_leaf_index: 101112 },
46+
new_l1_to_l2: AppendOnlyTreeSnapshot { root: 789, next_available_leaf_index: 101112 },
4747
vk_tree_root: 131415,
4848
protocol_contract_tree_root: 161718,
4949
global_variables: GlobalVariables {

noir-projects/noir-protocol-circuits/crates/types/src/constants.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ pub global AVM_CIRCUIT_PUBLIC_INPUTS_LENGTH: u32 = GLOBAL_VARIABLES_LENGTH
468468
+ 1 /* reverted */;
469469

470470
pub global BLOCK_CONSTANT_DATA_LENGTH: u32 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH /* last_archive */
471-
+ APPEND_ONLY_TREE_SNAPSHOT_LENGTH /* last_l1_to_l2_message_tree */
471+
+ APPEND_ONLY_TREE_SNAPSHOT_LENGTH /* new_l1_to_l2_message_tree */
472472
+ 1 /* vk_tree_root */
473473
+ 1 /* protocol_contract_tree_root */
474474
+ GLOBAL_VARIABLES_LENGTH;

0 commit comments

Comments
 (0)