@aztec/prover-client 0.59.0 → 0.61.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/test_context.js +2 -2
- package/dest/orchestrator/block-building-helpers.d.ts +2 -3
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +5 -12
- package/dest/orchestrator/orchestrator.d.ts +2 -12
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +83 -168
- package/dest/orchestrator/tx-proving-state.d.ts +17 -27
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +74 -112
- package/dest/prover-agent/memory-proving-queue.d.ts +4 -22
- package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
- package/dest/prover-agent/memory-proving-queue.js +6 -28
- package/dest/prover-agent/prover-agent.d.ts.map +1 -1
- package/dest/prover-agent/prover-agent.js +5 -11
- package/dest/prover-agent/rpc.d.ts.map +1 -1
- package/dest/prover-agent/rpc.js +6 -10
- package/dest/test/mock_prover.d.ts +4 -6
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +8 -14
- package/package.json +11 -11
- package/src/mocks/test_context.ts +1 -1
- package/src/orchestrator/block-building-helpers.ts +4 -29
- package/src/orchestrator/orchestrator.ts +99 -277
- package/src/orchestrator/tx-proving-state.ts +113 -153
- package/src/prover-agent/memory-proving-queue.ts +15 -51
- package/src/prover-agent/prover-agent.ts +4 -12
- package/src/prover-agent/rpc.ts +6 -12
- package/src/test/mock_prover.ts +13 -36
|
@@ -1,54 +1,41 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Body,
|
|
3
|
-
EncryptedNoteTxL2Logs,
|
|
4
|
-
EncryptedTxL2Logs,
|
|
5
3
|
L2Block,
|
|
6
4
|
MerkleTreeId,
|
|
7
5
|
type PaddingProcessedTx,
|
|
8
6
|
type ProcessedTx,
|
|
9
|
-
ProvingRequestType,
|
|
10
|
-
type PublicInputsAndRecursiveProof,
|
|
11
7
|
type ServerCircuitProver,
|
|
12
8
|
type TxEffect,
|
|
13
|
-
UnencryptedTxL2Logs,
|
|
14
9
|
makeEmptyProcessedTx,
|
|
15
10
|
makePaddingProcessedTx,
|
|
16
|
-
mapProvingRequestTypeToCircuitName,
|
|
17
11
|
toTxEffect,
|
|
18
12
|
} from '@aztec/circuit-types';
|
|
19
13
|
import { type EpochProver, type MerkleTreeWriteOperations } from '@aztec/circuit-types/interfaces';
|
|
20
14
|
import { type CircuitName } from '@aztec/circuit-types/stats';
|
|
21
15
|
import {
|
|
22
|
-
|
|
16
|
+
AVM_PROOF_LENGTH_IN_FIELDS,
|
|
17
|
+
AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS,
|
|
23
18
|
type BaseOrMergeRollupPublicInputs,
|
|
24
19
|
BaseParityInputs,
|
|
25
|
-
type
|
|
20
|
+
type BaseRollupHints,
|
|
26
21
|
type BlockRootOrBlockMergePublicInputs,
|
|
27
22
|
BlockRootRollupInputs,
|
|
28
23
|
EmptyBlockRootRollupInputs,
|
|
29
24
|
Fr,
|
|
30
25
|
type GlobalVariables,
|
|
31
26
|
type Header,
|
|
32
|
-
type KernelCircuitPublicInputs,
|
|
33
27
|
L1_TO_L2_MSG_SUBTREE_HEIGHT,
|
|
34
28
|
L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
|
|
35
|
-
NESTED_RECURSIVE_PROOF_LENGTH,
|
|
29
|
+
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
36
30
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
37
31
|
NUM_BASE_PARITY_PER_ROOT_PARITY,
|
|
38
32
|
PrivateKernelEmptyInputData,
|
|
39
|
-
type Proof,
|
|
40
|
-
type PublicKernelCircuitPublicInputs,
|
|
41
33
|
type RECURSIVE_PROOF_LENGTH,
|
|
42
34
|
type RecursiveProof,
|
|
43
35
|
type RootParityInput,
|
|
44
36
|
RootParityInputs,
|
|
45
|
-
TUBE_INDEX,
|
|
46
|
-
type TUBE_PROOF_LENGTH,
|
|
47
|
-
TubeInputs,
|
|
48
|
-
type VMCircuitPublicInputs,
|
|
49
37
|
type VerificationKeyAsFields,
|
|
50
38
|
VerificationKeyData,
|
|
51
|
-
makeEmptyProof,
|
|
52
39
|
makeEmptyRecursiveProof,
|
|
53
40
|
} from '@aztec/circuits.js';
|
|
54
41
|
import { makeTuple } from '@aztec/foundation/array';
|
|
@@ -59,14 +46,14 @@ import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
|
59
46
|
import { type Tuple } from '@aztec/foundation/serialize';
|
|
60
47
|
import { pushTestData } from '@aztec/foundation/testing';
|
|
61
48
|
import { elapsed } from '@aztec/foundation/timer';
|
|
62
|
-
import {
|
|
49
|
+
import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types';
|
|
63
50
|
import { protocolContractTreeRoot } from '@aztec/protocol-contracts';
|
|
64
51
|
import { Attributes, type TelemetryClient, type Tracer, trackSpan, wrapCallbackInSpan } from '@aztec/telemetry-client';
|
|
65
52
|
|
|
66
53
|
import { inspect } from 'util';
|
|
67
54
|
|
|
68
55
|
import {
|
|
69
|
-
|
|
56
|
+
buildBaseRollupHints,
|
|
70
57
|
buildHeaderFromCircuitOutputs,
|
|
71
58
|
buildHeaderFromTxEffects,
|
|
72
59
|
createBlockMergeRollupInputs,
|
|
@@ -87,7 +74,7 @@ import {
|
|
|
87
74
|
type TreeSnapshots,
|
|
88
75
|
} from './epoch-proving-state.js';
|
|
89
76
|
import { ProvingOrchestratorMetrics } from './orchestrator_metrics.js';
|
|
90
|
-
import {
|
|
77
|
+
import { TxProvingState } from './tx-proving-state.js';
|
|
91
78
|
|
|
92
79
|
const logger = createDebugLogger('aztec:prover:proving-orchestrator');
|
|
93
80
|
|
|
@@ -278,8 +265,8 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
278
265
|
return;
|
|
279
266
|
}
|
|
280
267
|
|
|
281
|
-
const [
|
|
282
|
-
this.enqueueFirstProofs(
|
|
268
|
+
const [hints, treeSnapshots] = await this.prepareTransaction(tx, provingState);
|
|
269
|
+
this.enqueueFirstProofs(hints, treeSnapshots, tx, provingState);
|
|
283
270
|
|
|
284
271
|
if (provingState.transactionsReceived === provingState.totalNumTxs) {
|
|
285
272
|
logger.verbose(`All transactions received for block ${provingState.globalVariables.blockNumber}.`);
|
|
@@ -333,11 +320,11 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
333
320
|
getVKTreeRoot(),
|
|
334
321
|
protocolContractTreeRoot,
|
|
335
322
|
);
|
|
336
|
-
const txInputs: Array<{
|
|
323
|
+
const txInputs: Array<{ hints: BaseRollupHints; snapshot: TreeSnapshots }> = [];
|
|
337
324
|
for (let i = 0; i < paddingTxCount; i++) {
|
|
338
|
-
const [
|
|
325
|
+
const [hints, snapshot] = await this.prepareTransaction(unprovenPaddingTx, provingState);
|
|
339
326
|
const txInput = {
|
|
340
|
-
|
|
327
|
+
hints,
|
|
341
328
|
snapshot,
|
|
342
329
|
};
|
|
343
330
|
txInputs.push(txInput);
|
|
@@ -471,7 +458,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
471
458
|
// If the fully proven padding transaction is not available, this will first be proven
|
|
472
459
|
private enqueuePaddingTxs(
|
|
473
460
|
provingState: BlockProvingState,
|
|
474
|
-
txInputs: Array<{
|
|
461
|
+
txInputs: Array<{ hints: BaseRollupHints; snapshot: TreeSnapshots }>,
|
|
475
462
|
unprovenPaddingTx: ProcessedTx,
|
|
476
463
|
) {
|
|
477
464
|
if (this.paddingTx) {
|
|
@@ -521,21 +508,18 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
521
508
|
* @param provingState - The block proving state
|
|
522
509
|
*/
|
|
523
510
|
private provePaddingTransactions(
|
|
524
|
-
txInputs: Array<{
|
|
511
|
+
txInputs: Array<{ hints: BaseRollupHints; snapshot: TreeSnapshots }>,
|
|
525
512
|
paddingTx: PaddingProcessedTx,
|
|
526
513
|
provingState: BlockProvingState,
|
|
527
514
|
) {
|
|
528
515
|
// The padding tx contains the proof and vk, generated separately from the base inputs
|
|
529
516
|
// Copy these into the base rollup inputs and enqueue the base rollup proof
|
|
530
517
|
for (let i = 0; i < txInputs.length; i++) {
|
|
531
|
-
txInputs[i]
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
txInputs[i].inputs.kernelData.vkIndex = getVKIndex(paddingTx.verificationKey);
|
|
535
|
-
txInputs[i].inputs.kernelData.vkPath = getVKSiblingPath(txInputs[i].inputs.kernelData.vkIndex);
|
|
536
|
-
const txProvingState = new TxProvingState(paddingTx, txInputs[i].inputs, txInputs[i].snapshot);
|
|
518
|
+
const { hints, snapshot } = txInputs[i];
|
|
519
|
+
const txProvingState = new TxProvingState(paddingTx, hints, snapshot);
|
|
520
|
+
txProvingState.assignTubeProof({ proof: paddingTx.recursiveProof, verificationKey: paddingTx.verificationKey });
|
|
537
521
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
538
|
-
this.enqueueBaseRollup(provingState,
|
|
522
|
+
this.enqueueBaseRollup(provingState, txIndex);
|
|
539
523
|
}
|
|
540
524
|
}
|
|
541
525
|
|
|
@@ -615,20 +599,24 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
615
599
|
}
|
|
616
600
|
|
|
617
601
|
private enqueueFirstProofs(
|
|
618
|
-
|
|
602
|
+
hints: BaseRollupHints,
|
|
619
603
|
treeSnapshots: TreeSnapshots,
|
|
620
604
|
tx: ProcessedTx,
|
|
621
605
|
provingState: BlockProvingState,
|
|
622
606
|
) {
|
|
623
|
-
const txProvingState = new TxProvingState(tx,
|
|
607
|
+
const txProvingState = new TxProvingState(tx, hints, treeSnapshots);
|
|
608
|
+
|
|
609
|
+
const rejectReason = txProvingState.verifyStateOrReject();
|
|
610
|
+
if (rejectReason) {
|
|
611
|
+
provingState.reject(rejectReason);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
|
|
624
615
|
const txIndex = provingState.addNewTx(txProvingState);
|
|
625
616
|
this.enqueueTube(provingState, txIndex);
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
for (let i = 0; i < numPublicKernels; i++) {
|
|
630
|
-
logger.debug(`Enqueueing public VM ${i} for tx ${txIndex}`);
|
|
631
|
-
this.enqueueVM(provingState, txIndex, i);
|
|
617
|
+
if (txProvingState.requireAvmProof) {
|
|
618
|
+
logger.debug(`Enqueueing public VM for tx ${txIndex}`);
|
|
619
|
+
this.enqueueVM(provingState, txIndex);
|
|
632
620
|
}
|
|
633
621
|
}
|
|
634
622
|
|
|
@@ -701,7 +689,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
701
689
|
private async prepareBaseRollupInputs(
|
|
702
690
|
provingState: BlockProvingState | undefined,
|
|
703
691
|
tx: ProcessedTx,
|
|
704
|
-
): Promise<[
|
|
692
|
+
): Promise<[BaseRollupHints, TreeSnapshots] | undefined> {
|
|
705
693
|
if (!provingState?.verifyState()) {
|
|
706
694
|
logger.debug('Not preparing base rollup inputs, state invalid');
|
|
707
695
|
return;
|
|
@@ -709,15 +697,7 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
709
697
|
|
|
710
698
|
// We build the base rollup inputs using a mock proof and verification key.
|
|
711
699
|
// These will be overwritten later once we have proven the tube circuit and any public kernels
|
|
712
|
-
const [ms,
|
|
713
|
-
buildBaseRollupInput(
|
|
714
|
-
tx,
|
|
715
|
-
makeEmptyRecursiveProof(NESTED_RECURSIVE_PROOF_LENGTH),
|
|
716
|
-
provingState.globalVariables,
|
|
717
|
-
this.db,
|
|
718
|
-
TubeVk,
|
|
719
|
-
),
|
|
720
|
-
);
|
|
700
|
+
const [ms, hints] = await elapsed(buildBaseRollupHints(tx, provingState.globalVariables, this.db));
|
|
721
701
|
|
|
722
702
|
if (!tx.isEmpty) {
|
|
723
703
|
this.metrics.recordBaseRollupInputs(ms);
|
|
@@ -734,81 +714,54 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
734
714
|
logger.debug(`Discarding proving job, state no longer valid`);
|
|
735
715
|
return;
|
|
736
716
|
}
|
|
737
|
-
return [
|
|
717
|
+
return [hints, treeSnapshots];
|
|
738
718
|
}
|
|
739
719
|
|
|
740
720
|
// Executes the base rollup circuit and stored the output as intermediate state for the parent merge/root circuit
|
|
741
721
|
// Executes the next level of merge if all inputs are available
|
|
742
|
-
private enqueueBaseRollup(provingState: BlockProvingState | undefined,
|
|
722
|
+
private enqueueBaseRollup(provingState: BlockProvingState | undefined, txIndex: number) {
|
|
743
723
|
if (!provingState?.verifyState()) {
|
|
744
724
|
logger.debug('Not running base rollup, state invalid');
|
|
745
725
|
return;
|
|
746
726
|
}
|
|
747
|
-
const txNoteEncryptedLogs = EncryptedNoteTxL2Logs.hashNoteLogs(
|
|
748
|
-
tx.baseRollupInputs.kernelData.publicInputs.end.noteEncryptedLogsHashes
|
|
749
|
-
.filter(log => !log.isEmpty())
|
|
750
|
-
.map(log => log.value.toBuffer()),
|
|
751
|
-
);
|
|
752
|
-
if (!txNoteEncryptedLogs.equals(tx.processedTx.noteEncryptedLogs.hash())) {
|
|
753
|
-
provingState.reject(
|
|
754
|
-
`Note encrypted logs hash mismatch: ${Fr.fromBuffer(txNoteEncryptedLogs)} === ${Fr.fromBuffer(
|
|
755
|
-
tx.processedTx.noteEncryptedLogs.hash(),
|
|
756
|
-
)}`,
|
|
757
|
-
);
|
|
758
|
-
return;
|
|
759
|
-
}
|
|
760
|
-
const txEncryptedLogs = EncryptedTxL2Logs.hashSiloedLogs(
|
|
761
|
-
tx.baseRollupInputs.kernelData.publicInputs.end.encryptedLogsHashes
|
|
762
|
-
.filter(log => !log.isEmpty())
|
|
763
|
-
.map(log => log.getSiloedHash()),
|
|
764
|
-
);
|
|
765
|
-
if (!txEncryptedLogs.equals(tx.processedTx.encryptedLogs.hash())) {
|
|
766
|
-
// @todo This rejection messages is never seen. Never making it out to the logs
|
|
767
|
-
provingState.reject(
|
|
768
|
-
`Encrypted logs hash mismatch: ${Fr.fromBuffer(txEncryptedLogs)} === ${Fr.fromBuffer(
|
|
769
|
-
tx.processedTx.encryptedLogs.hash(),
|
|
770
|
-
)}`,
|
|
771
|
-
);
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
727
|
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
.map(log => log.getSiloedHash()),
|
|
779
|
-
);
|
|
780
|
-
if (!txUnencryptedLogs.equals(tx.processedTx.unencryptedLogs.hash())) {
|
|
781
|
-
provingState.reject(
|
|
782
|
-
`Unencrypted logs hash mismatch: ${Fr.fromBuffer(txUnencryptedLogs)} === ${Fr.fromBuffer(
|
|
783
|
-
tx.processedTx.unencryptedLogs.hash(),
|
|
784
|
-
)}`,
|
|
785
|
-
);
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
728
|
+
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
729
|
+
const { processedTx } = txProvingState;
|
|
730
|
+
const rollupType = txProvingState.requireAvmProof ? 'public-base-rollup' : 'private-base-rollup';
|
|
788
731
|
|
|
789
732
|
logger.debug(
|
|
790
733
|
`Enqueuing deferred proving base rollup${
|
|
791
|
-
|
|
792
|
-
} for ${
|
|
734
|
+
processedTx.isEmpty ? ' with padding tx' : ''
|
|
735
|
+
} for ${processedTx.hash.toString()}`,
|
|
793
736
|
);
|
|
794
737
|
|
|
795
738
|
this.deferredProving(
|
|
796
739
|
provingState,
|
|
797
740
|
wrapCallbackInSpan(
|
|
798
741
|
this.tracer,
|
|
799
|
-
|
|
742
|
+
`ProvingOrchestrator.prover.${
|
|
743
|
+
rollupType === 'private-base-rollup' ? 'getPrivateBaseRollupProof' : 'getPublicBaseRollupProof'
|
|
744
|
+
}`,
|
|
800
745
|
{
|
|
801
|
-
[Attributes.TX_HASH]:
|
|
746
|
+
[Attributes.TX_HASH]: processedTx.hash.toString(),
|
|
802
747
|
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
803
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]:
|
|
748
|
+
[Attributes.PROTOCOL_CIRCUIT_NAME]: rollupType satisfies CircuitName,
|
|
749
|
+
},
|
|
750
|
+
signal => {
|
|
751
|
+
if (rollupType === 'private-base-rollup') {
|
|
752
|
+
const inputs = txProvingState.getPrivateBaseInputs();
|
|
753
|
+
return this.prover.getPrivateBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
754
|
+
} else {
|
|
755
|
+
const inputs = txProvingState.getPublicBaseInputs();
|
|
756
|
+
return this.prover.getPublicBaseRollupProof(inputs, signal, provingState.epochNumber);
|
|
757
|
+
}
|
|
804
758
|
},
|
|
805
|
-
signal => this.prover.getBaseRollupProof(tx.baseRollupInputs, signal, provingState.epochNumber),
|
|
806
759
|
),
|
|
807
760
|
result => {
|
|
808
|
-
logger.debug(`Completed proof for
|
|
809
|
-
validatePartialState(result.inputs.end,
|
|
761
|
+
logger.debug(`Completed proof for ${rollupType} for tx ${processedTx.hash.toString()}`);
|
|
762
|
+
validatePartialState(result.inputs.end, txProvingState.treeSnapshots);
|
|
810
763
|
const currentLevel = provingState.numMergeLevels + 1n;
|
|
811
|
-
this.storeAndExecuteNextMergeLevel(provingState, currentLevel,
|
|
764
|
+
this.storeAndExecuteNextMergeLevel(provingState, currentLevel, BigInt(txIndex), [
|
|
812
765
|
result.inputs,
|
|
813
766
|
result.proof,
|
|
814
767
|
result.verificationKey.keyAsFields,
|
|
@@ -838,23 +791,15 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
838
791
|
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
839
792
|
[Attributes.PROTOCOL_CIRCUIT_NAME]: 'tube-circuit' satisfies CircuitName,
|
|
840
793
|
},
|
|
841
|
-
signal =>
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
provingState.epochNumber,
|
|
846
|
-
),
|
|
794
|
+
signal => {
|
|
795
|
+
const inputs = txProvingState.getTubeInputs();
|
|
796
|
+
return this.prover.getTubeProof(inputs, signal, provingState.epochNumber);
|
|
797
|
+
},
|
|
847
798
|
),
|
|
848
799
|
result => {
|
|
849
800
|
logger.debug(`Completed tube proof for tx index: ${txIndex}`);
|
|
850
|
-
|
|
851
|
-
this.checkAndEnqueueNextTxCircuit(
|
|
852
|
-
provingState,
|
|
853
|
-
txIndex,
|
|
854
|
-
result.proof,
|
|
855
|
-
result.verificationKey,
|
|
856
|
-
nextKernelRequest,
|
|
857
|
-
);
|
|
801
|
+
txProvingState.assignTubeProof(result);
|
|
802
|
+
this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
|
|
858
803
|
},
|
|
859
804
|
);
|
|
860
805
|
}
|
|
@@ -1199,182 +1144,59 @@ export class ProvingOrchestrator implements EpochProver {
|
|
|
1199
1144
|
* previous kernel is ready
|
|
1200
1145
|
* @param provingState - The proving state being operated on
|
|
1201
1146
|
* @param txIndex - The index of the transaction being proven
|
|
1202
|
-
* @param functionIndex - The index of the function/kernel being proven
|
|
1203
1147
|
*/
|
|
1204
|
-
private enqueueVM(provingState: BlockProvingState | undefined, txIndex: number
|
|
1148
|
+
private enqueueVM(provingState: BlockProvingState | undefined, txIndex: number) {
|
|
1205
1149
|
if (!provingState?.verifyState()) {
|
|
1206
1150
|
logger.debug(`Not running VM circuit as state is no longer valid`);
|
|
1207
1151
|
return;
|
|
1208
1152
|
}
|
|
1209
1153
|
|
|
1210
1154
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1211
|
-
const publicFunction = txProvingState.getPublicFunctionState(functionIndex);
|
|
1212
1155
|
|
|
1213
|
-
// If there is a
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
throw err;
|
|
1237
|
-
} else {
|
|
1238
|
-
logger.warn(
|
|
1239
|
-
`Error thrown when proving AVM circuit, but AVM_PROVING_STRICT is off, so faking AVM proof and carrying on. Error: ${err}.`,
|
|
1240
|
-
);
|
|
1241
|
-
return {
|
|
1242
|
-
proof: makeEmptyProof(),
|
|
1243
|
-
verificationKey: VerificationKeyData.makeFakeHonk(),
|
|
1244
|
-
};
|
|
1245
|
-
}
|
|
1156
|
+
// This function tries to do AVM proving. If there is a failure, it fakes the proof unless AVM_PROVING_STRICT is defined.
|
|
1157
|
+
// Nothing downstream depends on the AVM proof yet. So having this mode lets us incrementally build the AVM circuit.
|
|
1158
|
+
const doAvmProving = wrapCallbackInSpan(
|
|
1159
|
+
this.tracer,
|
|
1160
|
+
'ProvingOrchestrator.prover.getAvmProof',
|
|
1161
|
+
{
|
|
1162
|
+
[Attributes.TX_HASH]: txProvingState.processedTx.hash.toString(),
|
|
1163
|
+
},
|
|
1164
|
+
async (signal: AbortSignal) => {
|
|
1165
|
+
const inputs = txProvingState.getAvmInputs();
|
|
1166
|
+
try {
|
|
1167
|
+
return await this.prover.getAvmProof(inputs, signal, provingState.epochNumber);
|
|
1168
|
+
} catch (err) {
|
|
1169
|
+
if (process.env.AVM_PROVING_STRICT) {
|
|
1170
|
+
throw err;
|
|
1171
|
+
} else {
|
|
1172
|
+
logger.warn(
|
|
1173
|
+
`Error thrown when proving AVM circuit, but AVM_PROVING_STRICT is off, so faking AVM proof and carrying on. Error: ${err}.`,
|
|
1174
|
+
);
|
|
1175
|
+
return {
|
|
1176
|
+
proof: makeEmptyRecursiveProof(AVM_PROOF_LENGTH_IN_FIELDS),
|
|
1177
|
+
verificationKey: VerificationKeyData.makeFake(AVM_VERIFICATION_KEY_LENGTH_IN_FIELDS),
|
|
1178
|
+
};
|
|
1246
1179
|
}
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
logger.debug(`Proven VM for function index ${functionIndex} of tx index ${txIndex}`);
|
|
1251
|
-
this.checkAndEnqueuePublicKernelFromVMProof(provingState, txIndex, functionIndex, proofAndVk.proof);
|
|
1252
|
-
});
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1180
|
+
}
|
|
1181
|
+
},
|
|
1182
|
+
);
|
|
1255
1183
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
) {
|
|
1262
|
-
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1263
|
-
const kernelRequest = txProvingState.getNextPublicKernelFromVMProof(functionIndex, vmProof);
|
|
1264
|
-
if (kernelRequest.code === TX_PROVING_CODE.READY) {
|
|
1265
|
-
if (kernelRequest.function === undefined) {
|
|
1266
|
-
// Should not be possible
|
|
1267
|
-
throw new Error(`Error occurred, public function request undefined after VM proof completed`);
|
|
1268
|
-
}
|
|
1269
|
-
logger.debug(`Enqueuing kernel from VM for tx ${txIndex}, function ${functionIndex}`);
|
|
1270
|
-
this.enqueuePublicKernel(provingState, txIndex, functionIndex);
|
|
1271
|
-
}
|
|
1184
|
+
this.deferredProving(provingState, doAvmProving, proofAndVk => {
|
|
1185
|
+
logger.debug(`Proven VM for tx index: ${txIndex}`);
|
|
1186
|
+
txProvingState.assignAvmProof(proofAndVk);
|
|
1187
|
+
this.checkAndEnqueueNextTxCircuit(provingState, txIndex);
|
|
1188
|
+
});
|
|
1272
1189
|
}
|
|
1273
1190
|
|
|
1274
|
-
|
|
1275
|
-
// This could be either a public kernel or the base rollup
|
|
1276
|
-
// Alternatively, if we are still waiting on a public VM prof then it will continue waiting
|
|
1277
|
-
private checkAndEnqueueNextTxCircuit(
|
|
1278
|
-
provingState: BlockProvingState,
|
|
1279
|
-
txIndex: number,
|
|
1280
|
-
proof: RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH> | RecursiveProof<typeof TUBE_PROOF_LENGTH>,
|
|
1281
|
-
verificationKey: VerificationKeyData,
|
|
1282
|
-
nextKernelRequest: TxProvingInstruction,
|
|
1283
|
-
) {
|
|
1191
|
+
private checkAndEnqueueNextTxCircuit(provingState: BlockProvingState, txIndex: number) {
|
|
1284
1192
|
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1285
|
-
|
|
1286
|
-
if (nextKernelRequest.code === TX_PROVING_CODE.NOT_READY) {
|
|
1287
|
-
// Must be waiting on a VM proof
|
|
1288
|
-
return;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
if (nextKernelRequest.code === TX_PROVING_CODE.COMPLETED) {
|
|
1292
|
-
// We must have completed all public function proving, we now move to the base rollup
|
|
1293
|
-
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1294
|
-
// Take the final proof and assign it to the base rollup inputs
|
|
1295
|
-
txProvingState.baseRollupInputs.kernelData.proof = proof;
|
|
1296
|
-
txProvingState.baseRollupInputs.kernelData.vk = verificationKey;
|
|
1297
|
-
try {
|
|
1298
|
-
txProvingState.baseRollupInputs.kernelData.vkIndex = getVKIndex(verificationKey);
|
|
1299
|
-
} catch (_ignored) {
|
|
1300
|
-
// TODO(#7410) The VK for the tube won't be in the tree for now, so we manually set it to the tube vk index
|
|
1301
|
-
txProvingState.baseRollupInputs.kernelData.vkIndex = TUBE_INDEX;
|
|
1302
|
-
}
|
|
1303
|
-
txProvingState.baseRollupInputs.kernelData.vkPath = getVKSiblingPath(
|
|
1304
|
-
txProvingState.baseRollupInputs.kernelData.vkIndex,
|
|
1305
|
-
);
|
|
1306
|
-
|
|
1307
|
-
this.enqueueBaseRollup(provingState, BigInt(txIndex), txProvingState);
|
|
1193
|
+
if (!txProvingState.ready()) {
|
|
1308
1194
|
return;
|
|
1309
1195
|
}
|
|
1310
|
-
// There must be another kernel ready to be proven
|
|
1311
|
-
if (nextKernelRequest.function === undefined) {
|
|
1312
|
-
// Should not be possible
|
|
1313
|
-
throw new Error(`Error occurred, public function request undefined after kernel proof completed`);
|
|
1314
|
-
}
|
|
1315
1196
|
|
|
1316
|
-
|
|
1317
|
-
|
|
1197
|
+
// We must have completed all proving (tube proof and (if required) vm proof are generated), we now move to the base rollup.
|
|
1198
|
+
logger.debug(`Public functions completed for tx ${txIndex} enqueueing base rollup`);
|
|
1318
1199
|
|
|
1319
|
-
|
|
1320
|
-
* Executes the kernel circuit for a public function, will enqueue the next kernel circuit if it's VM is already proven
|
|
1321
|
-
* or the base rollup circuit if there are no more kernels to be proven
|
|
1322
|
-
* @param provingState - The proving state being operated on
|
|
1323
|
-
* @param txIndex - The index of the transaction being proven
|
|
1324
|
-
* @param functionIndex - The index of the function/kernel being proven
|
|
1325
|
-
*/
|
|
1326
|
-
private enqueuePublicKernel(provingState: BlockProvingState | undefined, txIndex: number, functionIndex: number) {
|
|
1327
|
-
if (!provingState?.verifyState()) {
|
|
1328
|
-
logger.debug(`Not running public kernel circuit as state is no longer valid`);
|
|
1329
|
-
return;
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
const txProvingState = provingState.getTxProvingState(txIndex);
|
|
1333
|
-
const request = txProvingState.getPublicFunctionState(functionIndex).publicKernelRequest;
|
|
1334
|
-
|
|
1335
|
-
this.deferredProving(
|
|
1336
|
-
provingState,
|
|
1337
|
-
wrapCallbackInSpan(
|
|
1338
|
-
this.tracer,
|
|
1339
|
-
request.type === ProvingRequestType.PUBLIC_KERNEL_TAIL
|
|
1340
|
-
? 'ProvingOrchestrator.prover.getPublicTailProof'
|
|
1341
|
-
: request.type === ProvingRequestType.PUBLIC_KERNEL_MERGE
|
|
1342
|
-
? 'ProvingOrchestrator.prover.getPublicKernelMergeProof'
|
|
1343
|
-
: 'ProvingOrchestrator.prover.getPublicKernelInnerProof',
|
|
1344
|
-
{
|
|
1345
|
-
[Attributes.PROTOCOL_CIRCUIT_TYPE]: 'server',
|
|
1346
|
-
[Attributes.PROTOCOL_CIRCUIT_NAME]: mapProvingRequestTypeToCircuitName(request.type),
|
|
1347
|
-
},
|
|
1348
|
-
(
|
|
1349
|
-
signal,
|
|
1350
|
-
): Promise<
|
|
1351
|
-
PublicInputsAndRecursiveProof<
|
|
1352
|
-
KernelCircuitPublicInputs | PublicKernelCircuitPublicInputs | VMCircuitPublicInputs
|
|
1353
|
-
>
|
|
1354
|
-
> => {
|
|
1355
|
-
if (request.type === ProvingRequestType.PUBLIC_KERNEL_TAIL) {
|
|
1356
|
-
return this.prover.getPublicTailProof(request.inputs, signal, provingState.epochNumber);
|
|
1357
|
-
} else if (request.type === ProvingRequestType.PUBLIC_KERNEL_MERGE) {
|
|
1358
|
-
return this.prover.getPublicKernelMergeProof(request.inputs, signal, provingState.epochNumber);
|
|
1359
|
-
} else {
|
|
1360
|
-
return this.prover.getPublicKernelInnerProof(request.inputs, signal, provingState.epochNumber);
|
|
1361
|
-
}
|
|
1362
|
-
},
|
|
1363
|
-
),
|
|
1364
|
-
result => {
|
|
1365
|
-
const nextKernelRequest = txProvingState.getNextPublicKernelFromKernelProof(
|
|
1366
|
-
functionIndex,
|
|
1367
|
-
result.proof,
|
|
1368
|
-
result.verificationKey,
|
|
1369
|
-
);
|
|
1370
|
-
this.checkAndEnqueueNextTxCircuit(
|
|
1371
|
-
provingState,
|
|
1372
|
-
txIndex,
|
|
1373
|
-
result.proof,
|
|
1374
|
-
result.verificationKey,
|
|
1375
|
-
nextKernelRequest,
|
|
1376
|
-
);
|
|
1377
|
-
},
|
|
1378
|
-
);
|
|
1200
|
+
this.enqueueBaseRollup(provingState, txIndex);
|
|
1379
1201
|
}
|
|
1380
1202
|
}
|