@aztec/prover-client 0.0.1-fake-ceab37513c → 0.0.2-commit.217f559981
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/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +2 -2
- package/dest/index.d.ts +1 -1
- 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 +48 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +202 -0
- package/dest/mocks/fixtures.d.ts +5 -5
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +35 -16
- package/dest/mocks/test_context.d.ts +39 -33
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +141 -82
- package/dest/orchestrator/block-building-helpers.d.ts +34 -34
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +151 -187
- package/dest/orchestrator/block-proving-state.d.ts +71 -55
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +280 -185
- package/dest/orchestrator/checkpoint-proving-state.d.ts +76 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +243 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +40 -32
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +165 -85
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +51 -35
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +847 -329
- package/dest/orchestrator/orchestrator_metrics.d.ts +1 -3
- package/dest/orchestrator/orchestrator_metrics.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator_metrics.js +2 -15
- package/dest/orchestrator/tx-proving-state.d.ts +15 -12
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +27 -33
- package/dest/prover-client/factory.d.ts +3 -3
- package/dest/prover-client/factory.d.ts.map +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +5 -5
- package/dest/prover-client/prover-client.d.ts.map +1 -1
- package/dest/prover-client/prover-client.js +15 -10
- package/dest/prover-client/server-epoch-prover.d.ts +13 -11
- package/dest/prover-client/server-epoch-prover.d.ts.map +1 -1
- package/dest/prover-client/server-epoch-prover.js +9 -9
- package/dest/proving_broker/broker_prover_facade.d.ts +28 -21
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +45 -36
- package/dest/proving_broker/config.d.ts +24 -8
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +26 -3
- package/dest/proving_broker/factory.d.ts +1 -1
- package/dest/proving_broker/fixtures.d.ts +3 -2
- package/dest/proving_broker/fixtures.d.ts.map +1 -1
- package/dest/proving_broker/fixtures.js +3 -2
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -5
- package/dest/proving_broker/proof_store/factory.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/factory.js +7 -30
- 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 +2 -1
- 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/proof_store/inline_proof_store.d.ts +1 -1
- package/dest/proving_broker/proof_store/inline_proof_store.d.ts.map +1 -1
- package/dest/proving_broker/proof_store/proof_store.d.ts +1 -1
- package/dest/proving_broker/proving_agent.d.ts +5 -9
- package/dest/proving_broker/proving_agent.d.ts.map +1 -1
- package/dest/proving_broker/proving_agent.js +4 -19
- package/dest/proving_broker/proving_broker.d.ts +7 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +64 -30
- package/dest/proving_broker/proving_broker_database/memory.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/memory.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +5 -3
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +392 -3
- package/dest/proving_broker/proving_broker_database.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_instrumentation.js +15 -35
- package/dest/proving_broker/proving_job_controller.d.ts +5 -3
- package/dest/proving_broker/proving_job_controller.d.ts.map +1 -1
- package/dest/proving_broker/proving_job_controller.js +46 -24
- package/dest/proving_broker/rpc.d.ts +7 -5
- package/dest/proving_broker/rpc.d.ts.map +1 -1
- package/dest/proving_broker/rpc.js +8 -0
- package/dest/test/mock_proof_store.d.ts +1 -1
- package/dest/test/mock_proof_store.d.ts.map +1 -1
- package/dest/test/mock_prover.d.ts +23 -19
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -23
- package/package.json +21 -20
- package/src/config.ts +2 -2
- package/src/light/index.ts +1 -0
- package/src/light/lightweight_checkpoint_builder.ts +294 -0
- package/src/mocks/fixtures.ts +43 -37
- package/src/mocks/test_context.ts +201 -114
- package/src/orchestrator/block-building-helpers.ts +233 -313
- package/src/orchestrator/block-proving-state.ts +324 -247
- package/src/orchestrator/checkpoint-proving-state.ts +349 -0
- package/src/orchestrator/epoch-proving-state.ts +229 -132
- package/src/orchestrator/orchestrator.ts +630 -385
- package/src/orchestrator/orchestrator_metrics.ts +2 -25
- package/src/orchestrator/tx-proving-state.ts +49 -60
- package/src/prover-client/factory.ts +6 -2
- package/src/prover-client/prover-client.ts +31 -23
- package/src/prover-client/server-epoch-prover.ts +30 -21
- package/src/proving_broker/broker_prover_facade.ts +183 -118
- package/src/proving_broker/config.ts +30 -1
- package/src/proving_broker/fixtures.ts +8 -3
- package/src/proving_broker/proof_store/factory.ts +10 -32
- package/src/proving_broker/proof_store/file_store_proof_store.ts +78 -0
- package/src/proving_broker/proof_store/index.ts +1 -0
- package/src/proving_broker/proving_agent.ts +6 -19
- package/src/proving_broker/proving_broker.ts +72 -28
- package/src/proving_broker/proving_broker_database/memory.ts +2 -1
- package/src/proving_broker/proving_broker_database/persisted.ts +20 -5
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_broker_instrumentation.ts +14 -35
- package/src/proving_broker/proving_job_controller.ts +51 -25
- package/src/proving_broker/rpc.ts +14 -0
- package/src/test/mock_prover.ts +144 -74
- 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/dest/block-factory/index.d.ts +0 -2
- package/dest/block-factory/index.d.ts.map +0 -1
- package/dest/block-factory/index.js +0 -1
- package/dest/block-factory/light.d.ts +0 -36
- package/dest/block-factory/light.d.ts.map +0 -1
- package/dest/block-factory/light.js +0 -87
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +0 -14
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts.map +0 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.js +0 -52
- package/dest/proving_broker/proving_agent_instrumentation.d.ts +0 -8
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +0 -1
- package/dest/proving_broker/proving_agent_instrumentation.js +0 -16
- package/src/bin/get-proof-inputs.ts +0 -59
- package/src/block-factory/index.ts +0 -1
- package/src/block-factory/light.ts +0 -114
- package/src/proving_broker/proof_store/gcs_proof_store.ts +0 -76
- package/src/proving_broker/proving_agent_instrumentation.ts +0 -21
|
@@ -1,29 +1,37 @@
|
|
|
1
|
-
import { BatchedBlob, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
-
import
|
|
3
|
-
ARCHIVE_HEIGHT,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { BatchedBlob, BatchedBlobAccumulator, type FinalBlobBatchingChallenges } from '@aztec/blob-lib';
|
|
2
|
+
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
4
|
+
type L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH,
|
|
5
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
6
|
+
type NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH,
|
|
7
|
+
OUT_HASH_TREE_HEIGHT,
|
|
7
8
|
} from '@aztec/constants';
|
|
8
|
-
import
|
|
9
|
-
import
|
|
9
|
+
import { BlockNumber, EpochNumber } from '@aztec/foundation/branded-types';
|
|
10
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
11
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import {
|
|
13
|
+
MerkleTreeCalculator,
|
|
14
|
+
type TreeNodeLocation,
|
|
15
|
+
UnbalancedTreeStore,
|
|
16
|
+
shaMerkleHash,
|
|
17
|
+
} from '@aztec/foundation/trees';
|
|
18
|
+
import type { PublicInputsAndRecursiveProof } from '@aztec/stdlib/interfaces/server';
|
|
14
19
|
import type { Proof } from '@aztec/stdlib/proofs';
|
|
15
20
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
CheckpointConstantData,
|
|
22
|
+
CheckpointMergeRollupPrivateInputs,
|
|
23
|
+
CheckpointPaddingRollupPrivateInputs,
|
|
24
|
+
CheckpointRollupPublicInputs,
|
|
25
|
+
PublicChonkVerifierPublicInputs,
|
|
26
|
+
RootRollupPrivateInputs,
|
|
20
27
|
type RootRollupPublicInputs,
|
|
21
28
|
} from '@aztec/stdlib/rollup';
|
|
22
|
-
import
|
|
23
|
-
import type { BlockHeader
|
|
24
|
-
import { VkData } from '@aztec/stdlib/vks';
|
|
29
|
+
import { AppendOnlyTreeSnapshot, type MerkleTreeId } from '@aztec/stdlib/trees';
|
|
30
|
+
import type { BlockHeader } from '@aztec/stdlib/tx';
|
|
25
31
|
|
|
26
|
-
import {
|
|
32
|
+
import { toProofData } from './block-building-helpers.js';
|
|
33
|
+
import type { ProofState } from './block-proving-state.js';
|
|
34
|
+
import { CheckpointProvingState } from './checkpoint-proving-state.js';
|
|
27
35
|
|
|
28
36
|
export type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
|
|
29
37
|
|
|
@@ -43,66 +51,98 @@ export type ProvingResult = { status: 'success' } | { status: 'failure'; reason:
|
|
|
43
51
|
* Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
|
|
44
52
|
*/
|
|
45
53
|
export class EpochProvingState {
|
|
46
|
-
private
|
|
47
|
-
|
|
54
|
+
private checkpointProofs: UnbalancedTreeStore<
|
|
55
|
+
ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
48
56
|
>;
|
|
49
|
-
private
|
|
50
|
-
|
|
|
57
|
+
private checkpointPaddingProof:
|
|
58
|
+
| ProofState<CheckpointRollupPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
51
59
|
| undefined;
|
|
52
|
-
private
|
|
60
|
+
private rootRollupProof: ProofState<RootRollupPublicInputs, typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined;
|
|
61
|
+
private checkpoints: (CheckpointProvingState | undefined)[] = [];
|
|
62
|
+
private startBlobAccumulator: BatchedBlobAccumulator;
|
|
63
|
+
private endBlobAccumulator: BatchedBlobAccumulator | undefined;
|
|
53
64
|
private finalBatchedBlob: BatchedBlob | undefined;
|
|
54
65
|
private provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
|
|
55
66
|
|
|
56
|
-
// Map from tx hash to
|
|
57
|
-
public readonly
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
// Map from tx hash to chonk verifier proof promise. Used when kickstarting chonk verifier proofs before tx processing.
|
|
68
|
+
public readonly cachedChonkVerifierProofs = new Map<
|
|
69
|
+
string,
|
|
70
|
+
Promise<
|
|
71
|
+
PublicInputsAndRecursiveProof<PublicChonkVerifierPublicInputs, typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH>
|
|
72
|
+
>
|
|
73
|
+
>();
|
|
60
74
|
|
|
61
75
|
constructor(
|
|
62
|
-
public readonly epochNumber:
|
|
63
|
-
public readonly
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
public readonly epochNumber: EpochNumber,
|
|
77
|
+
public readonly totalNumCheckpoints: number,
|
|
78
|
+
private readonly finalBlobBatchingChallenges: FinalBlobBatchingChallenges,
|
|
79
|
+
private onCheckpointBlobAccumulatorSet: (checkpoint: CheckpointProvingState) => Promise<void>,
|
|
66
80
|
private completionCallback: (result: ProvingResult) => void,
|
|
67
81
|
private rejectionCallback: (reason: string) => void,
|
|
68
82
|
) {
|
|
69
|
-
this.
|
|
83
|
+
this.checkpointProofs = new UnbalancedTreeStore(totalNumCheckpoints);
|
|
84
|
+
this.startBlobAccumulator = BatchedBlobAccumulator.newWithChallenges(finalBlobBatchingChallenges);
|
|
70
85
|
}
|
|
71
86
|
|
|
72
87
|
// Adds a block to the proving state, returns its index
|
|
73
88
|
// Will update the proving life cycle if this is the last block
|
|
74
|
-
public
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
l1ToL2MessageSubtreeSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
|
|
79
|
-
l1ToL2MessageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
|
|
80
|
-
lastArchiveSnapshot: AppendOnlyTreeSnapshot,
|
|
81
|
-
lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
82
|
-
newArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
89
|
+
public startNewCheckpoint(
|
|
90
|
+
checkpointIndex: number,
|
|
91
|
+
constants: CheckpointConstantData,
|
|
92
|
+
totalNumBlocks: number,
|
|
83
93
|
previousBlockHeader: BlockHeader,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
95
|
+
l1ToL2Messages: Fr[],
|
|
96
|
+
lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
97
|
+
lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH>,
|
|
98
|
+
newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
99
|
+
newL1ToL2MessageSubtreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH>,
|
|
100
|
+
): CheckpointProvingState {
|
|
101
|
+
if (checkpointIndex >= this.totalNumCheckpoints) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Unable to start a new checkpoint at index ${checkpointIndex}. Expected at most ${this.totalNumCheckpoints} checkpoints.`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const checkpoint = new CheckpointProvingState(
|
|
108
|
+
checkpointIndex,
|
|
109
|
+
constants,
|
|
110
|
+
totalNumBlocks,
|
|
111
|
+
this.finalBlobBatchingChallenges,
|
|
97
112
|
previousBlockHeader,
|
|
98
|
-
|
|
113
|
+
lastArchiveSiblingPath,
|
|
114
|
+
l1ToL2Messages,
|
|
115
|
+
lastL1ToL2MessageTreeSnapshot,
|
|
116
|
+
lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
117
|
+
newL1ToL2MessageTreeSnapshot,
|
|
118
|
+
newL1ToL2MessageSubtreeRootSiblingPath,
|
|
99
119
|
this,
|
|
120
|
+
this.onCheckpointBlobAccumulatorSet,
|
|
100
121
|
);
|
|
101
|
-
this.
|
|
102
|
-
|
|
122
|
+
this.checkpoints[checkpointIndex] = checkpoint;
|
|
123
|
+
|
|
124
|
+
if (this.checkpoints.filter(c => !!c).length === this.totalNumCheckpoints) {
|
|
103
125
|
this.provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_FULL;
|
|
104
126
|
}
|
|
105
|
-
|
|
127
|
+
|
|
128
|
+
return checkpoint;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public getCheckpointProvingState(index: number) {
|
|
132
|
+
return this.checkpoints[index];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public getCheckpointProvingStateByBlockNumber(blockNumber: BlockNumber) {
|
|
136
|
+
return this.checkpoints.find(
|
|
137
|
+
c =>
|
|
138
|
+
c &&
|
|
139
|
+
Number(blockNumber) >= Number(c.firstBlockNumber) &&
|
|
140
|
+
Number(blockNumber) < Number(c.firstBlockNumber) + c.totalNumBlocks,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
public getBlockProvingStateByBlockNumber(blockNumber: BlockNumber) {
|
|
145
|
+
return this.getCheckpointProvingStateByBlockNumber(blockNumber)?.getBlockProvingStateByBlockNumber(blockNumber);
|
|
106
146
|
}
|
|
107
147
|
|
|
108
148
|
// Returns true if this proving state is still valid, false otherwise
|
|
@@ -113,120 +153,190 @@ export class EpochProvingState {
|
|
|
113
153
|
);
|
|
114
154
|
}
|
|
115
155
|
|
|
116
|
-
// Returns true if we are still able to accept
|
|
117
|
-
public
|
|
118
|
-
return this.
|
|
156
|
+
// Returns true if we are still able to accept checkpoints, false otherwise.
|
|
157
|
+
public isAcceptingCheckpoints() {
|
|
158
|
+
return this.checkpoints.filter(c => !!c).length < this.totalNumCheckpoints;
|
|
119
159
|
}
|
|
120
160
|
|
|
121
|
-
public
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
161
|
+
public setCheckpointRootRollupProof(
|
|
162
|
+
checkpointIndex: number,
|
|
163
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
164
|
+
CheckpointRollupPublicInputs,
|
|
125
165
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
126
166
|
>,
|
|
127
167
|
): TreeNodeLocation {
|
|
128
|
-
return this.
|
|
168
|
+
return this.checkpointProofs.setLeaf(checkpointIndex, { provingOutput });
|
|
129
169
|
}
|
|
130
170
|
|
|
131
|
-
public
|
|
171
|
+
public tryStartProvingCheckpointMerge(location: TreeNodeLocation) {
|
|
172
|
+
if (this.checkpointProofs.getNode(location)?.isProving) {
|
|
173
|
+
return false;
|
|
174
|
+
} else {
|
|
175
|
+
this.checkpointProofs.setNode(location, { isProving: true });
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public setCheckpointMergeRollupProof(
|
|
132
181
|
location: TreeNodeLocation,
|
|
133
|
-
|
|
134
|
-
|
|
182
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
183
|
+
CheckpointRollupPublicInputs,
|
|
135
184
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
136
185
|
>,
|
|
137
186
|
) {
|
|
138
|
-
this.
|
|
187
|
+
this.checkpointProofs.setNode(location, { provingOutput });
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
public tryStartProvingRootRollup() {
|
|
191
|
+
if (this.rootRollupProof?.isProving) {
|
|
192
|
+
return false;
|
|
193
|
+
} else {
|
|
194
|
+
this.rootRollupProof = { isProving: true };
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
public setRootRollupProof(provingOutput: PublicInputsAndRecursiveProof<RootRollupPublicInputs>) {
|
|
200
|
+
this.rootRollupProof = { provingOutput };
|
|
139
201
|
}
|
|
140
202
|
|
|
141
|
-
public
|
|
142
|
-
this.
|
|
203
|
+
public tryStartProvingPaddingCheckpoint() {
|
|
204
|
+
if (this.checkpointPaddingProof?.isProving) {
|
|
205
|
+
return false;
|
|
206
|
+
} else {
|
|
207
|
+
this.checkpointPaddingProof = { isProving: true };
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
143
210
|
}
|
|
144
211
|
|
|
145
|
-
public
|
|
146
|
-
|
|
147
|
-
|
|
212
|
+
public setCheckpointPaddingProof(
|
|
213
|
+
provingOutput: PublicInputsAndRecursiveProof<
|
|
214
|
+
CheckpointRollupPublicInputs,
|
|
148
215
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
149
216
|
>,
|
|
150
217
|
) {
|
|
151
|
-
this.
|
|
218
|
+
this.checkpointPaddingProof = { provingOutput };
|
|
152
219
|
}
|
|
153
220
|
|
|
154
|
-
public
|
|
155
|
-
|
|
221
|
+
public async accumulateCheckpointOutHashes() {
|
|
222
|
+
const treeCalculator = await MerkleTreeCalculator.create(OUT_HASH_TREE_HEIGHT, undefined, (left, right) =>
|
|
223
|
+
Promise.resolve(shaMerkleHash(left, right)),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
const computeOutHashHint = async (leaves: Fr[]) => {
|
|
227
|
+
const tree = await treeCalculator.computeTree(leaves.map(l => l.toBuffer()));
|
|
228
|
+
const nextAvailableLeafIndex = leaves.length;
|
|
229
|
+
return {
|
|
230
|
+
treeSnapshot: new AppendOnlyTreeSnapshot(Fr.fromBuffer(tree.root), nextAvailableLeafIndex),
|
|
231
|
+
siblingPath: tree.getSiblingPath(nextAvailableLeafIndex).map(Fr.fromBuffer) as Tuple<
|
|
232
|
+
Fr,
|
|
233
|
+
typeof OUT_HASH_TREE_HEIGHT
|
|
234
|
+
>,
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
let hint = this.checkpoints[0]?.getOutHashHint();
|
|
239
|
+
const outHashes = [];
|
|
240
|
+
for (let i = 0; i < this.totalNumCheckpoints; i++) {
|
|
241
|
+
const checkpoint = this.checkpoints[i];
|
|
242
|
+
if (!checkpoint) {
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// If hints are not set yet, it must be the first checkpoint. Compute the hints with an empty tree.
|
|
247
|
+
hint ??= await computeOutHashHint([]);
|
|
248
|
+
checkpoint.setOutHashHint(hint);
|
|
249
|
+
|
|
250
|
+
// Get the out hash for this checkpoint.
|
|
251
|
+
const outHash = checkpoint.accumulateBlockOutHashes();
|
|
252
|
+
if (!outHash) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
outHashes.push(outHash);
|
|
256
|
+
|
|
257
|
+
// If this is NOT the last checkpoint, get or create the hint for the next checkpoint.
|
|
258
|
+
if (i !== this.totalNumCheckpoints - 1) {
|
|
259
|
+
hint = checkpoint.getOutHashHintForNextCheckpoint() ?? (await computeOutHashHint(outHashes));
|
|
260
|
+
checkpoint.setOutHashHintForNextCheckpoint(hint);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
156
263
|
}
|
|
157
264
|
|
|
158
|
-
public async setBlobAccumulators(
|
|
159
|
-
let previousAccumulator;
|
|
160
|
-
const end = toBlock ? toBlock - this.firstBlockNumber : this.blocks.length;
|
|
265
|
+
public async setBlobAccumulators() {
|
|
266
|
+
let previousAccumulator = this.startBlobAccumulator;
|
|
161
267
|
// Accumulate blobs as far as we can for this epoch.
|
|
162
|
-
for (let i = 0; i
|
|
163
|
-
const
|
|
164
|
-
if (!
|
|
165
|
-
// If the block proving state does not have a .block property, it may be awaiting more txs.
|
|
268
|
+
for (let i = 0; i < this.totalNumCheckpoints; i++) {
|
|
269
|
+
const checkpoint = this.checkpoints[i];
|
|
270
|
+
if (!checkpoint) {
|
|
166
271
|
break;
|
|
167
272
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
273
|
+
|
|
274
|
+
const endAccumulator =
|
|
275
|
+
checkpoint.getEndBlobAccumulator() || (await checkpoint.accumulateBlobs(previousAccumulator));
|
|
276
|
+
if (!endAccumulator) {
|
|
277
|
+
break;
|
|
171
278
|
}
|
|
172
|
-
|
|
173
|
-
|
|
279
|
+
|
|
280
|
+
previousAccumulator = endAccumulator;
|
|
281
|
+
|
|
282
|
+
// If this is the last checkpoint, set the end blob accumulator.
|
|
283
|
+
if (i === this.totalNumCheckpoints - 1) {
|
|
284
|
+
this.endBlobAccumulator = endAccumulator;
|
|
174
285
|
}
|
|
175
|
-
previousAccumulator = block.endBlobAccumulator;
|
|
176
286
|
}
|
|
177
287
|
}
|
|
178
288
|
|
|
289
|
+
public async finalizeBatchedBlob() {
|
|
290
|
+
if (!this.endBlobAccumulator) {
|
|
291
|
+
throw new Error('End blob accumulator not ready.');
|
|
292
|
+
}
|
|
293
|
+
this.finalBatchedBlob = await this.endBlobAccumulator.finalize(true /* verifyProof */);
|
|
294
|
+
}
|
|
295
|
+
|
|
179
296
|
public getParentLocation(location: TreeNodeLocation) {
|
|
180
|
-
return this.
|
|
297
|
+
return this.checkpointProofs.getParentLocation(location);
|
|
181
298
|
}
|
|
182
299
|
|
|
183
|
-
public
|
|
184
|
-
const [left, right] = this.
|
|
300
|
+
public getCheckpointMergeRollupInputs(mergeLocation: TreeNodeLocation) {
|
|
301
|
+
const [left, right] = this.checkpointProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
|
|
185
302
|
if (!left || !right) {
|
|
186
|
-
throw new Error('At
|
|
303
|
+
throw new Error('At least one child is not ready for the checkpoint merge rollup.');
|
|
187
304
|
}
|
|
188
305
|
|
|
189
|
-
return new
|
|
306
|
+
return new CheckpointMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
|
|
190
307
|
}
|
|
191
308
|
|
|
192
309
|
public getRootRollupInputs() {
|
|
193
310
|
const [left, right] = this.#getChildProofsForRoot();
|
|
194
311
|
if (!left || !right) {
|
|
195
|
-
throw new Error('At
|
|
312
|
+
throw new Error('At least one child is not ready for the root rollup.');
|
|
196
313
|
}
|
|
197
314
|
|
|
198
|
-
return
|
|
199
|
-
|
|
315
|
+
return RootRollupPrivateInputs.from({
|
|
316
|
+
previousRollups: [toProofData(left), toProofData(right)],
|
|
200
317
|
});
|
|
201
318
|
}
|
|
202
319
|
|
|
203
|
-
public
|
|
204
|
-
|
|
205
|
-
throw new Error('Epoch needs one completed block in order to be padded.');
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return this.blocks[0].getPaddingBlockRootInputs();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Returns a specific transaction proving state
|
|
212
|
-
public getBlockProvingStateByBlockNumber(blockNumber: number) {
|
|
213
|
-
return this.blocks.find(block => block?.blockNumber === blockNumber);
|
|
320
|
+
public getPaddingCheckpointInputs() {
|
|
321
|
+
return new CheckpointPaddingRollupPrivateInputs();
|
|
214
322
|
}
|
|
215
323
|
|
|
216
324
|
public getEpochProofResult(): { proof: Proof; publicInputs: RootRollupPublicInputs; batchedBlobInputs: BatchedBlob } {
|
|
217
|
-
|
|
325
|
+
const provingOutput = this.rootRollupProof?.provingOutput;
|
|
326
|
+
|
|
327
|
+
if (!provingOutput || !this.finalBatchedBlob) {
|
|
218
328
|
throw new Error('Unable to get epoch proof result. Root rollup is not ready.');
|
|
219
329
|
}
|
|
220
330
|
|
|
221
331
|
return {
|
|
222
|
-
proof:
|
|
223
|
-
publicInputs:
|
|
332
|
+
proof: provingOutput.proof.binaryProof,
|
|
333
|
+
publicInputs: provingOutput.inputs,
|
|
224
334
|
batchedBlobInputs: this.finalBatchedBlob,
|
|
225
335
|
};
|
|
226
336
|
}
|
|
227
337
|
|
|
228
|
-
public
|
|
229
|
-
return this.
|
|
338
|
+
public isReadyForCheckpointMerge(location: TreeNodeLocation) {
|
|
339
|
+
return !!this.checkpointProofs.getSibling(location)?.provingOutput;
|
|
230
340
|
}
|
|
231
341
|
|
|
232
342
|
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
@@ -263,21 +373,8 @@ export class EpochProvingState {
|
|
|
263
373
|
#getChildProofsForRoot() {
|
|
264
374
|
const rootLocation = { level: 0, index: 0 };
|
|
265
375
|
// If there's only 1 block, its block root proof will be stored at the root.
|
|
266
|
-
return this.
|
|
267
|
-
? [this.
|
|
268
|
-
: this.
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
#getPreviousRollupData({
|
|
272
|
-
inputs,
|
|
273
|
-
proof,
|
|
274
|
-
verificationKey,
|
|
275
|
-
}: PublicInputsAndRecursiveProof<
|
|
276
|
-
BlockRootOrBlockMergePublicInputs,
|
|
277
|
-
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
278
|
-
>) {
|
|
279
|
-
const leafIndex = getVKIndex(verificationKey.keyAsFields);
|
|
280
|
-
const vkData = new VkData(verificationKey, leafIndex, getVKSiblingPath(leafIndex));
|
|
281
|
-
return new PreviousRollupBlockData(inputs, proof, vkData);
|
|
376
|
+
return this.totalNumCheckpoints === 1
|
|
377
|
+
? [this.checkpointProofs.getNode(rootLocation)?.provingOutput, this.checkpointPaddingProof?.provingOutput]
|
|
378
|
+
: this.checkpointProofs.getChildren(rootLocation).map(c => c?.provingOutput);
|
|
282
379
|
}
|
|
283
380
|
}
|