@aztec/stdlib 4.0.0-nightly.20260108 → 4.0.0-nightly.20260110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/abi/contract_artifact.d.ts +2 -2
- package/dest/abi/contract_artifact.d.ts.map +1 -1
- package/dest/abi/contract_artifact.js +1 -1
- package/dest/block/l2_block.d.ts +1 -1
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +4 -2
- package/dest/block/l2_block_code_to_purge.d.ts +2 -3
- package/dest/block/l2_block_code_to_purge.d.ts.map +1 -1
- package/dest/block/l2_block_code_to_purge.js +2 -8
- package/dest/block/l2_block_header.d.ts +8 -12
- package/dest/block/l2_block_header.d.ts.map +1 -1
- package/dest/block/l2_block_header.js +22 -17
- package/dest/interfaces/aztec-node.d.ts +7 -6
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +2 -2
- package/dest/interfaces/proving-job.d.ts +4 -4
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/proving-job.js +1 -7
- package/dest/interfaces/server_circuit_prover.d.ts +4 -3
- package/dest/interfaces/server_circuit_prover.d.ts.map +1 -1
- package/dest/messaging/in_hash.d.ts +4 -2
- package/dest/messaging/in_hash.d.ts.map +1 -1
- package/dest/messaging/in_hash.js +3 -1
- package/dest/messaging/l2_to_l1_membership.d.ts +88 -6
- package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
- package/dest/messaging/l2_to_l1_membership.js +158 -42
- package/dest/messaging/out_hash.d.ts +2 -1
- package/dest/messaging/out_hash.d.ts.map +1 -1
- package/dest/messaging/out_hash.js +13 -4
- package/dest/p2p/block_attestation.d.ts +3 -6
- package/dest/p2p/block_attestation.d.ts.map +1 -1
- package/dest/p2p/consensus_payload.d.ts +3 -6
- package/dest/p2p/consensus_payload.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.d.ts +11 -12
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +26 -18
- package/dest/rollup/checkpoint_rollup_public_inputs.d.ts +6 -1
- package/dest/rollup/checkpoint_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/checkpoint_rollup_public_inputs.js +6 -2
- package/dest/rollup/root_rollup_public_inputs.d.ts +8 -3
- package/dest/rollup/root_rollup_public_inputs.d.ts.map +1 -1
- package/dest/rollup/root_rollup_public_inputs.js +6 -3
- package/dest/tests/factories.d.ts +3 -7
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +6 -11
- package/dest/tests/mocks.d.ts +5 -2
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +5 -6
- package/dest/tx/index.d.ts +1 -2
- package/dest/tx/index.d.ts.map +1 -1
- package/dest/tx/index.js +0 -1
- package/package.json +8 -8
- package/src/abi/contract_artifact.ts +10 -10
- package/src/block/l2_block.ts +3 -2
- package/src/block/l2_block_code_to_purge.ts +3 -11
- package/src/block/l2_block_header.ts +26 -17
- package/src/interfaces/aztec-node.ts +9 -6
- package/src/interfaces/proving-job.ts +2 -11
- package/src/interfaces/server_circuit_prover.ts +3 -2
- package/src/messaging/in_hash.ts +3 -1
- package/src/messaging/l2_to_l1_membership.ts +176 -52
- package/src/messaging/out_hash.ts +17 -7
- package/src/rollup/checkpoint_header.ts +30 -20
- package/src/rollup/checkpoint_rollup_public_inputs.ts +6 -0
- package/src/rollup/root_rollup_public_inputs.ts +6 -0
- package/src/tests/factories.ts +11 -15
- package/src/tests/mocks.ts +20 -14
- package/src/tx/index.ts +0 -1
- package/dest/tx/content_commitment.d.ts +0 -49
- package/dest/tx/content_commitment.d.ts.map +0 -1
- package/dest/tx/content_commitment.js +0 -90
- package/src/tx/content_commitment.ts +0 -113
|
@@ -1,9 +1,99 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
|
|
2
|
+
import type { EpochNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
4
|
import { SiblingPath, UnbalancedMerkleTreeCalculator, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* # L2-to-L1 Message Tree Structure and Leaf IDs
|
|
8
|
+
*
|
|
9
|
+
* ## Overview
|
|
10
|
+
* L2-to-L1 messages are organized in a hierarchical 4-level tree structure within each epoch:
|
|
11
|
+
* Epoch → Checkpoints → Blocks → Transactions → Messages
|
|
12
|
+
*
|
|
13
|
+
* Each level uses an unbalanced Merkle tree, and some levels use compression (skipping zero hashes).
|
|
14
|
+
*
|
|
15
|
+
* ## Tree Levels
|
|
16
|
+
*
|
|
17
|
+
* 1. **Message Tree (TX Out Hash)**
|
|
18
|
+
* - Leaves: Individual L2-to-L1 messages within a transaction
|
|
19
|
+
* - Root: TX out hash
|
|
20
|
+
* - Type: Unbalanced, non-compressed (the circuits ensure that all messages are not empty.)
|
|
21
|
+
*
|
|
22
|
+
* 2. **Block Tree**
|
|
23
|
+
* - Leaves: TX out hashes from all transactions in a block
|
|
24
|
+
* - Root: Block out hash
|
|
25
|
+
* - Type: Unbalanced, compressed (zero hashes are skipped)
|
|
26
|
+
* - Compression: If a tx has no messages (out hash = 0), that branch is ignored
|
|
27
|
+
*
|
|
28
|
+
* 3. **Checkpoint Tree**
|
|
29
|
+
* - Leaves: Block out hashes from all blocks in a checkpoint
|
|
30
|
+
* - Root: Checkpoint out hash
|
|
31
|
+
* - Type: Unbalanced, compressed (zero hashes are skipped)
|
|
32
|
+
* - Compression: If a block has no messages (out hash = 0), that branch is ignored
|
|
33
|
+
*
|
|
34
|
+
* 4. **Epoch Tree**
|
|
35
|
+
* - Leaves: Checkpoint out hashes from all checkpoints in an epoch (padded to AZTEC_MAX_EPOCH_DURATION)
|
|
36
|
+
* - Root: Epoch out hash (set in the root rollup's public inputs and inserted into the Outbox on L1 when the epoch is proven)
|
|
37
|
+
* - Type: Unbalanced, non-compressed
|
|
38
|
+
* - **Important**: Padded with zeros up to AZTEC_MAX_EPOCH_DURATION to allow for proofs of partial epochs
|
|
39
|
+
*
|
|
40
|
+
* ## Combined Membership Proof
|
|
41
|
+
* To prove a message exists in an epoch, we combine the sibling paths from all 4 trees:
|
|
42
|
+
* [message siblings] + [tx siblings] + [block siblings] + [checkpoint siblings]
|
|
43
|
+
*
|
|
44
|
+
* ## Leaf ID: Stable Message Identification
|
|
45
|
+
*
|
|
46
|
+
* Each message gets a unique, stable **leaf ID** that identifies its position in the combined tree.
|
|
47
|
+
* The leaf ID is computed as:
|
|
48
|
+
* leafId = 2^pathSize + leafIndex
|
|
49
|
+
*
|
|
50
|
+
* Where:
|
|
51
|
+
* - `pathSize`: Total length of the combined sibling path (from all 4 tree levels)
|
|
52
|
+
* - `leafIndex`: The message's index in a balanced tree representation at that height
|
|
53
|
+
*
|
|
54
|
+
* ### Why Leaf IDs Are Stable
|
|
55
|
+
*
|
|
56
|
+
* The leaf ID is based on the message's position in the tree structure, which is determined by:
|
|
57
|
+
* - The checkpoint index within the epoch
|
|
58
|
+
* - The block index within the checkpoint
|
|
59
|
+
* - The transaction index within the block
|
|
60
|
+
* - The message index within the transaction
|
|
61
|
+
*
|
|
62
|
+
* These indices are structural and do NOT depend on the total number of blocks/checkpoints in the epoch.
|
|
63
|
+
*
|
|
64
|
+
* ### Critical Property: Preserving Consumed Status
|
|
65
|
+
*
|
|
66
|
+
* **Problem**: On L1, epoch proofs can be submitted incrementally. For example:
|
|
67
|
+
* - First, a proof for checkpoints 1-10 of epoch 0 is submitted (proves the first 10 checkpoints)
|
|
68
|
+
* - Later, a proof for checkpoints 1-20 of epoch 0 is submitted (proves all 20 checkpoints)
|
|
69
|
+
*
|
|
70
|
+
* When the longer proof is submitted, it updates the epoch's out hash root on L1 to reflect the complete epoch (all 20
|
|
71
|
+
* checkpoints). However, some messages from checkpoints 1-10 may have already been consumed.
|
|
72
|
+
*
|
|
73
|
+
* **Solution**: The Outbox on L1 tracks consumed messages using a bitmap indexed by leaf ID.
|
|
74
|
+
* Because leaf IDs are stable (they don't change when more checkpoints are added to the epoch), messages that were consumed
|
|
75
|
+
* under the shorter proof remain marked as consumed under the longer proof.
|
|
76
|
+
*
|
|
77
|
+
* This prevents double-spending of L2-to-L1 messages when longer epoch proofs are submitted.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Computes the unique leaf ID for an L2-to-L1 message.
|
|
82
|
+
*
|
|
83
|
+
* The leaf ID is stable across different epoch proof lengths and is used by the Outbox
|
|
84
|
+
* on L1 to track which messages have been consumed.
|
|
85
|
+
*
|
|
86
|
+
* @param membershipWitness - Contains the leafIndex and siblingPath for the message
|
|
87
|
+
* @returns The unique leaf ID used for tracking message consumption on L1
|
|
88
|
+
*/
|
|
89
|
+
export function getL2ToL1MessageLeafId(
|
|
90
|
+
membershipWitness: Pick<L2ToL1MembershipWitness, 'leafIndex' | 'siblingPath'>,
|
|
91
|
+
): bigint {
|
|
92
|
+
return 2n ** BigInt(membershipWitness.siblingPath.pathSize) + membershipWitness.leafIndex;
|
|
93
|
+
}
|
|
94
|
+
|
|
5
95
|
export interface MessageRetrieval {
|
|
6
|
-
getL2ToL1Messages(
|
|
96
|
+
getL2ToL1Messages(epoch: EpochNumber): Promise<Fr[][][][]>;
|
|
7
97
|
}
|
|
8
98
|
|
|
9
99
|
export type L2ToL1MembershipWitness = {
|
|
@@ -14,76 +104,99 @@ export type L2ToL1MembershipWitness = {
|
|
|
14
104
|
|
|
15
105
|
export async function computeL2ToL1MembershipWitness(
|
|
16
106
|
messageRetriever: MessageRetrieval,
|
|
17
|
-
|
|
107
|
+
epoch: EpochNumber,
|
|
18
108
|
message: Fr,
|
|
19
109
|
): Promise<L2ToL1MembershipWitness | undefined> {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
110
|
+
const messagesInEpoch = await messageRetriever.getL2ToL1Messages(epoch);
|
|
111
|
+
if (messagesInEpoch.length === 0) {
|
|
22
112
|
return undefined;
|
|
23
113
|
}
|
|
24
114
|
|
|
25
|
-
return
|
|
115
|
+
return computeL2ToL1MembershipWitnessFromMessagesInEpoch(messagesInEpoch, message);
|
|
26
116
|
}
|
|
27
117
|
|
|
28
118
|
// TODO: Allow to specify the message to consume by its index or by an offset, in case there are multiple messages with
|
|
29
119
|
// the same value.
|
|
30
|
-
export function
|
|
31
|
-
|
|
120
|
+
export function computeL2ToL1MembershipWitnessFromMessagesInEpoch(
|
|
121
|
+
messagesInEpoch: Fr[][][][],
|
|
32
122
|
message: Fr,
|
|
33
123
|
): L2ToL1MembershipWitness {
|
|
34
|
-
// Find index of message in
|
|
124
|
+
// Find the index of the message in the tx, index of the tx in the block, and index of the block in the epoch.
|
|
35
125
|
let messageIndexInTx = -1;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
126
|
+
let txIndex = -1;
|
|
127
|
+
let blockIndex = -1;
|
|
128
|
+
const checkpointIndex = messagesInEpoch.findIndex(messagesInCheckpoint => {
|
|
129
|
+
blockIndex = messagesInCheckpoint.findIndex(messagesInBlock => {
|
|
130
|
+
txIndex = messagesInBlock.findIndex(messagesInTx => {
|
|
131
|
+
messageIndexInTx = messagesInTx.findIndex(msg => msg.equals(message));
|
|
132
|
+
return messageIndexInTx !== -1;
|
|
133
|
+
});
|
|
134
|
+
return txIndex !== -1;
|
|
135
|
+
});
|
|
136
|
+
return blockIndex !== -1;
|
|
39
137
|
});
|
|
40
138
|
|
|
41
|
-
if (
|
|
139
|
+
if (checkpointIndex === -1) {
|
|
42
140
|
throw new Error('The L2ToL1Message you are trying to prove inclusion of does not exist');
|
|
43
141
|
}
|
|
44
142
|
|
|
45
|
-
//
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
// Calculate txOutHash for all txs.
|
|
52
|
-
const txSubtreeRoots = messagesForAllTxs.map((messages, i) => {
|
|
53
|
-
// For a tx with no messages, we have to set an out hash of 0 to match what the circuit does.
|
|
54
|
-
if (messages.length === 0) {
|
|
55
|
-
return Fr.ZERO;
|
|
56
|
-
}
|
|
143
|
+
// Build the tx tree.
|
|
144
|
+
const messagesInTx = messagesInEpoch[checkpointIndex][blockIndex][txIndex];
|
|
145
|
+
const txTree = UnbalancedMerkleTreeCalculator.create(messagesInTx.map(msg => msg.toBuffer()));
|
|
146
|
+
// Get the sibling path of the target message in the tx tree.
|
|
147
|
+
const pathToMessageInTxSubtree = txTree.getSiblingPathByLeafIndex(messageIndexInTx);
|
|
57
148
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
149
|
+
// Build the tree of the block containing the target message.
|
|
150
|
+
const blockTree = buildBlockTree(messagesInEpoch[checkpointIndex][blockIndex]);
|
|
151
|
+
// Get the sibling path of the tx out hash in the block tree.
|
|
152
|
+
const pathToTxOutHashInBlockTree = blockTree.getSiblingPathByLeafIndex(txIndex);
|
|
61
153
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
154
|
+
// Build the tree of the checkpoint containing the target message.
|
|
155
|
+
const checkpointTree = buildCheckpointTree(messagesInEpoch[checkpointIndex]);
|
|
156
|
+
// Get the sibling path of the block out hash in the checkpoint tree.
|
|
157
|
+
const pathToBlockOutHashInCheckpointTree = checkpointTree.getSiblingPathByLeafIndex(blockIndex);
|
|
65
158
|
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
159
|
+
// Compute the out hashes of all checkpoints in the epoch.
|
|
160
|
+
let checkpointOutHashes = messagesInEpoch.map((messagesInCheckpoint, i) => {
|
|
161
|
+
if (i === checkpointIndex) {
|
|
162
|
+
return checkpointTree.getRoot();
|
|
163
|
+
}
|
|
164
|
+
return buildCheckpointTree(messagesInCheckpoint).getRoot();
|
|
165
|
+
});
|
|
166
|
+
// Pad to AZTEC_MAX_EPOCH_DURATION with zeros.
|
|
167
|
+
checkpointOutHashes = checkpointOutHashes.concat(
|
|
168
|
+
Array.from({ length: AZTEC_MAX_EPOCH_DURATION - messagesInEpoch.length }, () => Buffer.alloc(32)),
|
|
74
169
|
);
|
|
75
|
-
const root = Fr.fromBuffer(topTree.getRoot());
|
|
76
170
|
|
|
77
|
-
//
|
|
78
|
-
const
|
|
79
|
-
|
|
171
|
+
// Build the epoch tree with all the checkpoint out hashes, including the padded zeros
|
|
172
|
+
const epochTree = UnbalancedMerkleTreeCalculator.create(checkpointOutHashes);
|
|
173
|
+
// Get the sibling path of the checkpoint out hash in the epoch tree.
|
|
174
|
+
const pathToCheckpointOutHashInEpochTree = epochTree.getSiblingPathByLeafIndex(checkpointIndex);
|
|
175
|
+
|
|
176
|
+
// The root of the epoch tree should match the `out_hash` in the root rollup's public inputs.
|
|
177
|
+
const root = Fr.fromBuffer(epochTree.getRoot());
|
|
178
|
+
|
|
179
|
+
// Compute the combined sibling path by appending the tx subtree path to the block tree path, then to the checkpoint
|
|
180
|
+
// tree path, then to the epoch tree path.
|
|
181
|
+
const combinedPath = pathToMessageInTxSubtree
|
|
182
|
+
.toBufferArray()
|
|
183
|
+
.concat(pathToTxOutHashInBlockTree.toBufferArray())
|
|
184
|
+
.concat(pathToBlockOutHashInCheckpointTree.toBufferArray())
|
|
185
|
+
.concat(pathToCheckpointOutHashInEpochTree.toBufferArray());
|
|
80
186
|
|
|
81
187
|
// Compute the combined index.
|
|
82
|
-
// It is the index of the message in the balanced tree at its current
|
|
83
|
-
|
|
84
|
-
const messageLeafPosition =
|
|
85
|
-
const
|
|
86
|
-
const
|
|
188
|
+
// It is the index of the message in the balanced tree (by filling up the wonky tree with empty nodes) at its current
|
|
189
|
+
// height. It's used to validate the membership proof.
|
|
190
|
+
const messageLeafPosition = txTree.getLeafLocation(messageIndexInTx);
|
|
191
|
+
const txLeafPosition = blockTree.getLeafLocation(txIndex);
|
|
192
|
+
const blockLeafPosition = checkpointTree.getLeafLocation(blockIndex);
|
|
193
|
+
const checkpointLeafPosition = epochTree.getLeafLocation(checkpointIndex);
|
|
194
|
+
const numLeavesInLeftCheckpoints = checkpointLeafPosition.index * (1 << blockLeafPosition.level);
|
|
195
|
+
const indexAtCheckpointLevel = numLeavesInLeftCheckpoints + blockLeafPosition.index;
|
|
196
|
+
const numLeavesInLeftBlocks = indexAtCheckpointLevel * (1 << txLeafPosition.level);
|
|
197
|
+
const indexAtTxLevel = numLeavesInLeftBlocks + txLeafPosition.index;
|
|
198
|
+
const numLeavesInLeftTxs = indexAtTxLevel * (1 << messageLeafPosition.level);
|
|
199
|
+
const combinedIndex = numLeavesInLeftTxs + messageLeafPosition.index;
|
|
87
200
|
|
|
88
201
|
return {
|
|
89
202
|
root,
|
|
@@ -92,8 +205,19 @@ export function computeL2ToL1MembershipWitnessFromMessagesForAllTxs(
|
|
|
92
205
|
};
|
|
93
206
|
}
|
|
94
207
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
|
|
208
|
+
function buildCheckpointTree(messagesInCheckpoint: Fr[][][]) {
|
|
209
|
+
const blockOutHashes = messagesInCheckpoint.map(messagesInBlock => buildBlockTree(messagesInBlock).getRoot());
|
|
210
|
+
return buildCompressedTree(blockOutHashes);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function buildBlockTree(messagesInBlock: Fr[][]) {
|
|
214
|
+
const txOutHashes = messagesInBlock.map(messages => computeUnbalancedShaRoot(messages.map(msg => msg.toBuffer())));
|
|
215
|
+
return buildCompressedTree(txOutHashes);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function buildCompressedTree(leaves: Buffer[]) {
|
|
219
|
+
// Note: If a block or tx has no messages (i.e. leaf == Buffer.alloc(32)), we ignore that branch and only accumulate
|
|
220
|
+
// the non-zero hashes to match what the circuits do.
|
|
221
|
+
const valueToCompress = Buffer.alloc(32);
|
|
222
|
+
return UnbalancedMerkleTreeCalculator.create(leaves, valueToCompress);
|
|
99
223
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { AZTEC_MAX_EPOCH_DURATION } from '@aztec/constants';
|
|
2
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
1
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import {
|
|
4
|
+
import { computeCompressedUnbalancedShaRoot, computeUnbalancedShaRoot } from '@aztec/foundation/trees';
|
|
3
5
|
|
|
4
6
|
export function computeTxOutHash(messages: Fr[]): Fr {
|
|
5
7
|
if (!messages.length) {
|
|
@@ -20,6 +22,19 @@ export function computeCheckpointOutHash(messagesForAllTxs: Fr[][][]): Fr {
|
|
|
20
22
|
return aggregateOutHashes(blockOutHashes);
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
export function computeEpochOutHash(messagesInEpoch: Fr[][][][]): Fr {
|
|
26
|
+
// Must match the implementation in `compute_epoch_out_hash.nr`.
|
|
27
|
+
const checkpointOutHashes = messagesInEpoch
|
|
28
|
+
.map(checkpoint => computeCheckpointOutHash(checkpoint))
|
|
29
|
+
.map(hash => hash.toBuffer());
|
|
30
|
+
if (checkpointOutHashes.every(hash => hash.equals(Buffer.alloc(32)))) {
|
|
31
|
+
return Fr.ZERO;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const paddedOutHashes = padArrayEnd(checkpointOutHashes, Buffer.alloc(32), AZTEC_MAX_EPOCH_DURATION);
|
|
35
|
+
return Fr.fromBuffer(computeUnbalancedShaRoot(paddedOutHashes));
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
// The root of this tree should match the `out_hash` calculated in the circuits. Zero hashes are compressed to reduce
|
|
24
39
|
// cost if the non-zero leaves result in a shorter path.
|
|
25
40
|
function aggregateOutHashes(outHashes: Fr[]): Fr {
|
|
@@ -27,10 +42,5 @@ function aggregateOutHashes(outHashes: Fr[]): Fr {
|
|
|
27
42
|
return Fr.ZERO;
|
|
28
43
|
}
|
|
29
44
|
|
|
30
|
-
|
|
31
|
-
const tree = UnbalancedMerkleTreeCalculator.create(
|
|
32
|
-
outHashes.map(hash => hash.toBuffer()),
|
|
33
|
-
valueToCompress,
|
|
34
|
-
);
|
|
35
|
-
return Fr.fromBuffer(tree.getRoot());
|
|
45
|
+
return Fr.fromBuffer(computeCompressedUnbalancedShaRoot(outHashes.map(hash => hash.toBuffer())));
|
|
36
46
|
}
|
|
@@ -14,7 +14,6 @@ import { z } from 'zod';
|
|
|
14
14
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
15
15
|
import { GasFees } from '../gas/index.js';
|
|
16
16
|
import { schemas } from '../schemas/index.js';
|
|
17
|
-
import { ContentCommitment } from '../tx/content_commitment.js';
|
|
18
17
|
import type { UInt64 } from '../types/shared.js';
|
|
19
18
|
|
|
20
19
|
/**
|
|
@@ -27,8 +26,10 @@ export class CheckpointHeader {
|
|
|
27
26
|
public lastArchiveRoot: Fr,
|
|
28
27
|
/** Hash of the headers of all blocks in this checkpoint. */
|
|
29
28
|
public blockHeadersHash: Fr,
|
|
30
|
-
/**
|
|
31
|
-
public
|
|
29
|
+
/** Hash of the blobs in the checkpoint. */
|
|
30
|
+
public blobsHash: Fr,
|
|
31
|
+
/** Root of the l1 to l2 messages subtree. */
|
|
32
|
+
public inHash: Fr,
|
|
32
33
|
/** Slot number of the L2 block */
|
|
33
34
|
public slotNumber: SlotNumber,
|
|
34
35
|
/** Timestamp of the L2 block. */
|
|
@@ -48,7 +49,8 @@ export class CheckpointHeader {
|
|
|
48
49
|
.object({
|
|
49
50
|
lastArchiveRoot: schemas.Fr,
|
|
50
51
|
blockHeadersHash: schemas.Fr,
|
|
51
|
-
|
|
52
|
+
blobsHash: schemas.Fr,
|
|
53
|
+
inHash: schemas.Fr,
|
|
52
54
|
slotNumber: schemas.SlotNumber,
|
|
53
55
|
timestamp: schemas.BigInt,
|
|
54
56
|
coinbase: schemas.EthAddress,
|
|
@@ -63,7 +65,8 @@ export class CheckpointHeader {
|
|
|
63
65
|
return [
|
|
64
66
|
fields.lastArchiveRoot,
|
|
65
67
|
fields.blockHeadersHash,
|
|
66
|
-
fields.
|
|
68
|
+
fields.blobsHash,
|
|
69
|
+
fields.inHash,
|
|
67
70
|
fields.slotNumber,
|
|
68
71
|
fields.timestamp,
|
|
69
72
|
fields.coinbase,
|
|
@@ -83,7 +86,8 @@ export class CheckpointHeader {
|
|
|
83
86
|
return new CheckpointHeader(
|
|
84
87
|
reader.readObject(Fr),
|
|
85
88
|
reader.readObject(Fr),
|
|
86
|
-
reader.readObject(
|
|
89
|
+
reader.readObject(Fr),
|
|
90
|
+
reader.readObject(Fr),
|
|
87
91
|
SlotNumber(Fr.fromBuffer(reader).toNumber()),
|
|
88
92
|
reader.readUInt64(),
|
|
89
93
|
reader.readObject(EthAddress),
|
|
@@ -97,7 +101,8 @@ export class CheckpointHeader {
|
|
|
97
101
|
return (
|
|
98
102
|
this.lastArchiveRoot.equals(other.lastArchiveRoot) &&
|
|
99
103
|
this.blockHeadersHash.equals(other.blockHeadersHash) &&
|
|
100
|
-
this.
|
|
104
|
+
this.blobsHash.equals(other.blobsHash) &&
|
|
105
|
+
this.inHash.equals(other.inHash) &&
|
|
101
106
|
this.slotNumber === other.slotNumber &&
|
|
102
107
|
this.timestamp === other.timestamp &&
|
|
103
108
|
this.coinbase.equals(other.coinbase) &&
|
|
@@ -112,7 +117,8 @@ export class CheckpointHeader {
|
|
|
112
117
|
return serializeToBuffer([
|
|
113
118
|
this.lastArchiveRoot,
|
|
114
119
|
this.blockHeadersHash,
|
|
115
|
-
this.
|
|
120
|
+
this.blobsHash,
|
|
121
|
+
this.inHash,
|
|
116
122
|
new Fr(this.slotNumber),
|
|
117
123
|
bigintToUInt64BE(this.timestamp),
|
|
118
124
|
this.coinbase,
|
|
@@ -130,7 +136,8 @@ export class CheckpointHeader {
|
|
|
130
136
|
return CheckpointHeader.from({
|
|
131
137
|
lastArchiveRoot: Fr.ZERO,
|
|
132
138
|
blockHeadersHash: Fr.ZERO,
|
|
133
|
-
|
|
139
|
+
blobsHash: Fr.ZERO,
|
|
140
|
+
inHash: Fr.ZERO,
|
|
134
141
|
slotNumber: SlotNumber.ZERO,
|
|
135
142
|
timestamp: 0n,
|
|
136
143
|
coinbase: EthAddress.ZERO,
|
|
@@ -141,13 +148,12 @@ export class CheckpointHeader {
|
|
|
141
148
|
});
|
|
142
149
|
}
|
|
143
150
|
|
|
144
|
-
static random(
|
|
145
|
-
overrides: Partial<FieldsOf<CheckpointHeader>> & Partial<FieldsOf<ContentCommitment>> = {},
|
|
146
|
-
): CheckpointHeader {
|
|
151
|
+
static random(overrides: Partial<FieldsOf<CheckpointHeader>> = {}): CheckpointHeader {
|
|
147
152
|
return CheckpointHeader.from({
|
|
148
153
|
lastArchiveRoot: Fr.random(),
|
|
149
154
|
blockHeadersHash: Fr.random(),
|
|
150
|
-
|
|
155
|
+
blobsHash: Fr.random(),
|
|
156
|
+
inHash: Fr.random(),
|
|
151
157
|
slotNumber: SlotNumber(Math.floor(Math.random() * 1000) + 1),
|
|
152
158
|
timestamp: BigInt(Math.floor(Date.now() / 1000)),
|
|
153
159
|
coinbase: EthAddress.random(),
|
|
@@ -162,7 +168,8 @@ export class CheckpointHeader {
|
|
|
162
168
|
return (
|
|
163
169
|
this.lastArchiveRoot.isZero() &&
|
|
164
170
|
this.blockHeadersHash.isZero() &&
|
|
165
|
-
this.
|
|
171
|
+
this.blobsHash.isZero() &&
|
|
172
|
+
this.inHash.isZero() &&
|
|
166
173
|
this.slotNumber === 0 &&
|
|
167
174
|
this.timestamp === 0n &&
|
|
168
175
|
this.coinbase.isZero() &&
|
|
@@ -188,7 +195,8 @@ export class CheckpointHeader {
|
|
|
188
195
|
return new CheckpointHeader(
|
|
189
196
|
Fr.fromString(header.lastArchiveRoot),
|
|
190
197
|
Fr.fromString(header.blockHeadersHash),
|
|
191
|
-
|
|
198
|
+
Fr.fromString(header.blobsHash),
|
|
199
|
+
Fr.fromString(header.inHash),
|
|
192
200
|
SlotNumber.fromBigInt(header.slotNumber),
|
|
193
201
|
header.timestamp,
|
|
194
202
|
new EthAddress(hexToBuffer(header.coinbase)),
|
|
@@ -210,7 +218,8 @@ export class CheckpointHeader {
|
|
|
210
218
|
return {
|
|
211
219
|
lastArchiveRoot: this.lastArchiveRoot.toString(),
|
|
212
220
|
blockHeadersHash: this.blockHeadersHash.toString(),
|
|
213
|
-
|
|
221
|
+
blobsHash: this.blobsHash.toString(),
|
|
222
|
+
inHash: this.inHash.toString(),
|
|
214
223
|
slotNumber: BigInt(this.slotNumber),
|
|
215
224
|
timestamp: this.timestamp,
|
|
216
225
|
coinbase: this.coinbase.toString(),
|
|
@@ -227,7 +236,8 @@ export class CheckpointHeader {
|
|
|
227
236
|
return {
|
|
228
237
|
lastArchive: this.lastArchiveRoot.toString(),
|
|
229
238
|
blockHeadersHash: this.blockHeadersHash.toString(),
|
|
230
|
-
|
|
239
|
+
blobsHash: this.blobsHash.toString(),
|
|
240
|
+
inHash: this.inHash.toString(),
|
|
231
241
|
slotNumber: this.slotNumber,
|
|
232
242
|
timestamp: this.timestamp,
|
|
233
243
|
coinbase: this.coinbase.toString(),
|
|
@@ -238,16 +248,16 @@ export class CheckpointHeader {
|
|
|
238
248
|
}
|
|
239
249
|
|
|
240
250
|
[inspect.custom]() {
|
|
241
|
-
const gasfees = `da:${this.gasFees.feePerDaGas}, l2:${this.gasFees.feePerL2Gas}`;
|
|
242
251
|
return `Header {
|
|
243
252
|
lastArchiveRoot: ${this.lastArchiveRoot.toString()},
|
|
244
253
|
blockHeadersHash: ${this.blockHeadersHash.toString()},
|
|
245
|
-
|
|
254
|
+
blobsHash: ${inspect(this.blobsHash)},
|
|
255
|
+
inHash: ${inspect(this.inHash)},
|
|
246
256
|
slotNumber: ${this.slotNumber},
|
|
247
257
|
timestamp: ${this.timestamp},
|
|
248
258
|
coinbase: ${this.coinbase.toString()},
|
|
249
259
|
feeRecipient: ${this.feeRecipient.toString()},
|
|
250
|
-
gasFees:
|
|
260
|
+
gasFees: { da:${this.gasFees.feePerDaGas}, l2:${this.gasFees.feePerL2Gas} },
|
|
251
261
|
totalManaUsed: ${this.totalManaUsed.toBigInt()},
|
|
252
262
|
}`;
|
|
253
263
|
}
|
|
@@ -31,6 +31,10 @@ export class CheckpointRollupPublicInputs {
|
|
|
31
31
|
* The hashes of the headers of the constituent checkpoints.
|
|
32
32
|
*/
|
|
33
33
|
public checkpointHeaderHashes: Tuple<Fr, typeof AZTEC_MAX_EPOCH_DURATION>,
|
|
34
|
+
/**
|
|
35
|
+
* The `out_hash` values from all checkpoints in this checkpoint range.
|
|
36
|
+
*/
|
|
37
|
+
public outHashes: Tuple<Fr, typeof AZTEC_MAX_EPOCH_DURATION>,
|
|
34
38
|
/**
|
|
35
39
|
* The summed transaction fees and recipients of the constituent checkpoints.
|
|
36
40
|
*/
|
|
@@ -56,6 +60,7 @@ export class CheckpointRollupPublicInputs {
|
|
|
56
60
|
reader.readObject(AppendOnlyTreeSnapshot),
|
|
57
61
|
reader.readObject(AppendOnlyTreeSnapshot),
|
|
58
62
|
reader.readArray(AZTEC_MAX_EPOCH_DURATION, Fr),
|
|
63
|
+
reader.readArray(AZTEC_MAX_EPOCH_DURATION, Fr),
|
|
59
64
|
reader.readArray(AZTEC_MAX_EPOCH_DURATION, FeeRecipient),
|
|
60
65
|
reader.readObject(BlobAccumulator),
|
|
61
66
|
reader.readObject(BlobAccumulator),
|
|
@@ -69,6 +74,7 @@ export class CheckpointRollupPublicInputs {
|
|
|
69
74
|
this.previousArchive,
|
|
70
75
|
this.newArchive,
|
|
71
76
|
this.checkpointHeaderHashes,
|
|
77
|
+
this.outHashes,
|
|
72
78
|
this.fees,
|
|
73
79
|
this.startBlobAccumulator,
|
|
74
80
|
this.endBlobAccumulator,
|
|
@@ -21,6 +21,9 @@ export class RootRollupPublicInputs {
|
|
|
21
21
|
public previousArchiveRoot: Fr,
|
|
22
22
|
/** Root of the archive tree after this rollup is processed */
|
|
23
23
|
public endArchiveRoot: Fr,
|
|
24
|
+
/** Root of the unbalanced merkle tree consisting of the `out_hash` values from all checkpoints in this rollup. */
|
|
25
|
+
public outHash: Fr,
|
|
26
|
+
/** Hashes of checkpoint headers for this rollup. */
|
|
24
27
|
public checkpointHeaderHashes: Tuple<Fr, typeof AZTEC_MAX_EPOCH_DURATION>,
|
|
25
28
|
public fees: Tuple<FeeRecipient, typeof AZTEC_MAX_EPOCH_DURATION>,
|
|
26
29
|
public constants: EpochConstantData,
|
|
@@ -31,6 +34,7 @@ export class RootRollupPublicInputs {
|
|
|
31
34
|
return [
|
|
32
35
|
fields.previousArchiveRoot,
|
|
33
36
|
fields.endArchiveRoot,
|
|
37
|
+
fields.outHash,
|
|
34
38
|
fields.checkpointHeaderHashes,
|
|
35
39
|
fields.fees,
|
|
36
40
|
fields.constants,
|
|
@@ -58,6 +62,7 @@ export class RootRollupPublicInputs {
|
|
|
58
62
|
public static fromBuffer(buffer: Buffer | BufferReader): RootRollupPublicInputs {
|
|
59
63
|
const reader = BufferReader.asReader(buffer);
|
|
60
64
|
return new RootRollupPublicInputs(
|
|
65
|
+
Fr.fromBuffer(reader),
|
|
61
66
|
Fr.fromBuffer(reader),
|
|
62
67
|
Fr.fromBuffer(reader),
|
|
63
68
|
reader.readArray(AZTEC_MAX_EPOCH_DURATION, Fr),
|
|
@@ -88,6 +93,7 @@ export class RootRollupPublicInputs {
|
|
|
88
93
|
/** Creates a random instance. Used for testing only - will not prove/verify. */
|
|
89
94
|
static random() {
|
|
90
95
|
return new RootRollupPublicInputs(
|
|
96
|
+
Fr.random(),
|
|
91
97
|
Fr.random(),
|
|
92
98
|
Fr.random(),
|
|
93
99
|
makeTuple(AZTEC_MAX_EPOCH_DURATION, Fr.random),
|
package/src/tests/factories.ts
CHANGED
|
@@ -164,7 +164,6 @@ import { NullifierLeaf, NullifierLeafPreimage } from '../trees/nullifier_leaf.js
|
|
|
164
164
|
import { PublicDataTreeLeaf, PublicDataTreeLeafPreimage } from '../trees/public_data_leaf.js';
|
|
165
165
|
import { BlockHeader } from '../tx/block_header.js';
|
|
166
166
|
import { CallContext } from '../tx/call_context.js';
|
|
167
|
-
import { ContentCommitment } from '../tx/content_commitment.js';
|
|
168
167
|
import { FunctionData } from '../tx/function_data.js';
|
|
169
168
|
import { GlobalVariables } from '../tx/global_variables.js';
|
|
170
169
|
import { PartialStateReference } from '../tx/partial_state_reference.js';
|
|
@@ -851,10 +850,11 @@ export function makeCheckpointRollupPublicInputs(seed = 0) {
|
|
|
851
850
|
makeAppendOnlyTreeSnapshot(seed + 0x100),
|
|
852
851
|
makeAppendOnlyTreeSnapshot(seed + 0x200),
|
|
853
852
|
makeTuple(AZTEC_MAX_EPOCH_DURATION, () => fr(seed), 0x300),
|
|
854
|
-
makeTuple(AZTEC_MAX_EPOCH_DURATION, () =>
|
|
855
|
-
|
|
853
|
+
makeTuple(AZTEC_MAX_EPOCH_DURATION, () => fr(seed), 0x400),
|
|
854
|
+
makeTuple(AZTEC_MAX_EPOCH_DURATION, () => makeFeeRecipient(seed), 0x500),
|
|
856
855
|
makeBlobAccumulator(seed + 0x600),
|
|
857
|
-
|
|
856
|
+
makeBlobAccumulator(seed + 0x700),
|
|
857
|
+
makeFinalBlobBatchingChallenges(seed + 0x800),
|
|
858
858
|
);
|
|
859
859
|
}
|
|
860
860
|
|
|
@@ -886,20 +886,14 @@ export function makeRootRollupPublicInputs(seed = 0): RootRollupPublicInputs {
|
|
|
886
886
|
return new RootRollupPublicInputs(
|
|
887
887
|
fr(seed + 0x100),
|
|
888
888
|
fr(seed + 0x200),
|
|
889
|
-
|
|
889
|
+
fr(seed + 0x300),
|
|
890
|
+
makeTuple(AZTEC_MAX_EPOCH_DURATION, () => fr(seed), 0x400),
|
|
890
891
|
makeTuple(AZTEC_MAX_EPOCH_DURATION, () => makeFeeRecipient(seed), 0x500),
|
|
891
892
|
makeEpochConstantData(seed + 0x600),
|
|
892
893
|
makeFinalBlobAccumulator(seed + 0x700),
|
|
893
894
|
);
|
|
894
895
|
}
|
|
895
896
|
|
|
896
|
-
/**
|
|
897
|
-
* Makes content commitment
|
|
898
|
-
*/
|
|
899
|
-
export function makeContentCommitment(seed = 0): ContentCommitment {
|
|
900
|
-
return new ContentCommitment(fr(seed + 0x100), fr(seed + 0x200), fr(seed + 0x300));
|
|
901
|
-
}
|
|
902
|
-
|
|
903
897
|
export function makeBlockHeader(
|
|
904
898
|
seed = 0,
|
|
905
899
|
overrides: Partial<FieldsOf<Omit<BlockHeader, 'globalVariables'>>> & Partial<FieldsOf<GlobalVariables>> = {},
|
|
@@ -923,7 +917,8 @@ export function makeL2BlockHeader(
|
|
|
923
917
|
) {
|
|
924
918
|
return new L2BlockHeader(
|
|
925
919
|
makeAppendOnlyTreeSnapshot(seed + 0x100),
|
|
926
|
-
overrides?.
|
|
920
|
+
overrides?.blobsHash ?? fr(seed + 0x200),
|
|
921
|
+
overrides?.inHash ?? fr(seed + 0x300),
|
|
927
922
|
overrides?.state ?? makeStateReference(seed + 0x600),
|
|
928
923
|
makeGlobalVariables((seed += 0x700), {
|
|
929
924
|
...(blockNumber !== undefined ? { blockNumber: BlockNumber(blockNumber) } : {}),
|
|
@@ -940,7 +935,8 @@ export function makeCheckpointHeader(seed = 0) {
|
|
|
940
935
|
return CheckpointHeader.from({
|
|
941
936
|
lastArchiveRoot: fr(seed + 0x100),
|
|
942
937
|
blockHeadersHash: fr(seed + 0x150),
|
|
943
|
-
|
|
938
|
+
blobsHash: fr(seed + 0x200),
|
|
939
|
+
inHash: fr(seed + 0x210),
|
|
944
940
|
slotNumber: SlotNumber(seed + 0x300),
|
|
945
941
|
timestamp: BigInt(seed + 0x400),
|
|
946
942
|
coinbase: makeEthAddress(seed + 0x500),
|
|
@@ -987,7 +983,7 @@ function makeCountedL2ToL1Message(seed = 0) {
|
|
|
987
983
|
return new CountedL2ToL1Message(makeL2ToL1Message(seed), seed + 2);
|
|
988
984
|
}
|
|
989
985
|
|
|
990
|
-
function makeScopedL2ToL1Message(seed = 1) {
|
|
986
|
+
export function makeScopedL2ToL1Message(seed = 1) {
|
|
991
987
|
return new ScopedL2ToL1Message(makeL2ToL1Message(seed), makeAztecAddress(seed + 3));
|
|
992
988
|
}
|
|
993
989
|
|