@aztec/prover-client 0.55.0 → 0.56.0
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/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -27
- package/dest/mocks/test_context.d.ts +4 -5
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +7 -9
- package/dest/orchestrator/block-building-helpers.d.ts +12 -3
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +34 -32
- package/dest/orchestrator/{proving-state.d.ts → block-proving-state.d.ts} +17 -13
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/block-proving-state.js +170 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +57 -0
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-state.js +151 -0
- package/dest/orchestrator/orchestrator.d.ts +32 -11
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +246 -139
- package/dest/orchestrator/tx-proving-state.d.ts +3 -2
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +54 -26
- package/dest/prover-agent/memory-proving-queue.d.ts +11 -5
- package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
- package/dest/prover-agent/memory-proving-queue.js +16 -6
- package/dest/prover-agent/prover-agent.d.ts.map +1 -1
- package/dest/prover-agent/prover-agent.js +10 -10
- package/dest/prover-agent/rpc.d.ts.map +1 -1
- package/dest/prover-agent/rpc.js +8 -2
- package/dest/test/mock_prover.d.ts +27 -0
- package/dest/test/mock_prover.d.ts.map +1 -0
- package/dest/test/mock_prover.js +58 -0
- package/package.json +13 -11
- package/src/mocks/fixtures.ts +5 -49
- package/src/mocks/test_context.ts +7 -12
- package/src/orchestrator/block-building-helpers.ts +90 -57
- package/src/orchestrator/{proving-state.ts → block-proving-state.ts} +42 -40
- package/src/orchestrator/epoch-proving-state.ts +232 -0
- package/src/orchestrator/orchestrator.ts +410 -244
- package/src/orchestrator/tx-proving-state.ts +63 -27
- package/src/prover-agent/memory-proving-queue.ts +30 -16
- package/src/prover-agent/prover-agent.ts +11 -9
- package/src/prover-agent/rpc.ts +9 -0
- package/src/test/mock_prover.ts +170 -0
- package/dest/orchestrator/proving-state.d.ts.map +0 -1
- package/dest/orchestrator/proving-state.js +0 -170
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { type MerkleTreeId, type ProvingResult } from '@aztec/circuit-types';
|
|
2
|
+
import {
|
|
3
|
+
type ARCHIVE_HEIGHT,
|
|
4
|
+
type AppendOnlyTreeSnapshot,
|
|
5
|
+
type BlockRootOrBlockMergePublicInputs,
|
|
6
|
+
Fr,
|
|
7
|
+
type GlobalVariables,
|
|
8
|
+
type L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
|
|
9
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
10
|
+
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
11
|
+
type Proof,
|
|
12
|
+
type RecursiveProof,
|
|
13
|
+
type RootRollupPublicInputs,
|
|
14
|
+
type VerificationKeyAsFields,
|
|
15
|
+
} from '@aztec/circuits.js';
|
|
16
|
+
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
17
|
+
import { type Tuple } from '@aztec/foundation/serialize';
|
|
18
|
+
|
|
19
|
+
import { BlockProvingState } from './block-proving-state.js';
|
|
20
|
+
|
|
21
|
+
export type TreeSnapshots = Map<MerkleTreeId, AppendOnlyTreeSnapshot>;
|
|
22
|
+
|
|
23
|
+
enum PROVING_STATE_LIFECYCLE {
|
|
24
|
+
PROVING_STATE_CREATED,
|
|
25
|
+
PROVING_STATE_FULL,
|
|
26
|
+
PROVING_STATE_RESOLVED,
|
|
27
|
+
PROVING_STATE_REJECTED,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type BlockMergeRollupInputData = {
|
|
31
|
+
inputs: [BlockRootOrBlockMergePublicInputs | undefined, BlockRootOrBlockMergePublicInputs | undefined];
|
|
32
|
+
proofs: [
|
|
33
|
+
RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined,
|
|
34
|
+
RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH> | undefined,
|
|
35
|
+
];
|
|
36
|
+
verificationKeys: [VerificationKeyAsFields | undefined, VerificationKeyAsFields | undefined];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The current state of the proving schedule for an epoch.
|
|
41
|
+
* Contains the raw inputs and intermediate state to generate every constituent proof in the tree.
|
|
42
|
+
* Carries an identifier so we can identify if the proving state is discarded and a new one started.
|
|
43
|
+
* Captures resolve and reject callbacks to provide a promise base interface to the consumer of our proving.
|
|
44
|
+
*/
|
|
45
|
+
export class EpochProvingState {
|
|
46
|
+
private provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
|
|
47
|
+
|
|
48
|
+
private mergeRollupInputs: BlockMergeRollupInputData[] = [];
|
|
49
|
+
public rootRollupPublicInputs: RootRollupPublicInputs | undefined;
|
|
50
|
+
public finalProof: Proof | undefined;
|
|
51
|
+
public blocks: BlockProvingState[] = [];
|
|
52
|
+
|
|
53
|
+
constructor(
|
|
54
|
+
public readonly epochNumber: number,
|
|
55
|
+
public readonly totalNumBlocks: number,
|
|
56
|
+
private completionCallback: (result: ProvingResult) => void,
|
|
57
|
+
private rejectionCallback: (reason: string) => void,
|
|
58
|
+
) {}
|
|
59
|
+
|
|
60
|
+
/** Returns the current block proving state */
|
|
61
|
+
public get currentBlock(): BlockProvingState | undefined {
|
|
62
|
+
return this.blocks[this.blocks.length - 1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Returns the number of levels of merge rollups
|
|
66
|
+
public get numMergeLevels() {
|
|
67
|
+
return BigInt(Math.ceil(Math.log2(this.totalNumBlocks)) - 1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Calculates the index and level of the parent rollup circuit
|
|
71
|
+
// Based on tree implementation in unbalanced_tree.ts -> batchInsert()
|
|
72
|
+
// REFACTOR: This is repeated from the block orchestrator
|
|
73
|
+
public findMergeLevel(currentLevel: bigint, currentIndex: bigint) {
|
|
74
|
+
const moveUpMergeLevel = (levelSize: number, index: bigint, nodeToShift: boolean) => {
|
|
75
|
+
levelSize /= 2;
|
|
76
|
+
if (levelSize & 1) {
|
|
77
|
+
[levelSize, nodeToShift] = nodeToShift ? [levelSize + 1, false] : [levelSize - 1, true];
|
|
78
|
+
}
|
|
79
|
+
index >>= 1n;
|
|
80
|
+
return { thisLevelSize: levelSize, thisIndex: index, shiftUp: nodeToShift };
|
|
81
|
+
};
|
|
82
|
+
let [thisLevelSize, shiftUp] =
|
|
83
|
+
this.totalNumBlocks & 1 ? [this.totalNumBlocks - 1, true] : [this.totalNumBlocks, false];
|
|
84
|
+
const maxLevel = this.numMergeLevels + 1n;
|
|
85
|
+
let placeholder = currentIndex;
|
|
86
|
+
for (let i = 0; i < maxLevel - currentLevel; i++) {
|
|
87
|
+
({ thisLevelSize, thisIndex: placeholder, shiftUp } = moveUpMergeLevel(thisLevelSize, placeholder, shiftUp));
|
|
88
|
+
}
|
|
89
|
+
let thisIndex = currentIndex;
|
|
90
|
+
let mergeLevel = currentLevel;
|
|
91
|
+
while (thisIndex >= thisLevelSize && mergeLevel != 0n) {
|
|
92
|
+
mergeLevel -= 1n;
|
|
93
|
+
({ thisLevelSize, thisIndex, shiftUp } = moveUpMergeLevel(thisLevelSize, thisIndex, shiftUp));
|
|
94
|
+
}
|
|
95
|
+
return [mergeLevel - 1n, thisIndex >> 1n, thisIndex & 1n];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Adds a block to the proving state, returns its index
|
|
99
|
+
// Will update the proving life cycle if this is the last block
|
|
100
|
+
public startNewBlock(
|
|
101
|
+
numTxs: number,
|
|
102
|
+
globalVariables: GlobalVariables,
|
|
103
|
+
l1ToL2Messages: Fr[],
|
|
104
|
+
messageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
105
|
+
messageTreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
|
|
106
|
+
messageTreeSnapshotAfterInsertion: AppendOnlyTreeSnapshot,
|
|
107
|
+
archiveTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
108
|
+
archiveTreeRootSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
109
|
+
previousBlockHash: Fr,
|
|
110
|
+
completionCallback?: (result: ProvingResult) => void,
|
|
111
|
+
rejectionCallback?: (reason: string) => void,
|
|
112
|
+
) {
|
|
113
|
+
const block = new BlockProvingState(
|
|
114
|
+
this.blocks.length,
|
|
115
|
+
numTxs,
|
|
116
|
+
globalVariables,
|
|
117
|
+
padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
|
|
118
|
+
messageTreeSnapshot,
|
|
119
|
+
messageTreeRootSiblingPath,
|
|
120
|
+
messageTreeSnapshotAfterInsertion,
|
|
121
|
+
archiveTreeSnapshot,
|
|
122
|
+
archiveTreeRootSiblingPath,
|
|
123
|
+
previousBlockHash,
|
|
124
|
+
completionCallback,
|
|
125
|
+
reason => {
|
|
126
|
+
// Reject the block
|
|
127
|
+
if (rejectionCallback) {
|
|
128
|
+
rejectionCallback(reason);
|
|
129
|
+
}
|
|
130
|
+
// An error on any block rejects this whole epoch
|
|
131
|
+
this.reject(reason);
|
|
132
|
+
},
|
|
133
|
+
);
|
|
134
|
+
this.blocks.push(block);
|
|
135
|
+
if (this.blocks.length === this.totalNumBlocks) {
|
|
136
|
+
this.provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_FULL;
|
|
137
|
+
}
|
|
138
|
+
return this.blocks.length - 1;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Returns true if this proving state is still valid, false otherwise
|
|
142
|
+
public verifyState() {
|
|
143
|
+
return (
|
|
144
|
+
this.provingStateLifecycle === PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED ||
|
|
145
|
+
this.provingStateLifecycle === PROVING_STATE_LIFECYCLE.PROVING_STATE_FULL
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Returns true if we are still able to accept blocks, false otherwise
|
|
150
|
+
public isAcceptingBlocks() {
|
|
151
|
+
return this.provingStateLifecycle === PROVING_STATE_LIFECYCLE.PROVING_STATE_CREATED;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Stores the inputs to a merge circuit and determines if the circuit is ready to be executed
|
|
156
|
+
* @param mergeInputs - The inputs to store
|
|
157
|
+
* @param indexWithinMerge - The index in the set of inputs to this merge circuit
|
|
158
|
+
* @param indexOfMerge - The global index of this merge circuit
|
|
159
|
+
* @returns True if the merge circuit is ready to be executed, false otherwise
|
|
160
|
+
*/
|
|
161
|
+
public storeMergeInputs(
|
|
162
|
+
mergeInputs: [
|
|
163
|
+
BlockRootOrBlockMergePublicInputs,
|
|
164
|
+
RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>,
|
|
165
|
+
VerificationKeyAsFields,
|
|
166
|
+
],
|
|
167
|
+
indexWithinMerge: number,
|
|
168
|
+
indexOfMerge: number,
|
|
169
|
+
) {
|
|
170
|
+
if (!this.mergeRollupInputs[indexOfMerge]) {
|
|
171
|
+
const mergeInputData: BlockMergeRollupInputData = {
|
|
172
|
+
inputs: [undefined, undefined],
|
|
173
|
+
proofs: [undefined, undefined],
|
|
174
|
+
verificationKeys: [undefined, undefined],
|
|
175
|
+
};
|
|
176
|
+
mergeInputData.inputs[indexWithinMerge] = mergeInputs[0];
|
|
177
|
+
mergeInputData.proofs[indexWithinMerge] = mergeInputs[1];
|
|
178
|
+
mergeInputData.verificationKeys[indexWithinMerge] = mergeInputs[2];
|
|
179
|
+
this.mergeRollupInputs[indexOfMerge] = mergeInputData;
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
const mergeInputData = this.mergeRollupInputs[indexOfMerge];
|
|
183
|
+
mergeInputData.inputs[indexWithinMerge] = mergeInputs[0];
|
|
184
|
+
mergeInputData.proofs[indexWithinMerge] = mergeInputs[1];
|
|
185
|
+
mergeInputData.verificationKeys[indexWithinMerge] = mergeInputs[2];
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Returns a specific transaction proving state
|
|
190
|
+
public getBlockProvingState(index: number) {
|
|
191
|
+
return this.blocks[index];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Returns a set of merge rollup inputs
|
|
195
|
+
public getMergeInputs(indexOfMerge: number) {
|
|
196
|
+
return this.mergeRollupInputs[indexOfMerge];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
200
|
+
public isReadyForRootRollup() {
|
|
201
|
+
return !(this.mergeRollupInputs[0] === undefined || this.mergeRollupInputs[0].inputs.findIndex(p => !p) !== -1);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Attempts to reject the proving state promise with a reason of 'cancelled'
|
|
205
|
+
public cancel() {
|
|
206
|
+
this.reject('Proving cancelled');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Attempts to reject the proving state promise with the given reason
|
|
210
|
+
// Does nothing if not in a valid state
|
|
211
|
+
public reject(reason: string) {
|
|
212
|
+
if (!this.verifyState()) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_REJECTED;
|
|
216
|
+
this.rejectionCallback(reason);
|
|
217
|
+
|
|
218
|
+
for (const block of this.blocks) {
|
|
219
|
+
block.reject('Proving cancelled');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Attempts to resolve the proving state promise with the given result
|
|
224
|
+
// Does nothing if not in a valid state
|
|
225
|
+
public resolve(result: ProvingResult) {
|
|
226
|
+
if (!this.verifyState()) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
this.provingStateLifecycle = PROVING_STATE_LIFECYCLE.PROVING_STATE_RESOLVED;
|
|
230
|
+
this.completionCallback(result);
|
|
231
|
+
}
|
|
232
|
+
}
|