@aztec/prover-client 3.0.0-nightly.20250916 → 3.0.0-nightly.20250918

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.
Files changed (51) hide show
  1. package/dest/block-factory/light.d.ts +5 -3
  2. package/dest/block-factory/light.d.ts.map +1 -1
  3. package/dest/block-factory/light.js +16 -9
  4. package/dest/mocks/fixtures.d.ts +3 -1
  5. package/dest/mocks/fixtures.d.ts.map +1 -1
  6. package/dest/mocks/fixtures.js +19 -2
  7. package/dest/mocks/test_context.d.ts +30 -9
  8. package/dest/mocks/test_context.d.ts.map +1 -1
  9. package/dest/mocks/test_context.js +68 -15
  10. package/dest/orchestrator/block-building-helpers.d.ts +16 -14
  11. package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
  12. package/dest/orchestrator/block-building-helpers.js +69 -66
  13. package/dest/orchestrator/block-proving-state.d.ts +53 -46
  14. package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
  15. package/dest/orchestrator/block-proving-state.js +209 -172
  16. package/dest/orchestrator/checkpoint-proving-state.d.ts +62 -0
  17. package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
  18. package/dest/orchestrator/checkpoint-proving-state.js +208 -0
  19. package/dest/orchestrator/epoch-proving-state.d.ts +32 -25
  20. package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
  21. package/dest/orchestrator/epoch-proving-state.js +132 -81
  22. package/dest/orchestrator/orchestrator.d.ts +25 -24
  23. package/dest/orchestrator/orchestrator.d.ts.map +1 -1
  24. package/dest/orchestrator/orchestrator.js +318 -190
  25. package/dest/prover-client/server-epoch-prover.d.ts +8 -7
  26. package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
  27. package/dest/prover-client/server-epoch-prover.js +7 -7
  28. package/dest/proving_broker/broker_prover_facade.d.ts +12 -7
  29. package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
  30. package/dest/proving_broker/broker_prover_facade.js +30 -15
  31. package/dest/proving_broker/proving_broker.d.ts.map +1 -1
  32. package/dest/proving_broker/proving_broker.js +18 -7
  33. package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
  34. package/dest/proving_broker/proving_job_controller.js +26 -6
  35. package/dest/test/mock_prover.d.ts +12 -7
  36. package/dest/test/mock_prover.d.ts.map +1 -1
  37. package/dest/test/mock_prover.js +25 -10
  38. package/package.json +15 -15
  39. package/src/block-factory/light.ts +33 -9
  40. package/src/mocks/fixtures.ts +25 -7
  41. package/src/mocks/test_context.ts +113 -21
  42. package/src/orchestrator/block-building-helpers.ts +107 -93
  43. package/src/orchestrator/block-proving-state.ts +225 -212
  44. package/src/orchestrator/checkpoint-proving-state.ts +294 -0
  45. package/src/orchestrator/epoch-proving-state.ts +169 -121
  46. package/src/orchestrator/orchestrator.ts +466 -247
  47. package/src/prover-client/server-epoch-prover.ts +30 -16
  48. package/src/proving_broker/broker_prover_facade.ts +145 -71
  49. package/src/proving_broker/proving_broker.ts +24 -6
  50. package/src/proving_broker/proving_job_controller.ts +26 -6
  51. package/src/test/mock_prover.ts +105 -28
