@aztec/sequencer-client 0.1.0-alpha23 → 0.1.0-alpha40
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/.tsbuildinfo +1 -1
- package/dest/block_builder/index.d.ts +2 -2
- package/dest/block_builder/index.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.d.ts +7 -7
- package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.js +49 -53
- package/dest/block_builder/solo_block_builder.test.d.ts +2 -2
- package/dest/block_builder/solo_block_builder.test.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.test.js +27 -26
- package/dest/block_builder/types.d.ts +1 -1
- package/dest/block_builder/types.d.ts.map +1 -1
- package/dest/client/sequencer-client.d.ts +1 -1
- package/dest/client/sequencer-client.d.ts.map +1 -1
- package/dest/client/sequencer-client.js +3 -3
- package/dest/config.d.ts +2 -2
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +8 -5
- package/dest/global_variable_builder/global_builder.d.ts +17 -0
- package/dest/global_variable_builder/global_builder.d.ts.map +1 -1
- package/dest/global_variable_builder/global_builder.js +1 -1
- package/dest/global_variable_builder/viem-reader.d.ts +0 -12
- package/dest/global_variable_builder/viem-reader.d.ts.map +1 -1
- package/dest/global_variable_builder/viem-reader.js +2 -14
- package/dest/prover/empty.d.ts.map +1 -1
- package/dest/prover/empty.js +1 -1
- package/dest/prover/index.d.ts +23 -0
- package/dest/prover/index.d.ts.map +1 -1
- package/dest/publisher/config.d.ts +3 -3
- package/dest/publisher/config.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.d.ts +3 -3
- package/dest/publisher/l1-publisher.d.ts.map +1 -1
- package/dest/publisher/l1-publisher.js +5 -3
- package/dest/publisher/l1-publisher.test.js +2 -2
- package/dest/publisher/viem-tx-sender.d.ts +4 -4
- package/dest/publisher/viem-tx-sender.d.ts.map +1 -1
- package/dest/publisher/viem-tx-sender.js +11 -11
- package/dest/sequencer/config.d.ts +1 -1
- package/dest/sequencer/config.d.ts.map +1 -1
- package/dest/sequencer/processed_tx.d.ts +2 -2
- package/dest/sequencer/processed_tx.d.ts.map +1 -1
- package/dest/sequencer/processed_tx.js +3 -3
- package/dest/sequencer/public_processor.d.ts +11 -10
- package/dest/sequencer/public_processor.d.ts.map +1 -1
- package/dest/sequencer/public_processor.js +24 -22
- package/dest/sequencer/public_processor.test.js +15 -17
- package/dest/sequencer/sequencer.d.ts +4 -4
- package/dest/sequencer/sequencer.d.ts.map +1 -1
- package/dest/sequencer/sequencer.js +18 -15
- package/dest/sequencer/sequencer.test.js +5 -5
- package/dest/sequencer/utils.d.ts +2 -2
- package/dest/sequencer/utils.d.ts.map +1 -1
- package/dest/sequencer/utils.js +8 -5
- package/dest/simulator/index.d.ts +2 -2
- package/dest/simulator/public_executor.d.ts +3 -20
- package/dest/simulator/public_executor.d.ts.map +1 -1
- package/dest/simulator/public_executor.js +16 -35
- package/dest/simulator/public_kernel.d.ts.map +1 -1
- package/dest/simulator/public_kernel.js +1 -1
- package/dest/simulator/rollup.d.ts.map +1 -1
- package/dest/simulator/rollup.js +1 -1
- package/package.json +10 -10
- package/src/block_builder/index.ts +3 -2
- package/src/block_builder/solo_block_builder.test.ts +46 -38
- package/src/block_builder/solo_block_builder.ts +79 -88
- package/src/block_builder/types.ts +1 -1
- package/src/client/sequencer-client.ts +3 -3
- package/src/config.ts +11 -7
- package/src/global_variable_builder/global_builder.ts +17 -0
- package/src/global_variable_builder/viem-reader.ts +5 -15
- package/src/prover/empty.ts +1 -0
- package/src/prover/index.ts +26 -0
- package/src/publisher/config.ts +3 -2
- package/src/publisher/l1-publisher.test.ts +3 -2
- package/src/publisher/l1-publisher.ts +18 -8
- package/src/publisher/viem-tx-sender.ts +14 -13
- package/src/sequencer/config.ts +1 -1
- package/src/sequencer/processed_tx.ts +3 -3
- package/src/sequencer/public_processor.test.ts +38 -18
- package/src/sequencer/public_processor.ts +33 -25
- package/src/sequencer/sequencer.test.ts +7 -5
- package/src/sequencer/sequencer.ts +20 -16
- package/src/sequencer/utils.ts +19 -11
- package/src/simulator/index.ts +2 -2
- package/src/simulator/public_executor.ts +15 -34
- package/src/simulator/public_kernel.ts +1 -0
- package/src/simulator/rollup.ts +1 -0
|
@@ -6,14 +6,15 @@ import {
|
|
|
6
6
|
ContractStorageUpdateRequest,
|
|
7
7
|
Fr,
|
|
8
8
|
GlobalVariables,
|
|
9
|
-
|
|
10
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
9
|
+
HistoricBlockData,
|
|
11
10
|
KernelCircuitPublicInputs,
|
|
12
|
-
MembershipWitness,
|
|
13
11
|
MAX_NEW_COMMITMENTS_PER_CALL,
|
|
14
12
|
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
|
|
15
13
|
MAX_NEW_NULLIFIERS_PER_CALL,
|
|
16
14
|
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
15
|
+
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
16
|
+
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
17
|
+
MembershipWitness,
|
|
17
18
|
PreviousKernelData,
|
|
18
19
|
Proof,
|
|
19
20
|
PublicCallData,
|
|
@@ -30,6 +31,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
|
|
|
30
31
|
import { Tuple, mapTuple, to2Fields } from '@aztec/foundation/serialize';
|
|
31
32
|
import { ContractDataSource, FunctionL2Logs, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types';
|
|
32
33
|
import { MerkleTreeOperations } from '@aztec/world-state';
|
|
34
|
+
|
|
33
35
|
import { getVerificationKeys } from '../index.js';
|
|
34
36
|
import { EmptyPublicProver } from '../prover/empty.js';
|
|
35
37
|
import { PublicProver } from '../prover/index.js';
|
|
@@ -37,7 +39,7 @@ import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
|
37
39
|
import { getPublicExecutor } from '../simulator/public_executor.js';
|
|
38
40
|
import { WasmPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
|
|
39
41
|
import { ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
|
|
40
|
-
import {
|
|
42
|
+
import { getHistoricBlockData } from './utils.js';
|
|
41
43
|
|
|
42
44
|
/**
|
|
43
45
|
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
@@ -51,15 +53,23 @@ export class PublicProcessorFactory {
|
|
|
51
53
|
|
|
52
54
|
/**
|
|
53
55
|
* Creates a new instance of a PublicProcessor.
|
|
56
|
+
* @param prevGlobalVariables - The global variables for the previous block, used to calculate the prev global variables hash.
|
|
57
|
+
* @param globalVariables - The global variables for the block being processed.
|
|
54
58
|
* @returns A new instance of a PublicProcessor.
|
|
55
59
|
*/
|
|
56
|
-
public create(
|
|
60
|
+
public async create(
|
|
61
|
+
prevGlobalVariables: GlobalVariables,
|
|
62
|
+
globalVariables: GlobalVariables,
|
|
63
|
+
): Promise<PublicProcessor> {
|
|
64
|
+
const blockData = await getHistoricBlockData(this.merkleTree, prevGlobalVariables);
|
|
57
65
|
return new PublicProcessor(
|
|
58
66
|
this.merkleTree,
|
|
59
|
-
getPublicExecutor(this.merkleTree, this.contractDataSource, this.l1Tol2MessagesDataSource),
|
|
67
|
+
getPublicExecutor(this.merkleTree, this.contractDataSource, this.l1Tol2MessagesDataSource, blockData),
|
|
60
68
|
new WasmPublicKernelCircuitSimulator(),
|
|
61
69
|
new EmptyPublicProver(),
|
|
62
70
|
this.contractDataSource,
|
|
71
|
+
globalVariables,
|
|
72
|
+
blockData,
|
|
63
73
|
);
|
|
64
74
|
}
|
|
65
75
|
}
|
|
@@ -75,6 +85,8 @@ export class PublicProcessor {
|
|
|
75
85
|
protected publicKernel: PublicKernelCircuitSimulator,
|
|
76
86
|
protected publicProver: PublicProver,
|
|
77
87
|
protected contractDataSource: ContractDataSource,
|
|
88
|
+
protected globalVariables: GlobalVariables,
|
|
89
|
+
protected blockData: HistoricBlockData,
|
|
78
90
|
|
|
79
91
|
private log = createDebugLogger('aztec:sequencer:public-processor'),
|
|
80
92
|
) {}
|
|
@@ -82,17 +94,16 @@ export class PublicProcessor {
|
|
|
82
94
|
/**
|
|
83
95
|
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
84
96
|
* @param txs - Txs to process.
|
|
85
|
-
* @param globalVariables - The global variables for the block.
|
|
86
97
|
* @returns The list of processed txs with their circuit simulation outputs.
|
|
87
98
|
*/
|
|
88
|
-
public async process(txs: Tx[]
|
|
99
|
+
public async process(txs: Tx[]): Promise<[ProcessedTx[], Tx[]]> {
|
|
89
100
|
const result: ProcessedTx[] = [];
|
|
90
101
|
const failed: Tx[] = [];
|
|
91
102
|
|
|
92
103
|
for (const tx of txs) {
|
|
93
104
|
this.log(`Processing tx ${await tx.getTxHash()}`);
|
|
94
105
|
try {
|
|
95
|
-
result.push(await this.processTx(tx
|
|
106
|
+
result.push(await this.processTx(tx));
|
|
96
107
|
} catch (err) {
|
|
97
108
|
this.log(`Error processing tx ${await tx.getTxHash()}: ${err}`);
|
|
98
109
|
failed.push(tx);
|
|
@@ -103,20 +114,17 @@ export class PublicProcessor {
|
|
|
103
114
|
|
|
104
115
|
/**
|
|
105
116
|
* Makes an empty processed tx. Useful for padding a block to a power of two number of txs.
|
|
106
|
-
* @param chainId - The chain id of the rollup.
|
|
107
|
-
* @param version - The version of the rollup.
|
|
108
117
|
* @returns A processed tx with empty data.
|
|
109
118
|
*/
|
|
110
|
-
public
|
|
111
|
-
const
|
|
112
|
-
return makeEmptyProcessedTx(
|
|
119
|
+
public makeEmptyProcessedTx(): Promise<ProcessedTx> {
|
|
120
|
+
const { chainId, version } = this.globalVariables;
|
|
121
|
+
return makeEmptyProcessedTx(this.blockData, chainId, version);
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
protected async processTx(tx: Tx
|
|
124
|
+
protected async processTx(tx: Tx): Promise<ProcessedTx> {
|
|
116
125
|
if (!isArrayEmpty(tx.data.end.publicCallStack, item => item.isZero())) {
|
|
117
126
|
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs] = await this.processEnqueuedPublicCalls(
|
|
118
127
|
tx,
|
|
119
|
-
globalVariables,
|
|
120
128
|
);
|
|
121
129
|
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
122
130
|
|
|
@@ -126,10 +134,7 @@ export class PublicProcessor {
|
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
|
|
129
|
-
protected async processEnqueuedPublicCalls(
|
|
130
|
-
tx: Tx,
|
|
131
|
-
globalVariables: GlobalVariables,
|
|
132
|
-
): Promise<[PublicKernelPublicInputs, Proof, FunctionL2Logs[]]> {
|
|
137
|
+
protected async processEnqueuedPublicCalls(tx: Tx): Promise<[PublicKernelPublicInputs, Proof, FunctionL2Logs[]]> {
|
|
133
138
|
this.log(`Executing enqueued public calls for tx ${await tx.getTxHash()}`);
|
|
134
139
|
if (!tx.enqueuedPublicFunctionCalls) throw new Error(`Missing preimages for enqueued public calls`);
|
|
135
140
|
|
|
@@ -143,13 +148,14 @@ export class PublicProcessor {
|
|
|
143
148
|
while (executionStack.length) {
|
|
144
149
|
const current = executionStack.pop()!;
|
|
145
150
|
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
146
|
-
const result = isExecutionRequest ? await this.publicExecutor.execute(current, globalVariables) : current;
|
|
151
|
+
const result = isExecutionRequest ? await this.publicExecutor.execute(current, this.globalVariables) : current;
|
|
147
152
|
newUnencryptedFunctionLogs.push(result.unencryptedLogs);
|
|
148
153
|
const functionSelector = result.execution.functionData.functionSelectorBuffer.toString('hex');
|
|
149
154
|
this.log(`Running public kernel circuit for ${functionSelector}@${result.execution.contractAddress.toString()}`);
|
|
150
155
|
executionStack.push(...result.nestedExecutions);
|
|
151
156
|
const preimages = await this.getPublicCallStackPreimages(result);
|
|
152
157
|
const callData = await this.getPublicCallData(result, preimages, isExecutionRequest);
|
|
158
|
+
|
|
153
159
|
[kernelOutput, kernelProof] = await this.runKernelCircuit(callData, kernelOutput, kernelProof);
|
|
154
160
|
}
|
|
155
161
|
|
|
@@ -195,20 +201,22 @@ export class PublicProcessor {
|
|
|
195
201
|
|
|
196
202
|
protected async getPublicCircuitPublicInputs(result: PublicExecutionResult) {
|
|
197
203
|
const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE);
|
|
198
|
-
|
|
204
|
+
this.blockData.publicDataTreeRoot = Fr.fromBuffer(publicDataTreeInfo.root);
|
|
205
|
+
|
|
199
206
|
const callStackPreimages = await this.getPublicCallStackPreimages(result);
|
|
200
207
|
const wasm = await CircuitsWasm.get();
|
|
208
|
+
|
|
201
209
|
const publicCallStack = mapTuple(callStackPreimages, item =>
|
|
202
210
|
item.isEmpty() ? Fr.zero() : computeCallStackItemHash(wasm, item),
|
|
203
211
|
);
|
|
204
212
|
|
|
205
|
-
// TODO(
|
|
213
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) --> set this in Noir
|
|
206
214
|
const unencryptedLogsHash = to2Fields(result.unencryptedLogs.hash());
|
|
207
215
|
const unencryptedLogPreimagesLength = new Fr(result.unencryptedLogs.getSerializedLength());
|
|
208
216
|
|
|
209
217
|
return PublicCircuitPublicInputs.from({
|
|
210
218
|
callContext: result.execution.callContext,
|
|
211
|
-
proverAddress: AztecAddress.
|
|
219
|
+
proverAddress: AztecAddress.ZERO,
|
|
212
220
|
argsHash: await computeVarArgsHash(wasm, result.execution.args),
|
|
213
221
|
newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL),
|
|
214
222
|
newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL),
|
|
@@ -227,7 +235,7 @@ export class PublicProcessor {
|
|
|
227
235
|
publicCallStack,
|
|
228
236
|
unencryptedLogsHash,
|
|
229
237
|
unencryptedLogPreimagesLength,
|
|
230
|
-
|
|
238
|
+
historicBlockData: this.blockData,
|
|
231
239
|
});
|
|
232
240
|
}
|
|
233
241
|
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CombinedHistoricTreeRoots,
|
|
3
2
|
Fr,
|
|
4
3
|
GlobalVariables,
|
|
4
|
+
HistoricBlockData,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
makeEmptyProof,
|
|
7
7
|
} from '@aztec/circuits.js';
|
|
8
8
|
import { P2P, P2PClientState } from '@aztec/p2p';
|
|
9
|
-
import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId,
|
|
9
|
+
import { L1ToL2MessageSource, L2Block, L2BlockSource, MerkleTreeId, Tx, TxHash, mockTx } from '@aztec/types';
|
|
10
10
|
import { MerkleTreeOperations, WorldStateRunningState, WorldStateSynchroniser } from '@aztec/world-state';
|
|
11
|
+
|
|
11
12
|
import { MockProxy, mock } from 'jest-mock-extended';
|
|
12
13
|
import times from 'lodash.times';
|
|
14
|
+
|
|
13
15
|
import { BlockBuilder } from '../block_builder/index.js';
|
|
16
|
+
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
14
17
|
import { L1Publisher } from '../index.js';
|
|
15
18
|
import { makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
|
|
16
19
|
import { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
|
|
17
20
|
import { Sequencer } from './sequencer.js';
|
|
18
|
-
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
19
21
|
|
|
20
22
|
describe('sequencer', () => {
|
|
21
23
|
let publisher: MockProxy<L1Publisher>;
|
|
@@ -55,11 +57,11 @@ describe('sequencer', () => {
|
|
|
55
57
|
|
|
56
58
|
publicProcessor = mock<PublicProcessor>({
|
|
57
59
|
process: async txs => [await Promise.all(txs.map(tx => makeProcessedTx(tx))), []],
|
|
58
|
-
makeEmptyProcessedTx: () => makeEmptyProcessedTx(
|
|
60
|
+
makeEmptyProcessedTx: () => makeEmptyProcessedTx(HistoricBlockData.empty(), chainId, version),
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
publicProcessorFactory = mock<PublicProcessorFactory>({
|
|
62
|
-
create: () => publicProcessor,
|
|
64
|
+
create: (_, __) => Promise.resolve(publicProcessor),
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
l2BlockSource = mock<L2BlockSource>({
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { GlobalVariables } from '@aztec/circuits.js';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { createDebugLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { RunningPromise } from '@aztec/foundation/running-promise';
|
|
4
5
|
import { P2P } from '@aztec/p2p';
|
|
5
6
|
import {
|
|
6
7
|
ContractData,
|
|
7
|
-
|
|
8
|
+
ContractDataAndBytecode,
|
|
8
9
|
L1ToL2MessageSource,
|
|
9
10
|
L2Block,
|
|
10
11
|
L2BlockSource,
|
|
@@ -12,15 +13,16 @@ import {
|
|
|
12
13
|
Tx,
|
|
13
14
|
} from '@aztec/types';
|
|
14
15
|
import { WorldStateStatus, WorldStateSynchroniser } from '@aztec/world-state';
|
|
16
|
+
|
|
15
17
|
import times from 'lodash.times';
|
|
18
|
+
|
|
16
19
|
import { BlockBuilder } from '../block_builder/index.js';
|
|
20
|
+
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
17
21
|
import { L1Publisher } from '../publisher/l1-publisher.js';
|
|
18
22
|
import { ceilPowerOfTwo } from '../utils.js';
|
|
19
23
|
import { SequencerConfig } from './config.js';
|
|
20
24
|
import { ProcessedTx } from './processed_tx.js';
|
|
21
25
|
import { PublicProcessorFactory } from './public_processor.js';
|
|
22
|
-
import { GlobalVariables } from '@aztec/circuits.js';
|
|
23
|
-
import { GlobalVariableBuilder } from '../global_variable_builder/global_builder.js';
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Sequencer client
|
|
@@ -53,7 +55,7 @@ export class Sequencer {
|
|
|
53
55
|
config: SequencerConfig,
|
|
54
56
|
private log = createDebugLogger('aztec:sequencer'),
|
|
55
57
|
) {
|
|
56
|
-
this.pollingIntervalMs = config.
|
|
58
|
+
this.pollingIntervalMs = config.transactionPollingIntervalMS ?? 1_000;
|
|
57
59
|
if (config.maxTxsPerBlock) {
|
|
58
60
|
this.maxTxsPerBlock = config.maxTxsPerBlock;
|
|
59
61
|
}
|
|
@@ -139,12 +141,13 @@ export class Sequencer {
|
|
|
139
141
|
this.state = SequencerState.CREATING_BLOCK;
|
|
140
142
|
|
|
141
143
|
const blockNumber = (await this.l2BlockSource.getBlockHeight()) + 1;
|
|
142
|
-
const
|
|
144
|
+
const newGlobalVariables = await this.globalsBuilder.buildGlobalVariables(new Fr(blockNumber));
|
|
145
|
+
const prevGlobalVariables = (await this.l2BlockSource.getL2Block(-1))?.globalVariables ?? GlobalVariables.empty();
|
|
143
146
|
|
|
144
147
|
// Process txs and drop the ones that fail processing
|
|
145
148
|
// We create a fresh processor each time to reset any cached state (eg storage writes)
|
|
146
|
-
const processor = this.publicProcessorFactory.create();
|
|
147
|
-
const [processedTxs, failedTxs] = await processor.process(validTxs
|
|
149
|
+
const processor = await this.publicProcessorFactory.create(prevGlobalVariables, newGlobalVariables);
|
|
150
|
+
const [processedTxs, failedTxs] = await processor.process(validTxs);
|
|
148
151
|
if (failedTxs.length > 0) {
|
|
149
152
|
this.log(`Dropping failed txs ${(await Tx.getHashes(failedTxs)).join(', ')}`);
|
|
150
153
|
await this.p2pClient.deleteTxs(await Tx.getHashes(failedTxs));
|
|
@@ -162,27 +165,28 @@ export class Sequencer {
|
|
|
162
165
|
|
|
163
166
|
// Build the new block by running the rollup circuits
|
|
164
167
|
this.log(`Assembling block with txs ${processedTxs.map(tx => tx.hash).join(', ')}`);
|
|
165
|
-
const emptyTx = await processor.makeEmptyProcessedTx(this.chainId, this.version);
|
|
166
168
|
|
|
167
|
-
const
|
|
169
|
+
const emptyTx = await processor.makeEmptyProcessedTx();
|
|
170
|
+
const block = await this.buildBlock(processedTxs, l1ToL2Messages, emptyTx, newGlobalVariables);
|
|
168
171
|
this.log(`Assembled block ${block.number}`);
|
|
169
172
|
|
|
170
|
-
await this.
|
|
173
|
+
await this.publishContractDataAndBytecode(validTxs, block);
|
|
171
174
|
|
|
172
175
|
await this.publishL2Block(block);
|
|
176
|
+
this.log.info(`Submitted rollup block ${block.number} with ${processedTxs.length} transactions`);
|
|
173
177
|
} catch (err) {
|
|
174
|
-
this.log(err);
|
|
175
|
-
this.log(`Rolling back world state DB`);
|
|
178
|
+
this.log.error(err);
|
|
179
|
+
this.log.error(`Rolling back world state DB`);
|
|
176
180
|
await this.worldState.getLatest().rollback();
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
/**
|
|
181
|
-
* Gets new contract
|
|
185
|
+
* Gets new contract data and bytecode from the txs and publishes it on chain.
|
|
182
186
|
* @param validTxs - The set of real transactions being published as part of the block.
|
|
183
187
|
* @param block - The L2Block to be published.
|
|
184
188
|
*/
|
|
185
|
-
protected async
|
|
189
|
+
protected async publishContractDataAndBytecode(validTxs: Tx[], block: L2Block) {
|
|
186
190
|
// Publishes contract data for txs to the network and awaits the tx to be mined
|
|
187
191
|
this.state = SequencerState.PUBLISHING_CONTRACT_DATA;
|
|
188
192
|
const newContractData = validTxs
|
|
@@ -190,7 +194,7 @@ export class Sequencer {
|
|
|
190
194
|
// Currently can only have 1 new contract per tx
|
|
191
195
|
const newContract = tx.data?.end.newContracts[0];
|
|
192
196
|
if (newContract && tx.newContractPublicFunctions?.length) {
|
|
193
|
-
return new
|
|
197
|
+
return new ContractDataAndBytecode(
|
|
194
198
|
new ContractData(newContract.contractAddress, newContract.portalContractAddress),
|
|
195
199
|
tx.newContractPublicFunctions,
|
|
196
200
|
);
|
|
@@ -199,7 +203,7 @@ export class Sequencer {
|
|
|
199
203
|
.filter((cd): cd is Exclude<typeof cd, undefined> => cd !== undefined);
|
|
200
204
|
|
|
201
205
|
const blockHash = block.getCalldataHash();
|
|
202
|
-
this.log(`Publishing contract
|
|
206
|
+
this.log(`Publishing contract data and bytecode with block hash ${blockHash.toString('hex')}`);
|
|
203
207
|
|
|
204
208
|
const publishedContractData = await this.publisher.processNewContractData(block.number, blockHash, newContractData);
|
|
205
209
|
if (publishedContractData) {
|
package/src/sequencer/utils.ts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CircuitsWasm, Fr, GlobalVariables, HistoricBlockData } from '@aztec/circuits.js';
|
|
2
|
+
import { computeGlobalsHash } from '@aztec/circuits.js/abis';
|
|
3
3
|
import { MerkleTreeOperations } from '@aztec/world-state';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Fetches the private, nullifier, contract tree and l1 to l2 messages tree roots from a given db and assembles a CombinedHistoricTreeRoots object.
|
|
7
7
|
*/
|
|
8
|
-
export async function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
export async function getHistoricBlockData(
|
|
9
|
+
db: MerkleTreeOperations,
|
|
10
|
+
prevBlockGlobalVariables: GlobalVariables = GlobalVariables.empty(),
|
|
11
|
+
) {
|
|
12
|
+
const wasm = await CircuitsWasm.get();
|
|
13
|
+
const prevGlobalsHash = computeGlobalsHash(wasm, prevBlockGlobalVariables);
|
|
14
|
+
const roots = db.getTreeRoots();
|
|
15
|
+
|
|
16
|
+
return new HistoricBlockData(
|
|
17
|
+
Fr.fromBuffer(roots.privateDataTreeRoot),
|
|
18
|
+
Fr.fromBuffer(roots.nullifierTreeRoot),
|
|
19
|
+
Fr.fromBuffer(roots.contractDataTreeRoot),
|
|
20
|
+
Fr.fromBuffer(roots.l1Tol2MessagesTreeRoot),
|
|
21
|
+
Fr.fromBuffer(roots.blocksTreeRoot),
|
|
22
|
+
Fr.ZERO,
|
|
23
|
+
Fr.fromBuffer(roots.publicDataTreeRoot),
|
|
24
|
+
prevGlobalsHash,
|
|
17
25
|
);
|
|
18
26
|
}
|
package/src/simulator/index.ts
CHANGED
|
@@ -38,13 +38,13 @@ export interface RollupSimulator {
|
|
|
38
38
|
export interface PublicKernelCircuitSimulator {
|
|
39
39
|
/**
|
|
40
40
|
* Simulates the public kernel circuit (with a previous private kernel circuit run) from its inputs.
|
|
41
|
-
* @param
|
|
41
|
+
* @param inputs - Inputs to the circuit.
|
|
42
42
|
* @returns The public inputs as outputs of the simulation.
|
|
43
43
|
*/
|
|
44
44
|
publicKernelCircuitPrivateInput(inputs: PublicKernelInputs): Promise<PublicKernelPublicInputs>;
|
|
45
45
|
/**
|
|
46
46
|
* Simulates the public kernel circuit (with no previous public kernel circuit run) from its inputs.
|
|
47
|
-
* @param
|
|
47
|
+
* @param inputs - Inputs to the circuit.
|
|
48
48
|
* @returns The public inputs as outputs of the simulation.
|
|
49
49
|
*/
|
|
50
50
|
publicKernelCircuitNonFirstIteration(inputs: PublicKernelInputs): Promise<PublicKernelPublicInputs>;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
PublicExecutor,
|
|
7
7
|
PublicStateDB,
|
|
8
8
|
} from '@aztec/acir-simulator';
|
|
9
|
-
import { AztecAddress, CircuitsWasm, EthAddress, Fr,
|
|
9
|
+
import { AztecAddress, CircuitsWasm, EthAddress, Fr, HistoricBlockData } from '@aztec/circuits.js';
|
|
10
10
|
import { siloCommitment } from '@aztec/circuits.js/abis';
|
|
11
11
|
import { ContractDataSource, L1ToL2MessageSource, MerkleTreeId } from '@aztec/types';
|
|
12
12
|
import { MerkleTreeOperations, computePublicDataTreeLeafIndex } from '@aztec/world-state';
|
|
@@ -21,11 +21,13 @@ export function getPublicExecutor(
|
|
|
21
21
|
merkleTree: MerkleTreeOperations,
|
|
22
22
|
contractDataSource: ContractDataSource,
|
|
23
23
|
l1toL2MessageSource: L1ToL2MessageSource,
|
|
24
|
+
blockData: HistoricBlockData,
|
|
24
25
|
) {
|
|
25
26
|
return new PublicExecutor(
|
|
26
27
|
new WorldStatePublicDB(merkleTree),
|
|
27
28
|
new ContractsDataSourcePublicDB(contractDataSource),
|
|
28
29
|
new WorldStateDB(merkleTree, l1toL2MessageSource),
|
|
30
|
+
blockData,
|
|
29
31
|
);
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -37,8 +39,11 @@ class ContractsDataSourcePublicDB implements PublicContractsDB {
|
|
|
37
39
|
async getBytecode(address: AztecAddress, functionSelector: Buffer): Promise<Buffer | undefined> {
|
|
38
40
|
return (await this.db.getPublicFunction(address, functionSelector))?.bytecode;
|
|
39
41
|
}
|
|
42
|
+
async getIsInternal(address: AztecAddress, functionSelector: Buffer): Promise<boolean | undefined> {
|
|
43
|
+
return (await this.db.getPublicFunction(address, functionSelector))?.isInternal;
|
|
44
|
+
}
|
|
40
45
|
async getPortalContractAddress(address: AztecAddress): Promise<EthAddress | undefined> {
|
|
41
|
-
return (await this.db.
|
|
46
|
+
return (await this.db.getContractData(address))?.portalContractAddress;
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
|
|
@@ -82,12 +87,6 @@ class WorldStatePublicDB implements PublicStateDB {
|
|
|
82
87
|
export class WorldStateDB implements CommitmentsDB {
|
|
83
88
|
constructor(private db: MerkleTreeOperations, private l1ToL2MessageSource: L1ToL2MessageSource) {}
|
|
84
89
|
|
|
85
|
-
/**
|
|
86
|
-
* Gets a confirmed L1 to L2 message for the given message key.
|
|
87
|
-
* TODO(Maddiaa): Can be combined with aztec-node method that does the same thing.
|
|
88
|
-
* @param messageKey - The message Key.
|
|
89
|
-
* @returns - The l1 to l2 message object
|
|
90
|
-
*/
|
|
91
90
|
public async getL1ToL2Message(messageKey: Fr): Promise<MessageLoadOracleInputs> {
|
|
92
91
|
// todo: #697 - make this one lookup.
|
|
93
92
|
const message = await this.l1ToL2MessageSource.getConfirmedL1ToL2Message(messageKey);
|
|
@@ -96,42 +95,24 @@ export class WorldStateDB implements CommitmentsDB {
|
|
|
96
95
|
|
|
97
96
|
return {
|
|
98
97
|
message: message.toFieldArray(),
|
|
99
|
-
index,
|
|
100
98
|
siblingPath: siblingPath.toFieldArray(),
|
|
99
|
+
index,
|
|
101
100
|
};
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
public async getCommitmentOracle(address: AztecAddress, commitment: Fr): Promise<CommitmentDataOracleInputs> {
|
|
111
|
-
const siloedCommitment = siloCommitment(await CircuitsWasm.get(), address, commitment);
|
|
103
|
+
public async getCommitmentOracle(address: AztecAddress, innerCommitment: Fr): Promise<CommitmentDataOracleInputs> {
|
|
104
|
+
const siloedCommitment = siloCommitment(await CircuitsWasm.get(), address, innerCommitment);
|
|
105
|
+
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386): shoild be
|
|
106
|
+
// unique commitment that exists in tree (should be siloed and then made unique via
|
|
107
|
+
// nonce). Once public kernel or base rollup circuit injects nonces, this can be updated
|
|
108
|
+
// to use uniqueSiloedCommitment.
|
|
112
109
|
const index = (await this.db.findLeafIndex(MerkleTreeId.PRIVATE_DATA_TREE, siloedCommitment.toBuffer()))!;
|
|
113
110
|
const siblingPath = await this.db.getSiblingPath(MerkleTreeId.PRIVATE_DATA_TREE, index);
|
|
114
111
|
|
|
115
112
|
return {
|
|
116
113
|
commitment: siloedCommitment,
|
|
117
|
-
index,
|
|
118
114
|
siblingPath: siblingPath.toFieldArray(),
|
|
115
|
+
index,
|
|
119
116
|
};
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Gets the current tree roots from the merkle db.
|
|
124
|
-
* @returns current tree roots.
|
|
125
|
-
*/
|
|
126
|
-
public getTreeRoots(): PrivateHistoricTreeRoots {
|
|
127
|
-
const roots = this.db.getCommitmentTreeRoots();
|
|
128
|
-
|
|
129
|
-
return PrivateHistoricTreeRoots.from({
|
|
130
|
-
privateKernelVkTreeRoot: Fr.ZERO,
|
|
131
|
-
privateDataTreeRoot: Fr.fromBuffer(roots.privateDataTreeRoot),
|
|
132
|
-
contractTreeRoot: Fr.fromBuffer(roots.contractDataTreeRoot),
|
|
133
|
-
nullifierTreeRoot: Fr.fromBuffer(roots.nullifierTreeRoot),
|
|
134
|
-
l1ToL2MessagesTreeRoot: Fr.fromBuffer(roots.l1Tol2MessagesTreeRoot),
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
118
|
}
|