@aztec/prover-client 0.55.1 → 0.57.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/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/mocks/fixtures.d.ts.map +1 -1
- package/dest/mocks/fixtures.js +6 -27
- package/dest/mocks/test_context.d.ts +9 -10
- package/dest/mocks/test_context.d.ts.map +1 -1
- package/dest/mocks/test_context.js +13 -15
- package/dest/orchestrator/block-building-helpers.d.ts +12 -3
- package/dest/orchestrator/block-building-helpers.d.ts.map +1 -1
- package/dest/orchestrator/block-building-helpers.js +34 -32
- package/dest/orchestrator/{proving-state.d.ts → block-proving-state.d.ts} +19 -16
- package/dest/orchestrator/block-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/block-proving-state.js +147 -0
- package/dest/orchestrator/epoch-proving-state.d.ts +63 -0
- package/dest/orchestrator/epoch-proving-state.d.ts.map +1 -0
- package/dest/orchestrator/epoch-proving-state.js +143 -0
- package/dest/orchestrator/orchestrator.d.ts +33 -15
- package/dest/orchestrator/orchestrator.d.ts.map +1 -1
- package/dest/orchestrator/orchestrator.js +315 -172
- package/dest/orchestrator/tx-proving-state.d.ts +3 -2
- package/dest/orchestrator/tx-proving-state.d.ts.map +1 -1
- package/dest/orchestrator/tx-proving-state.js +54 -26
- package/dest/prover-agent/memory-proving-queue.d.ts +11 -5
- package/dest/prover-agent/memory-proving-queue.d.ts.map +1 -1
- package/dest/prover-agent/memory-proving-queue.js +16 -6
- package/dest/prover-agent/prover-agent.d.ts.map +1 -1
- package/dest/prover-agent/prover-agent.js +10 -10
- package/dest/prover-agent/rpc.d.ts.map +1 -1
- package/dest/prover-agent/rpc.js +8 -2
- package/dest/test/mock_prover.d.ts +6 -4
- package/dest/test/mock_prover.d.ts.map +1 -1
- package/dest/test/mock_prover.js +9 -3
- package/dest/tx-prover/tx-prover.d.ts +3 -3
- package/dest/tx-prover/tx-prover.d.ts.map +1 -1
- package/dest/tx-prover/tx-prover.js +1 -1
- package/package.json +15 -11
- package/src/index.ts +1 -1
- package/src/mocks/fixtures.ts +5 -49
- package/src/mocks/test_context.ts +15 -20
- package/src/orchestrator/block-building-helpers.ts +90 -57
- package/src/orchestrator/{proving-state.ts → block-proving-state.ts} +29 -53
- package/src/orchestrator/epoch-proving-state.ts +221 -0
- package/src/orchestrator/orchestrator.ts +494 -292
- package/src/orchestrator/tx-proving-state.ts +63 -27
- package/src/prover-agent/memory-proving-queue.ts +31 -16
- package/src/prover-agent/prover-agent.ts +11 -9
- package/src/prover-agent/rpc.ts +9 -0
- package/src/test/mock_prover.ts +23 -1
- package/src/tx-prover/tx-prover.ts +4 -4
- package/dest/orchestrator/proving-state.d.ts.map +0 -1
- package/dest/orchestrator/proving-state.js +0 -170
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type EpochProver, type EpochProverManager, type ProvingJobSource } from '@aztec/circuit-types/interfaces';
|
|
2
2
|
import { Fr } from '@aztec/circuits.js';
|
|
3
3
|
import { type TelemetryClient } from '@aztec/telemetry-client';
|
|
4
4
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
@@ -7,14 +7,14 @@ import { type ProverClientConfig } from '../config.js';
|
|
|
7
7
|
* A prover factory.
|
|
8
8
|
* TODO(palla/prover-node): Rename this class
|
|
9
9
|
*/
|
|
10
|
-
export declare class TxProver implements
|
|
10
|
+
export declare class TxProver implements EpochProverManager {
|
|
11
11
|
private config;
|
|
12
12
|
private telemetry;
|
|
13
13
|
private agent?;
|
|
14
14
|
private queue;
|
|
15
15
|
private running;
|
|
16
16
|
private constructor();
|
|
17
|
-
|
|
17
|
+
createEpochProver(db: MerkleTreeOperations): EpochProver;
|
|
18
18
|
getProverId(): Fr;
|
|
19
19
|
updateProverConfig(config: Partial<ProverClientConfig>): Promise<void>;
|
|
20
20
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx-prover.d.ts","sourceRoot":"","sources":["../../src/tx-prover/tx-prover.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,
|
|
1
|
+
{"version":3,"file":"tx-prover.d.ts","sourceRoot":"","sources":["../../src/tx-prover/tx-prover.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EAEtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,oBAAoB,CAAC;AAExC,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAKvD;;;GAGG;AACH,qBAAa,QAAS,YAAW,kBAAkB;IAK/C,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,KAAK,CAAC;IANhB,OAAO,CAAC,KAAK,CAAqB;IAClC,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO;IAUA,iBAAiB,CAAC,EAAE,EAAE,oBAAoB,GAAG,WAAW;IAIxD,WAAW,IAAI,EAAE;IAIlB,kBAAkB,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB5E;;OAEG;IACI,KAAK;IAWZ;;OAEG;IACU,IAAI;IAWjB;;;;;;OAMG;WACiB,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,SAAS,EAAE,eAAe;mBAczD,kBAAkB;IAehC,mBAAmB,IAAI,gBAAgB;CAG/C"}
|
|
@@ -18,7 +18,7 @@ export class TxProver {
|
|
|
18
18
|
// so it can be reused across multiple ones and not recomputed every time.
|
|
19
19
|
this.queue = new MemoryProvingQueue(telemetry, config.proverJobTimeoutMs, config.proverJobPollIntervalMs);
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
createEpochProver(db) {
|
|
22
22
|
return new ProvingOrchestrator(db, this.queue, this.telemetry, this.config.proverId);
|
|
23
23
|
}
|
|
24
24
|
getProverId() {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/prover-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.57.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dest/index.js",
|
|
7
7
|
"./prover-agent": "./dest/prover-agent/index.js",
|
|
8
|
-
"./orchestrator": "./dest/orchestrator/index.js"
|
|
8
|
+
"./orchestrator": "./dest/orchestrator/index.js",
|
|
9
|
+
"./helpers": "./dest/orchestrator/block-building-helpers.js"
|
|
9
10
|
},
|
|
10
11
|
"typedocOptions": {
|
|
11
12
|
"entryPoints": [
|
|
@@ -41,6 +42,9 @@
|
|
|
41
42
|
"parser": {
|
|
42
43
|
"syntax": "typescript",
|
|
43
44
|
"decorators": true
|
|
45
|
+
},
|
|
46
|
+
"transform": {
|
|
47
|
+
"decoratorVersion": "2022-03"
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
}
|
|
@@ -59,15 +63,15 @@
|
|
|
59
63
|
]
|
|
60
64
|
},
|
|
61
65
|
"dependencies": {
|
|
62
|
-
"@aztec/bb-prover": "0.
|
|
63
|
-
"@aztec/circuit-types": "0.
|
|
64
|
-
"@aztec/circuits.js": "0.
|
|
65
|
-
"@aztec/foundation": "0.
|
|
66
|
-
"@aztec/kv-store": "0.
|
|
67
|
-
"@aztec/noir-protocol-circuits-types": "0.
|
|
68
|
-
"@aztec/simulator": "0.
|
|
69
|
-
"@aztec/telemetry-client": "0.
|
|
70
|
-
"@aztec/world-state": "0.
|
|
66
|
+
"@aztec/bb-prover": "0.57.0",
|
|
67
|
+
"@aztec/circuit-types": "0.57.0",
|
|
68
|
+
"@aztec/circuits.js": "0.57.0",
|
|
69
|
+
"@aztec/foundation": "0.57.0",
|
|
70
|
+
"@aztec/kv-store": "0.57.0",
|
|
71
|
+
"@aztec/noir-protocol-circuits-types": "0.57.0",
|
|
72
|
+
"@aztec/simulator": "0.57.0",
|
|
73
|
+
"@aztec/telemetry-client": "0.57.0",
|
|
74
|
+
"@aztec/world-state": "0.57.0",
|
|
71
75
|
"@noir-lang/types": "portal:../../noir/packages/types",
|
|
72
76
|
"commander": "^12.1.0",
|
|
73
77
|
"lodash.chunk": "^4.2.0",
|
package/src/index.ts
CHANGED
package/src/mocks/fixtures.ts
CHANGED
|
@@ -2,29 +2,20 @@ import {
|
|
|
2
2
|
MerkleTreeId,
|
|
3
3
|
type ProcessedTx,
|
|
4
4
|
makeEmptyProcessedTx as makeEmptyProcessedTxFromHistoricalTreeRoots,
|
|
5
|
-
makeProcessedTx,
|
|
6
|
-
mockTx,
|
|
7
5
|
} from '@aztec/circuit-types';
|
|
6
|
+
import { makeBloatedProcessedTx as makeBloatedProcessedTxWithVKRoot } from '@aztec/circuit-types/test';
|
|
8
7
|
import {
|
|
9
8
|
AztecAddress,
|
|
10
9
|
EthAddress,
|
|
11
10
|
Fr,
|
|
12
11
|
GasFees,
|
|
13
12
|
GlobalVariables,
|
|
14
|
-
KernelCircuitPublicInputs,
|
|
15
|
-
LogHash,
|
|
16
|
-
MAX_L2_TO_L1_MSGS_PER_TX,
|
|
17
13
|
MAX_NOTE_HASHES_PER_TX,
|
|
18
14
|
MAX_NULLIFIERS_PER_TX,
|
|
19
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
20
15
|
NULLIFIER_TREE_HEIGHT,
|
|
21
16
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
22
17
|
PublicDataTreeLeaf,
|
|
23
|
-
PublicDataUpdateRequest,
|
|
24
|
-
ScopedLogHash,
|
|
25
18
|
} from '@aztec/circuits.js';
|
|
26
|
-
import { fr, makeScopedL2ToL1Message } from '@aztec/circuits.js/testing';
|
|
27
|
-
import { makeTuple } from '@aztec/foundation/array';
|
|
28
19
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
29
20
|
import { randomBytes } from '@aztec/foundation/crypto';
|
|
30
21
|
import { type DebugLogger } from '@aztec/foundation/log';
|
|
@@ -98,43 +89,8 @@ export async function getSimulationProvider(
|
|
|
98
89
|
return new WASMSimulator();
|
|
99
90
|
}
|
|
100
91
|
|
|
101
|
-
export const makeBloatedProcessedTx = (builderDb: MerkleTreeOperations, seed = 0x1) =>
|
|
102
|
-
|
|
103
|
-
const tx = mockTx(seed);
|
|
104
|
-
const kernelOutput = KernelCircuitPublicInputs.empty();
|
|
105
|
-
kernelOutput.constants.vkTreeRoot = getVKTreeRoot();
|
|
106
|
-
kernelOutput.constants.historicalHeader = builderDb.getInitialHeader();
|
|
107
|
-
kernelOutput.end.publicDataUpdateRequests = makeTuple(
|
|
108
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
109
|
-
i => new PublicDataUpdateRequest(fr(i), fr(i + 10), i + 20),
|
|
110
|
-
seed + 0x500,
|
|
111
|
-
);
|
|
112
|
-
kernelOutput.end.publicDataUpdateRequests = makeTuple(
|
|
113
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
114
|
-
i => new PublicDataUpdateRequest(fr(i), fr(i + 10), i + 20),
|
|
115
|
-
seed + 0x600,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const processedTx = makeProcessedTx(tx, kernelOutput, []);
|
|
119
|
-
|
|
120
|
-
processedTx.data.end.noteHashes = makeTuple(MAX_NOTE_HASHES_PER_TX, fr, seed + 0x100);
|
|
121
|
-
processedTx.data.end.nullifiers = makeTuple(MAX_NULLIFIERS_PER_TX, fr, seed + 0x100000);
|
|
122
|
-
|
|
123
|
-
processedTx.data.end.nullifiers[tx.data.forPublic!.end.nullifiers.length - 1] = Fr.zero();
|
|
124
|
-
|
|
125
|
-
processedTx.data.end.l2ToL1Msgs = makeTuple(MAX_L2_TO_L1_MSGS_PER_TX, makeScopedL2ToL1Message, seed + 0x300);
|
|
126
|
-
processedTx.noteEncryptedLogs.unrollLogs().forEach((log, i) => {
|
|
127
|
-
processedTx.data.end.noteEncryptedLogsHashes[i] = new LogHash(Fr.fromBuffer(log.hash()), 0, new Fr(log.length));
|
|
128
|
-
});
|
|
129
|
-
processedTx.encryptedLogs.unrollLogs().forEach((log, i) => {
|
|
130
|
-
processedTx.data.end.encryptedLogsHashes[i] = new ScopedLogHash(
|
|
131
|
-
new LogHash(Fr.fromBuffer(log.hash()), 0, new Fr(log.length)),
|
|
132
|
-
log.maskedContractAddress,
|
|
133
|
-
);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
return processedTx;
|
|
137
|
-
};
|
|
92
|
+
export const makeBloatedProcessedTx = (builderDb: MerkleTreeOperations, seed = 0x1) =>
|
|
93
|
+
makeBloatedProcessedTxWithVKRoot(builderDb, getVKTreeRoot(), seed);
|
|
138
94
|
|
|
139
95
|
export const makeEmptyProcessedTx = (builderDb: MerkleTreeOperations, chainId: Fr, version: Fr) => {
|
|
140
96
|
const header = builderDb.getInitialHeader();
|
|
@@ -179,9 +135,9 @@ export const makeGlobals = (blockNumber: number) => {
|
|
|
179
135
|
return new GlobalVariables(
|
|
180
136
|
Fr.ZERO,
|
|
181
137
|
Fr.ZERO,
|
|
182
|
-
new Fr(blockNumber)
|
|
138
|
+
new Fr(blockNumber) /** block number */,
|
|
183
139
|
new Fr(blockNumber) /** slot number */,
|
|
184
|
-
Fr
|
|
140
|
+
new Fr(blockNumber) /** timestamp */,
|
|
185
141
|
EthAddress.ZERO,
|
|
186
142
|
AztecAddress.ZERO,
|
|
187
143
|
GasFees.empty(),
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { type BBProverConfig } from '@aztec/bb-prover';
|
|
2
2
|
import {
|
|
3
|
-
type BlockProver,
|
|
4
3
|
type MerkleTreeAdminOperations,
|
|
5
4
|
type ProcessedTx,
|
|
5
|
+
type ProcessedTxHandler,
|
|
6
6
|
type PublicExecutionRequest,
|
|
7
7
|
type ServerCircuitProver,
|
|
8
8
|
type Tx,
|
|
9
9
|
type TxValidator,
|
|
10
10
|
} from '@aztec/circuit-types';
|
|
11
|
-
import { type Gas, GlobalVariables, Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
|
|
11
|
+
import { type Gas, type GlobalVariables, Header, type Nullifier, type TxContext } from '@aztec/circuits.js';
|
|
12
12
|
import { type Fr } from '@aztec/foundation/fields';
|
|
13
13
|
import { type DebugLogger } from '@aztec/foundation/log';
|
|
14
14
|
import { openTmpStore } from '@aztec/kv-store/utils';
|
|
15
15
|
import {
|
|
16
|
-
type ContractsDataSourcePublicDB,
|
|
17
16
|
type PublicExecutionResult,
|
|
18
17
|
PublicExecutionResultBuilder,
|
|
19
18
|
type PublicExecutor,
|
|
@@ -21,7 +20,7 @@ import {
|
|
|
21
20
|
RealPublicKernelCircuitSimulator,
|
|
22
21
|
type SimulationProvider,
|
|
23
22
|
WASMSimulator,
|
|
24
|
-
type
|
|
23
|
+
type WorldStateDB,
|
|
25
24
|
} from '@aztec/simulator';
|
|
26
25
|
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
|
|
27
26
|
import { MerkleTrees } from '@aztec/world-state';
|
|
@@ -33,7 +32,7 @@ import { tmpdir } from 'os';
|
|
|
33
32
|
import { join } from 'path';
|
|
34
33
|
|
|
35
34
|
import { TestCircuitProver } from '../../../bb-prover/src/test/test_circuit_prover.js';
|
|
36
|
-
import { ProvingOrchestrator } from '../orchestrator/
|
|
35
|
+
import { ProvingOrchestrator } from '../orchestrator/index.js';
|
|
37
36
|
import { MemoryProvingQueue } from '../prover-agent/memory-proving-queue.js';
|
|
38
37
|
import { ProverAgent } from '../prover-agent/prover-agent.js';
|
|
39
38
|
import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixtures.js';
|
|
@@ -41,8 +40,7 @@ import { getEnvironmentConfig, getSimulationProvider, makeGlobals } from './fixt
|
|
|
41
40
|
export class TestContext {
|
|
42
41
|
constructor(
|
|
43
42
|
public publicExecutor: MockProxy<PublicExecutor>,
|
|
44
|
-
public
|
|
45
|
-
public publicWorldStateDB: MockProxy<WorldStatePublicDB>,
|
|
43
|
+
public worldStateDB: MockProxy<WorldStateDB>,
|
|
46
44
|
public publicProcessor: PublicProcessor,
|
|
47
45
|
public simulationProvider: SimulationProvider,
|
|
48
46
|
public globalVariables: GlobalVariables,
|
|
@@ -55,7 +53,7 @@ export class TestContext {
|
|
|
55
53
|
public logger: DebugLogger,
|
|
56
54
|
) {}
|
|
57
55
|
|
|
58
|
-
public get
|
|
56
|
+
public get epochProver() {
|
|
59
57
|
return this.orchestrator;
|
|
60
58
|
}
|
|
61
59
|
|
|
@@ -71,8 +69,7 @@ export class TestContext {
|
|
|
71
69
|
const globalVariables = makeGlobals(blockNumber);
|
|
72
70
|
|
|
73
71
|
const publicExecutor = mock<PublicExecutor>();
|
|
74
|
-
const
|
|
75
|
-
const publicWorldStateDB = mock<WorldStatePublicDB>();
|
|
72
|
+
const worldStateDB = mock<WorldStateDB>();
|
|
76
73
|
const publicKernel = new RealPublicKernelCircuitSimulator(new WASMSimulator());
|
|
77
74
|
const telemetry = new NoopTelemetryClient();
|
|
78
75
|
|
|
@@ -88,14 +85,13 @@ export class TestContext {
|
|
|
88
85
|
actualDb = ws.asLatest();
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
const processor =
|
|
88
|
+
const processor = PublicProcessor.create(
|
|
92
89
|
actualDb,
|
|
93
90
|
publicExecutor,
|
|
94
91
|
publicKernel,
|
|
95
|
-
|
|
92
|
+
globalVariables,
|
|
96
93
|
Header.empty(),
|
|
97
|
-
|
|
98
|
-
publicWorldStateDB,
|
|
94
|
+
worldStateDB,
|
|
99
95
|
telemetry,
|
|
100
96
|
);
|
|
101
97
|
|
|
@@ -130,8 +126,7 @@ export class TestContext {
|
|
|
130
126
|
|
|
131
127
|
return new this(
|
|
132
128
|
publicExecutor,
|
|
133
|
-
|
|
134
|
-
publicWorldStateDB,
|
|
129
|
+
worldStateDB,
|
|
135
130
|
processor,
|
|
136
131
|
simulationProvider,
|
|
137
132
|
globalVariables,
|
|
@@ -155,7 +150,7 @@ export class TestContext {
|
|
|
155
150
|
public async processPublicFunctions(
|
|
156
151
|
txs: Tx[],
|
|
157
152
|
maxTransactions: number,
|
|
158
|
-
|
|
153
|
+
txHandler?: ProcessedTxHandler,
|
|
159
154
|
txValidator?: TxValidator<ProcessedTx>,
|
|
160
155
|
) {
|
|
161
156
|
const defaultExecutorImplementation = (
|
|
@@ -187,7 +182,7 @@ export class TestContext {
|
|
|
187
182
|
return await this.processPublicFunctionsWithMockExecutorImplementation(
|
|
188
183
|
txs,
|
|
189
184
|
maxTransactions,
|
|
190
|
-
|
|
185
|
+
txHandler,
|
|
191
186
|
txValidator,
|
|
192
187
|
defaultExecutorImplementation,
|
|
193
188
|
);
|
|
@@ -196,7 +191,7 @@ export class TestContext {
|
|
|
196
191
|
public async processPublicFunctionsWithMockExecutorImplementation(
|
|
197
192
|
txs: Tx[],
|
|
198
193
|
maxTransactions: number,
|
|
199
|
-
|
|
194
|
+
txHandler?: ProcessedTxHandler,
|
|
200
195
|
txValidator?: TxValidator<ProcessedTx>,
|
|
201
196
|
executorMock?: (
|
|
202
197
|
execution: PublicExecutionRequest,
|
|
@@ -211,6 +206,6 @@ export class TestContext {
|
|
|
211
206
|
if (executorMock) {
|
|
212
207
|
this.publicExecutor.simulate.mockImplementation(executorMock);
|
|
213
208
|
}
|
|
214
|
-
return await this.publicProcessor.process(txs, maxTransactions,
|
|
209
|
+
return await this.publicProcessor.process(txs, maxTransactions, txHandler, txValidator);
|
|
215
210
|
}
|
|
216
211
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MerkleTreeId, type ProcessedTx } from '@aztec/circuit-types';
|
|
1
|
+
import { type Body, MerkleTreeId, type ProcessedTx, TxEffect, getTreeHeight } from '@aztec/circuit-types';
|
|
2
2
|
import {
|
|
3
3
|
ARCHIVE_HEIGHT,
|
|
4
4
|
AppendOnlyTreeSnapshot,
|
|
@@ -6,28 +6,29 @@ import {
|
|
|
6
6
|
BaseRollupInputs,
|
|
7
7
|
BlockMergeRollupInputs,
|
|
8
8
|
type BlockRootOrBlockMergePublicInputs,
|
|
9
|
-
BlockRootRollupInputs,
|
|
10
9
|
ConstantRollupData,
|
|
10
|
+
ContentCommitment,
|
|
11
11
|
Fr,
|
|
12
12
|
type GlobalVariables,
|
|
13
|
-
|
|
13
|
+
Header,
|
|
14
14
|
KernelData,
|
|
15
|
-
type L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH,
|
|
16
15
|
MAX_NULLIFIERS_PER_TX,
|
|
17
16
|
MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
18
17
|
MembershipWitness,
|
|
19
18
|
MergeRollupInputs,
|
|
19
|
+
MerkleTreeCalculator,
|
|
20
20
|
type NESTED_RECURSIVE_PROOF_LENGTH,
|
|
21
21
|
NOTE_HASH_SUBTREE_HEIGHT,
|
|
22
22
|
NOTE_HASH_SUBTREE_SIBLING_PATH_LENGTH,
|
|
23
23
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
24
24
|
NULLIFIER_SUBTREE_SIBLING_PATH_LENGTH,
|
|
25
25
|
NULLIFIER_TREE_HEIGHT,
|
|
26
|
-
|
|
26
|
+
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
27
27
|
NullifierLeafPreimage,
|
|
28
28
|
PUBLIC_DATA_SUBTREE_HEIGHT,
|
|
29
29
|
PUBLIC_DATA_SUBTREE_SIBLING_PATH_LENGTH,
|
|
30
30
|
PUBLIC_DATA_TREE_HEIGHT,
|
|
31
|
+
type ParityPublicInputs,
|
|
31
32
|
PartialStateReference,
|
|
32
33
|
PreviousRollupBlockData,
|
|
33
34
|
PreviousRollupData,
|
|
@@ -37,21 +38,25 @@ import {
|
|
|
37
38
|
PublicDataUpdateRequest,
|
|
38
39
|
type RECURSIVE_PROOF_LENGTH,
|
|
39
40
|
type RecursiveProof,
|
|
40
|
-
type RootParityInput,
|
|
41
41
|
RootRollupInputs,
|
|
42
42
|
StateDiffHints,
|
|
43
|
-
|
|
43
|
+
StateReference,
|
|
44
44
|
VK_TREE_HEIGHT,
|
|
45
45
|
type VerificationKeyAsFields,
|
|
46
46
|
type VerificationKeyData,
|
|
47
47
|
} from '@aztec/circuits.js';
|
|
48
48
|
import { assertPermutation, makeTuple } from '@aztec/foundation/array';
|
|
49
49
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
50
|
+
import { sha256Trunc } from '@aztec/foundation/crypto';
|
|
51
|
+
import { type DebugLogger } from '@aztec/foundation/log';
|
|
50
52
|
import { type Tuple, assertLength, toFriendlyJSON } from '@aztec/foundation/serialize';
|
|
53
|
+
import { computeUnbalancedMerkleRoot } from '@aztec/foundation/trees';
|
|
51
54
|
import { getVKIndex, getVKSiblingPath, getVKTreeRoot } from '@aztec/noir-protocol-circuits-types';
|
|
52
55
|
import { HintsBuilder, computeFeePayerBalanceLeafSlot } from '@aztec/simulator';
|
|
53
56
|
import { type MerkleTreeOperations } from '@aztec/world-state';
|
|
54
57
|
|
|
58
|
+
import { inspect } from 'util';
|
|
59
|
+
|
|
55
60
|
/**
|
|
56
61
|
* Type representing the names of the trees for the base rollup.
|
|
57
62
|
*/
|
|
@@ -189,7 +194,6 @@ export function createMergeRollupInputs(
|
|
|
189
194
|
return mergeInputs;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
|
-
// TODO(#7346): Integrate batch rollup circuits and test below
|
|
193
197
|
export function createBlockMergeRollupInputs(
|
|
194
198
|
left: [
|
|
195
199
|
BlockRootOrBlockMergePublicInputs,
|
|
@@ -209,6 +213,80 @@ export function createBlockMergeRollupInputs(
|
|
|
209
213
|
return mergeInputs;
|
|
210
214
|
}
|
|
211
215
|
|
|
216
|
+
export function buildHeaderFromCircuitOutputs(
|
|
217
|
+
previousMergeData: [BaseOrMergeRollupPublicInputs, BaseOrMergeRollupPublicInputs],
|
|
218
|
+
parityPublicInputs: ParityPublicInputs,
|
|
219
|
+
rootRollupOutputs: BlockRootOrBlockMergePublicInputs,
|
|
220
|
+
updatedL1ToL2TreeSnapshot: AppendOnlyTreeSnapshot,
|
|
221
|
+
logger?: DebugLogger,
|
|
222
|
+
) {
|
|
223
|
+
const contentCommitment = new ContentCommitment(
|
|
224
|
+
new Fr(previousMergeData[0].numTxs + previousMergeData[1].numTxs),
|
|
225
|
+
sha256Trunc(
|
|
226
|
+
Buffer.concat([previousMergeData[0].txsEffectsHash.toBuffer(), previousMergeData[1].txsEffectsHash.toBuffer()]),
|
|
227
|
+
),
|
|
228
|
+
parityPublicInputs.shaRoot.toBuffer(),
|
|
229
|
+
sha256Trunc(Buffer.concat([previousMergeData[0].outHash.toBuffer(), previousMergeData[1].outHash.toBuffer()])),
|
|
230
|
+
);
|
|
231
|
+
const state = new StateReference(updatedL1ToL2TreeSnapshot, previousMergeData[1].end);
|
|
232
|
+
const header = new Header(
|
|
233
|
+
rootRollupOutputs.previousArchive,
|
|
234
|
+
contentCommitment,
|
|
235
|
+
state,
|
|
236
|
+
previousMergeData[0].constants.globalVariables,
|
|
237
|
+
previousMergeData[0].accumulatedFees.add(previousMergeData[1].accumulatedFees),
|
|
238
|
+
);
|
|
239
|
+
if (!header.hash().equals(rootRollupOutputs.endBlockHash)) {
|
|
240
|
+
logger?.error(
|
|
241
|
+
`Block header mismatch when building header from circuit outputs.` +
|
|
242
|
+
`\n\nHeader: ${inspect(header)}` +
|
|
243
|
+
`\n\nCircuit: ${toFriendlyJSON(rootRollupOutputs)}`,
|
|
244
|
+
);
|
|
245
|
+
throw new Error(`Block header mismatch when building from circuit outputs`);
|
|
246
|
+
}
|
|
247
|
+
return header;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export async function buildHeaderFromTxEffects(
|
|
251
|
+
body: Body,
|
|
252
|
+
globalVariables: GlobalVariables,
|
|
253
|
+
l1ToL2Messages: Fr[],
|
|
254
|
+
db: MerkleTreeOperations,
|
|
255
|
+
) {
|
|
256
|
+
const stateReference = new StateReference(
|
|
257
|
+
await getTreeSnapshot(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, db),
|
|
258
|
+
new PartialStateReference(
|
|
259
|
+
await getTreeSnapshot(MerkleTreeId.NOTE_HASH_TREE, db),
|
|
260
|
+
await getTreeSnapshot(MerkleTreeId.NULLIFIER_TREE, db),
|
|
261
|
+
await getTreeSnapshot(MerkleTreeId.PUBLIC_DATA_TREE, db),
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const previousArchive = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
266
|
+
|
|
267
|
+
const outHash = computeUnbalancedMerkleRoot(
|
|
268
|
+
body.txEffects.map(tx => tx.txOutHash()),
|
|
269
|
+
TxEffect.empty().txOutHash(),
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
l1ToL2Messages = padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP);
|
|
273
|
+
const hasher = (left: Buffer, right: Buffer) => sha256Trunc(Buffer.concat([left, right]));
|
|
274
|
+
const parityHeight = Math.ceil(Math.log2(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP));
|
|
275
|
+
const parityShaRoot = new MerkleTreeCalculator(parityHeight, Fr.ZERO.toBuffer(), hasher).computeTreeRoot(
|
|
276
|
+
l1ToL2Messages.map(msg => msg.toBuffer()),
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
const contentCommitment = new ContentCommitment(
|
|
280
|
+
new Fr(body.numberOfTxsIncludingPadded),
|
|
281
|
+
body.getTxsEffectsHash(),
|
|
282
|
+
parityShaRoot,
|
|
283
|
+
outHash,
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
const fees = body.txEffects.reduce((acc, tx) => acc.add(tx.transactionFee), Fr.ZERO);
|
|
287
|
+
return new Header(previousArchive, contentCommitment, stateReference, globalVariables, fees);
|
|
288
|
+
}
|
|
289
|
+
|
|
212
290
|
// Validate that the roots of all local trees match the output of the root circuit simulation
|
|
213
291
|
export async function validateBlockRootOutput(
|
|
214
292
|
blockRootOutput: BlockRootOrBlockMergePublicInputs,
|
|
@@ -238,58 +316,13 @@ export async function validateState(state: StateReference, db: MerkleTreeOperati
|
|
|
238
316
|
);
|
|
239
317
|
}
|
|
240
318
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
verificationKeyLeft: VerificationKeyAsFields,
|
|
246
|
-
rollupOutputRight: BaseOrMergeRollupPublicInputs,
|
|
247
|
-
rollupProofRight: RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>,
|
|
248
|
-
verificationKeyRight: VerificationKeyAsFields,
|
|
249
|
-
l1ToL2Roots: RootParityInput<typeof NESTED_RECURSIVE_PROOF_LENGTH>,
|
|
250
|
-
newL1ToL2Messages: Tuple<Fr, typeof NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP>,
|
|
251
|
-
messageTreeSnapshot: AppendOnlyTreeSnapshot,
|
|
252
|
-
messageTreeRootSiblingPath: Tuple<Fr, typeof L1_TO_L2_MSG_SUBTREE_SIBLING_PATH_LENGTH>,
|
|
253
|
-
db: MerkleTreeOperations,
|
|
254
|
-
proverId: Fr,
|
|
255
|
-
) {
|
|
256
|
-
const previousRollupData: BlockRootRollupInputs['previousRollupData'] = [
|
|
257
|
-
getPreviousRollupDataFromPublicInputs(rollupOutputLeft, rollupProofLeft, verificationKeyLeft),
|
|
258
|
-
getPreviousRollupDataFromPublicInputs(rollupOutputRight, rollupProofRight, verificationKeyRight),
|
|
259
|
-
];
|
|
260
|
-
|
|
261
|
-
const getRootTreeSiblingPath = async (treeId: MerkleTreeId) => {
|
|
262
|
-
const { size } = await db.getTreeInfo(treeId);
|
|
263
|
-
const path = await db.getSiblingPath(treeId, size);
|
|
264
|
-
return path.toFields();
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
// Get blocks tree
|
|
268
|
-
const startArchiveSnapshot = await getTreeSnapshot(MerkleTreeId.ARCHIVE, db);
|
|
269
|
-
const newArchiveSiblingPathArray = await getRootTreeSiblingPath(MerkleTreeId.ARCHIVE);
|
|
270
|
-
|
|
271
|
-
const newArchiveSiblingPath = makeTuple(
|
|
272
|
-
ARCHIVE_HEIGHT,
|
|
273
|
-
i => (i < newArchiveSiblingPathArray.length ? newArchiveSiblingPathArray[i] : Fr.ZERO),
|
|
274
|
-
0,
|
|
275
|
-
);
|
|
276
|
-
|
|
277
|
-
return BlockRootRollupInputs.from({
|
|
278
|
-
previousRollupData,
|
|
279
|
-
l1ToL2Roots,
|
|
280
|
-
newL1ToL2Messages,
|
|
281
|
-
newL1ToL2MessageTreeRootSiblingPath: messageTreeRootSiblingPath,
|
|
282
|
-
startL1ToL2MessageTreeSnapshot: messageTreeSnapshot,
|
|
283
|
-
startArchiveSnapshot,
|
|
284
|
-
newArchiveSiblingPath,
|
|
285
|
-
// TODO(#7346): Inject previous block hash (required when integrating batch rollup circuits)
|
|
286
|
-
previousBlockHash: Fr.ZERO,
|
|
287
|
-
proverId,
|
|
288
|
-
});
|
|
319
|
+
export async function getRootTreeSiblingPath<TID extends MerkleTreeId>(treeId: TID, db: MerkleTreeOperations) {
|
|
320
|
+
const { size } = await db.getTreeInfo(treeId);
|
|
321
|
+
const path = await db.getSiblingPath(treeId, size);
|
|
322
|
+
return padArrayEnd(path.toFields(), Fr.ZERO, getTreeHeight(treeId));
|
|
289
323
|
}
|
|
290
324
|
|
|
291
325
|
// Builds the inputs for the final root rollup circuit, without making any changes to trees
|
|
292
|
-
// TODO(#7346): Integrate batch rollup circuits and test below
|
|
293
326
|
export function getRootRollupInput(
|
|
294
327
|
rollupOutputLeft: BlockRootOrBlockMergePublicInputs,
|
|
295
328
|
rollupProofLeft: RecursiveProof<typeof NESTED_RECURSIVE_PROOF_LENGTH>,
|