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