@@ -0,0 +1,208 @@
1
+ import { BlobAccumulatorPublicInputs, SpongeBlob } from '@aztec/blob-lib';
2
+ import { BLOBS_PER_BLOCK, FIELDS_PER_BLOB, NUM_MSGS_PER_BASE_PARITY } from '@aztec/constants';
3
+ import { padArrayEnd } from '@aztec/foundation/collection';
4
+ import { BLS12Point, Fr } from '@aztec/foundation/fields';
5
+ import { UnbalancedTreeStore } from '@aztec/foundation/trees';
6
+ import { BaseParityInputs } from '@aztec/stdlib/parity';
7
+ import { BlockMergeRollupPrivateInputs, CheckpointRootRollupHints, CheckpointRootRollupPrivateInputs, CheckpointRootSingleBlockRollupPrivateInputs } from '@aztec/stdlib/rollup';
8
+ import { accumulateBlobs, buildBlobHints, toProofData } from './block-building-helpers.js';
9
+ import { BlockProvingState } from './block-proving-state.js';
10
+ export class CheckpointProvingState {
11
+ index;
12
+ constants;
13
+ totalNumBlocks;
14
+ totalNumBlobFields;
15
+ finalBlobBatchingChallenges;
16
+ headerOfLastBlockInPreviousCheckpoint;
17
+ lastArchiveSiblingPath;
18
+ l1ToL2Messages;
19
+ lastL1ToL2MessageTreeSnapshot;
20
+ lastL1ToL2MessageSubtreeSiblingPath;
21
+ newL1ToL2MessageTreeSnapshot;
22
+ newL1ToL2MessageSubtreeSiblingPath;
23
+ parentEpoch;
24
+ onBlobAccumulatorSet;
25
+ blockProofs;
26
+ checkpointRootProof;
27
+ blocks;
28
+ startBlobAccumulator;
29
+ endBlobAccumulator;
30
+ error;
31
+ firstBlockNumber;
32
+ constructor(index, constants, totalNumBlocks, totalNumBlobFields, finalBlobBatchingChallenges, headerOfLastBlockInPreviousCheckpoint, lastArchiveSiblingPath, l1ToL2Messages, // The snapshot and sibling path before the new l1 to l2 message subtree is inserted.
33
+ lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeSiblingPath, // The snapshot and sibling path after the new l1 to l2 message subtree is inserted.
34
+ newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeSiblingPath, parentEpoch, onBlobAccumulatorSet){
35
+ this.index = index;
36
+ this.constants = constants;
37
+ this.totalNumBlocks = totalNumBlocks;
38
+ this.totalNumBlobFields = totalNumBlobFields;
39
+ this.finalBlobBatchingChallenges = finalBlobBatchingChallenges;
40
+ this.headerOfLastBlockInPreviousCheckpoint = headerOfLastBlockInPreviousCheckpoint;
41
+ this.lastArchiveSiblingPath = lastArchiveSiblingPath;
42
+ this.l1ToL2Messages = l1ToL2Messages;
43
+ this.lastL1ToL2MessageTreeSnapshot = lastL1ToL2MessageTreeSnapshot;
44
+ this.lastL1ToL2MessageSubtreeSiblingPath = lastL1ToL2MessageSubtreeSiblingPath;
45
+ this.newL1ToL2MessageTreeSnapshot = newL1ToL2MessageTreeSnapshot;
46
+ this.newL1ToL2MessageSubtreeSiblingPath = newL1ToL2MessageSubtreeSiblingPath;
47
+ this.parentEpoch = parentEpoch;
48
+ this.onBlobAccumulatorSet = onBlobAccumulatorSet;
49
+ this.blocks = [];
50
+ this.blockProofs = new UnbalancedTreeStore(totalNumBlocks);
51
+ this.firstBlockNumber = headerOfLastBlockInPreviousCheckpoint.globalVariables.blockNumber + 1;
52
+ }
53
+ get epochNumber() {
54
+ return this.parentEpoch.epochNumber;
55
+ }
56
+ startNewBlock(blockNumber, timestamp, totalNumTxs, lastArchiveTreeSnapshot, lastArchiveSiblingPath) {
57
+ const index = blockNumber - this.firstBlockNumber;
58
+ if (index >= this.totalNumBlocks) {
59
+ throw new Error(`Unable to start a new block at index ${index}. Expected at most ${this.totalNumBlocks} blocks.`);
60
+ }
61
+ // If this is the first block, we use the snapshot and sibling path before the new l1 to l2 messages are inserted.
62
+ // Otherwise, we use the snapshot and sibling path after the new l1 to l2 messages are inserted, which will always
63
+ // happen in the first block.
64
+ const lastL1ToL2MessageTreeSnapshot = index === 0 ? this.lastL1ToL2MessageTreeSnapshot : this.newL1ToL2MessageTreeSnapshot;
65
+ const lastL1ToL2MessageSubtreeSiblingPath = index === 0 ? this.lastL1ToL2MessageSubtreeSiblingPath : this.newL1ToL2MessageSubtreeSiblingPath;
66
+ const startSpongeBlob = index === 0 ? SpongeBlob.init(this.totalNumBlobFields) : this.blocks[index - 1]?.getEndSpongeBlob();
67
+ if (!startSpongeBlob) {
68
+ throw new Error('Cannot start a new block before the trees have progressed from the tx effects in the previous block.');
69
+ }
70
+ const block = new BlockProvingState(index, blockNumber, totalNumTxs, this.constants, timestamp, lastArchiveTreeSnapshot, lastArchiveSiblingPath, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeSiblingPath, this.newL1ToL2MessageTreeSnapshot, this.headerOfLastBlockInPreviousCheckpoint, startSpongeBlob, this);
71
+ this.blocks[index] = block;
72
+ return block;
73
+ }
74
+ // Returns true if we are still able to accept blocks, false otherwise.
75
+ isAcceptingBlocks() {
76
+ return this.blocks.filter((b)=>!!b).length < this.totalNumBlocks;
77
+ }
78
+ setBlockRootRollupProof(blockIndex, provingOutput) {
79
+ return this.blockProofs.setLeaf(blockIndex, {
80
+ provingOutput
81
+ });
82
+ }
83
+ tryStartProvingBlockMerge(location) {
84
+ if (this.blockProofs.getNode(location)?.isProving) {
85
+ return false;
86
+ } else {
87
+ this.blockProofs.setNode(location, {
88
+ isProving: true
89
+ });
90
+ return true;
91
+ }
92
+ }
93
+ setBlockMergeRollupProof(location, provingOutput) {
94
+ this.blockProofs.setNode(location, {
95
+ provingOutput
96
+ });
97
+ }
98
+ tryStartProvingCheckpointRoot() {
99
+ if (this.checkpointRootProof?.isProving) {
100
+ return false;
101
+ } else {
102
+ this.checkpointRootProof = {
103
+ isProving: true
104
+ };
105
+ return true;
106
+ }
107
+ }
108
+ setCheckpointRootRollupProof(provingOutput) {
109
+ this.checkpointRootProof = {
110
+ provingOutput
111
+ };
112
+ return this.parentEpoch.setCheckpointRootRollupProof(this.index, provingOutput);
113
+ }
114
+ getBaseParityInputs(baseParityIndex) {
115
+ const messages = padArrayEnd(this.l1ToL2Messages.slice(baseParityIndex * NUM_MSGS_PER_BASE_PARITY, (baseParityIndex + 1) * NUM_MSGS_PER_BASE_PARITY), Fr.ZERO, NUM_MSGS_PER_BASE_PARITY);
116
+ return new BaseParityInputs(messages, this.constants.vkTreeRoot);
117
+ }
118
+ async accumulateBlobs(startBlobAccumulator) {
119
+ if (this.isAcceptingBlocks() || this.blocks.some((b)=>b.isAcceptingTxs())) {
120
+ return;
121
+ }
122
+ const blobFields = this.blocks.flatMap((b)=>b.getBlockBlobFields());
123
+ this.endBlobAccumulator = await accumulateBlobs(blobFields, startBlobAccumulator);
124
+ this.startBlobAccumulator = startBlobAccumulator;
125
+ this.onBlobAccumulatorSet(this);
126
+ return this.endBlobAccumulator;
127
+ }
128
+ getEndBlobAccumulator() {
129
+ return this.endBlobAccumulator;
130
+ }
131
+ getParentLocation(location) {
132
+ return this.blockProofs.getParentLocation(location);
133
+ }
134
+ getBlockMergeRollupInputs(mergeLocation) {
135
+ const [left, right] = this.blockProofs.getChildren(mergeLocation).map((c)=>c?.provingOutput);
136
+ if (!left || !right) {
137
+ throw new Error('At least one child is not ready for the block merge rollup.');
138
+ }
139
+ return new BlockMergeRollupPrivateInputs([
140
+ toProofData(left),
141
+ toProofData(right)
142
+ ]);
143
+ }
144
+ getCheckpointRootRollupType() {
145
+ return this.totalNumBlocks === 1 ? 'checkpoint-root-single-block-rollup' : 'checkpoint-root-rollup';
146
+ }
147
+ async getCheckpointRootRollupInputs() {
148
+ const proofs = this.#getChildProofsForRoot();
149
+ const nonEmptyProofs = proofs.filter((p)=>!!p);
150
+ if (proofs.length !== nonEmptyProofs.length) {
151
+ throw new Error('At least one child is not ready for the checkpoint root rollup.');
152
+ }
153
+ if (!this.startBlobAccumulator) {
154
+ throw new Error('Start blob accumulator is not set.');
155
+ }
156
+ const blobFields = this.blocks.flatMap((b)=>b.getBlockBlobFields());
157
+ const { blobCommitments, blobsHash } = await buildBlobHints(blobFields);
158
+ const hints = CheckpointRootRollupHints.from({
159
+ previousBlockHeader: this.headerOfLastBlockInPreviousCheckpoint,
160
+ previousArchiveSiblingPath: this.lastArchiveSiblingPath,
161
+ startBlobAccumulator: BlobAccumulatorPublicInputs.fromBatchedBlobAccumulator(this.startBlobAccumulator),
162
+ finalBlobChallenges: this.finalBlobBatchingChallenges,
163
+ blobFields: padArrayEnd(blobFields, Fr.ZERO, FIELDS_PER_BLOB * BLOBS_PER_BLOCK),
164
+ blobCommitments: padArrayEnd(blobCommitments, BLS12Point.ZERO, BLOBS_PER_BLOCK),
165
+ blobsHash
166
+ });
167
+ const [left, right] = nonEmptyProofs.map((p)=>toProofData(p));
168
+ return !right ? new CheckpointRootSingleBlockRollupPrivateInputs(left, hints) : new CheckpointRootRollupPrivateInputs([
169
+ left,
170
+ right
171
+ ], hints);
172
+ }
173
+ getBlockProvingStateByBlockNumber(blockNumber) {
174
+ const index = blockNumber - this.firstBlockNumber;
175
+ return this.blocks[index];
176
+ }
177
+ isReadyForBlockMerge(location) {
178
+ return !!this.blockProofs.getSibling(location)?.provingOutput;
179
+ }
180
+ isReadyForCheckpointRoot() {
181
+ const allChildProofsReady = this.#getChildProofsForRoot().every((p)=>!!p);
182
+ return allChildProofsReady && !!this.startBlobAccumulator;
183
+ }
184
+ verifyState() {
185
+ return this.parentEpoch.verifyState();
186
+ }
187
+ getError() {
188
+ return this.error;
189
+ }
190
+ // Attempts to reject the proving state promise with a reason of 'cancelled'
191
+ cancel() {
192
+ this.reject('Proving cancelled');
193
+ }
194
+ reject(reason) {
195
+ this.error = reason;
196
+ this.parentEpoch.reject(reason);
197
+ }
198
+ #getChildProofsForRoot() {
199
+ const rootLocation = {
200
+ level: 0,
201
+ index: 0
202
+ };
203
+ return this.totalNumBlocks === 1 ? [
204
+ this.blockProofs.getNode(rootLocation)?.provingOutput
205
+ ] // If there's only 1 block, its proof will be stored at the root.
206
+ : this.blockProofs.getChildren(rootLocation).map((c)=>c?.provingOutput);
207
+ }
208
+ }
@@ -1,16 +1,15 @@
1
1
  import { BatchedBlob, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
2
2
  import type { ARCHIVE_HEIGHT, L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH, NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH } from '@aztec/constants';
3
- import type { EthAddress } from '@aztec/foundation/eth-address';
4
3
  import type { Fr } from '@aztec/foundation/fields';
5
4
  import type { Tuple } from '@aztec/foundation/serialize';
6
5
  import { type TreeNodeLocation } from '@aztec/foundation/trees';
7
6
  import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
8
7
  import type { PrivateToPublicKernelCircuitPublicInputs } from '@aztec/stdlib/kernel';
9
8
  import type { Proof } from '@aztec/stdlib/proofs';
10
- import { BlockMergeRollupInputs, type BlockRootOrBlockMergePublicInputs, RootRollupInputs, type RootRollupPublicInputs } from '@aztec/stdlib/rollup';
9
+ import { CheckpointConstantData, CheckpointMergeRollupPrivateInputs, CheckpointPaddingRollupPrivateInputs, CheckpointRollupPublicInputs, RootRollupPrivateInputs, type RootRollupPublicInputs } from '@aztec/stdlib/rollup';
11
10
  import type { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
12
- import type { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
13
- import { BlockProvingState } from './block-proving-state.js';
11
+ import type { BlockHeader } from '@aztec/stdlib/tx';
12
+ import { CheckpointProvingState } from './checkpoint-proving-state.js';
14
13
  export type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
15
14
  export type ProvingResult = {
16
15
  status: 'success';
@@ -27,39 +26,47 @@ export type ProvingResult = {
27
26
  export declare class EpochProvingState {
28
27
  #private;
29
28
  readonly epochNumber: number;
30
- readonly firstBlockNumber: number;
31
- readonly totalNumBlocks: number;
32
- readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges;
29
+ private readonly firstCheckpointNumber;
30
+ readonly totalNumCheckpoints: number;
31
+ private readonly finalBlobBatchingChallenges;
32
+ private onCheckpointBlobAccumulatorSet;
33
33
  private completionCallback;
34
34
  private rejectionCallback;
35
- private blockRootOrMergeProvingOutputs;
36
- private paddingBlockRootProvingOutput;
37
- private rootRollupProvingOutput;
35
+ private checkpointProofs;
36
+ private checkpointPaddingProof;
37
+ private rootRollupProof;
38
+ private checkpoints;
39
+ private startBlobAccumulator;
40
+ private endBlobAccumulator;
38
41
  private finalBatchedBlob;
39
42
  private provingStateLifecycle;
40
43
  readonly cachedTubeProofs: Map<string, Promise<PublicInputsAndRecursiveProof<PrivateToPublicKernelCircuitPublicInputs, 535>>>;
41
- blocks: (BlockProvingState | undefined)[];
42
- constructor(epochNumber: number, firstBlockNumber: number, totalNumBlocks: number, finalBlobBatchingChallenges: FinalBlobBatchingChallenges, completionCallback: (result: ProvingResult) => void, rejectionCallback: (reason: string) => void);
43
- startNewBlock(globalVariables: GlobalVariables, l1ToL2Messages: Fr[], l1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>, l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot, lastArchiveSnapshot: AppendOnlyTreeSnapshot, lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, previousBlockHeader: BlockHeader, proverId: EthAddress): BlockProvingState;
44
+ constructor(epochNumber: number, firstCheckpointNumber: Fr, totalNumCheckpoints: number, finalBlobBatchingChallenges: FinalBlobBatchingChallenges, onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => void, completionCallback: (result: ProvingResult) => void, rejectionCallback: (reason: string) => void);
45
+ startNewCheckpoint(constants: CheckpointConstantData, totalNumBlocks: number, totalNumBlobFields: number, previousBlockHeader: BlockHeader, lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>, l1ToL2Messages: Fr[], lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, lastL1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>, newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot, newL1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>): CheckpointProvingState;
46
+ getCheckpointProvingState(index: number): CheckpointProvingState | undefined;
47
+ getCheckpointProvingStateByBlockNumber(blockNumber: number): CheckpointProvingState | undefined;
48
+ getBlockProvingStateByBlockNumber(blockNumber: number): import("./block-proving-state.js").BlockProvingState | undefined;
44
49
  verifyState(): boolean;
45
- isAcceptingBlocks(): boolean;
46
- setBlockRootRollupProof(blockIndex: number, proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): TreeNodeLocation;
47
- setBlockMergeRollupProof(location: TreeNodeLocation, proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
48
- setRootRollupProof(proof: PublicInputsAndRecursiveProof<RootRollupPublicInputs>): void;
49
- setPaddingBlockRootProof(proof: PublicInputsAndRecursiveProof<BlockRootOrBlockMergePublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
50
- setFinalBatchedBlob(batchedBlob: BatchedBlob): void;
51
- setBlobAccumulators(toBlock?: number): Promise<void>;
50
+ isAcceptingCheckpoints(): boolean;
51
+ setCheckpointRootRollupProof(checkpointIndex: number, provingOutput: PublicInputsAndRecursiveProof<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): TreeNodeLocation;
52
+ tryStartProvingCheckpointMerge(location: TreeNodeLocation): boolean;
53
+ setCheckpointMergeRollupProof(location: TreeNodeLocation, provingOutput: PublicInputsAndRecursiveProof<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
54
+ tryStartProvingRootRollup(): boolean;
55
+ setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>): void;
56
+ tryStartProvingPaddingCheckpoint(): boolean;
57
+ setCheckpointPaddingProof(provingOutput: PublicInputsAndRecursiveProof<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>): void;
58
+ setBlobAccumulators(): Promise<void>;
59
+ finalizeBatchedBlob(): Promise<void>;
52
60
  getParentLocation(location: TreeNodeLocation): TreeNodeLocation;
53
- getBlockMergeRollupInputs(mergeLocation: TreeNodeLocation): BlockMergeRollupInputs;
54
- getRootRollupInputs(): RootRollupInputs;
55
- getPaddingBlockRootInputs(): import("@aztec/stdlib/rollup").PaddingBlockRootRollupInputs;
56
- getBlockProvingStateByBlockNumber(blockNumber: number): BlockProvingState | undefined;
61
+ getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation): CheckpointMergeRollupPrivateInputs;
62
+ getRootRollupInputs(): RootRollupPrivateInputs;
63
+ getPaddingCheckpointInputs(): CheckpointPaddingRollupPrivateInputs;
57
64
  getEpochProofResult(): {
58
65
  proof: Proof;
59
66
  publicInputs: RootRollupPublicInputs;
60
67
  batchedBlobInputs: BatchedBlob;
61
68
  };
62
- isReadyForBlockMerge(location: TreeNodeLocation): boolean;
69
+ isReadyForCheckpointMerge(location: TreeNodeLocation): boolean;
63
70
  isReadyForRootRollup(): boolean;
64
71
  cancel(): void;
65
72
  reject(reason: string): void;
@@ -1 +1 @@
1
- {"version":3,"file":"epoch-proving-state.d.ts","sourceRoot":"","sources":["../../src/orchestrator/epoch-proving-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,KAAK,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAChF,OAAO,KAAK,EACV,cAAc,EACd,wCAAwC,EACxC,yCAAyC,EAC1C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,KAAK,gBAAgB,EAAuB,MAAM,yBAAyB,CAAC;AAErF,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AACrF,OAAO,KAAK,EAAE,wCAAwC,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EACL,sBAAsB,EACtB,KAAK,iCAAiC,EAEtC,gBAAgB,EAChB,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAA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W;IAQX,sBAAsB;IAItB,4BAA4B,CACjC,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,6BAA6B,CAC1C,4BAA4B,EAC5B,OAAO,yCAAyC,CACjD,GACA,gBAAgB;IAIZ,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB;IASzD,6BAA6B,CAClC,QAAQ,EAAE,gBAAgB,EAC1B,aAAa,EAAE,6BAA6B,CAC1C,4BAA4B,EAC5B,OAAO,yCAAyC,CACjD;IAKI,yBAAyB;IASzB,kBAAkB,CAAC,aAAa,EAAE,6BAA6B,CAAC,sBAAsB,CAAC;IAIvF,gCAAgC;IAShC,yBAAyB,CAC9B,aAAa,EAAE,6BAA6B,CAC1C,4BAA4B,EAC5B,OAAO,yCAAyC,CACjD;IAKU,mBAAmB;IAwBnB,mBAAmB;IAOzB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB;IAI5C,8BAA8B,CAAC,aAAa,EAAE,gBAAgB;IAS9D,mBAAmB;IAWnB,0BAA0B;IAI1B,mBAAmB,IAAI;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,YAAY,EAAE,sBAAsB,CAAC;QAAC,iBAAiB,EAAE,WAAW,CAAA;KAAE;IAc7G,yBAAyB,CAAC,QAAQ,EAAE,gBAAgB;IAKpD,oBAAoB;IAMpB,MAAM;IAMN,MAAM,CAAC,MAAM,EAAE,MAAM;IAUrB,OAAO,CAAC,MAAM,EAAE,aAAa;CAerC"}
@@ -1,8 +1,8 @@
1
+ import { BatchedBlobAccumulator } from '@aztec/blob-lib';
1
2
  import { UnbalancedTreeStore } from '@aztec/foundation/trees';
2
- import { getVKIndex, getVKSiblingPath } from '@aztec/noir-protocol-circuits-types/vk-tree';
3
- import { BlockMergeRollupInputs, PreviousRollupBlockData, RootRollupInputs } from '@aztec/stdlib/rollup';
4
- import { VkData } from '@aztec/stdlib/vks';
5
- import { BlockProvingState } from './block-proving-state.js';
3
+ import { CheckpointMergeRollupPrivateInputs, CheckpointPaddingRollupPrivateInputs, RootRollupPrivateInputs } from '@aztec/stdlib/rollup';
4
+ import { toProofData } from './block-building-helpers.js';
5
+ import { CheckpointProvingState } from './checkpoint-proving-state.js';
6
6
  var PROVING_STATE_LIFECYCLE = /*#__PURE__*/ function(PROVING_STATE_LIFECYCLE) {
7
7
  PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_CREATED"] = 0] = "PROVING_STATE_CREATED";
8
8
  PROVING_STATE_LIFECYCLE[PROVING_STATE_LIFECYCLE["PROVING_STATE_FULL"] = 1] = "PROVING_STATE_FULL";
@@ -17,131 +17,187 @@ var PROVING_STATE_LIFECYCLE = /*#__PURE__*/ function(PROVING_STATE_LIFECYCLE) {
17
17
  * Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
18
18
  */ export class EpochProvingState {
19
19
  epochNumber;
20
- firstBlockNumber;
21
- totalNumBlocks;
20
+ firstCheckpointNumber;
21
+ totalNumCheckpoints;
22
22
  finalBlobBatchingChallenges;
23
+ onCheckpointBlobAccumulatorSet;
23
24
  completionCallback;
24
25
  rejectionCallback;
25
- blockRootOrMergeProvingOutputs;
26
- paddingBlockRootProvingOutput;
27
- rootRollupProvingOutput;
26
+ checkpointProofs;
27
+ checkpointPaddingProof;
28
+ rootRollupProof;
29
+ checkpoints;
30
+ startBlobAccumulator;
31
+ endBlobAccumulator;
28
32
  finalBatchedBlob;
29
33
  provingStateLifecycle;
30
34
  // Map from tx hash to tube proof promise. Used when kickstarting tube proofs before tx processing.
31
35
  cachedTubeProofs;
32
- blocks;
33
- constructor(epochNumber, firstBlockNumber, totalNumBlocks, finalBlobBatchingChallenges, completionCallback, rejectionCallback){
36
+ constructor(epochNumber, firstCheckpointNumber, totalNumCheckpoints, finalBlobBatchingChallenges, onCheckpointBlobAccumulatorSet, completionCallback, rejectionCallback){
34
37
  this.epochNumber = epochNumber;
35
- this.firstBlockNumber = firstBlockNumber;
36
- this.totalNumBlocks = totalNumBlocks;
38
+ this.firstCheckpointNumber = firstCheckpointNumber;
39
+ this.totalNumCheckpoints = totalNumCheckpoints;
37
40
  this.finalBlobBatchingChallenges = finalBlobBatchingChallenges;
41
+ this.onCheckpointBlobAccumulatorSet = onCheckpointBlobAccumulatorSet;
38
42
  this.completionCallback = completionCallback;
39
43
  this.rejectionCallback = rejectionCallback;
44
+ this.checkpoints = [];
40
45
  this.provingStateLifecycle = 0;
41
46
  this.cachedTubeProofs = new Map();
42
- this.blocks = [];
43
- this.blockRootOrMergeProvingOutputs = new UnbalancedTreeStore(totalNumBlocks);
47
+ this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
48
+ this.startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(finalBlobBatchingChallenges);
44
49
  }
45
50
  // Adds a block to the proving state, returns its index
46
51
  // Will update the proving life cycle if this is the last block
47
- startNewBlock(globalVariables, l1ToL2Messages, l1ToL2MessageTreeSnapshot, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchiveSnapshot, lastArchiveSiblingPath, newArchiveSiblingPath, previousBlockHeader, proverId) {
48
- const index = globalVariables.blockNumber - this.firstBlockNumber;
49
- const block = new BlockProvingState(index, globalVariables, l1ToL2Messages, l1ToL2MessageTreeSnapshot, l1ToL2MessageSubtreeSiblingPath, l1ToL2MessageTreeSnapshotAfterInsertion, lastArchiveSnapshot, lastArchiveSiblingPath, newArchiveSiblingPath, previousBlockHeader, proverId, this);
50
- this.blocks[index] = block;
51
- if (this.blocks.filter((b)=>!!b).length === this.totalNumBlocks) {
52
+ startNewCheckpoint(constants, totalNumBlocks, totalNumBlobFields, previousBlockHeader, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeSiblingPath) {
53
+ const slotNumber = constants.slotNumber;
54
+ if (slotNumber.lt(this.firstCheckpointNumber)) {
55
+ throw new Error(`Unable to start a new checkpoint - checkpoint too old. Epoch started at ${this.firstCheckpointNumber.toNumber()}. Got ${slotNumber.toNumber()}.`);
56
+ }
57
+ const index = slotNumber.sub(this.firstCheckpointNumber).toNumber();
58
+ if (index >= this.totalNumCheckpoints) {
59
+ throw new Error(`Unable to start a new checkpoint at index ${index}. Expected at most ${this.totalNumCheckpoints} checkpoints.`);
60
+ }
61
+ const checkpoint = new CheckpointProvingState(index, constants, totalNumBlocks, totalNumBlobFields, this.finalBlobBatchingChallenges, previousBlockHeader, lastArchiveSiblingPath, l1ToL2Messages, lastL1ToL2MessageTreeSnapshot, lastL1ToL2MessageSubtreeSiblingPath, newL1ToL2MessageTreeSnapshot, newL1ToL2MessageSubtreeSiblingPath, this, this.onCheckpointBlobAccumulatorSet);
62
+ this.checkpoints[index] = checkpoint;
63
+ if (this.checkpoints.filter((c)=>!!c).length === this.totalNumCheckpoints) {
52
64
  this.provingStateLifecycle = 1;
53
65
  }
54
- return block;
66
+ return checkpoint;
67
+ }
68
+ getCheckpointProvingState(index) {
69
+ return this.checkpoints[index];
70
+ }
71
+ getCheckpointProvingStateByBlockNumber(blockNumber) {
72
+ return this.checkpoints.find((c)=>c && blockNumber >= c.firstBlockNumber && blockNumber < c.firstBlockNumber + c.totalNumBlocks);
73
+ }
74
+ getBlockProvingStateByBlockNumber(blockNumber) {
75
+ return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
55
76
  }
56
77
  // Returns true if this proving state is still valid, false otherwise
57
78
  verifyState() {
58
79
  return this.provingStateLifecycle === 0 || this.provingStateLifecycle === 1;
59
80
  }
60
- // Returns true if we are still able to accept blocks, false otherwise
61
- isAcceptingBlocks() {
62
- return this.provingStateLifecycle === 0;
81
+ // Returns true if we are still able to accept checkpoints, false otherwise.
82
+ isAcceptingCheckpoints() {
83
+ return this.checkpoints.filter((c)=>!!c).length < this.totalNumCheckpoints;
63
84
  }
64
- setBlockRootRollupProof(blockIndex, proof) {
65
- return this.blockRootOrMergeProvingOutputs.setLeaf(blockIndex, proof);
85
+ setCheckpointRootRollupProof(checkpointIndex, provingOutput) {
86
+ return this.checkpointProofs.setLeaf(checkpointIndex, {
87
+ provingOutput
88
+ });
66
89
  }
67
- setBlockMergeRollupProof(location, proof) {
68
- this.blockRootOrMergeProvingOutputs.setNode(location, proof);
90
+ tryStartProvingCheckpointMerge(location) {
91
+ if (this.checkpointProofs.getNode(location)?.isProving) {
92
+ return false;
93
+ } else {
94
+ this.checkpointProofs.setNode(location, {
95
+ isProving: true
96
+ });
97
+ return true;
98
+ }
69
99
  }
70
- setRootRollupProof(proof) {
71
- this.rootRollupProvingOutput = proof;
100
+ setCheckpointMergeRollupProof(location, provingOutput) {
101
+ this.checkpointProofs.setNode(location, {
102
+ provingOutput
103
+ });
72
104
  }
73
- setPaddingBlockRootProof(proof) {
74
- this.paddingBlockRootProvingOutput = proof;
105
+ tryStartProvingRootRollup() {
106
+ if (this.rootRollupProof?.isProving) {
107
+ return false;
108
+ } else {
109
+ this.rootRollupProof = {
110
+ isProving: true
111
+ };
112
+ return true;
113
+ }
75
114
  }
76
- setFinalBatchedBlob(batchedBlob) {
77
- this.finalBatchedBlob = batchedBlob;
115
+ setRootRollupProof(provingOutput) {
116
+ this.rootRollupProof = {
117
+ provingOutput
118
+ };
78
119
  }
79
- async setBlobAccumulators(toBlock) {
80
- let previousAccumulator;
81
- const end = toBlock ? toBlock - this.firstBlockNumber : this.blocks.length;
120
+ tryStartProvingPaddingCheckpoint() {
121
+ if (this.checkpointPaddingProof?.isProving) {
122
+ return false;
123
+ } else {
124
+ this.checkpointPaddingProof = {
125
+ isProving: true
126
+ };
127
+ return true;
128
+ }
129
+ }
130
+ setCheckpointPaddingProof(provingOutput) {
131
+ this.checkpointPaddingProof = {
132
+ provingOutput
133
+ };
134
+ }
135
+ async setBlobAccumulators() {
136
+ let previousAccumulator = this.startBlobAccumulator;
82
137
  // Accumulate blobs as far as we can for this epoch.
83
- for(let i = 0; i <= end; i++){
84
- const block = this.blocks[i];
85
- if (!block || !block.block) {
138
+ for(let i = 0; i < this.totalNumCheckpoints; i++){
139
+ const checkpoint = this.checkpoints[i];
140
+ if (!checkpoint) {
86
141
  break;
87
142
  }
88
- if (!block.startBlobAccumulator) {
89
- // startBlobAccumulator always exists for firstBlockNumber, so the below should never assign an undefined:
90
- block.setStartBlobAccumulator(previousAccumulator);
143
+ const endAccumulator = checkpoint.getEndBlobAccumulator() || await checkpoint.accumulateBlobs(previousAccumulator);
144
+ if (!endAccumulator) {
145
+ break;
91
146
  }
92
- if (block.startBlobAccumulator && !block.endBlobAccumulator) {
93
- await block.accumulateBlobs();
147
+ previousAccumulator = endAccumulator;
148
+ // If this is the last checkpoint, set the end blob accumulator.
149
+ if (i === this.totalNumCheckpoints - 1) {
150
+ this.endBlobAccumulator = endAccumulator;
94
151
  }
95
- previousAccumulator = block.endBlobAccumulator;
96
152
  }
97
153
  }
154
+ async finalizeBatchedBlob() {
155
+ if (!this.endBlobAccumulator) {
156
+ throw new Error('End blob accumulator not ready.');
157
+ }
158
+ this.finalBatchedBlob = await this.endBlobAccumulator.finalize();
159
+ }
98
160
  getParentLocation(location) {
99
- return this.blockRootOrMergeProvingOutputs.getParentLocation(location);
161
+ return this.checkpointProofs.getParentLocation(location);
100
162
  }
101
- getBlockMergeRollupInputs(mergeLocation) {
102
- const [left, right] = this.blockRootOrMergeProvingOutputs.getChildren(mergeLocation);
163
+ getCheckpointMergeRollupInputs(mergeLocation) {
164
+ const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map((c)=>c?.provingOutput);
103
165
  if (!left || !right) {
104
- throw new Error('At lease one child is not ready.');
166
+ throw new Error('At least one child is not ready for the checkpoint merge rollup.');
105
167
  }
106
- return new BlockMergeRollupInputs([
107
- this.#getPreviousRollupData(left),
108
- this.#getPreviousRollupData(right)
168
+ return new CheckpointMergeRollupPrivateInputs([
169
+ toProofData(left),
170
+ toProofData(right)
109
171
  ]);
110
172
  }
111
173
  getRootRollupInputs() {
112
174
  const [left, right] = this.#getChildProofsForRoot();
113
175
  if (!left || !right) {
114
- throw new Error('At lease one child is not ready.');
176
+ throw new Error('At least one child is not ready for the root rollup.');
115
177
  }
116
- return RootRollupInputs.from({
117
- previousRollupData: [
118
- this.#getPreviousRollupData(left),
119
- this.#getPreviousRollupData(right)
178
+ return RootRollupPrivateInputs.from({
179
+ previousRollups: [
180
+ toProofData(left),
181
+ toProofData(right)
120
182
  ]
121
183
  });
122
184
  }
123
- getPaddingBlockRootInputs() {
124
- if (!this.blocks[0]?.isComplete()) {
125
- throw new Error('Epoch needs one completed block in order to be padded.');
126
- }
127
- return this.blocks[0].getPaddingBlockRootInputs();
128
- }
129
- // Returns a specific transaction proving state
130
- getBlockProvingStateByBlockNumber(blockNumber) {
131
- return this.blocks.find((block)=>block?.blockNumber === blockNumber);
185
+ getPaddingCheckpointInputs() {
186
+ return new CheckpointPaddingRollupPrivateInputs();
132
187
  }
133
188
  getEpochProofResult() {
134
- if (!this.rootRollupProvingOutput || !this.finalBatchedBlob) {
189
+ const provingOutput = this.rootRollupProof?.provingOutput;
190
+ if (!provingOutput || !this.finalBatchedBlob) {
135
191
  throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
136
192
  }
137
193
  return {
138
- proof: this.rootRollupProvingOutput.proof.binaryProof,
139
- publicInputs: this.rootRollupProvingOutput.inputs,
194
+ proof: provingOutput.proof.binaryProof,
195
+ publicInputs: provingOutput.inputs,
140
196
  batchedBlobInputs: this.finalBatchedBlob
141
197
  };
142
198
  }
143
- isReadyForBlockMerge(location) {
144
- return this.blockRootOrMergeProvingOutputs.getSibling(location) !== undefined;
199
+ isReadyForCheckpointMerge(location) {
200
+ return !!this.checkpointProofs.getSibling(location)?.provingOutput;
145
201
  }
146
202
  // Returns true if we have sufficient inputs to execute the block root rollup
147
203
  isReadyForRootRollup() {
@@ -176,14 +232,9 @@ var PROVING_STATE_LIFECYCLE = /*#__PURE__*/ function(PROVING_STATE_LIFECYCLE) {
176
232
  index: 0
177
233
  };
178
234
  // If there's only 1 block, its block root proof will be stored at the root.
179
- return this.totalNumBlocks === 1 ? [
180
- this.blockRootOrMergeProvingOutputs.getNode(rootLocation),
181
- this.paddingBlockRootProvingOutput
182
- ] : this.blockRootOrMergeProvingOutputs.getChildren(rootLocation);
183
- }
184
- #getPreviousRollupData({ inputs, proof, verificationKey }) {
185
- const leafIndex = getVKIndex(verificationKey.keyAsFields);
186
- const vkData = new VkData(verificationKey, leafIndex, getVKSiblingPath(leafIndex));
187
- return new PreviousRollupBlockData(inputs, proof, vkData);
235
+ return this.totalNumCheckpoints === 1 ? [
236
+ this.checkpointProofs.getNode(rootLocation)?.provingOutput,
237
+ this.checkpointPaddingProof?.provingOutput
238
+ ] : this.checkpointProofs.getChildren(rootLocation).map((c)=>c?.provingOutput);
188
239
  }
189
240
  }