@aztec/prover-client 0.0.0-test.0 → 0.0.1-commit.21caa21
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 +108 -0
- package/dest/config.d.ts +7 -7
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +11 -1
- package/dest/index.d.ts +1 -1
- package/dest/light/lightweight_checkpoint_builder.d.ts +28 -0
- package/dest/light/lightweight_checkpoint_builder.d.ts.map +1 -0
- package/dest/light/lightweight_checkpoint_builder.js +107 -0
- package/dest/mocks/fixtures.d.ts +8 -8
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +32 -14
- package/dest/mocks/test_context.d.ts +40 -31
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +134 -86
- package/dest/orchestrator/block-building-helpers.d.ts +36 -29
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +168 -188
- package/dest/orchestrator/block-proving-state.d.ts +68 -47
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/block-proving-state.js +281 -176
- package/dest/orchestrator/checkpoint-proving-state.d.ts +62 -0
- package/dest/orchestrator/checkpoint-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/checkpoint-proving-state.js +208 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +40 -26
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/epoch-proving-state.js +143 -73
- package/dest/orchestrator/index.d.ts +1 -1
- package/dest/orchestrator/orchestrator.d.ts +35 -32
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +389 -239
- package/dest/orchestrator/orchestrator_metrics.d.ts +3 -1
- 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 +13 -11
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +23 -40
- package/dest/prover-client/factory.d.ts +1 -1
- package/dest/prover-client/index.d.ts +1 -1
- package/dest/prover-client/prover-client.d.ts +4 -4
- 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 +15 -11
- 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 +23 -16
- package/dest/proving_broker/broker_prover_facade.d.ts.map +1 -1
- package/dest/proving_broker/broker_prover_facade.js +67 -41
- package/dest/proving_broker/config.d.ts +18 -9
- package/dest/proving_broker/config.d.ts.map +1 -1
- package/dest/proving_broker/config.js +22 -5
- package/dest/proving_broker/factory.d.ts +2 -2
- package/dest/proving_broker/factory.d.ts.map +1 -1
- package/dest/proving_broker/factory.js +5 -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 +2 -1
- package/dest/proving_broker/index.d.ts +1 -1
- package/dest/proving_broker/proof_store/factory.d.ts +2 -2
- package/dest/proving_broker/proof_store/factory.js +1 -1
- package/dest/proving_broker/proof_store/gcs_proof_store.d.ts +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 +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 +4 -4
- 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_agent_instrumentation.d.ts +1 -1
- package/dest/proving_broker/proving_agent_instrumentation.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.d.ts +13 -4
- package/dest/proving_broker/proving_broker.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker.js +36 -23
- 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/memory.js +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.d.ts +3 -2
- package/dest/proving_broker/proving_broker_database/persisted.d.ts.map +1 -1
- package/dest/proving_broker/proving_broker_database/persisted.js +12 -10
- 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_job_controller.d.ts +9 -9
- 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 +4 -6
- 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 -17
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +38 -20
- package/package.json +32 -31
- package/src/block-factory/index.ts +1 -0
- package/src/block-factory/light.ts +137 -0
- package/src/config.ts +24 -8
- package/src/light/lightweight_checkpoint_builder.ts +142 -0
- package/src/mocks/fixtures.ts +42 -37
- package/src/mocks/test_context.ts +207 -115
- package/src/orchestrator/block-building-helpers.ts +256 -333
- package/src/orchestrator/block-proving-state.ts +323 -230
- package/src/orchestrator/checkpoint-proving-state.ts +301 -0
- package/src/orchestrator/epoch-proving-state.ts +187 -112
- package/src/orchestrator/orchestrator.ts +592 -299
- package/src/orchestrator/orchestrator_metrics.ts +20 -1
- package/src/orchestrator/tx-proving-state.ts +50 -64
- package/src/prover-client/prover-client.ts +16 -14
- package/src/prover-client/server-epoch-prover.ts +39 -21
- package/src/proving_broker/broker_prover_facade.ts +214 -126
- package/src/proving_broker/config.ts +24 -6
- package/src/proving_broker/factory.ts +2 -1
- package/src/proving_broker/fixtures.ts +7 -2
- 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 +53 -33
- package/src/proving_broker/proving_broker_database/memory.ts +3 -2
- package/src/proving_broker/proving_broker_database/persisted.ts +14 -12
- package/src/proving_broker/proving_broker_database.ts +2 -1
- package/src/proving_broker/proving_job_controller.ts +94 -82
- 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,158 @@
|
|
|
1
|
-
import { SpongeBlob } from '@aztec/blob-lib';
|
|
1
|
+
import { type BlockBlobData, type BlockEndBlobData, type SpongeBlob, encodeBlockEndBlobData } 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 {
|
|
27
|
+
import { AppendOnlyTreeSnapshot } from '@aztec/stdlib/trees';
|
|
28
|
+
import { BlockHeader, GlobalVariables, StateReference } 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
|
-
|
|
60
|
-
public totalNumTxs: number;
|
|
56
|
+
private builtBlockHeader: BlockHeader | undefined;
|
|
57
|
+
private endState: StateReference | undefined;
|
|
58
|
+
private endSpongeBlob: SpongeBlob | undefined;
|
|
61
59
|
private txs: TxProvingState[] = [];
|
|
62
|
-
|
|
60
|
+
private isFirstBlock: boolean;
|
|
61
|
+
private error: string | undefined;
|
|
63
62
|
|
|
64
63
|
constructor(
|
|
65
64
|
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
|
|
65
|
+
public readonly blockNumber: number,
|
|
66
|
+
public readonly totalNumTxs: number,
|
|
67
|
+
private readonly constants: CheckpointConstantData,
|
|
68
|
+
private readonly timestamp: UInt64,
|
|
69
|
+
public readonly lastArchiveTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
70
|
+
private readonly lastArchiveSiblingPath: Tuple<Fr, typeof ARCHIVE_HEIGHT>,
|
|
71
|
+
private readonly lastL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
72
|
+
private readonly lastL1ToL2MessageSubtreeRootSiblingPath: Tuple<
|
|
73
|
+
Fr,
|
|
74
|
+
typeof L1_TO_L2_MSG_SUBTREE_ROOT_SIBLING_PATH_LENGTH
|
|
75
|
+
>,
|
|
76
|
+
public readonly newL1ToL2MessageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
77
|
+
private readonly headerOfLastBlockInPreviousCheckpoint: BlockHeader,
|
|
78
|
+
private readonly startSpongeBlob: SpongeBlob,
|
|
79
|
+
public parentCheckpoint: CheckpointProvingState,
|
|
74
80
|
) {
|
|
75
|
-
this.
|
|
76
|
-
this.
|
|
77
|
-
|
|
81
|
+
this.isFirstBlock = index === 0;
|
|
82
|
+
if (!totalNumTxs && !this.isFirstBlock) {
|
|
83
|
+
throw new Error(`Cannot create a block with 0 txs, unless it's the first block.`);
|
|
84
|
+
}
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
return this.globalVariables.blockNumber.toNumber();
|
|
86
|
+
this.baseOrMergeProofs = new UnbalancedTreeStore(totalNumTxs);
|
|
81
87
|
}
|
|
82
88
|
|
|
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;
|
|
89
|
+
public get epochNumber(): number {
|
|
90
|
+
return this.parentCheckpoint.epochNumber;
|
|
93
91
|
}
|
|
94
92
|
|
|
95
93
|
// Adds a transaction to the proving state, returns it's index
|
|
96
94
|
public addNewTx(tx: TxProvingState) {
|
|
97
|
-
if (!this.
|
|
98
|
-
throw new Error(`
|
|
95
|
+
if (!this.isAcceptingTxs()) {
|
|
96
|
+
throw new Error(`Cannot add more txs to block ${this.blockNumber}.`);
|
|
99
97
|
}
|
|
100
|
-
|
|
101
98
|
const txIndex = this.txs.length;
|
|
102
99
|
this.txs[txIndex] = tx;
|
|
103
100
|
return txIndex;
|
|
104
101
|
}
|
|
105
102
|
|
|
103
|
+
public isAcceptingTxs() {
|
|
104
|
+
return this.txs.length < this.totalNumTxs;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public getProcessedTxs() {
|
|
108
|
+
return this.txs.map(t => t.processedTx);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public tryStartProvingBase(txIndex: number) {
|
|
112
|
+
if (this.baseOrMergeProofs.getLeaf(txIndex)?.isProving) {
|
|
113
|
+
return false;
|
|
114
|
+
} else {
|
|
115
|
+
this.baseOrMergeProofs.setLeaf(txIndex, { isProving: true });
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
106
120
|
public setBaseRollupProof(
|
|
107
121
|
txIndex: number,
|
|
108
122
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
109
|
-
|
|
123
|
+
TxRollupPublicInputs,
|
|
110
124
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
111
125
|
>,
|
|
112
126
|
): TreeNodeLocation {
|
|
113
|
-
return this.
|
|
127
|
+
return this.baseOrMergeProofs.setLeaf(txIndex, { provingOutput });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
public tryStartProvingMerge(location: TreeNodeLocation) {
|
|
131
|
+
if (this.baseOrMergeProofs.getNode(location)?.isProving) {
|
|
132
|
+
return false;
|
|
133
|
+
} else {
|
|
134
|
+
this.baseOrMergeProofs.setNode(location, { isProving: true });
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
114
137
|
}
|
|
115
138
|
|
|
116
139
|
public setMergeRollupProof(
|
|
117
140
|
location: TreeNodeLocation,
|
|
118
141
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
119
|
-
|
|
142
|
+
TxRollupPublicInputs,
|
|
120
143
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
121
144
|
>,
|
|
122
145
|
) {
|
|
123
|
-
this.
|
|
146
|
+
this.baseOrMergeProofs.setNode(location, { provingOutput });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public tryStartProvingBaseParity(index: number) {
|
|
150
|
+
if (this.baseParityProofs[index]?.isProving) {
|
|
151
|
+
return false;
|
|
152
|
+
} else {
|
|
153
|
+
this.baseParityProofs[index] = { isProving: true };
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
124
156
|
}
|
|
125
157
|
|
|
126
158
|
// Stores a set of root parity inputs at the given index
|
|
@@ -130,136 +162,228 @@ export class BlockProvingState {
|
|
|
130
162
|
`Unable to set a base parity proofs at index ${index}. Expected at most ${NUM_BASE_PARITY_PER_ROOT_PARITY} proofs.`,
|
|
131
163
|
);
|
|
132
164
|
}
|
|
133
|
-
this.
|
|
165
|
+
this.baseParityProofs[index] = { provingOutput };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
public tryStartProvingRootParity() {
|
|
169
|
+
if (this.rootParityProof?.isProving) {
|
|
170
|
+
return false;
|
|
171
|
+
} else {
|
|
172
|
+
this.rootParityProof = { isProving: true };
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
134
175
|
}
|
|
135
176
|
|
|
136
177
|
public setRootParityProof(provingOutput: PublicInputsAndRecursiveProof<ParityPublicInputs>) {
|
|
137
|
-
this.
|
|
178
|
+
this.rootParityProof = { provingOutput };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
public tryStartProvingBlockRoot() {
|
|
182
|
+
if (this.blockRootProof?.isProving) {
|
|
183
|
+
return false;
|
|
184
|
+
} else {
|
|
185
|
+
this.blockRootProof = { isProving: true };
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
138
188
|
}
|
|
139
189
|
|
|
140
190
|
public setBlockRootRollupProof(
|
|
141
191
|
provingOutput: PublicInputsAndRecursiveProof<
|
|
142
|
-
|
|
192
|
+
BlockRollupPublicInputs,
|
|
143
193
|
typeof NESTED_RECURSIVE_ROLLUP_HONK_PROOF_LENGTH
|
|
144
194
|
>,
|
|
145
|
-
) {
|
|
146
|
-
this.
|
|
195
|
+
): TreeNodeLocation {
|
|
196
|
+
this.blockRootProof = { provingOutput };
|
|
197
|
+
return this.parentCheckpoint.setBlockRootRollupProof(this.index, provingOutput);
|
|
147
198
|
}
|
|
148
199
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return this.txs;
|
|
200
|
+
public getBlockRootRollupOutput() {
|
|
201
|
+
return this.blockRootProof?.provingOutput?.inputs;
|
|
152
202
|
}
|
|
153
203
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
204
|
+
public async buildBlockHeader() {
|
|
205
|
+
if (this.isAcceptingTxs()) {
|
|
206
|
+
throw new Error('All txs must be added to the block before building the header.');
|
|
207
|
+
}
|
|
208
|
+
if (!this.endState) {
|
|
209
|
+
throw new Error('Call `setEndState` first.');
|
|
210
|
+
}
|
|
211
|
+
if (!this.endSpongeBlob) {
|
|
212
|
+
throw new Error('Call `setEndSpongeBlob` first.');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const endSpongeBlob = this.endSpongeBlob.clone();
|
|
216
|
+
const endSpongeBlobHash = await endSpongeBlob.squeeze();
|
|
217
|
+
|
|
218
|
+
this.builtBlockHeader = new BlockHeader(
|
|
219
|
+
this.lastArchiveTreeSnapshot,
|
|
220
|
+
this.endState,
|
|
221
|
+
endSpongeBlobHash,
|
|
222
|
+
this.#getGlobalVariables(),
|
|
223
|
+
this.#getTotalFees(),
|
|
224
|
+
new Fr(this.#getTotalManaUsed()),
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return this.builtBlockHeader;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
public getBuiltBlockHeader() {
|
|
231
|
+
return this.builtBlockHeader;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
public getStartSpongeBlob() {
|
|
235
|
+
return this.startSpongeBlob;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
public setEndSpongeBlob(endSpongeBlob: SpongeBlob) {
|
|
239
|
+
this.endSpongeBlob = endSpongeBlob;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
public getEndSpongeBlob() {
|
|
243
|
+
return this.endSpongeBlob;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
public setEndState(endState: StateReference) {
|
|
247
|
+
this.endState = endState;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
public hasEndState() {
|
|
251
|
+
return !!this.endState;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
public getBlockEndBlobFields(): Fr[] {
|
|
255
|
+
return encodeBlockEndBlobData(this.getBlockEndBlobData());
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
getBlockEndBlobData(): BlockEndBlobData {
|
|
259
|
+
if (!this.endState) {
|
|
260
|
+
throw new Error('Call `setEndState` first.');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const partial = this.endState.partial;
|
|
264
|
+
return {
|
|
265
|
+
blockEndMarker: {
|
|
266
|
+
numTxs: this.totalNumTxs,
|
|
267
|
+
timestamp: this.timestamp,
|
|
268
|
+
blockNumber: this.blockNumber,
|
|
269
|
+
},
|
|
270
|
+
blockEndStateField: {
|
|
271
|
+
l1ToL2MessageNextAvailableLeafIndex: this.newL1ToL2MessageTreeSnapshot.nextAvailableLeafIndex,
|
|
272
|
+
noteHashNextAvailableLeafIndex: partial.noteHashTree.nextAvailableLeafIndex,
|
|
273
|
+
nullifierNextAvailableLeafIndex: partial.nullifierTree.nextAvailableLeafIndex,
|
|
274
|
+
publicDataNextAvailableLeafIndex: partial.publicDataTree.nextAvailableLeafIndex,
|
|
275
|
+
totalManaUsed: this.#getTotalManaUsed(),
|
|
276
|
+
},
|
|
277
|
+
lastArchiveRoot: this.lastArchiveTreeSnapshot.root,
|
|
278
|
+
noteHashRoot: partial.noteHashTree.root,
|
|
279
|
+
nullifierRoot: partial.nullifierTree.root,
|
|
280
|
+
publicDataRoot: partial.publicDataTree.root,
|
|
281
|
+
l1ToL2MessageRoot: this.isFirstBlock ? this.newL1ToL2MessageTreeSnapshot.root : undefined,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
public getBlockBlobData(): BlockBlobData {
|
|
286
|
+
return {
|
|
287
|
+
...this.getBlockEndBlobData(),
|
|
288
|
+
txs: this.getTxEffects().map(t => t.toTxBlobData()),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
public getTxEffects() {
|
|
293
|
+
return this.txs.map(t => t.processedTx.txEffect);
|
|
157
294
|
}
|
|
158
295
|
|
|
159
296
|
public getParentLocation(location: TreeNodeLocation) {
|
|
160
|
-
return this.
|
|
297
|
+
return this.baseOrMergeProofs.getParentLocation(location);
|
|
161
298
|
}
|
|
162
299
|
|
|
163
300
|
public getMergeRollupInputs(mergeLocation: TreeNodeLocation) {
|
|
164
|
-
const [left, right] = this.
|
|
301
|
+
const [left, right] = this.baseOrMergeProofs.getChildren(mergeLocation).map(c => c?.provingOutput);
|
|
165
302
|
if (!left || !right) {
|
|
166
|
-
throw new Error('At
|
|
303
|
+
throw new Error('At least one child is not ready for the merge rollup.');
|
|
167
304
|
}
|
|
168
305
|
|
|
169
|
-
return new
|
|
306
|
+
return new TxMergeRollupPrivateInputs([toProofData(left), toProofData(right)]);
|
|
170
307
|
}
|
|
171
308
|
|
|
172
|
-
public
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const proofs = this.#getChildProofsForBlockRoot();
|
|
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.');
|
|
309
|
+
public getBlockRootRollupTypeAndInputs() {
|
|
310
|
+
const provingOutputs = this.#getChildProvingOutputsForBlockRoot();
|
|
311
|
+
if (!provingOutputs.every(p => !!p)) {
|
|
312
|
+
throw new Error('At least one child is not ready for the block root rollup.');
|
|
181
313
|
}
|
|
182
314
|
|
|
183
|
-
const
|
|
315
|
+
const previousRollups = provingOutputs.map(p => toProofData(p));
|
|
184
316
|
|
|
185
|
-
if (this.
|
|
186
|
-
|
|
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
|
-
};
|
|
317
|
+
if (this.isFirstBlock) {
|
|
318
|
+
return this.#getFirstBlockRootRollupTypeAndInputs(previousRollups);
|
|
201
319
|
}
|
|
202
320
|
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (previousRollupData.length === 1) {
|
|
321
|
+
const [leftRollup, rightRollup] = previousRollups;
|
|
322
|
+
if (!rightRollup) {
|
|
207
323
|
return {
|
|
208
|
-
rollupType: '
|
|
209
|
-
inputs: new
|
|
324
|
+
rollupType: 'rollup-block-root-single-tx' satisfies CircuitName,
|
|
325
|
+
inputs: new BlockRootSingleTxRollupPrivateInputs(leftRollup, this.lastArchiveSiblingPath),
|
|
210
326
|
};
|
|
211
327
|
} else {
|
|
212
328
|
return {
|
|
213
|
-
rollupType: 'block-root
|
|
214
|
-
inputs: new
|
|
215
|
-
previousRollupData as [PreviousRollupData, PreviousRollupData],
|
|
216
|
-
data,
|
|
217
|
-
blobData,
|
|
218
|
-
),
|
|
329
|
+
rollupType: 'rollup-block-root' satisfies CircuitName,
|
|
330
|
+
inputs: new BlockRootRollupPrivateInputs([leftRollup, rightRollup], this.lastArchiveSiblingPath),
|
|
219
331
|
};
|
|
220
332
|
}
|
|
221
333
|
}
|
|
222
334
|
|
|
223
|
-
|
|
224
|
-
if (!this.
|
|
335
|
+
#getFirstBlockRootRollupTypeAndInputs([leftRollup, rightRollup]: RollupHonkProofData<TxRollupPublicInputs>[]) {
|
|
336
|
+
if (!this.rootParityProof?.provingOutput) {
|
|
225
337
|
throw new Error('Root parity is not ready.');
|
|
226
338
|
}
|
|
339
|
+
const l1ToL2Roots = toProofData(this.rootParityProof.provingOutput);
|
|
227
340
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
341
|
+
if (!leftRollup) {
|
|
342
|
+
return {
|
|
343
|
+
rollupType: 'rollup-block-root-first-empty-tx' satisfies CircuitName,
|
|
344
|
+
inputs: new BlockRootEmptyTxFirstRollupPrivateInputs(
|
|
345
|
+
l1ToL2Roots,
|
|
346
|
+
this.lastArchiveTreeSnapshot,
|
|
347
|
+
this.headerOfLastBlockInPreviousCheckpoint.state,
|
|
348
|
+
this.constants,
|
|
349
|
+
this.timestamp,
|
|
350
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
351
|
+
this.lastArchiveSiblingPath,
|
|
352
|
+
),
|
|
353
|
+
};
|
|
354
|
+
} else if (!rightRollup) {
|
|
355
|
+
return {
|
|
356
|
+
rollupType: 'rollup-block-root-first-single-tx' satisfies CircuitName,
|
|
357
|
+
inputs: new BlockRootSingleTxFirstRollupPrivateInputs(
|
|
358
|
+
l1ToL2Roots,
|
|
359
|
+
leftRollup,
|
|
360
|
+
this.lastL1ToL2MessageTreeSnapshot,
|
|
361
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
362
|
+
this.lastArchiveSiblingPath,
|
|
363
|
+
),
|
|
364
|
+
};
|
|
365
|
+
} else {
|
|
366
|
+
return {
|
|
367
|
+
rollupType: 'rollup-block-root-first' satisfies CircuitName,
|
|
368
|
+
inputs: new BlockRootFirstRollupPrivateInputs(
|
|
369
|
+
l1ToL2Roots,
|
|
370
|
+
[leftRollup, rightRollup],
|
|
371
|
+
this.lastL1ToL2MessageTreeSnapshot,
|
|
372
|
+
this.lastL1ToL2MessageSubtreeRootSiblingPath,
|
|
373
|
+
this.lastArchiveSiblingPath,
|
|
374
|
+
),
|
|
375
|
+
};
|
|
376
|
+
}
|
|
252
377
|
}
|
|
253
378
|
|
|
254
|
-
public
|
|
255
|
-
|
|
379
|
+
public getParityRootInputs() {
|
|
380
|
+
const baseParityProvingOutputs = this.baseParityProofs.filter(p => !!p?.provingOutput).map(p => p!.provingOutput!);
|
|
381
|
+
if (baseParityProvingOutputs.length !== this.baseParityProofs.length) {
|
|
256
382
|
throw new Error('At lease one base parity is not ready.');
|
|
257
383
|
}
|
|
258
384
|
|
|
259
|
-
const children =
|
|
260
|
-
return new
|
|
261
|
-
children as Tuple<RootParityInput<typeof RECURSIVE_PROOF_LENGTH>, typeof NUM_BASE_PARITY_PER_ROOT_PARITY>,
|
|
262
|
-
);
|
|
385
|
+
const children = baseParityProvingOutputs.map(p => toProofData(p));
|
|
386
|
+
return new ParityRootPrivateInputs(assertLength(children, NUM_BASE_PARITY_PER_ROOT_PARITY));
|
|
263
387
|
}
|
|
264
388
|
|
|
265
389
|
// Returns a specific transaction proving state
|
|
@@ -267,82 +391,47 @@ export class BlockProvingState {
|
|
|
267
391
|
return this.txs[txIndex];
|
|
268
392
|
}
|
|
269
393
|
|
|
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;
|
|
394
|
+
public async buildHeaderFromProvingOutputs() {
|
|
395
|
+
if (!this.blockRootProof?.provingOutput) {
|
|
396
|
+
throw new Error('Block root rollup is not ready.');
|
|
284
397
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
return buildHeaderFromCircuitOutputs(
|
|
288
|
-
previousRollupData.map(d => d.baseOrMergeRollupPublicInputs),
|
|
289
|
-
this.rootParityProvingOutput!.inputs,
|
|
290
|
-
this.blockRootProvingOutput!.inputs,
|
|
291
|
-
endState,
|
|
292
|
-
logger,
|
|
293
|
-
);
|
|
398
|
+
|
|
399
|
+
return await buildHeaderFromCircuitOutputs(this.blockRootProof.provingOutput.inputs);
|
|
294
400
|
}
|
|
295
401
|
|
|
296
402
|
public isReadyForMergeRollup(location: TreeNodeLocation) {
|
|
297
|
-
return this.
|
|
403
|
+
return !!this.baseOrMergeProofs.getSibling(location)?.provingOutput;
|
|
298
404
|
}
|
|
299
405
|
|
|
300
406
|
// Returns true if we have sufficient inputs to execute the block root rollup
|
|
301
407
|
public isReadyForBlockRootRollup() {
|
|
302
|
-
const childProofs = this.#
|
|
303
|
-
return this.
|
|
408
|
+
const childProofs = this.#getChildProvingOutputsForBlockRoot();
|
|
409
|
+
return (!this.isFirstBlock || !!this.rootParityProof?.provingOutput) && childProofs.every(p => !!p);
|
|
304
410
|
}
|
|
305
411
|
|
|
306
412
|
// Returns true if we have sufficient root parity inputs to execute the root parity circuit
|
|
307
413
|
public isReadyForRootParity() {
|
|
308
|
-
return this.
|
|
414
|
+
return this.baseParityProofs.every(p => !!p?.provingOutput);
|
|
309
415
|
}
|
|
310
416
|
|
|
311
417
|
public isComplete() {
|
|
312
|
-
return !!this.
|
|
418
|
+
return !!this.blockRootProof;
|
|
313
419
|
}
|
|
314
420
|
|
|
315
|
-
// Returns whether the proving state is still valid
|
|
316
421
|
public verifyState() {
|
|
317
|
-
return this.
|
|
422
|
+
return this.parentCheckpoint.verifyState();
|
|
318
423
|
}
|
|
319
424
|
|
|
320
|
-
public
|
|
321
|
-
this.error
|
|
322
|
-
this.parentEpoch.reject(reason);
|
|
425
|
+
public getError() {
|
|
426
|
+
return this.error;
|
|
323
427
|
}
|
|
324
428
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
l1ToL2MessageSubtreeSiblingPath: this.l1ToL2MessageSubtreeSiblingPath,
|
|
329
|
-
newArchiveSiblingPath: this.newArchiveSiblingPath,
|
|
330
|
-
previousBlockHeader: this.previousBlockHeader,
|
|
331
|
-
proverId,
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async #getBlockRootRollupBlobData() {
|
|
336
|
-
const txEffects = this.txs.map(txProvingState => txProvingState.processedTx.txEffect);
|
|
337
|
-
const { blobFields, blobCommitments, blobsHash } = await buildBlobHints(txEffects);
|
|
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
|
-
});
|
|
429
|
+
public reject(reason: string) {
|
|
430
|
+
this.error = reason;
|
|
431
|
+
this.parentCheckpoint.reject(reason);
|
|
343
432
|
}
|
|
344
433
|
|
|
345
|
-
#
|
|
434
|
+
#getChildProvingOutputsForBlockRoot() {
|
|
346
435
|
if (this.totalNumTxs === 0) {
|
|
347
436
|
return [];
|
|
348
437
|
}
|
|
@@ -350,30 +439,34 @@ export class BlockProvingState {
|
|
|
350
439
|
const rootLocation = { level: 0, index: 0 };
|
|
351
440
|
// If there's only 1 tx, its base rollup proof will be stored at the root.
|
|
352
441
|
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
|
-
);
|
|
442
|
+
? [this.baseOrMergeProofs.getNode(rootLocation)?.provingOutput]
|
|
443
|
+
: this.baseOrMergeProofs.getChildren(rootLocation).map(c => c?.provingOutput);
|
|
369
444
|
}
|
|
370
445
|
|
|
371
|
-
#
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
446
|
+
#getGlobalVariables() {
|
|
447
|
+
if (this.txs.length) {
|
|
448
|
+
return this.txs[0].processedTx.globalVariables;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const constants = this.constants;
|
|
452
|
+
|
|
453
|
+
return GlobalVariables.from({
|
|
454
|
+
chainId: constants.chainId,
|
|
455
|
+
version: constants.version,
|
|
456
|
+
blockNumber: this.blockNumber,
|
|
457
|
+
slotNumber: constants.slotNumber,
|
|
458
|
+
timestamp: this.timestamp,
|
|
459
|
+
coinbase: constants.coinbase,
|
|
460
|
+
feeRecipient: constants.feeRecipient,
|
|
461
|
+
gasFees: constants.gasFees,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
#getTotalFees() {
|
|
466
|
+
return this.txs.reduce((acc, tx) => acc.add(tx.processedTx.txEffect.transactionFee), Fr.ZERO);
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
#getTotalManaUsed() {
|
|
470
|
+
return this.txs.reduce((acc, tx) => acc + BigInt(tx.processedTx.gasUsed.billedGas.l2Gas), 0n);
|
|
378
471
|
}
|
|
379
472
|
}
|