@aztec/sequencer-client 0.16.4 → 0.16.5
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_builder/solo_block_builder.d.ts +3 -3
- package/dest/block_builder/solo_block_builder.d.ts.map +1 -1
- package/dest/block_builder/solo_block_builder.js +26 -26
- package/dest/block_builder/types.d.ts +11 -2
- package/dest/block_builder/types.d.ts.map +1 -1
- package/dest/sequencer/utils.js +2 -2
- package/package.json +11 -11
- package/src/block_builder/index.ts +0 -24
- package/src/block_builder/solo_block_builder.ts +0 -758
- package/src/block_builder/types.ts +0 -16
- package/src/client/index.ts +0 -1
- package/src/client/sequencer-client.ts +0 -87
- package/src/config.ts +0 -76
- package/src/global_variable_builder/config.ts +0 -20
- package/src/global_variable_builder/global_builder.ts +0 -87
- package/src/global_variable_builder/index.ts +0 -16
- package/src/global_variable_builder/viem-reader.ts +0 -61
- package/src/index.ts +0 -15
- package/src/mocks/verification_keys.ts +0 -36
- package/src/prover/empty.ts +0 -74
- package/src/prover/index.ts +0 -53
- package/src/publisher/config.ts +0 -41
- package/src/publisher/index.ts +0 -14
- package/src/publisher/l1-publisher.ts +0 -291
- package/src/publisher/viem-tx-sender.ts +0 -195
- package/src/receiver.ts +0 -13
- package/src/sequencer/config.ts +0 -1
- package/src/sequencer/index.ts +0 -3
- package/src/sequencer/processed_tx.ts +0 -107
- package/src/sequencer/public_processor.ts +0 -433
- package/src/sequencer/sequencer.ts +0 -434
- package/src/sequencer/utils.ts +0 -25
- package/src/simulator/index.ts +0 -51
- package/src/simulator/public_executor.ts +0 -153
- package/src/simulator/public_kernel.ts +0 -54
- package/src/simulator/rollup.ts +0 -76
- package/src/utils.ts +0 -16
|
@@ -1,433 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PublicExecution,
|
|
3
|
-
PublicExecutionResult,
|
|
4
|
-
PublicExecutor,
|
|
5
|
-
PublicStateDB,
|
|
6
|
-
collectPublicDataReads,
|
|
7
|
-
collectPublicDataUpdateRequests,
|
|
8
|
-
isPublicExecutionResult,
|
|
9
|
-
} from '@aztec/acir-simulator';
|
|
10
|
-
import {
|
|
11
|
-
AztecAddress,
|
|
12
|
-
BlockHeader,
|
|
13
|
-
CallRequest,
|
|
14
|
-
CombinedAccumulatedData,
|
|
15
|
-
ContractStorageRead,
|
|
16
|
-
ContractStorageUpdateRequest,
|
|
17
|
-
Fr,
|
|
18
|
-
GlobalVariables,
|
|
19
|
-
KernelCircuitPublicInputs,
|
|
20
|
-
MAX_NEW_COMMITMENTS_PER_CALL,
|
|
21
|
-
MAX_NEW_L2_TO_L1_MSGS_PER_CALL,
|
|
22
|
-
MAX_NEW_NULLIFIERS_PER_CALL,
|
|
23
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
24
|
-
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
25
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
26
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
27
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
28
|
-
MembershipWitness,
|
|
29
|
-
PreviousKernelData,
|
|
30
|
-
Proof,
|
|
31
|
-
PublicCallData,
|
|
32
|
-
PublicCallStackItem,
|
|
33
|
-
PublicCircuitPublicInputs,
|
|
34
|
-
PublicDataRead,
|
|
35
|
-
PublicDataUpdateRequest,
|
|
36
|
-
PublicKernelInputs,
|
|
37
|
-
PublicKernelPublicInputs,
|
|
38
|
-
RETURN_VALUES_LENGTH,
|
|
39
|
-
VK_TREE_HEIGHT,
|
|
40
|
-
} from '@aztec/circuits.js';
|
|
41
|
-
import { computeVarArgsHash } from '@aztec/circuits.js/abis';
|
|
42
|
-
import { arrayNonEmptyLength, isArrayEmpty, padArrayEnd } from '@aztec/foundation/collection';
|
|
43
|
-
import { createDebugLogger } from '@aztec/foundation/log';
|
|
44
|
-
import { to2Fields } from '@aztec/foundation/serialize';
|
|
45
|
-
import { ContractDataSource, FunctionL2Logs, L1ToL2MessageSource, MerkleTreeId, Tx } from '@aztec/types';
|
|
46
|
-
import { MerkleTreeOperations } from '@aztec/world-state';
|
|
47
|
-
|
|
48
|
-
import { getVerificationKeys } from '../index.js';
|
|
49
|
-
import { EmptyPublicProver } from '../prover/empty.js';
|
|
50
|
-
import { PublicProver } from '../prover/index.js';
|
|
51
|
-
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
|
|
52
|
-
import { ContractsDataSourcePublicDB, WorldStateDB, WorldStatePublicDB } from '../simulator/public_executor.js';
|
|
53
|
-
import { RealPublicKernelCircuitSimulator } from '../simulator/public_kernel.js';
|
|
54
|
-
import { FailedTx, ProcessedTx, makeEmptyProcessedTx, makeProcessedTx } from './processed_tx.js';
|
|
55
|
-
import { getBlockHeader } from './utils.js';
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Creates new instances of PublicProcessor given the provided merkle tree db and contract data source.
|
|
59
|
-
*/
|
|
60
|
-
export class PublicProcessorFactory {
|
|
61
|
-
constructor(
|
|
62
|
-
private merkleTree: MerkleTreeOperations,
|
|
63
|
-
private contractDataSource: ContractDataSource,
|
|
64
|
-
private l1Tol2MessagesDataSource: L1ToL2MessageSource,
|
|
65
|
-
) {}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new instance of a PublicProcessor.
|
|
69
|
-
* @param prevGlobalVariables - The global variables for the previous block, used to calculate the prev global variables hash.
|
|
70
|
-
* @param globalVariables - The global variables for the block being processed.
|
|
71
|
-
* @param newContracts - Provides access to contract bytecode for public executions.
|
|
72
|
-
* @returns A new instance of a PublicProcessor.
|
|
73
|
-
*/
|
|
74
|
-
public async create(
|
|
75
|
-
prevGlobalVariables: GlobalVariables,
|
|
76
|
-
globalVariables: GlobalVariables,
|
|
77
|
-
): Promise<PublicProcessor> {
|
|
78
|
-
const blockHeader = await getBlockHeader(this.merkleTree, prevGlobalVariables);
|
|
79
|
-
const publicContractsDB = new ContractsDataSourcePublicDB(this.contractDataSource);
|
|
80
|
-
const worldStatePublicDB = new WorldStatePublicDB(this.merkleTree);
|
|
81
|
-
const worldStateDB = new WorldStateDB(this.merkleTree, this.l1Tol2MessagesDataSource);
|
|
82
|
-
const publicExecutor = new PublicExecutor(worldStatePublicDB, publicContractsDB, worldStateDB, blockHeader);
|
|
83
|
-
return new PublicProcessor(
|
|
84
|
-
this.merkleTree,
|
|
85
|
-
publicExecutor,
|
|
86
|
-
new RealPublicKernelCircuitSimulator(),
|
|
87
|
-
new EmptyPublicProver(),
|
|
88
|
-
globalVariables,
|
|
89
|
-
blockHeader,
|
|
90
|
-
publicContractsDB,
|
|
91
|
-
worldStatePublicDB,
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Converts Txs lifted from the P2P module into ProcessedTx objects by executing
|
|
98
|
-
* any public function calls in them. Txs with private calls only are unaffected.
|
|
99
|
-
*/
|
|
100
|
-
export class PublicProcessor {
|
|
101
|
-
constructor(
|
|
102
|
-
protected db: MerkleTreeOperations,
|
|
103
|
-
protected publicExecutor: PublicExecutor,
|
|
104
|
-
protected publicKernel: PublicKernelCircuitSimulator,
|
|
105
|
-
protected publicProver: PublicProver,
|
|
106
|
-
protected globalVariables: GlobalVariables,
|
|
107
|
-
protected blockHeader: BlockHeader,
|
|
108
|
-
protected publicContractsDB: ContractsDataSourcePublicDB,
|
|
109
|
-
protected publicStateDB: PublicStateDB,
|
|
110
|
-
|
|
111
|
-
private log = createDebugLogger('aztec:sequencer:public-processor'),
|
|
112
|
-
) {}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Run each tx through the public circuit and the public kernel circuit if needed.
|
|
116
|
-
* @param txs - Txs to process.
|
|
117
|
-
* @returns The list of processed txs with their circuit simulation outputs.
|
|
118
|
-
*/
|
|
119
|
-
public async process(txs: Tx[]): Promise<[ProcessedTx[], FailedTx[]]> {
|
|
120
|
-
// The processor modifies the tx objects in place, so we need to clone them.
|
|
121
|
-
txs = txs.map(tx => Tx.clone(tx));
|
|
122
|
-
const result: ProcessedTx[] = [];
|
|
123
|
-
const failed: FailedTx[] = [];
|
|
124
|
-
|
|
125
|
-
for (const tx of txs) {
|
|
126
|
-
this.log(`Processing tx ${await tx.getTxHash()}`);
|
|
127
|
-
try {
|
|
128
|
-
// add new contracts to the contracts db so that their functions may be found and called
|
|
129
|
-
await this.publicContractsDB.addNewContracts(tx);
|
|
130
|
-
result.push(await this.processTx(tx));
|
|
131
|
-
// commit the state updates from this transaction
|
|
132
|
-
await this.publicStateDB.commit();
|
|
133
|
-
} catch (err) {
|
|
134
|
-
this.log.warn(`Error processing tx ${await tx.getTxHash()}: ${err}`);
|
|
135
|
-
failed.push({
|
|
136
|
-
tx,
|
|
137
|
-
error: err instanceof Error ? err : new Error('Unknown error'),
|
|
138
|
-
});
|
|
139
|
-
// remove contracts on failure
|
|
140
|
-
await this.publicContractsDB.removeNewContracts(tx);
|
|
141
|
-
// rollback any state updates from this failed transaction
|
|
142
|
-
await this.publicStateDB.rollback();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return [result, failed];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Makes an empty processed tx. Useful for padding a block to a power of two number of txs.
|
|
151
|
-
* @returns A processed tx with empty data.
|
|
152
|
-
*/
|
|
153
|
-
public makeEmptyProcessedTx(): Promise<ProcessedTx> {
|
|
154
|
-
const { chainId, version } = this.globalVariables;
|
|
155
|
-
return makeEmptyProcessedTx(this.blockHeader, chainId, version);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
protected async processTx(tx: Tx): Promise<ProcessedTx> {
|
|
159
|
-
if (!isArrayEmpty(tx.data.end.publicCallStack, item => item.isEmpty())) {
|
|
160
|
-
const [publicKernelOutput, publicKernelProof, newUnencryptedFunctionLogs] = await this.processEnqueuedPublicCalls(
|
|
161
|
-
tx,
|
|
162
|
-
);
|
|
163
|
-
tx.unencryptedLogs.addFunctionLogs(newUnencryptedFunctionLogs);
|
|
164
|
-
|
|
165
|
-
return makeProcessedTx(tx, publicKernelOutput, publicKernelProof);
|
|
166
|
-
} else {
|
|
167
|
-
return makeProcessedTx(tx);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
protected async processEnqueuedPublicCalls(tx: Tx): Promise<[PublicKernelPublicInputs, Proof, FunctionL2Logs[]]> {
|
|
172
|
-
this.log(`Executing enqueued public calls for tx ${await tx.getTxHash()}`);
|
|
173
|
-
if (!tx.enqueuedPublicFunctionCalls) {
|
|
174
|
-
throw new Error(`Missing preimages for enqueued public calls`);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
let kernelOutput = new KernelCircuitPublicInputs(
|
|
178
|
-
CombinedAccumulatedData.fromFinalAccumulatedData(tx.data.end),
|
|
179
|
-
tx.data.constants,
|
|
180
|
-
tx.data.isPrivate,
|
|
181
|
-
);
|
|
182
|
-
let kernelProof = tx.proof;
|
|
183
|
-
const newUnencryptedFunctionLogs: FunctionL2Logs[] = [];
|
|
184
|
-
|
|
185
|
-
// TODO(#1684): Should multiple separately enqueued public calls be treated as
|
|
186
|
-
// separate public callstacks to be proven by separate public kernel sequences
|
|
187
|
-
// and submitted separately to the base rollup?
|
|
188
|
-
|
|
189
|
-
// TODO(dbanks12): why must these be reversed?
|
|
190
|
-
const enqueuedCallsReversed = tx.enqueuedPublicFunctionCalls.slice().reverse();
|
|
191
|
-
for (const enqueuedCall of enqueuedCallsReversed) {
|
|
192
|
-
const executionStack: (PublicExecution | PublicExecutionResult)[] = [enqueuedCall];
|
|
193
|
-
|
|
194
|
-
// Keep track of which result is for the top/enqueued call
|
|
195
|
-
let enqueuedExecutionResult: PublicExecutionResult | undefined;
|
|
196
|
-
|
|
197
|
-
while (executionStack.length) {
|
|
198
|
-
const current = executionStack.pop()!;
|
|
199
|
-
const isExecutionRequest = !isPublicExecutionResult(current);
|
|
200
|
-
const result = isExecutionRequest ? await this.publicExecutor.simulate(current, this.globalVariables) : current;
|
|
201
|
-
newUnencryptedFunctionLogs.push(result.unencryptedLogs);
|
|
202
|
-
const functionSelector = result.execution.functionData.selector.toString();
|
|
203
|
-
this.log(
|
|
204
|
-
`Running public kernel circuit for ${functionSelector}@${result.execution.contractAddress.toString()}`,
|
|
205
|
-
);
|
|
206
|
-
executionStack.push(...result.nestedExecutions);
|
|
207
|
-
const callData = await this.getPublicCallData(result, isExecutionRequest);
|
|
208
|
-
|
|
209
|
-
[kernelOutput, kernelProof] = await this.runKernelCircuit(callData, kernelOutput, kernelProof);
|
|
210
|
-
|
|
211
|
-
if (!enqueuedExecutionResult) {
|
|
212
|
-
enqueuedExecutionResult = result;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// HACK(#1622): Manually patches the ordering of public state actions
|
|
216
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
217
|
-
this.patchPublicStorageActionOrdering(kernelOutput, enqueuedExecutionResult!);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return [kernelOutput, kernelProof, newUnencryptedFunctionLogs];
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
protected async runKernelCircuit(
|
|
224
|
-
callData: PublicCallData,
|
|
225
|
-
previousOutput: KernelCircuitPublicInputs,
|
|
226
|
-
previousProof: Proof,
|
|
227
|
-
): Promise<[KernelCircuitPublicInputs, Proof]> {
|
|
228
|
-
const output = await this.getKernelCircuitOutput(callData, previousOutput, previousProof);
|
|
229
|
-
const proof = await this.publicProver.getPublicKernelCircuitProof(output);
|
|
230
|
-
return [output, proof];
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
protected getKernelCircuitOutput(
|
|
234
|
-
callData: PublicCallData,
|
|
235
|
-
previousOutput: KernelCircuitPublicInputs,
|
|
236
|
-
previousProof: Proof,
|
|
237
|
-
): Promise<KernelCircuitPublicInputs> {
|
|
238
|
-
if (previousOutput?.isPrivate && previousProof) {
|
|
239
|
-
// Run the public kernel circuit with previous private kernel
|
|
240
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
241
|
-
const inputs = new PublicKernelInputs(previousKernel, callData);
|
|
242
|
-
return this.publicKernel.publicKernelCircuitPrivateInput(inputs);
|
|
243
|
-
} else if (previousOutput && previousProof) {
|
|
244
|
-
// Run the public kernel circuit with previous public kernel
|
|
245
|
-
const previousKernel = this.getPreviousKernelData(previousOutput, previousProof);
|
|
246
|
-
const inputs = new PublicKernelInputs(previousKernel, callData);
|
|
247
|
-
return this.publicKernel.publicKernelCircuitNonFirstIteration(inputs);
|
|
248
|
-
} else {
|
|
249
|
-
throw new Error(`No public kernel circuit for inputs`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
protected getPreviousKernelData(previousOutput: KernelCircuitPublicInputs, previousProof: Proof): PreviousKernelData {
|
|
254
|
-
const vk = getVerificationKeys().publicKernelCircuit;
|
|
255
|
-
const vkIndex = 0;
|
|
256
|
-
const vkSiblingPath = MembershipWitness.random(VK_TREE_HEIGHT).siblingPath;
|
|
257
|
-
return new PreviousKernelData(previousOutput, previousProof, vk, vkIndex, vkSiblingPath);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
protected async getPublicCircuitPublicInputs(result: PublicExecutionResult) {
|
|
261
|
-
const publicDataTreeInfo = await this.db.getTreeInfo(MerkleTreeId.PUBLIC_DATA_TREE);
|
|
262
|
-
this.blockHeader.publicDataTreeRoot = Fr.fromBuffer(publicDataTreeInfo.root);
|
|
263
|
-
|
|
264
|
-
const callStackPreimages = await this.getPublicCallStackPreimages(result);
|
|
265
|
-
const publicCallStackHashes = padArrayEnd(
|
|
266
|
-
callStackPreimages.map(c => c.hash()),
|
|
267
|
-
Fr.ZERO,
|
|
268
|
-
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
|
|
269
|
-
);
|
|
270
|
-
|
|
271
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/1165) --> set this in Noir
|
|
272
|
-
const unencryptedLogsHash = to2Fields(result.unencryptedLogs.hash());
|
|
273
|
-
const unencryptedLogPreimagesLength = new Fr(result.unencryptedLogs.getSerializedLength());
|
|
274
|
-
|
|
275
|
-
return PublicCircuitPublicInputs.from({
|
|
276
|
-
callContext: result.execution.callContext,
|
|
277
|
-
proverAddress: AztecAddress.ZERO,
|
|
278
|
-
argsHash: computeVarArgsHash(result.execution.args),
|
|
279
|
-
newCommitments: padArrayEnd(result.newCommitments, Fr.ZERO, MAX_NEW_COMMITMENTS_PER_CALL),
|
|
280
|
-
newNullifiers: padArrayEnd(result.newNullifiers, Fr.ZERO, MAX_NEW_NULLIFIERS_PER_CALL),
|
|
281
|
-
newL2ToL1Msgs: padArrayEnd(result.newL2ToL1Messages, Fr.ZERO, MAX_NEW_L2_TO_L1_MSGS_PER_CALL),
|
|
282
|
-
returnValues: padArrayEnd(result.returnValues, Fr.ZERO, RETURN_VALUES_LENGTH),
|
|
283
|
-
contractStorageReads: padArrayEnd(
|
|
284
|
-
result.contractStorageReads,
|
|
285
|
-
ContractStorageRead.empty(),
|
|
286
|
-
MAX_PUBLIC_DATA_READS_PER_CALL,
|
|
287
|
-
),
|
|
288
|
-
contractStorageUpdateRequests: padArrayEnd(
|
|
289
|
-
result.contractStorageUpdateRequests,
|
|
290
|
-
ContractStorageUpdateRequest.empty(),
|
|
291
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
|
|
292
|
-
),
|
|
293
|
-
publicCallStackHashes,
|
|
294
|
-
unencryptedLogsHash,
|
|
295
|
-
unencryptedLogPreimagesLength,
|
|
296
|
-
blockHeader: this.blockHeader,
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
protected async getPublicCallStackItem(result: PublicExecutionResult, isExecutionRequest = false) {
|
|
301
|
-
return new PublicCallStackItem(
|
|
302
|
-
result.execution.contractAddress,
|
|
303
|
-
result.execution.functionData,
|
|
304
|
-
await this.getPublicCircuitPublicInputs(result),
|
|
305
|
-
isExecutionRequest,
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
protected async getPublicCallStackPreimages(result: PublicExecutionResult): Promise<PublicCallStackItem[]> {
|
|
310
|
-
const nested = result.nestedExecutions;
|
|
311
|
-
if (nested.length > MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL) {
|
|
312
|
-
throw new Error(
|
|
313
|
-
`Public call stack size exceeded (max ${MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}, got ${nested.length})`,
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return await Promise.all(nested.map(n => this.getPublicCallStackItem(n)));
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
protected getBytecodeHash(_result: PublicExecutionResult) {
|
|
321
|
-
// TODO: Determine how to calculate bytecode hash. Circuits just check it isn't zero for now.
|
|
322
|
-
// See https://github.com/AztecProtocol/aztec3-packages/issues/378
|
|
323
|
-
const bytecodeHash = new Fr(1n);
|
|
324
|
-
return Promise.resolve(bytecodeHash);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Calculates the PublicCircuitOutput for this execution result along with its proof,
|
|
329
|
-
* and assembles a PublicCallData object from it.
|
|
330
|
-
* @param result - The execution result.
|
|
331
|
-
* @param preimages - The preimages of the callstack items.
|
|
332
|
-
* @param isExecutionRequest - Whether the current callstack item should be considered a public fn execution request.
|
|
333
|
-
* @returns A corresponding PublicCallData object.
|
|
334
|
-
*/
|
|
335
|
-
protected async getPublicCallData(result: PublicExecutionResult, isExecutionRequest = false) {
|
|
336
|
-
const bytecodeHash = await this.getBytecodeHash(result);
|
|
337
|
-
const callStackItem = await this.getPublicCallStackItem(result, isExecutionRequest);
|
|
338
|
-
const publicCallRequests = (await this.getPublicCallStackPreimages(result)).map(c => c.toCallRequest());
|
|
339
|
-
const publicCallStack = padArrayEnd(publicCallRequests, CallRequest.empty(), MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL);
|
|
340
|
-
const portalContractAddress = result.execution.callContext.portalContractAddress.toField();
|
|
341
|
-
const proof = await this.publicProver.getPublicCircuitProof(callStackItem.publicInputs);
|
|
342
|
-
return new PublicCallData(callStackItem, publicCallStack, proof, portalContractAddress, bytecodeHash);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// HACK(#1622): this is a hack to fix ordering of public state in the call stack. Since the private kernel
|
|
346
|
-
// cannot keep track of side effects that happen after or before a nested call, we override the public
|
|
347
|
-
// state actions it emits with whatever we got from the simulator. As a sanity check, we at least verify
|
|
348
|
-
// that the elements are the same, so we are only tweaking their ordering.
|
|
349
|
-
// See yarn-project/end-to-end/src/e2e_ordering.test.ts
|
|
350
|
-
// See https://github.com/AztecProtocol/aztec-packages/issues/1616
|
|
351
|
-
// TODO(#757): Enforce proper ordering of public state actions
|
|
352
|
-
/**
|
|
353
|
-
* Patch the ordering of storage actions output from the public kernel.
|
|
354
|
-
* @param publicInputs - to be patched here: public inputs to the kernel iteration up to this point
|
|
355
|
-
* @param execResult - result of the top/first execution for this enqueued public call
|
|
356
|
-
*/
|
|
357
|
-
private patchPublicStorageActionOrdering(publicInputs: KernelCircuitPublicInputs, execResult: PublicExecutionResult) {
|
|
358
|
-
// Convert ContractStorage* objects to PublicData* objects and sort them in execution order
|
|
359
|
-
const simPublicDataReads = collectPublicDataReads(execResult);
|
|
360
|
-
const simPublicDataUpdateRequests = collectPublicDataUpdateRequests(execResult);
|
|
361
|
-
|
|
362
|
-
const { publicDataReads, publicDataUpdateRequests } = publicInputs.end; // from kernel
|
|
363
|
-
|
|
364
|
-
// Validate all items in enqueued public calls are in the kernel emitted stack
|
|
365
|
-
const readsAreEqual = simPublicDataReads.reduce(
|
|
366
|
-
(accum, read) =>
|
|
367
|
-
accum && !!publicDataReads.find(item => item.leafIndex.equals(read.leafIndex) && item.value.equals(read.value)),
|
|
368
|
-
true,
|
|
369
|
-
);
|
|
370
|
-
const updatesAreEqual = simPublicDataUpdateRequests.reduce(
|
|
371
|
-
(accum, update) =>
|
|
372
|
-
accum &&
|
|
373
|
-
!!publicDataUpdateRequests.find(
|
|
374
|
-
item =>
|
|
375
|
-
item.leafIndex.equals(update.leafIndex) &&
|
|
376
|
-
item.oldValue.equals(update.oldValue) &&
|
|
377
|
-
item.newValue.equals(update.newValue),
|
|
378
|
-
),
|
|
379
|
-
true,
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
if (!readsAreEqual) {
|
|
383
|
-
throw new Error(
|
|
384
|
-
`Public data reads from simulator do not match those from public kernel.\nFrom simulator: ${simPublicDataReads
|
|
385
|
-
.map(p => p.toFriendlyJSON())
|
|
386
|
-
.join(', ')}\nFrom public kernel: ${publicDataReads.map(i => i.toFriendlyJSON()).join(', ')}`,
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
if (!updatesAreEqual) {
|
|
390
|
-
throw new Error(
|
|
391
|
-
`Public data update requests from simulator do not match those from public kernel.\nFrom simulator: ${simPublicDataUpdateRequests
|
|
392
|
-
.map(p => p.toFriendlyJSON())
|
|
393
|
-
.join(', ')}\nFrom public kernel: ${publicDataUpdateRequests.map(i => i.toFriendlyJSON()).join(', ')}`,
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Assume that kernel public inputs has the right number of items.
|
|
398
|
-
// We only want to reorder the items from the public inputs of the
|
|
399
|
-
// most recently processed top/enqueued call.
|
|
400
|
-
const numTotalReadsInKernel = arrayNonEmptyLength(
|
|
401
|
-
publicInputs.end.publicDataReads,
|
|
402
|
-
f => f.leafIndex.equals(Fr.ZERO) && f.value.equals(Fr.ZERO),
|
|
403
|
-
);
|
|
404
|
-
const numTotalUpdatesInKernel = arrayNonEmptyLength(
|
|
405
|
-
publicInputs.end.publicDataUpdateRequests,
|
|
406
|
-
f => f.leafIndex.equals(Fr.ZERO) && f.oldValue.equals(Fr.ZERO) && f.newValue.equals(Fr.ZERO),
|
|
407
|
-
);
|
|
408
|
-
const numReadsBeforeThisEnqueuedCall = numTotalReadsInKernel - simPublicDataReads.length;
|
|
409
|
-
const numUpdatesBeforeThisEnqueuedCall = numTotalUpdatesInKernel - simPublicDataUpdateRequests.length;
|
|
410
|
-
|
|
411
|
-
// Override kernel output
|
|
412
|
-
publicInputs.end.publicDataReads = padArrayEnd(
|
|
413
|
-
[
|
|
414
|
-
// do not mess with items from previous top/enqueued calls in kernel output
|
|
415
|
-
...publicDataReads.slice(0, numReadsBeforeThisEnqueuedCall),
|
|
416
|
-
...simPublicDataReads,
|
|
417
|
-
],
|
|
418
|
-
PublicDataRead.empty(),
|
|
419
|
-
MAX_PUBLIC_DATA_READS_PER_TX,
|
|
420
|
-
);
|
|
421
|
-
|
|
422
|
-
// Override kernel output
|
|
423
|
-
publicInputs.end.publicDataUpdateRequests = padArrayEnd(
|
|
424
|
-
[
|
|
425
|
-
// do not mess with items from previous top/enqueued calls in kernel output
|
|
426
|
-
...publicDataUpdateRequests.slice(0, numUpdatesBeforeThisEnqueuedCall),
|
|
427
|
-
...simPublicDataUpdateRequests,
|
|
428
|
-
],
|
|
429
|
-
PublicDataUpdateRequest.empty(),
|
|
430
|
-
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
|
|
431
|
-
);
|
|
432
|
-
}
|
|
433
|
-
}
|