@aztec-labs/prover-client 6.0.0-nightly.20260829
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/README.md +1 -0
- package/dest/config.d.ts +17 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +63 -0
- package/dest/index.d.ts +4 -0
- package/dest/index.d.ts.map +1 -0
- package/dest/index.js +2 -0
- package/dest/light/index.d.ts +2 -0
- package/dest/light/index.d.ts.map +1 -0
- package/dest/light/index.js +1 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts +58 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +243 -0
- package/dest/mocks/fixtures.d.ts +20 -0
- package/dest/mocks/fixtures.d.ts.map +1 -0
- package/dest/mocks/fixtures.js +96 -0
- package/dest/mocks/test_context.d.ts +93 -0
- package/dest/mocks/test_context.d.ts.map +1 -0
- package/dest/mocks/test_context.js +354 -0
- package/dest/orchestrator/block-building-helpers.d.ts +67 -0
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -0
- package/dest/orchestrator/block-building-helpers.js +274 -0
- package/dest/orchestrator/block-proving-state.d.ts +107 -0
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/block-proving-state.js +339 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts +67 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +175 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts +169 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-sub-tree-orchestrator.js +1047 -0
- package/dest/orchestrator/chonk-cache.d.ts +39 -0
- package/dest/orchestrator/chonk-cache.d.ts.map +1 -0
- package/dest/orchestrator/chonk-cache.js +80 -0
- package/dest/orchestrator/index.d.ts +4 -0
- package/dest/orchestrator/index.d.ts.map +1 -0
- package/dest/orchestrator/index.js +3 -0
- package/dest/orchestrator/orchestrator_metrics.d.ts +8 -0
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -0
- package/dest/orchestrator/orchestrator_metrics.js +13 -0
- package/dest/orchestrator/proving-scheduler.d.ts +81 -0
- package/dest/orchestrator/proving-scheduler.d.ts.map +1 -0
- package/dest/orchestrator/proving-scheduler.js +120 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts +89 -0
- package/dest/orchestrator/top-tree-orchestrator.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-orchestrator.js +233 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts +61 -0
- package/dest/orchestrator/top-tree-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/top-tree-proving-state.js +185 -0
- package/dest/orchestrator/tx-proving-state.d.ts +37 -0
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/tx-proving-state.js +77 -0
- package/dest/prover-client/factory.d.ts +6 -0
- package/dest/prover-client/factory.d.ts.map +1 -0
- package/dest/prover-client/factory.js +5 -0
- package/dest/prover-client/index.d.ts +3 -0
- package/dest/prover-client/index.d.ts.map +1 -0
- package/dest/prover-client/index.js +2 -0
- package/dest/prover-client/prover-client.d.ts +99 -0
- package/dest/prover-client/prover-client.d.ts.map +1 -0
- package/dest/prover-client/prover-client.js +163 -0
- package/dest/proving_broker/broker_prover_facade.d.ts +52 -0
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -0
- package/dest/proving_broker/broker_prover_facade.js +360 -0
- package/dest/proving_broker/config.d.ts +40 -0
- package/dest/proving_broker/config.d.ts.map +1 -0
- package/dest/proving_broker/config.js +138 -0
- package/dest/proving_broker/factory.d.ts +5 -0
- package/dest/proving_broker/factory.d.ts.map +1 -0
- package/dest/proving_broker/factory.js +13 -0
- package/dest/proving_broker/fixtures.d.ts +6 -0
- package/dest/proving_broker/fixtures.d.ts.map +1 -0
- package/dest/proving_broker/fixtures.js +13 -0
- package/dest/proving_broker/index.d.ts +11 -0
- package/dest/proving_broker/index.d.ts.map +1 -0
- package/dest/proving_broker/index.js +10 -0
- package/dest/proving_broker/proof_store/factory.d.ts +3 -0
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/factory.js +13 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts +18 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/file_store_proof_store.js +60 -0
- package/dest/proving_broker/proof_store/index.d.ts +5 -0
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/index.js +4 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts +15 -0
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/inline_proof_store.js +41 -0
- package/dest/proving_broker/proof_store/proof_store.d.ts +36 -0
- package/dest/proving_broker/proof_store/proof_store.d.ts.map +1 -0
- package/dest/proving_broker/proof_store/proof_store.js +3 -0
- package/dest/proving_broker/proving_agent.d.ts +42 -0
- package/dest/proving_broker/proving_agent.d.ts.map +1 -0
- package/dest/proving_broker/proving_agent.js +155 -0
- package/dest/proving_broker/proving_broker.d.ts +77 -0
- package/dest/proving_broker/proving_broker.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker.js +780 -0
- package/dest/proving_broker/proving_broker_database/memory.d.ts +20 -0
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database/memory.js +67 -0
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +40 -0
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database/persisted.js +623 -0
- package/dest/proving_broker/proving_broker_database.d.ts +66 -0
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_database.js +3 -0
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +31 -0
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -0
- package/dest/proving_broker/proving_broker_instrumentation.js +97 -0
- package/dest/proving_broker/proving_job_controller.d.ts +34 -0
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -0
- package/dest/proving_broker/proving_job_controller.js +184 -0
- package/dest/proving_broker/rpc.d.ts +38 -0
- package/dest/proving_broker/rpc.d.ts.map +1 -0
- package/dest/proving_broker/rpc.js +138 -0
- package/dest/test/epoch_settlement.d.ts +36 -0
- package/dest/test/epoch_settlement.d.ts.map +1 -0
- package/dest/test/epoch_settlement.js +52 -0
- package/dest/test/index.d.ts +2 -0
- package/dest/test/index.d.ts.map +1 -0
- package/dest/test/index.js +1 -0
- package/dest/test/mock_proof_store.d.ts +9 -0
- package/dest/test/mock_proof_store.d.ts.map +1 -0
- package/dest/test/mock_proof_store.js +10 -0
- package/dest/test/mock_prover.d.ts +38 -0
- package/dest/test/mock_prover.d.ts.map +1 -0
- package/dest/test/mock_prover.js +91 -0
- package/package.json +113 -0
- package/src/config.ts +87 -0
- package/src/index.ts +4 -0
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +342 -0
- package/src/mocks/fixtures.ts +120 -0
- package/src/mocks/test_context.ts +477 -0
- package/src/orchestrator/block-building-helpers.ts +486 -0
- package/src/orchestrator/block-proving-state.ts +457 -0
- package/src/orchestrator/checkpoint-proving-state.ts +247 -0
- package/src/orchestrator/checkpoint-sub-tree-orchestrator.ts +1010 -0
- package/src/orchestrator/chonk-cache.ts +99 -0
- package/src/orchestrator/index.ts +12 -0
- package/src/orchestrator/orchestrator_metrics.ts +18 -0
- package/src/orchestrator/proving-scheduler.ts +160 -0
- package/src/orchestrator/top-tree-orchestrator.ts +394 -0
- package/src/orchestrator/top-tree-proving-state.ts +219 -0
- package/src/orchestrator/tx-proving-state.ts +121 -0
- package/src/prover-client/factory.ts +18 -0
- package/src/prover-client/index.ts +2 -0
- package/src/prover-client/prover-client.ts +286 -0
- package/src/proving_broker/broker_prover_facade.ts +626 -0
- package/src/proving_broker/config.ts +178 -0
- package/src/proving_broker/factory.ts +19 -0
- package/src/proving_broker/fixtures.ts +20 -0
- package/src/proving_broker/index.ts +10 -0
- package/src/proving_broker/proof_store/factory.ts +20 -0
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +4 -0
- package/src/proving_broker/proof_store/inline_proof_store.ts +63 -0
- package/src/proving_broker/proof_store/proof_store.ts +54 -0
- package/src/proving_broker/proving_agent.ts +210 -0
- package/src/proving_broker/proving_broker.ts +888 -0
- package/src/proving_broker/proving_broker_database/memory.ts +78 -0
- package/src/proving_broker/proving_broker_database/persisted.ts +296 -0
- package/src/proving_broker/proving_broker_database.ts +75 -0
- package/src/proving_broker/proving_broker_instrumentation.ts +133 -0
- package/src/proving_broker/proving_job_controller.ts +199 -0
- package/src/proving_broker/rpc.ts +131 -0
- package/src/test/epoch_settlement.ts +82 -0
- package/src/test/index.ts +1 -0
- package/src/test/mock_proof_store.ts +14 -0
- package/src/test/mock_prover.ts +304 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { encodeBlockEndBlobData } from '@aztec-labs/blob-lib';
|
|
2
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
3
|
+
import { UnbalancedTreeStore } from '@aztec-labs/foundation/trees';
|
|
4
|
+
import { L1ToL2MessageBundle, makeL1ToL2MessageBundle } from '@aztec-labs/stdlib/messaging';
|
|
5
|
+
import { BlockRootNoTxsRollupPrivateInputs, BlockRootRollupPrivateInputs, BlockRootSingleTxRollupPrivateInputs, TxMergeRollupPrivateInputs } from '@aztec-labs/stdlib/rollup';
|
|
6
|
+
import { BlockHeader, GlobalVariables } from '@aztec-labs/stdlib/tx';
|
|
7
|
+
import { buildHeaderFromCircuitOutputs, toProofData } from './block-building-helpers.js';
|
|
8
|
+
/**
|
|
9
|
+
* The current state of the proving schedule for a given block. Managed by ProvingState.
|
|
10
|
+
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
11
|
+
*/ export class BlockProvingState {
|
|
12
|
+
index;
|
|
13
|
+
blockNumber;
|
|
14
|
+
totalNumTxs;
|
|
15
|
+
constants;
|
|
16
|
+
timestamp;
|
|
17
|
+
lastArchiveTreeSnapshot;
|
|
18
|
+
lastArchiveSiblingPath;
|
|
19
|
+
previousState;
|
|
20
|
+
startL1ToL2MessageTreeSnapshot;
|
|
21
|
+
newL1ToL2MessageTreeSnapshot;
|
|
22
|
+
l1ToL2MessageFrontierHint;
|
|
23
|
+
l1ToL2Messages;
|
|
24
|
+
startMsgSponge;
|
|
25
|
+
endMsgSponge;
|
|
26
|
+
startSpongeBlob;
|
|
27
|
+
parentCheckpoint;
|
|
28
|
+
baseOrMergeProofs;
|
|
29
|
+
blockRootProof;
|
|
30
|
+
builtBlockHeader;
|
|
31
|
+
builtArchive;
|
|
32
|
+
endState;
|
|
33
|
+
endSpongeBlob;
|
|
34
|
+
txs;
|
|
35
|
+
error;
|
|
36
|
+
constructor(index, blockNumber, totalNumTxs, constants, timestamp, lastArchiveTreeSnapshot, lastArchiveSiblingPath, // The full state reference of the previous block, before this block's bundle is appended. Feeds the msgs-only
|
|
37
|
+
// block root, whose zero-tx block has no tx constants to pin the previous state.
|
|
38
|
+
previousState, // This block's L1-to-L2 message tree snapshot before and after its own bundle. The start is
|
|
39
|
+
// the previous block's end (block-merge continuity); the end is this block's own post-bundle snapshot.
|
|
40
|
+
startL1ToL2MessageTreeSnapshot, newL1ToL2MessageTreeSnapshot, // Full-height frontier (left-sibling path) at the block's start index, pinning the append at a compact index.
|
|
41
|
+
l1ToL2MessageFrontierHint, // This block's own real L1-to-L2 message leaves (unpadded slice).
|
|
42
|
+
l1ToL2Messages, // Message sponge threaded across the checkpoint's blocks: the start is the previous block's
|
|
43
|
+
// end sponge (empty for the first block), the end absorbs this block's own slice. Block merges assert the
|
|
44
|
+
// continuity, so the end is exposed for the next block to inherit.
|
|
45
|
+
startMsgSponge, endMsgSponge, startSpongeBlob, parentCheckpoint){
|
|
46
|
+
this.index = index;
|
|
47
|
+
this.blockNumber = blockNumber;
|
|
48
|
+
this.totalNumTxs = totalNumTxs;
|
|
49
|
+
this.constants = constants;
|
|
50
|
+
this.timestamp = timestamp;
|
|
51
|
+
this.lastArchiveTreeSnapshot = lastArchiveTreeSnapshot;
|
|
52
|
+
this.lastArchiveSiblingPath = lastArchiveSiblingPath;
|
|
53
|
+
this.previousState = previousState;
|
|
54
|
+
this.startL1ToL2MessageTreeSnapshot = startL1ToL2MessageTreeSnapshot;
|
|
55
|
+
this.newL1ToL2MessageTreeSnapshot = newL1ToL2MessageTreeSnapshot;
|
|
56
|
+
this.l1ToL2MessageFrontierHint = l1ToL2MessageFrontierHint;
|
|
57
|
+
this.l1ToL2Messages = l1ToL2Messages;
|
|
58
|
+
this.startMsgSponge = startMsgSponge;
|
|
59
|
+
this.endMsgSponge = endMsgSponge;
|
|
60
|
+
this.startSpongeBlob = startSpongeBlob;
|
|
61
|
+
this.parentCheckpoint = parentCheckpoint;
|
|
62
|
+
this.baseOrMergeProofs = new UnbalancedTreeStore(0);
|
|
63
|
+
this.txs = [];
|
|
64
|
+
this.baseOrMergeProofs = new UnbalancedTreeStore(totalNumTxs);
|
|
65
|
+
}
|
|
66
|
+
/** The message sponge after absorbing this block's slice; inherited by the next block as its start sponge. */ getEndMsgSponge() {
|
|
67
|
+
return this.endMsgSponge;
|
|
68
|
+
}
|
|
69
|
+
get epochNumber() {
|
|
70
|
+
return this.parentCheckpoint.epochNumber;
|
|
71
|
+
}
|
|
72
|
+
// Adds a transaction to the proving state, returns it's index
|
|
73
|
+
addNewTx(tx) {
|
|
74
|
+
if (!this.isAcceptingTxs()) {
|
|
75
|
+
throw new Error(`Cannot add more txs to block ${this.blockNumber}.`);
|
|
76
|
+
}
|
|
77
|
+
const txIndex = this.txs.length;
|
|
78
|
+
this.txs[txIndex] = tx;
|
|
79
|
+
return txIndex;
|
|
80
|
+
}
|
|
81
|
+
isAcceptingTxs() {
|
|
82
|
+
return this.txs.length < this.totalNumTxs;
|
|
83
|
+
}
|
|
84
|
+
getProcessedTxs() {
|
|
85
|
+
return this.txs.map((t)=>t.processedTx);
|
|
86
|
+
}
|
|
87
|
+
tryStartProvingBase(txIndex) {
|
|
88
|
+
if (this.baseOrMergeProofs.getLeaf(txIndex)?.isProving) {
|
|
89
|
+
return false;
|
|
90
|
+
} else {
|
|
91
|
+
this.baseOrMergeProofs.setLeaf(txIndex, {
|
|
92
|
+
isProving: true
|
|
93
|
+
});
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
setBaseRollupProof(txIndex, provingOutput) {
|
|
98
|
+
return this.baseOrMergeProofs.setLeaf(txIndex, {
|
|
99
|
+
provingOutput
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
tryStartProvingMerge(location) {
|
|
103
|
+
if (this.baseOrMergeProofs.getNode(location)?.isProving) {
|
|
104
|
+
return false;
|
|
105
|
+
} else {
|
|
106
|
+
this.baseOrMergeProofs.setNode(location, {
|
|
107
|
+
isProving: true
|
|
108
|
+
});
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
setMergeRollupProof(location, provingOutput) {
|
|
113
|
+
this.baseOrMergeProofs.setNode(location, {
|
|
114
|
+
provingOutput
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
tryStartProvingBlockRoot() {
|
|
118
|
+
if (this.blockRootProof?.isProving) {
|
|
119
|
+
return false;
|
|
120
|
+
} else {
|
|
121
|
+
this.blockRootProof = {
|
|
122
|
+
isProving: true
|
|
123
|
+
};
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
setBlockRootRollupProof(provingOutput) {
|
|
128
|
+
this.blockRootProof = {
|
|
129
|
+
provingOutput
|
|
130
|
+
};
|
|
131
|
+
return this.parentCheckpoint.setBlockRootRollupProof(this.index, provingOutput);
|
|
132
|
+
}
|
|
133
|
+
getBlockRootRollupOutput() {
|
|
134
|
+
return this.blockRootProof?.provingOutput?.inputs;
|
|
135
|
+
}
|
|
136
|
+
async buildBlockHeader() {
|
|
137
|
+
if (this.isAcceptingTxs()) {
|
|
138
|
+
throw new Error('All txs must be added to the block before building the header.');
|
|
139
|
+
}
|
|
140
|
+
if (!this.endState) {
|
|
141
|
+
throw new Error('Call `setEndState` first.');
|
|
142
|
+
}
|
|
143
|
+
if (!this.endSpongeBlob) {
|
|
144
|
+
throw new Error('Call `setEndSpongeBlob` first.');
|
|
145
|
+
}
|
|
146
|
+
const endSpongeBlob = this.endSpongeBlob.clone();
|
|
147
|
+
const endSpongeBlobHash = await endSpongeBlob.squeeze();
|
|
148
|
+
this.builtBlockHeader = new BlockHeader(this.lastArchiveTreeSnapshot, this.endState, endSpongeBlobHash, this.#getGlobalVariables(), this.#getTotalFees(), new Fr(this.#getTotalManaUsed()));
|
|
149
|
+
return this.builtBlockHeader;
|
|
150
|
+
}
|
|
151
|
+
getBuiltBlockHeader() {
|
|
152
|
+
return this.builtBlockHeader;
|
|
153
|
+
}
|
|
154
|
+
setBuiltArchive(archive) {
|
|
155
|
+
this.builtArchive = archive;
|
|
156
|
+
}
|
|
157
|
+
getBuiltArchive() {
|
|
158
|
+
return this.builtArchive;
|
|
159
|
+
}
|
|
160
|
+
getStartSpongeBlob() {
|
|
161
|
+
return this.startSpongeBlob;
|
|
162
|
+
}
|
|
163
|
+
setEndSpongeBlob(endSpongeBlob) {
|
|
164
|
+
this.endSpongeBlob = endSpongeBlob;
|
|
165
|
+
}
|
|
166
|
+
getEndSpongeBlob() {
|
|
167
|
+
return this.endSpongeBlob;
|
|
168
|
+
}
|
|
169
|
+
setEndState(endState) {
|
|
170
|
+
this.endState = endState;
|
|
171
|
+
}
|
|
172
|
+
hasEndState() {
|
|
173
|
+
return !!this.endState;
|
|
174
|
+
}
|
|
175
|
+
getBlockEndBlobFields() {
|
|
176
|
+
return encodeBlockEndBlobData(this.getBlockEndBlobData());
|
|
177
|
+
}
|
|
178
|
+
getBlockEndBlobData() {
|
|
179
|
+
if (!this.endState) {
|
|
180
|
+
throw new Error('Call `setEndState` first.');
|
|
181
|
+
}
|
|
182
|
+
const partial = this.endState.partial;
|
|
183
|
+
return {
|
|
184
|
+
blockEndMarker: {
|
|
185
|
+
numTxs: this.totalNumTxs,
|
|
186
|
+
timestamp: this.timestamp,
|
|
187
|
+
blockNumber: this.blockNumber
|
|
188
|
+
},
|
|
189
|
+
blockEndStateField: {
|
|
190
|
+
l1ToL2MessageNextAvailableLeafIndex: this.newL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex,
|
|
191
|
+
noteHashNextAvailableLeafIndex: partial.noteHashTree.nextAvailableLeafIndex,
|
|
192
|
+
nullifierNextAvailableLeafIndex: partial.nullifierTree.nextAvailableLeafIndex,
|
|
193
|
+
publicDataNextAvailableLeafIndex: partial.publicDataTree.nextAvailableLeafIndex,
|
|
194
|
+
totalManaUsed: this.#getTotalManaUsed()
|
|
195
|
+
},
|
|
196
|
+
lastArchiveRoot: this.lastArchiveTreeSnapshot.root,
|
|
197
|
+
noteHashRoot: partial.noteHashTree.root,
|
|
198
|
+
nullifierRoot: partial.nullifierTree.root,
|
|
199
|
+
publicDataRoot: partial.publicDataTree.root,
|
|
200
|
+
// Every block carries its own post-bundle l1-to-l2 message tree root.
|
|
201
|
+
l1ToL2MessageRoot: this.newL1ToL2MessageTreeSnapshot.root
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
getBlockBlobData() {
|
|
205
|
+
return {
|
|
206
|
+
...this.getBlockEndBlobData(),
|
|
207
|
+
txs: this.getTxEffects().map((t)=>t.toTxBlobData())
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
getTxEffects() {
|
|
211
|
+
return this.txs.map((t)=>t.processedTx.txEffect);
|
|
212
|
+
}
|
|
213
|
+
getParentLocation(location) {
|
|
214
|
+
return this.baseOrMergeProofs.getParentLocation(location);
|
|
215
|
+
}
|
|
216
|
+
getMergeRollupInputs(mergeLocation) {
|
|
217
|
+
const [left, right] = this.baseOrMergeProofs.getChildren(mergeLocation).map((c)=>c?.provingOutput);
|
|
218
|
+
if (!left || !right) {
|
|
219
|
+
throw new Error('At least one child is not ready for the merge rollup.');
|
|
220
|
+
}
|
|
221
|
+
return new TxMergeRollupPrivateInputs([
|
|
222
|
+
toProofData(left),
|
|
223
|
+
toProofData(right)
|
|
224
|
+
]);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The block root variant is selected by transaction count alone. Whether this is the checkpoint's first block is
|
|
228
|
+
* expressed through the start sponge values it feeds the circuit, which the checkpoint root pins to their initial
|
|
229
|
+
* values for the leftmost block and the block merge pins to the previous block's end values otherwise.
|
|
230
|
+
*/ getBlockRootRollupTypeAndInputs() {
|
|
231
|
+
const provingOutputs = this.#getChildProvingOutputsForBlockRoot();
|
|
232
|
+
if (!provingOutputs.every((p)=>!!p)) {
|
|
233
|
+
throw new Error('At least one child is not ready for the block root rollup.');
|
|
234
|
+
}
|
|
235
|
+
const previousRollups = provingOutputs.map((p)=>toProofData(p));
|
|
236
|
+
const messageBundle = this.#getMessageBundle();
|
|
237
|
+
const frontierHint = this.#getFrontierHint();
|
|
238
|
+
const startMsgSponge = this.startMsgSponge;
|
|
239
|
+
const [leftRollup, rightRollup] = previousRollups;
|
|
240
|
+
if (!leftRollup) {
|
|
241
|
+
return {
|
|
242
|
+
rollupType: 'rollup-block-root-no-txs',
|
|
243
|
+
inputs: new BlockRootNoTxsRollupPrivateInputs(this.lastArchiveTreeSnapshot, this.previousState, this.constants, this.timestamp, this.startSpongeBlob, startMsgSponge, messageBundle, frontierHint, this.lastArchiveSiblingPath)
|
|
244
|
+
};
|
|
245
|
+
} else if (!rightRollup) {
|
|
246
|
+
return {
|
|
247
|
+
rollupType: 'rollup-block-root-single-tx',
|
|
248
|
+
inputs: new BlockRootSingleTxRollupPrivateInputs(leftRollup, messageBundle, this.startL1ToL2MessageTreeSnapshot, startMsgSponge, frontierHint, this.lastArchiveSiblingPath)
|
|
249
|
+
};
|
|
250
|
+
} else {
|
|
251
|
+
return {
|
|
252
|
+
rollupType: 'rollup-block-root',
|
|
253
|
+
inputs: new BlockRootRollupPrivateInputs([
|
|
254
|
+
leftRollup,
|
|
255
|
+
rightRollup
|
|
256
|
+
], messageBundle, this.startL1ToL2MessageTreeSnapshot, startMsgSponge, frontierHint, this.lastArchiveSiblingPath)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* The real-count message bundle this block appends: the block's own message slice, inserted at
|
|
262
|
+
* compact indices and absorbed into its block-root message sponge.
|
|
263
|
+
*/ #getMessageBundle() {
|
|
264
|
+
return this.l1ToL2Messages.length === 0 ? L1ToL2MessageBundle.empty() : makeL1ToL2MessageBundle(this.l1ToL2Messages);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Full-height frontier hint for the bundle append: the left-sibling path at the block's compact start index, which
|
|
268
|
+
* the block-root circuit re-hashes against its start snapshot root.
|
|
269
|
+
*/ #getFrontierHint() {
|
|
270
|
+
return this.l1ToL2MessageFrontierHint;
|
|
271
|
+
}
|
|
272
|
+
// Returns a specific transaction proving state
|
|
273
|
+
getTxProvingState(txIndex) {
|
|
274
|
+
return this.txs[txIndex];
|
|
275
|
+
}
|
|
276
|
+
async buildHeaderFromProvingOutputs() {
|
|
277
|
+
if (!this.blockRootProof?.provingOutput) {
|
|
278
|
+
throw new Error('Block root rollup is not ready.');
|
|
279
|
+
}
|
|
280
|
+
return await buildHeaderFromCircuitOutputs(this.blockRootProof.provingOutput.inputs);
|
|
281
|
+
}
|
|
282
|
+
isReadyForMergeRollup(location) {
|
|
283
|
+
return !!this.baseOrMergeProofs.getSibling(location)?.provingOutput;
|
|
284
|
+
}
|
|
285
|
+
// Returns true if we have sufficient inputs to execute the block root rollup. Parity no longer gates the block root
|
|
286
|
+
// (it moved to the checkpoint root), so the block root is ready once its child tx proofs land.
|
|
287
|
+
isReadyForBlockRootRollup() {
|
|
288
|
+
const childProofs = this.#getChildProvingOutputsForBlockRoot();
|
|
289
|
+
return childProofs.every((p)=>!!p);
|
|
290
|
+
}
|
|
291
|
+
isComplete() {
|
|
292
|
+
return !!this.blockRootProof;
|
|
293
|
+
}
|
|
294
|
+
verifyState() {
|
|
295
|
+
return this.parentCheckpoint.verifyState();
|
|
296
|
+
}
|
|
297
|
+
getError() {
|
|
298
|
+
return this.error;
|
|
299
|
+
}
|
|
300
|
+
reject(reason) {
|
|
301
|
+
this.error = reason;
|
|
302
|
+
this.parentCheckpoint.reject(reason);
|
|
303
|
+
}
|
|
304
|
+
#getChildProvingOutputsForBlockRoot() {
|
|
305
|
+
if (this.totalNumTxs === 0) {
|
|
306
|
+
return [];
|
|
307
|
+
}
|
|
308
|
+
const rootLocation = {
|
|
309
|
+
level: 0,
|
|
310
|
+
index: 0
|
|
311
|
+
};
|
|
312
|
+
// If there's only 1 tx, its base rollup proof will be stored at the root.
|
|
313
|
+
return this.totalNumTxs === 1 ? [
|
|
314
|
+
this.baseOrMergeProofs.getNode(rootLocation)?.provingOutput
|
|
315
|
+
] : this.baseOrMergeProofs.getChildren(rootLocation).map((c)=>c?.provingOutput);
|
|
316
|
+
}
|
|
317
|
+
#getGlobalVariables() {
|
|
318
|
+
if (this.txs.length) {
|
|
319
|
+
return this.txs[0].processedTx.globalVariables;
|
|
320
|
+
}
|
|
321
|
+
const constants = this.constants;
|
|
322
|
+
return GlobalVariables.from({
|
|
323
|
+
chainId: constants.chainId,
|
|
324
|
+
version: constants.version,
|
|
325
|
+
blockNumber: this.blockNumber,
|
|
326
|
+
slotNumber: constants.slotNumber,
|
|
327
|
+
timestamp: this.timestamp,
|
|
328
|
+
coinbase: constants.coinbase,
|
|
329
|
+
feeRecipient: constants.feeRecipient,
|
|
330
|
+
gasFees: constants.gasFees
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
#getTotalFees() {
|
|
334
|
+
return this.txs.reduce((acc, tx)=>acc.add(tx.processedTx.txEffect.transactionFee), Fr.ZERO);
|
|
335
|
+
}
|
|
336
|
+
#getTotalManaUsed() {
|
|
337
|
+
return this.txs.reduce((acc, tx)=>acc + BigInt(tx.processedTx.gasUsed.billedGas.l2Gas), 0n);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ARCHIVE_HEIGHT, L1_TO_L2_MSG_TREE_HEIGHT, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec-labs/constants';
|
|
2
|
+
import { BlockNumber } from '@aztec-labs/foundation/branded-types';
|
|
3
|
+
import { Fr } from '@aztec-labs/foundation/curves/bn254';
|
|
4
|
+
import type { Tuple } from '@aztec-labs/foundation/serialize';
|
|
5
|
+
import { type TreeNodeLocation } from '@aztec-labs/foundation/trees';
|
|
6
|
+
import type { PublicInputsAndRecursiveProof } from '@aztec-labs/stdlib/interfaces/server';
|
|
7
|
+
import { InboxParityPrivateInputs, type ParityPublicInputs } from '@aztec-labs/stdlib/parity';
|
|
8
|
+
import { BlockMergeRollupPrivateInputs, BlockRollupPublicInputs, CheckpointConstantData } from '@aztec-labs/stdlib/rollup';
|
|
9
|
+
import type { AppendOnlyTreeSnapshot } from '@aztec-labs/stdlib/trees';
|
|
10
|
+
import type { BlockHeader, StateReference } from '@aztec-labs/stdlib/tx';
|
|
11
|
+
import type { UInt64 } from '@aztec-labs/stdlib/types';
|
|
12
|
+
import { BlockProvingState } from './block-proving-state.js';
|
|
13
|
+
export declare class CheckpointProvingState {
|
|
14
|
+
readonly index: number;
|
|
15
|
+
readonly constants: CheckpointConstantData;
|
|
16
|
+
readonly totalNumBlocks: number;
|
|
17
|
+
private readonly headerOfLastBlockInPreviousCheckpoint;
|
|
18
|
+
private readonly lastArchiveSiblingPath;
|
|
19
|
+
private readonly l1ToL2Messages;
|
|
20
|
+
private readonly startInboxRollingHash;
|
|
21
|
+
readonly epochNumber: number;
|
|
22
|
+
/** Owner's liveness check. `verifyState()` returns false once this returns false. */
|
|
23
|
+
private readonly isAlive;
|
|
24
|
+
/** Owner's failure callback. Invoked from `reject` to surface the error upward. */
|
|
25
|
+
private readonly onReject;
|
|
26
|
+
private blockProofs;
|
|
27
|
+
private inboxParityProof;
|
|
28
|
+
private blocks;
|
|
29
|
+
private error;
|
|
30
|
+
readonly firstBlockNumber: BlockNumber;
|
|
31
|
+
constructor(index: number, constants: CheckpointConstantData, totalNumBlocks: number, headerOfLastBlockInPreviousCheckpoint: BlockHeader, lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, l1ToL2Messages: Fr[], startInboxRollingHash: Fr, epochNumber: number,
|
|
32
|
+
/** Owner's liveness check. `verifyState()` returns false once this returns false. */
|
|
33
|
+
isAlive: () => boolean,
|
|
34
|
+
/** Owner's failure callback. Invoked from `reject` to surface the error upward. */
|
|
35
|
+
onReject: (reason: string) => void);
|
|
36
|
+
/** The checkpoint's real L1-to-L2 messages (unpadded), consumed across its blocks. */
|
|
37
|
+
getL1ToL2Messages(): Fr[];
|
|
38
|
+
startNewBlock(blockNumber: BlockNumber, timestamp: UInt64, totalNumTxs: number, lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot, lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, previousState: StateReference, startL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, endL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, l1ToL2MessageFrontierHint: Tuple<Fr, typeof L1_TO_L2_MSG_TREE_HEIGHT>, l1ToL2Messages: Fr[]): Promise<BlockProvingState>;
|
|
39
|
+
isAcceptingBlocks(): boolean;
|
|
40
|
+
setBlockRootRollupProof(blockIndex: number, provingOutput: PublicInputsAndRecursiveProof<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): TreeNodeLocation;
|
|
41
|
+
tryStartProvingBlockMerge(location: TreeNodeLocation): boolean;
|
|
42
|
+
setBlockMergeRollupProof(location: TreeNodeLocation, provingOutput: PublicInputsAndRecursiveProof<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
|
|
43
|
+
/**
|
|
44
|
+
* Builds the checkpoint's single InboxParity input. The circuit is sized to the smallest ladder rung that fits the
|
|
45
|
+
* message count and the rolling hash starts from the previous checkpoint's end.
|
|
46
|
+
*/
|
|
47
|
+
getInboxParityInputs(): InboxParityPrivateInputs;
|
|
48
|
+
tryStartProvingInboxParity(): boolean;
|
|
49
|
+
setInboxParityProof(provingOutput: PublicInputsAndRecursiveProof<ParityPublicInputs>): void;
|
|
50
|
+
getInboxParityProof(): PublicInputsAndRecursiveProof<ParityPublicInputs, 410> | undefined;
|
|
51
|
+
getParentLocation(location: TreeNodeLocation): TreeNodeLocation;
|
|
52
|
+
getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation): BlockMergeRollupPrivateInputs;
|
|
53
|
+
getBlockProvingStateByBlockNumber(blockNumber: BlockNumber): BlockProvingState | undefined;
|
|
54
|
+
isReadyForBlockMerge(location: TreeNodeLocation): boolean;
|
|
55
|
+
verifyState(): boolean;
|
|
56
|
+
getError(): string | undefined;
|
|
57
|
+
cancel(): void;
|
|
58
|
+
reject(reason: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the block-level proof outputs that feed into the checkpoint root rollup.
|
|
61
|
+
* Used by `CheckpointSubTreeOrchestrator` to surface its sub-tree result.
|
|
62
|
+
*/
|
|
63
|
+
getSubTreeOutputProofs(): (PublicInputsAndRecursiveProof<BlockRollupPublicInputs, 480> | undefined)[];
|
|
64
|
+
/** Sibling path of the archive tree captured before any block in this checkpoint landed. */
|
|
65
|
+
getLastArchiveSiblingPath(): [Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr, Fr,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E,MAAM,QAG3B;IAED;;;OAGG;IACI,sBAAsB,gFAK5B;IAED,4FAA4F;IACrF,yBAAyB,6HAE/B;CACF"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { SpongeBlob } from '@aztec-labs/blob-lib';
|
|
2
|
+
import { BlockNumber } from '@aztec-labs/foundation/branded-types';
|
|
3
|
+
import { UnbalancedTreeStore } from '@aztec-labs/foundation/trees';
|
|
4
|
+
import { L1ToL2MessageSponge } from '@aztec-labs/stdlib/messaging';
|
|
5
|
+
import { InboxParityPrivateInputs } from '@aztec-labs/stdlib/parity';
|
|
6
|
+
import { BlockMergeRollupPrivateInputs } from '@aztec-labs/stdlib/rollup';
|
|
7
|
+
import { toProofData } from './block-building-helpers.js';
|
|
8
|
+
import { BlockProvingState } from './block-proving-state.js';
|
|
9
|
+
export class CheckpointProvingState {
|
|
10
|
+
index;
|
|
11
|
+
constants;
|
|
12
|
+
totalNumBlocks;
|
|
13
|
+
headerOfLastBlockInPreviousCheckpoint;
|
|
14
|
+
lastArchiveSiblingPath;
|
|
15
|
+
l1ToL2Messages;
|
|
16
|
+
startInboxRollingHash;
|
|
17
|
+
epochNumber;
|
|
18
|
+
isAlive;
|
|
19
|
+
onReject;
|
|
20
|
+
blockProofs;
|
|
21
|
+
// The checkpoint's single InboxParity proof. Parity gates the checkpoint root, not the first block root: one
|
|
22
|
+
// variable-size proof per checkpoint replaces the former base + root parity fan-in. Surfaced as part of the
|
|
23
|
+
// sub-tree result.
|
|
24
|
+
inboxParityProof;
|
|
25
|
+
blocks;
|
|
26
|
+
error;
|
|
27
|
+
firstBlockNumber;
|
|
28
|
+
constructor(index, constants, totalNumBlocks, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, // Inbox rolling hash before this checkpoint's messages (the previous checkpoint's end value; genesis is zero).
|
|
29
|
+
// Threaded into the InboxParity circuit so the resulting checkpoint header rolling hash matches the proposer's.
|
|
30
|
+
startInboxRollingHash, epochNumber, /** Owner's liveness check. `verifyState()` returns false once this returns false. */ isAlive, /** Owner's failure callback. Invoked from `reject` to surface the error upward. */ onReject){
|
|
31
|
+
this.index = index;
|
|
32
|
+
this.constants = constants;
|
|
33
|
+
this.totalNumBlocks = totalNumBlocks;
|
|
34
|
+
this.headerOfLastBlockInPreviousCheckpoint = headerOfLastBlockInPreviousCheckpoint;
|
|
35
|
+
this.lastArchiveSiblingPath = lastArchiveSiblingPath;
|
|
36
|
+
this.l1ToL2Messages = l1ToL2Messages;
|
|
37
|
+
this.startInboxRollingHash = startInboxRollingHash;
|
|
38
|
+
this.epochNumber = epochNumber;
|
|
39
|
+
this.isAlive = isAlive;
|
|
40
|
+
this.onReject = onReject;
|
|
41
|
+
this.blocks = [];
|
|
42
|
+
this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
|
|
43
|
+
this.firstBlockNumber = BlockNumber(headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1);
|
|
44
|
+
}
|
|
45
|
+
/** The checkpoint's real L1-to-L2 messages (unpadded), consumed across its blocks. */ getL1ToL2Messages() {
|
|
46
|
+
return this.l1ToL2Messages;
|
|
47
|
+
}
|
|
48
|
+
async startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath, // The full state reference of the previous block (before this block's message bundle is appended). Feeds the
|
|
49
|
+
// msgs-only block root, whose zero-tx block carries no tx constants to pin the previous state.
|
|
50
|
+
previousState, // Per-block L1-to-L2 message state: the block's start snapshot (its parent's end), its own
|
|
51
|
+
// post-bundle end snapshot, the full-height frontier at the start index, and its own real message slice.
|
|
52
|
+
startL1ToL2MessageTreeSnapshot, endL1ToL2MessageTreeSnapshot, l1ToL2MessageFrontierHint, l1ToL2Messages) {
|
|
53
|
+
const index = Number(blockNumber) - Number(this.firstBlockNumber);
|
|
54
|
+
if (index >= this.totalNumBlocks) {
|
|
55
|
+
throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
|
|
56
|
+
}
|
|
57
|
+
const startSpongeBlob = index === 0 ? SpongeBlob.init() : this.blocks[index - 1]?.getEndSpongeBlob();
|
|
58
|
+
if (!startSpongeBlob) {
|
|
59
|
+
throw new Error('Cannot start a new block before the trees have progressed from the tx effects in the previous block.');
|
|
60
|
+
}
|
|
61
|
+
// Thread the message sponge across the checkpoint's blocks: each block starts from the
|
|
62
|
+
// previous block's end sponge (empty for the first block) and absorbs its own real slice. The block merge and
|
|
63
|
+
// checkpoint root circuits assert exactly this continuity (`right.start_msg_sponge == left.end_msg_sponge`, first
|
|
64
|
+
// block starts empty, merged end equals the InboxParity sponge), so the end sponge is computed eagerly here for
|
|
65
|
+
// the next block to inherit. Blocks must therefore be started in order, which the sequential per-block message
|
|
66
|
+
// appends already require.
|
|
67
|
+
const startMsgSponge = index === 0 ? L1ToL2MessageSponge.empty() : this.blocks[index - 1]?.getEndMsgSponge();
|
|
68
|
+
if (!startMsgSponge) {
|
|
69
|
+
throw new Error('Cannot start a new block before the previous block in the checkpoint has been started.');
|
|
70
|
+
}
|
|
71
|
+
const endMsgSponge = startMsgSponge.clone();
|
|
72
|
+
await endMsgSponge.absorb(l1ToL2Messages);
|
|
73
|
+
const block = new BlockProvingState(index, blockNumber, totalNumTxs, this.constants, timestamp, lastArchiveTreeSnapshot, lastArchiveSiblingPath, previousState, startL1ToL2MessageTreeSnapshot, endL1ToL2MessageTreeSnapshot, l1ToL2MessageFrontierHint, l1ToL2Messages, startMsgSponge, endMsgSponge, startSpongeBlob, this);
|
|
74
|
+
this.blocks[index] = block;
|
|
75
|
+
return block;
|
|
76
|
+
}
|
|
77
|
+
// Returns true if we are still able to accept blocks, false otherwise.
|
|
78
|
+
isAcceptingBlocks() {
|
|
79
|
+
return this.blocks.filter((b)=>!!b).length < this.totalNumBlocks;
|
|
80
|
+
}
|
|
81
|
+
setBlockRootRollupProof(blockIndex, provingOutput) {
|
|
82
|
+
return this.blockProofs.setLeaf(blockIndex, {
|
|
83
|
+
provingOutput
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
tryStartProvingBlockMerge(location) {
|
|
87
|
+
if (this.blockProofs.getNode(location)?.isProving) {
|
|
88
|
+
return false;
|
|
89
|
+
} else {
|
|
90
|
+
this.blockProofs.setNode(location, {
|
|
91
|
+
isProving: true
|
|
92
|
+
});
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
setBlockMergeRollupProof(location, provingOutput) {
|
|
97
|
+
this.blockProofs.setNode(location, {
|
|
98
|
+
provingOutput
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// ---------------- inbox parity proof orchestration ----------------
|
|
102
|
+
/**
|
|
103
|
+
* Builds the checkpoint's single InboxParity input. The circuit is sized to the smallest ladder rung that fits the
|
|
104
|
+
* message count and the rolling hash starts from the previous checkpoint's end.
|
|
105
|
+
*/ getInboxParityInputs() {
|
|
106
|
+
return InboxParityPrivateInputs.fromMessages(this.l1ToL2Messages, this.startInboxRollingHash, this.constants.proverId);
|
|
107
|
+
}
|
|
108
|
+
tryStartProvingInboxParity() {
|
|
109
|
+
if (this.inboxParityProof?.isProving) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
this.inboxParityProof = {
|
|
113
|
+
isProving: true
|
|
114
|
+
};
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
setInboxParityProof(provingOutput) {
|
|
118
|
+
this.inboxParityProof = {
|
|
119
|
+
provingOutput
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
getInboxParityProof() {
|
|
123
|
+
return this.inboxParityProof?.provingOutput;
|
|
124
|
+
}
|
|
125
|
+
getParentLocation(location) {
|
|
126
|
+
return this.blockProofs.getParentLocation(location);
|
|
127
|
+
}
|
|
128
|
+
getBlockMergeRollupInputs(mergeLocation) {
|
|
129
|
+
const [left, right] = this.blockProofs.getChildren(mergeLocation).map((c)=>c?.provingOutput);
|
|
130
|
+
if (!left || !right) {
|
|
131
|
+
throw new Error('At least one child is not ready for the block merge rollup.');
|
|
132
|
+
}
|
|
133
|
+
return new BlockMergeRollupPrivateInputs([
|
|
134
|
+
toProofData(left),
|
|
135
|
+
toProofData(right)
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
getBlockProvingStateByBlockNumber(blockNumber) {
|
|
139
|
+
const index = Number(blockNumber) - Number(this.firstBlockNumber);
|
|
140
|
+
return this.blocks[index];
|
|
141
|
+
}
|
|
142
|
+
isReadyForBlockMerge(location) {
|
|
143
|
+
return !!this.blockProofs.getSibling(location)?.provingOutput;
|
|
144
|
+
}
|
|
145
|
+
verifyState() {
|
|
146
|
+
return this.isAlive();
|
|
147
|
+
}
|
|
148
|
+
getError() {
|
|
149
|
+
return this.error;
|
|
150
|
+
}
|
|
151
|
+
// Attempts to reject the proving state promise with a reason of 'cancelled'
|
|
152
|
+
cancel() {
|
|
153
|
+
this.reject('Proving cancelled');
|
|
154
|
+
}
|
|
155
|
+
reject(reason) {
|
|
156
|
+
this.error = reason;
|
|
157
|
+
this.onReject(reason);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns the block-level proof outputs that feed into the checkpoint root rollup.
|
|
161
|
+
* Used by `CheckpointSubTreeOrchestrator` to surface its sub-tree result.
|
|
162
|
+
*/ getSubTreeOutputProofs() {
|
|
163
|
+
const rootLocation = {
|
|
164
|
+
level: 0,
|
|
165
|
+
index: 0
|
|
166
|
+
};
|
|
167
|
+
return this.totalNumBlocks === 1 ? [
|
|
168
|
+
this.blockProofs.getNode(rootLocation)?.provingOutput
|
|
169
|
+
] // If there's only 1 block, its proof will be stored at the root.
|
|
170
|
+
: this.blockProofs.getChildren(rootLocation).map((c)=>c?.provingOutput);
|
|
171
|
+
}
|
|
172
|
+
/** Sibling path of the archive tree captured before any block in this checkpoint landed. */ getLastArchiveSiblingPath() {
|
|
173
|
+
return this.lastArchiveSiblingPath;
|
|
174
|
+
}
|
|
175
|
+
}
|