@aztec/prover-client 3.0.0-canary.a9708bd → 3.0.0-devnet.3
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/block-factory/light.d.ts +5 -3
- package/dest/block-factory/light.d.ts.map +1 -1
- package/dest/block-factory/light.js +16 -9
- package/dest/mocks/fixtures.d.ts +4 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +31 -3
- package/dest/mocks/test_context.d.ts +32 -9
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +78 -22
- package/dest/orchestrator/block-building-helpers.d.ts +33 -31
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +126 -137
- package/dest/orchestrator/block-proving-state.d.ts +60 -53
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +214 -187
- package/dest/orchestrator/checkpoint-proving-state.d.ts +63 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +211 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +34 -28
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +125 -81
- package/dest/orchestrator/orchestrator.d.ts +26 -25
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +350 -218
- package/dest/orchestrator/tx-proving-state.d.ts +11 -9
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +26 -23
- package/dest/prover-client/server-epoch-prover.d.ts +8 -7
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +7 -7
- package/dest/proving_broker/broker_prover_facade.d.ts +20 -15
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +36 -21
- package/dest/proving_broker/config.d.ts +8 -8
- package/dest/proving_broker/config.js +5 -5
- package/dest/proving_broker/factory.js +1 -1
- package/dest/proving_broker/fixtures.js +1 -1
- package/dest/proving_broker/proof_store/index.d.ts +1 -0
- package/dest/proving_broker/proof_store/index.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/index.js +1 -0
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +29 -18
- package/dest/proving_broker/proving_broker_database/persisted.js +5 -5
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +38 -18
- package/dest/test/mock_prover.d.ts +22 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +35 -20
- package/package.json +16 -17
- package/src/block-factory/light.ts +35 -9
- package/src/mocks/fixtures.ts +39 -11
- package/src/mocks/test_context.ts +137 -31
- package/src/orchestrator/block-building-helpers.ts +213 -211
- package/src/orchestrator/block-proving-state.ts +235 -245
- package/src/orchestrator/checkpoint-proving-state.ts +299 -0
- package/src/orchestrator/epoch-proving-state.ts +169 -126
- package/src/orchestrator/orchestrator.ts +519 -286
- package/src/orchestrator/tx-proving-state.ts +45 -43
- package/src/prover-client/server-epoch-prover.ts +26 -16
- package/src/proving_broker/broker_prover_facade.ts +157 -88
- package/src/proving_broker/config.ts +7 -7
- package/src/proving_broker/factory.ts +1 -1
- package/src/proving_broker/fixtures.ts +1 -1
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proving_broker.ts +36 -18
- package/src/proving_broker/proving_broker_database/persisted.ts +5 -5
- package/src/proving_broker/proving_job_controller.ts +38 -18
- package/src/test/mock_prover.ts +142 -62
- package/dest/bin/get-proof-inputs.d.ts +0 -2
- package/dest/bin/get-proof-inputs.d.ts.map +0 -1
- package/dest/bin/get-proof-inputs.js +0 -51
- package/src/bin/get-proof-inputs.ts +0 -59
|
@@ -1,140 +1,157 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { SpongeBlob } from '@aztec/blob-lib';
|
|
2
2
|
import {
|
|
3
3
|
type ARCHIVE_HEIGHT,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
|
|
4
|
+
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
+
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
7
6
|
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
8
7
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
9
|
-
type RECURSIVE_PROOF_LENGTH,
|
|
10
8
|
} from '@aztec/constants';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import type { Tuple } from '@aztec/foundation/serialize';
|
|
9
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
10
|
+
import { type Tuple, assertLength } from '@aztec/foundation/serialize';
|
|
14
11
|
import { type TreeNodeLocation, UnbalancedTreeStore } from '@aztec/foundation/trees';
|
|
15
|
-
import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
|
|
16
|
-
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
17
|
-
import type { EthAddress, L2Block } from '@aztec/stdlib/block';
|
|
18
12
|
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
19
|
-
import { type ParityPublicInputs,
|
|
13
|
+
import { type ParityPublicInputs, ParityRootPrivateInputs } from '@aztec/stdlib/parity';
|
|
14
|
+
import type { RollupHonkProofData } from '@aztec/stdlib/proofs';
|
|
20
15
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
PaddingBlockRootRollupInputs,
|
|
31
|
-
PreviousRollupData,
|
|
32
|
-
SingleTxBlockRootRollupInputs,
|
|
16
|
+
BlockRollupPublicInputs,
|
|
17
|
+
BlockRootEmptyTxFirstRollupPrivateInputs,
|
|
18
|
+
BlockRootFirstRollupPrivateInputs,
|
|
19
|
+
BlockRootRollupPrivateInputs,
|
|
20
|
+
BlockRootSingleTxFirstRollupPrivateInputs,
|
|
21
|
+
BlockRootSingleTxRollupPrivateInputs,
|
|
22
|
+
CheckpointConstantData,
|
|
23
|
+
TxMergeRollupPrivateInputs,
|
|
24
|
+
type TxRollupPublicInputs,
|
|
33
25
|
} from '@aztec/stdlib/rollup';
|
|
34
26
|
import type { CircuitName } from '@aztec/stdlib/stats';
|
|
35
|
-
import { AppendOnlyTreeSnapshot
|
|
36
|
-
import { type BlockHeader,
|
|
37
|
-
import {
|
|
27
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
28
|
+
import { type BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
29
|
+
import type { UInt64 } from '@aztec/stdlib/types';
|
|
38
30
|
|
|
39
|
-
import {
|
|
40
|
-
|
|
41
|
-
buildBlobHints,
|
|
42
|
-
buildHeaderFromCircuitOutputs,
|
|
43
|
-
getEmptyBlockBlobsHash,
|
|
44
|
-
} from './block-building-helpers.js';
|
|
45
|
-
import type { EpochProvingState } from './epoch-proving-state.js';
|
|
31
|
+
import { buildHeaderFromCircuitOutputs, toProofData } from './block-building-helpers.js';
|
|
32
|
+
import type { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
46
33
|
import type { TxProvingState } from './tx-proving-state.js';
|
|
47
34
|
|
|
48
|
-
export type
|
|
35
|
+
export type ProofState<T, PROOF_LENGTH extends number> = {
|
|
36
|
+
provingOutput?: PublicInputsAndRecursiveProof<T, PROOF_LENGTH>;
|
|
37
|
+
isProving?: boolean;
|
|
38
|
+
};
|
|
49
39
|
|
|
50
40
|
/**
|
|
51
41
|
* The current state of the proving schedule for a given block. Managed by ProvingState.
|
|
52
42
|
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
53
43
|
*/
|
|
54
44
|
export class BlockProvingState {
|
|
55
|
-
private
|
|
56
|
-
|
|
45
|
+
private baseOrMergeProofs: UnbalancedTreeStore<
|
|
46
|
+
ProofState<TxRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
57
47
|
> = new UnbalancedTreeStore(0);
|
|
58
|
-
private
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
private baseParityProofs: (ProofState<ParityPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined)[] =
|
|
49
|
+
Array.from({
|
|
50
|
+
length: NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
51
|
+
}).map(_ => undefined);
|
|
52
|
+
private rootParityProof: ProofState<ParityPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
|
|
53
|
+
private blockRootProof:
|
|
54
|
+
| ProofState<BlockRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
62
55
|
| undefined;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
public spongeBlobState: SpongeBlob | undefined;
|
|
66
|
-
public startBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
67
|
-
public endBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
68
|
-
public blobsHash: Fr | undefined;
|
|
69
|
-
public totalNumTxs: number;
|
|
56
|
+
private builtBlockHeader: BlockHeader | undefined;
|
|
57
|
+
private endSpongeBlob: SpongeBlob | undefined;
|
|
70
58
|
private txs: TxProvingState[] = [];
|
|
71
|
-
|
|
59
|
+
private isFirstBlock: boolean;
|
|
60
|
+
private error: string | undefined;
|
|
72
61
|
|
|
73
62
|
constructor(
|
|
74
63
|
public readonly index: number,
|
|
75
|
-
public readonly
|
|
76
|
-
public readonly
|
|
77
|
-
|
|
78
|
-
private readonly
|
|
79
|
-
public readonly
|
|
80
|
-
private readonly lastArchiveSnapshot: AppendOnlyTreeSnapshot,
|
|
64
|
+
public readonly blockNumber: number,
|
|
65
|
+
public readonly totalNumTxs: number,
|
|
66
|
+
private readonly constants: CheckpointConstantData,
|
|
67
|
+
private readonly timestamp: UInt64,
|
|
68
|
+
public readonly lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
81
69
|
private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
82
|
-
private readonly
|
|
83
|
-
private readonly
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
private readonly lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
71
|
+
private readonly lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<
|
|
72
|
+
Fr,
|
|
73
|
+
typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
|
|
74
|
+
>,
|
|
75
|
+
public readonly newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
76
|
+
private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
77
|
+
private readonly startSpongeBlob: SpongeBlob,
|
|
78
|
+
public parentCheckpoint: CheckpointProvingState,
|
|
86
79
|
) {
|
|
87
|
-
this.
|
|
88
|
-
this.
|
|
89
|
-
|
|
90
|
-
this.startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(parentEpoch.finalBlobBatchingChallenges);
|
|
80
|
+
this.isFirstBlock = index === 0;
|
|
81
|
+
if (!totalNumTxs && !this.isFirstBlock) {
|
|
82
|
+
throw new Error(`Cannot create a block with 0 txs, unless it's the first block.`);
|
|
91
83
|
}
|
|
92
|
-
}
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
return this.globalVariables.blockNumber;
|
|
85
|
+
this.baseOrMergeProofs = new UnbalancedTreeStore(totalNumTxs);
|
|
96
86
|
}
|
|
97
87
|
|
|
98
|
-
public
|
|
99
|
-
|
|
100
|
-
throw new Error(`Block ${this.blockNumber} already initalised.`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this.baseOrMergeProvingOutputs = new UnbalancedTreeStore(numTxs);
|
|
104
|
-
// Initialize the sponge which will eventually absorb all tx effects to be added to the blob.
|
|
105
|
-
// Like l1 to l2 messages, we need to know beforehand how many effects will be absorbed.
|
|
106
|
-
this.spongeBlobState = SpongeBlob.init(numBlobFields);
|
|
107
|
-
this.totalNumTxs = numTxs;
|
|
88
|
+
public get epochNumber(): number {
|
|
89
|
+
return this.parentCheckpoint.epochNumber;
|
|
108
90
|
}
|
|
109
91
|
|
|
110
92
|
// Adds a transaction to the proving state, returns it's index
|
|
111
93
|
public addNewTx(tx: TxProvingState) {
|
|
112
|
-
if (!this.
|
|
113
|
-
throw new Error(`
|
|
94
|
+
if (!this.isAcceptingTxs()) {
|
|
95
|
+
throw new Error(`Cannot add more txs to block ${this.blockNumber}.`);
|
|
114
96
|
}
|
|
115
97
|
const txIndex = this.txs.length;
|
|
116
98
|
this.txs[txIndex] = tx;
|
|
117
99
|
return txIndex;
|
|
118
100
|
}
|
|
119
101
|
|
|
102
|
+
public isAcceptingTxs() {
|
|
103
|
+
return this.txs.length < this.totalNumTxs;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public getProcessedTxs() {
|
|
107
|
+
return this.txs.map(t => t.processedTx);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public tryStartProvingBase(txIndex: number) {
|
|
111
|
+
if (this.baseOrMergeProofs.getLeaf(txIndex)?.isProving) {
|
|
112
|
+
return false;
|
|
113
|
+
} else {
|
|
114
|
+
this.baseOrMergeProofs.setLeaf(txIndex, { isProving: true });
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
120
119
|
public setBaseRollupProof(
|
|
121
120
|
txIndex: number,
|
|
122
121
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
123
|
-
|
|
122
|
+
TxRollupPublicInputs,
|
|
124
123
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
125
124
|
>,
|
|
126
125
|
): TreeNodeLocation {
|
|
127
|
-
return this.
|
|
126
|
+
return this.baseOrMergeProofs.setLeaf(txIndex, { provingOutput });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public tryStartProvingMerge(location: TreeNodeLocation) {
|
|
130
|
+
if (this.baseOrMergeProofs.getNode(location)?.isProving) {
|
|
131
|
+
return false;
|
|
132
|
+
} else {
|
|
133
|
+
this.baseOrMergeProofs.setNode(location, { isProving: true });
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
128
136
|
}
|
|
129
137
|
|
|
130
138
|
public setMergeRollupProof(
|
|
131
139
|
location: TreeNodeLocation,
|
|
132
140
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
133
|
-
|
|
141
|
+
TxRollupPublicInputs,
|
|
134
142
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
135
143
|
>,
|
|
136
144
|
) {
|
|
137
|
-
this.
|
|
145
|
+
this.baseOrMergeProofs.setNode(location, { provingOutput });
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public tryStartProvingBaseParity(index: number) {
|
|
149
|
+
if (this.baseParityProofs[index]?.isProving) {
|
|
150
|
+
return false;
|
|
151
|
+
} else {
|
|
152
|
+
this.baseParityProofs[index] = { isProving: true };
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
138
155
|
}
|
|
139
156
|
|
|
140
157
|
// Stores a set of root parity inputs at the given index
|
|
@@ -144,144 +161,179 @@ export class BlockProvingState {
|
|
|
144
161
|
`Unable to set a base parity proofs at index ${index}. Expected at most ${NUM_BASE_PARITY_PER_ROOT_PARITY} proofs.`,
|
|
145
162
|
);
|
|
146
163
|
}
|
|
147
|
-
this.
|
|
164
|
+
this.baseParityProofs[index] = { provingOutput };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public tryStartProvingRootParity() {
|
|
168
|
+
if (this.rootParityProof?.isProving) {
|
|
169
|
+
return false;
|
|
170
|
+
} else {
|
|
171
|
+
this.rootParityProof = { isProving: true };
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
148
174
|
}
|
|
149
175
|
|
|
150
176
|
public setRootParityProof(provingOutput: PublicInputsAndRecursiveProof<ParityPublicInputs>) {
|
|
151
|
-
this.
|
|
177
|
+
this.rootParityProof = { provingOutput };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public tryStartProvingBlockRoot() {
|
|
181
|
+
if (this.blockRootProof?.isProving) {
|
|
182
|
+
return false;
|
|
183
|
+
} else {
|
|
184
|
+
this.blockRootProof = { isProving: true };
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
152
187
|
}
|
|
153
188
|
|
|
154
189
|
public setBlockRootRollupProof(
|
|
155
190
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
156
|
-
|
|
191
|
+
BlockRollupPublicInputs,
|
|
157
192
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
158
193
|
>,
|
|
159
|
-
) {
|
|
160
|
-
this.
|
|
194
|
+
): TreeNodeLocation {
|
|
195
|
+
this.blockRootProof = { provingOutput };
|
|
196
|
+
return this.parentCheckpoint.setBlockRootRollupProof(this.index, provingOutput);
|
|
161
197
|
}
|
|
162
198
|
|
|
163
|
-
public
|
|
164
|
-
this.
|
|
199
|
+
public getBlockRootRollupOutput() {
|
|
200
|
+
return this.blockRootProof?.provingOutput?.inputs;
|
|
165
201
|
}
|
|
166
202
|
|
|
167
|
-
public
|
|
168
|
-
this.
|
|
203
|
+
public setBuiltBlockHeader(blockHeader: BlockHeader) {
|
|
204
|
+
this.builtBlockHeader = blockHeader;
|
|
169
205
|
}
|
|
170
206
|
|
|
171
|
-
public
|
|
172
|
-
this.
|
|
207
|
+
public getBuiltBlockHeader() {
|
|
208
|
+
return this.builtBlockHeader;
|
|
173
209
|
}
|
|
174
210
|
|
|
175
|
-
public
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
return;
|
|
211
|
+
public getGlobalVariables() {
|
|
212
|
+
if (this.txs.length) {
|
|
213
|
+
return this.txs[0].processedTx.globalVariables;
|
|
179
214
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
215
|
+
|
|
216
|
+
const constants = this.constants;
|
|
217
|
+
return GlobalVariables.from({
|
|
218
|
+
chainId: constants.chainId,
|
|
219
|
+
version: constants.version,
|
|
220
|
+
blockNumber: this.blockNumber,
|
|
221
|
+
slotNumber: constants.slotNumber,
|
|
222
|
+
timestamp: this.timestamp,
|
|
223
|
+
coinbase: constants.coinbase,
|
|
224
|
+
feeRecipient: constants.feeRecipient,
|
|
225
|
+
gasFees: constants.gasFees,
|
|
226
|
+
});
|
|
185
227
|
}
|
|
186
228
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return this.txs;
|
|
229
|
+
public getStartSpongeBlob() {
|
|
230
|
+
return this.startSpongeBlob;
|
|
190
231
|
}
|
|
191
232
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
233
|
+
public setEndSpongeBlob(endSpongeBlob: SpongeBlob) {
|
|
234
|
+
this.endSpongeBlob = endSpongeBlob;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
public getEndSpongeBlob() {
|
|
238
|
+
return this.endSpongeBlob;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public getTxEffects() {
|
|
242
|
+
return this.txs.map(t => t.processedTx.txEffect);
|
|
195
243
|
}
|
|
196
244
|
|
|
197
245
|
public getParentLocation(location: TreeNodeLocation) {
|
|
198
|
-
return this.
|
|
246
|
+
return this.baseOrMergeProofs.getParentLocation(location);
|
|
199
247
|
}
|
|
200
248
|
|
|
201
249
|
public getMergeRollupInputs(mergeLocation: TreeNodeLocation) {
|
|
202
|
-
const [left, right] = this.
|
|
250
|
+
const [left, right] = this.baseOrMergeProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
|
|
203
251
|
if (!left || !right) {
|
|
204
|
-
throw new Error('At
|
|
252
|
+
throw new Error('At least one child is not ready for the merge rollup.');
|
|
205
253
|
}
|
|
206
254
|
|
|
207
|
-
return new
|
|
255
|
+
return new TxMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
|
|
208
256
|
}
|
|
209
257
|
|
|
210
|
-
public
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const proofs = this.#getChildProofsForBlockRoot();
|
|
216
|
-
const nonEmptyProofs = proofs.filter(p => !!p);
|
|
217
|
-
if (proofs.length !== nonEmptyProofs.length) {
|
|
218
|
-
throw new Error('At lease one child is not ready for the block root.');
|
|
258
|
+
public getBlockRootRollupTypeAndInputs() {
|
|
259
|
+
const provingOutputs = this.#getChildProvingOutputsForBlockRoot();
|
|
260
|
+
if (!provingOutputs.every(p => !!p)) {
|
|
261
|
+
throw new Error('At least one child is not ready for the block root rollup.');
|
|
219
262
|
}
|
|
220
263
|
|
|
221
|
-
const
|
|
264
|
+
const previousRollups = provingOutputs.map(p => toProofData(p));
|
|
222
265
|
|
|
223
|
-
if (this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
newL1ToL2: this.l1ToL2MessageTreeSnapshotAfterInsertion,
|
|
227
|
-
globalVariables: this.globalVariables,
|
|
228
|
-
vkTreeRoot: getVKTreeRoot(),
|
|
229
|
-
protocolContractTreeRoot,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
this.blobsHash = await getEmptyBlockBlobsHash();
|
|
266
|
+
if (this.isFirstBlock) {
|
|
267
|
+
return this.#getFirstBlockRootRollupTypeAndInputs(previousRollups);
|
|
268
|
+
}
|
|
233
269
|
|
|
270
|
+
const [leftRollup, rightRollup] = previousRollups;
|
|
271
|
+
if (!rightRollup) {
|
|
272
|
+
return {
|
|
273
|
+
rollupType: 'rollup-block-root-single-tx' satisfies CircuitName,
|
|
274
|
+
inputs: new BlockRootSingleTxRollupPrivateInputs(leftRollup, this.lastArchiveSiblingPath),
|
|
275
|
+
};
|
|
276
|
+
} else {
|
|
234
277
|
return {
|
|
235
|
-
rollupType: '
|
|
236
|
-
inputs:
|
|
237
|
-
data,
|
|
238
|
-
constants,
|
|
239
|
-
}),
|
|
278
|
+
rollupType: 'rollup-block-root' satisfies CircuitName,
|
|
279
|
+
inputs: new BlockRootRollupPrivateInputs([leftRollup, rightRollup], this.lastArchiveSiblingPath),
|
|
240
280
|
};
|
|
241
281
|
}
|
|
282
|
+
}
|
|
242
283
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
284
|
+
#getFirstBlockRootRollupTypeAndInputs([leftRollup, rightRollup]: RollupHonkProofData<TxRollupPublicInputs>[]) {
|
|
285
|
+
if (!this.rootParityProof?.provingOutput) {
|
|
286
|
+
throw new Error('Root parity is not ready.');
|
|
287
|
+
}
|
|
288
|
+
const l1ToL2Roots = toProofData(this.rootParityProof.provingOutput);
|
|
246
289
|
|
|
247
|
-
if (
|
|
290
|
+
if (!leftRollup) {
|
|
291
|
+
return {
|
|
292
|
+
rollupType: 'rollup-block-root-first-empty-tx' satisfies CircuitName,
|
|
293
|
+
inputs: new BlockRootEmptyTxFirstRollupPrivateInputs(
|
|
294
|
+
l1ToL2Roots,
|
|
295
|
+
this.lastArchiveTreeSnapshot,
|
|
296
|
+
this.headerOfLastBlockInPreviousCheckpoint.state,
|
|
297
|
+
this.constants,
|
|
298
|
+
this.startSpongeBlob,
|
|
299
|
+
this.timestamp,
|
|
300
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
301
|
+
this.lastArchiveSiblingPath,
|
|
302
|
+
),
|
|
303
|
+
};
|
|
304
|
+
} else if (!rightRollup) {
|
|
248
305
|
return {
|
|
249
|
-
rollupType: '
|
|
250
|
-
inputs: new
|
|
306
|
+
rollupType: 'rollup-block-root-first-single-tx' satisfies CircuitName,
|
|
307
|
+
inputs: new BlockRootSingleTxFirstRollupPrivateInputs(
|
|
308
|
+
l1ToL2Roots,
|
|
309
|
+
leftRollup,
|
|
310
|
+
this.lastL1ToL2MessageTreeSnapshot,
|
|
311
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
312
|
+
this.lastArchiveSiblingPath,
|
|
313
|
+
),
|
|
251
314
|
};
|
|
252
315
|
} else {
|
|
253
316
|
return {
|
|
254
|
-
rollupType: 'block-root-
|
|
255
|
-
inputs: new
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
317
|
+
rollupType: 'rollup-block-root-first' satisfies CircuitName,
|
|
318
|
+
inputs: new BlockRootFirstRollupPrivateInputs(
|
|
319
|
+
l1ToL2Roots,
|
|
320
|
+
[leftRollup, rightRollup],
|
|
321
|
+
this.lastL1ToL2MessageTreeSnapshot,
|
|
322
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
323
|
+
this.lastArchiveSiblingPath,
|
|
259
324
|
),
|
|
260
325
|
};
|
|
261
326
|
}
|
|
262
327
|
}
|
|
263
328
|
|
|
264
|
-
public
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
protocolContractTreeRoot,
|
|
268
|
-
proverId: this.proverId.toField(),
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
return PaddingBlockRootRollupInputs.from({
|
|
272
|
-
constants,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public getRootParityInputs() {
|
|
277
|
-
if (!this.baseParityProvingOutputs.every(p => !!p)) {
|
|
329
|
+
public getParityRootInputs() {
|
|
330
|
+
const baseParityProvingOutputs = this.baseParityProofs.filter(p => !!p?.provingOutput).map(p => p!.provingOutput!);
|
|
331
|
+
if (baseParityProvingOutputs.length !== this.baseParityProofs.length) {
|
|
278
332
|
throw new Error('At lease one base parity is not ready.');
|
|
279
333
|
}
|
|
280
334
|
|
|
281
|
-
const children =
|
|
282
|
-
return new
|
|
283
|
-
children as Tuple<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>, typeof NUM_BASE_PARITY_PER_ROOT_PARITY>,
|
|
284
|
-
);
|
|
335
|
+
const children = baseParityProvingOutputs.map(p => toProofData(p));
|
|
336
|
+
return new ParityRootPrivateInputs(assertLength(children, NUM_BASE_PARITY_PER_ROOT_PARITY));
|
|
285
337
|
}
|
|
286
338
|
|
|
287
339
|
// Returns a specific transaction proving state
|
|
@@ -290,89 +342,46 @@ export class BlockProvingState {
|
|
|
290
342
|
}
|
|
291
343
|
|
|
292
344
|
public async buildHeaderFromProvingOutputs() {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
? []
|
|
296
|
-
: await Promise.all(this.#getChildProofsForBlockRoot().map(p => this.#getPreviousRollupData(p!)));
|
|
297
|
-
|
|
298
|
-
let endPartialState = this.previousBlockHeader.state.partial;
|
|
299
|
-
if (this.totalNumTxs !== 0) {
|
|
300
|
-
const previousRollupData = this.#getChildProofsForBlockRoot();
|
|
301
|
-
const lastRollup = previousRollupData[previousRollupData.length - 1];
|
|
302
|
-
if (!lastRollup) {
|
|
303
|
-
throw new Error('End state of the block is not available. Last rollup is not ready yet.');
|
|
304
|
-
}
|
|
305
|
-
endPartialState = lastRollup.inputs.end;
|
|
345
|
+
if (!this.blockRootProof?.provingOutput) {
|
|
346
|
+
throw new Error('Block root rollup is not ready.');
|
|
306
347
|
}
|
|
307
|
-
const endState = new StateReference(this.l1ToL2MessageTreeSnapshotAfterInsertion, endPartialState);
|
|
308
348
|
|
|
309
|
-
return buildHeaderFromCircuitOutputs(
|
|
310
|
-
previousRollupData.map(d => d.baseOrMergeRollupPublicInputs),
|
|
311
|
-
this.rootParityProvingOutput!.inputs,
|
|
312
|
-
this.blockRootProvingOutput!.inputs,
|
|
313
|
-
this.blobsHash!,
|
|
314
|
-
endState,
|
|
315
|
-
);
|
|
349
|
+
return await buildHeaderFromCircuitOutputs(this.blockRootProof.provingOutput.inputs);
|
|
316
350
|
}
|
|
317
351
|
|
|
318
352
|
public isReadyForMergeRollup(location: TreeNodeLocation) {
|
|
319
|
-
return this.
|
|
353
|
+
return !!this.baseOrMergeProofs.getSibling(location)?.provingOutput;
|
|
320
354
|
}
|
|
321
355
|
|
|
322
356
|
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
323
357
|
public isReadyForBlockRootRollup() {
|
|
324
|
-
const childProofs = this.#
|
|
325
|
-
return (
|
|
326
|
-
this.block !== undefined &&
|
|
327
|
-
this.rootParityProvingOutput !== undefined &&
|
|
328
|
-
this.endBlobAccumulator !== undefined &&
|
|
329
|
-
childProofs.every(p => !!p)
|
|
330
|
-
);
|
|
358
|
+
const childProofs = this.#getChildProvingOutputsForBlockRoot();
|
|
359
|
+
return (!this.isFirstBlock || !!this.rootParityProof?.provingOutput) && childProofs.every(p => !!p);
|
|
331
360
|
}
|
|
332
361
|
|
|
333
362
|
// Returns true if we have sufficient root parity inputs to execute the root parity circuit
|
|
334
363
|
public isReadyForRootParity() {
|
|
335
|
-
return this.
|
|
364
|
+
return this.baseParityProofs.every(p => !!p?.provingOutput);
|
|
336
365
|
}
|
|
337
366
|
|
|
338
367
|
public isComplete() {
|
|
339
|
-
return !!this.
|
|
368
|
+
return !!this.blockRootProof;
|
|
340
369
|
}
|
|
341
370
|
|
|
342
|
-
// Returns whether the proving state is still valid
|
|
343
371
|
public verifyState() {
|
|
344
|
-
return this.
|
|
372
|
+
return this.parentCheckpoint.verifyState();
|
|
345
373
|
}
|
|
346
374
|
|
|
347
|
-
public
|
|
348
|
-
this.error
|
|
349
|
-
this.parentEpoch.reject(reason);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
#getBlockRootRollupData() {
|
|
353
|
-
return BlockRootRollupData.from({
|
|
354
|
-
l1ToL2Roots: this.#getRootParityData(this.rootParityProvingOutput!),
|
|
355
|
-
l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
|
|
356
|
-
previousArchiveSiblingPath: this.lastArchiveSiblingPath,
|
|
357
|
-
newArchiveSiblingPath: this.newArchiveSiblingPath,
|
|
358
|
-
previousBlockHeader: this.previousBlockHeader,
|
|
359
|
-
startBlobAccumulator: BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(this.startBlobAccumulator!),
|
|
360
|
-
finalBlobChallenges: this.startBlobAccumulator!.finalBlobChallenges,
|
|
361
|
-
proverId: this.proverId.toField(),
|
|
362
|
-
});
|
|
375
|
+
public getError() {
|
|
376
|
+
return this.error;
|
|
363
377
|
}
|
|
364
378
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return BlockRootRollupBlobData.from({
|
|
369
|
-
blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
|
|
370
|
-
blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_BLOCK),
|
|
371
|
-
blobsHash,
|
|
372
|
-
});
|
|
379
|
+
public reject(reason: string) {
|
|
380
|
+
this.error = reason;
|
|
381
|
+
this.parentCheckpoint.reject(reason);
|
|
373
382
|
}
|
|
374
383
|
|
|
375
|
-
#
|
|
384
|
+
#getChildProvingOutputsForBlockRoot() {
|
|
376
385
|
if (this.totalNumTxs === 0) {
|
|
377
386
|
return [];
|
|
378
387
|
}
|
|
@@ -380,26 +389,7 @@ export class BlockProvingState {
|
|
|
380
389
|
const rootLocation = { level: 0, index: 0 };
|
|
381
390
|
// If there's only 1 tx, its base rollup proof will be stored at the root.
|
|
382
391
|
return this.totalNumTxs === 1
|
|
383
|
-
? [this.
|
|
384
|
-
: this.
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
#getPreviousRollupData({
|
|
388
|
-
inputs,
|
|
389
|
-
proof,
|
|
390
|
-
verificationKey,
|
|
391
|
-
}: PublicInputsAndRecursiveProof<BaseOrMergeRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>) {
|
|
392
|
-
const leafIndex = getVKIndex(verificationKey.keyAsFields);
|
|
393
|
-
const vkData = new VkData(verificationKey, leafIndex, getVKSiblingPath(leafIndex));
|
|
394
|
-
return new PreviousRollupData(inputs, proof, vkData);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
#getRootParityData({ inputs, proof, verificationKey }: PublicInputsAndRecursiveProof<ParityPublicInputs>) {
|
|
398
|
-
return new RootParityInput(
|
|
399
|
-
proof,
|
|
400
|
-
verificationKey.keyAsFields,
|
|
401
|
-
getVKSiblingPath(getVKIndex(verificationKey)),
|
|
402
|
-
inputs,
|
|
403
|
-
);
|
|
392
|
+
? [this.baseOrMergeProofs.getNode(rootLocation)?.provingOutput]
|
|
393
|
+
: this.baseOrMergeProofs.getChildren(rootLocation).map(c => c?.provingOutput);
|
|
404
394
|
}
|
|
405
395
|
}
|