@aztec/txe 3.0.0-nightly.20250926 → 3.0.0-nightly.20250928
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/oracle/txe_oracle_top_level_context.js +2 -2
- package/dest/rpc_translator.js +4 -4
- package/dest/txe_session.d.ts +12 -14
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +125 -97
- package/dest/utils/tx_effect_creation.d.ts +5 -0
- package/dest/utils/tx_effect_creation.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.js +16 -0
- package/package.json +15 -15
- package/src/oracle/txe_oracle_top_level_context.ts +1 -1
- package/src/rpc_translator.ts +4 -4
- package/src/txe_session.ts +170 -119
- package/src/utils/tx_effect_creation.ts +37 -0
- package/dest/oracle/txe_oracle.d.ts +0 -79
- package/dest/oracle/txe_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_oracle.js +0 -303
- package/src/oracle/txe_oracle.ts +0 -462
package/src/txe_session.ts
CHANGED
|
@@ -11,18 +11,25 @@ import {
|
|
|
11
11
|
PrivateEventDataProvider,
|
|
12
12
|
TaggingDataProvider,
|
|
13
13
|
} from '@aztec/pxe/server';
|
|
14
|
-
import
|
|
14
|
+
import {
|
|
15
|
+
ExecutionNoteCache,
|
|
16
|
+
HashedValuesCache,
|
|
17
|
+
type IPrivateExecutionOracle,
|
|
18
|
+
type IUtilityExecutionOracle,
|
|
19
|
+
PrivateExecutionOracle,
|
|
20
|
+
UtilityExecutionOracle,
|
|
21
|
+
} from '@aztec/pxe/simulator';
|
|
15
22
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
16
23
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
17
24
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
25
|
+
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
18
26
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
19
27
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
20
|
-
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
28
|
+
import { makeAppendOnlyTreeSnapshot, makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
21
29
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
22
30
|
import type { UInt32 } from '@aztec/stdlib/types';
|
|
23
31
|
|
|
24
32
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
25
|
-
import { TXE } from './oracle/txe_oracle.js';
|
|
26
33
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
27
34
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
28
35
|
import { RPCTranslator } from './rpc_translator.js';
|
|
@@ -30,34 +37,49 @@ import { TXEStateMachine } from './state_machine/index.js';
|
|
|
30
37
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
31
38
|
import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
|
|
32
39
|
import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
|
|
33
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
getSingleTxBlockRequestHash,
|
|
42
|
+
insertTxEffectIntoWorldTrees,
|
|
43
|
+
makeTXEBlockHeader,
|
|
44
|
+
} from './utils/block_creation.js';
|
|
45
|
+
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
34
46
|
|
|
35
47
|
/**
|
|
36
|
-
* A TXE Session can be
|
|
37
|
-
* The current state determines which oracles are available.
|
|
48
|
+
* A TXE Session can be in one of four states, which change as the test progresses and different oracles are called.
|
|
49
|
+
* The current state determines which oracles are available. Some states also have data associated with them.
|
|
38
50
|
*/
|
|
39
|
-
|
|
51
|
+
type SessionState =
|
|
40
52
|
/**
|
|
41
53
|
* The top-level state is the default state, before any other state has been entered. This is where contracts can be
|
|
42
54
|
* deployed, accounts created, blocks mined, etc.
|
|
43
55
|
*/
|
|
44
|
-
|
|
56
|
+
| {
|
|
57
|
+
name: 'TOP_LEVEL';
|
|
58
|
+
}
|
|
45
59
|
/**
|
|
46
60
|
* The private state is entered via the `private_context` function. In this state the PXE oracles that `#[private]`
|
|
47
61
|
* functions use are available, such as those related to note retrieval, notification of side-effects, capsule access,
|
|
48
62
|
* etc. */
|
|
49
|
-
|
|
63
|
+
| {
|
|
64
|
+
name: 'PRIVATE';
|
|
65
|
+
nextBlockGlobalVariables: GlobalVariables;
|
|
66
|
+
txRequestHash: Fr;
|
|
67
|
+
noteCache: ExecutionNoteCache;
|
|
68
|
+
}
|
|
50
69
|
/**
|
|
51
70
|
* The public state is entered via the `public_context` function. In this state the AVM opcodes that `#[public]`
|
|
52
71
|
* functions execute are resolved as oracles by TXE, since Noir tests are not transpiled. */
|
|
53
|
-
|
|
72
|
+
| {
|
|
73
|
+
name: 'PUBLIC';
|
|
74
|
+
}
|
|
54
75
|
/**
|
|
55
76
|
* The utility state is entered via the `utility_context` function. In this state the PXE oracles that `#[utility]`
|
|
56
77
|
* functions use are available, such as those related to (unconstrained) note retrieval, capsule access, public
|
|
57
78
|
* storage reads, etc.
|
|
58
79
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
80
|
+
| {
|
|
81
|
+
name: 'UTILITY';
|
|
82
|
+
};
|
|
61
83
|
|
|
62
84
|
type MethodNames<T> = {
|
|
63
85
|
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
@@ -70,10 +92,10 @@ type MethodNames<T> = {
|
|
|
70
92
|
export type TXEOracleFunctionName = MethodNames<RPCTranslator>;
|
|
71
93
|
|
|
72
94
|
export interface TXESessionStateHandler {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
95
|
+
enterTopLevelState(): Promise<void>;
|
|
96
|
+
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
97
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: UInt32): Promise<PrivateContextInputs>;
|
|
98
|
+
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
77
99
|
}
|
|
78
100
|
|
|
79
101
|
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
@@ -83,7 +105,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
83
105
|
* state, etc., independent of all other tests running in parallel.
|
|
84
106
|
*/
|
|
85
107
|
export class TXESession implements TXESessionStateHandler {
|
|
86
|
-
private state =
|
|
108
|
+
private state: SessionState = { name: 'TOP_LEVEL' };
|
|
87
109
|
private authwits: Map<string, AuthWitness> = new Map();
|
|
88
110
|
|
|
89
111
|
constructor(
|
|
@@ -181,27 +203,36 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
181
203
|
} catch (error) {
|
|
182
204
|
if (error instanceof Error) {
|
|
183
205
|
throw new Error(
|
|
184
|
-
`Execution error while processing function ${functionName} in state ${
|
|
206
|
+
`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`,
|
|
185
207
|
);
|
|
186
208
|
} else {
|
|
187
209
|
throw new Error(
|
|
188
|
-
`Unknown execution error while processing function ${functionName} in state ${
|
|
210
|
+
`Unknown execution error while processing function ${functionName} in state ${this.state.name}`,
|
|
189
211
|
);
|
|
190
212
|
}
|
|
191
213
|
}
|
|
192
214
|
}
|
|
193
215
|
|
|
194
|
-
async
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
216
|
+
async enterTopLevelState() {
|
|
217
|
+
switch (this.state.name) {
|
|
218
|
+
case 'PRIVATE': {
|
|
219
|
+
await this.exitPrivateState();
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case 'PUBLIC': {
|
|
223
|
+
await this.exitPublicState();
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case 'UTILITY': {
|
|
227
|
+
this.exitUtilityContext();
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
case 'TOP_LEVEL': {
|
|
231
|
+
throw new Error(`Expected to be in state other than TOP_LEVEL`);
|
|
232
|
+
}
|
|
233
|
+
default: {
|
|
234
|
+
this.state satisfies never;
|
|
235
|
+
}
|
|
205
236
|
}
|
|
206
237
|
|
|
207
238
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
@@ -217,99 +248,105 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
217
248
|
this.authwits,
|
|
218
249
|
);
|
|
219
250
|
|
|
220
|
-
this.state =
|
|
221
|
-
this.logger.debug(`Entered state ${
|
|
251
|
+
this.state = { name: 'TOP_LEVEL' };
|
|
252
|
+
this.logger.debug(`Entered state ${this.state.name}`);
|
|
222
253
|
}
|
|
223
254
|
|
|
224
|
-
async
|
|
225
|
-
|
|
255
|
+
async enterPrivateState(
|
|
256
|
+
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
257
|
+
anchorBlockNumber?: UInt32,
|
|
258
|
+
): Promise<PrivateContextInputs> {
|
|
259
|
+
this.exitTopLevelState();
|
|
260
|
+
|
|
261
|
+
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
262
|
+
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
263
|
+
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
264
|
+
// be removed from the database.
|
|
265
|
+
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
266
|
+
await this.pxeOracleInterface.removeNullifiedNotes(contractAddress);
|
|
267
|
+
|
|
268
|
+
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
269
|
+
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
270
|
+
// a single transaction with the effects of what was done in the test.
|
|
271
|
+
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
272
|
+
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
226
273
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
230
|
-
const globalVariables = makeGlobalVariables(undefined, {
|
|
231
|
-
blockNumber: latestBlockNumber + 1,
|
|
274
|
+
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
275
|
+
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
232
276
|
timestamp: this.nextBlockTimestamp,
|
|
233
277
|
version: this.version,
|
|
234
278
|
chainId: this.chainId,
|
|
235
279
|
});
|
|
236
280
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
await this.stateMachine.synchronizer.nativeWorldStateService.fork(),
|
|
240
|
-
getSingleTxBlockRequestHash(globalVariables.blockNumber),
|
|
241
|
-
globalVariables,
|
|
242
|
-
);
|
|
281
|
+
const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
|
|
282
|
+
const noteCache = new ExecutionNoteCache(txRequestHash);
|
|
243
283
|
|
|
244
|
-
this.
|
|
245
|
-
|
|
246
|
-
|
|
284
|
+
this.oracleHandler = new PrivateExecutionOracle(
|
|
285
|
+
Fr.ZERO,
|
|
286
|
+
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
287
|
+
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
288
|
+
anchorBlock!,
|
|
289
|
+
[],
|
|
290
|
+
[],
|
|
291
|
+
new HashedValuesCache(),
|
|
292
|
+
noteCache,
|
|
293
|
+
this.pxeOracleInterface,
|
|
294
|
+
);
|
|
247
295
|
|
|
248
|
-
|
|
249
|
-
this.
|
|
296
|
+
// We store the note cache fed into the PrivateExecutionOracle (along with some other auxiliary data) in order to
|
|
297
|
+
// refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The difference resides
|
|
298
|
+
// in that the simulator has all information needed in order to run the simulation, while ours will be ongoing as
|
|
299
|
+
// the different oracles will be invoked from the Noir test, until eventually the private execution finishes.
|
|
300
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, txRequestHash, noteCache };
|
|
301
|
+
this.logger.debug(`Entered state ${this.state.name}`);
|
|
250
302
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
// contains the effects of what was done in the test.
|
|
254
|
-
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
255
|
-
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
303
|
+
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
304
|
+
}
|
|
256
305
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
timestamp: anchorBlock!.globalVariables.timestamp,
|
|
260
|
-
version: this.version,
|
|
261
|
-
chainId: this.chainId,
|
|
262
|
-
});
|
|
306
|
+
async enterPublicState(contractAddress?: AztecAddress) {
|
|
307
|
+
this.exitTopLevelState();
|
|
263
308
|
|
|
264
|
-
|
|
265
|
-
|
|
309
|
+
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
310
|
+
// the test. The block therefore gets the *next* block number and timestamp.
|
|
311
|
+
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
312
|
+
const globalVariables = makeGlobalVariables(undefined, {
|
|
313
|
+
blockNumber: latestBlockNumber + 1,
|
|
266
314
|
timestamp: this.nextBlockTimestamp,
|
|
267
315
|
version: this.version,
|
|
268
316
|
chainId: this.chainId,
|
|
269
317
|
});
|
|
270
318
|
|
|
271
|
-
|
|
272
|
-
anchorBlockGlobalVariables.blockNumber,
|
|
273
|
-
contractAddress ?? DEFAULT_ADDRESS,
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
this.oracleHandler = await TXE.create(
|
|
319
|
+
this.oracleHandler = new TXEOraclePublicContext(
|
|
277
320
|
contractAddress ?? DEFAULT_ADDRESS,
|
|
278
|
-
this.pxeOracleInterface,
|
|
279
321
|
await this.stateMachine.synchronizer.nativeWorldStateService.fork(),
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber), // The tx will be inserted in the *next* block
|
|
322
|
+
getSingleTxBlockRequestHash(globalVariables.blockNumber),
|
|
323
|
+
globalVariables,
|
|
283
324
|
);
|
|
284
325
|
|
|
285
|
-
this.state =
|
|
286
|
-
this.logger.debug(`Entered state ${
|
|
287
|
-
|
|
288
|
-
return privateContextInputs;
|
|
326
|
+
this.state = { name: 'PUBLIC' };
|
|
327
|
+
this.logger.debug(`Entered state ${this.state.name}`);
|
|
289
328
|
}
|
|
290
329
|
|
|
291
|
-
async
|
|
292
|
-
this.
|
|
330
|
+
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
331
|
+
this.exitTopLevelState();
|
|
293
332
|
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
|
|
333
|
+
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
334
|
+
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
335
|
+
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
336
|
+
// be removed from the database.
|
|
337
|
+
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
338
|
+
await this.pxeOracleInterface.removeNullifiedNotes(contractAddress);
|
|
297
339
|
|
|
298
|
-
this.oracleHandler =
|
|
299
|
-
contractAddress ?? DEFAULT_ADDRESS,
|
|
300
|
-
this.pxeOracleInterface,
|
|
301
|
-
await this.stateMachine.synchronizer.nativeWorldStateService.fork(),
|
|
302
|
-
latestBlock!.globalVariables,
|
|
303
|
-
GlobalVariables.empty(), // unused - will be removed after private/utility split
|
|
304
|
-
Fr.random(), // unused - will be removed after private/utility split
|
|
305
|
-
);
|
|
340
|
+
this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], this.pxeOracleInterface);
|
|
306
341
|
|
|
307
|
-
this.state =
|
|
308
|
-
this.logger.debug(`Entered state ${
|
|
342
|
+
this.state = { name: 'UTILITY' };
|
|
343
|
+
this.logger.debug(`Entered state ${this.state.name}`);
|
|
309
344
|
}
|
|
310
345
|
|
|
311
|
-
private
|
|
312
|
-
this.
|
|
346
|
+
private exitTopLevelState() {
|
|
347
|
+
if (this.state.name != 'TOP_LEVEL') {
|
|
348
|
+
throw new Error(`Expected to be in state 'TOP_LEVEL', but got '${this.state.name}' instead`);
|
|
349
|
+
}
|
|
313
350
|
|
|
314
351
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
315
352
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
@@ -323,40 +360,54 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
323
360
|
[this.nextBlockTimestamp, this.authwits] = (this.oracleHandler as TXEOracleTopLevelContext).close();
|
|
324
361
|
}
|
|
325
362
|
|
|
326
|
-
private async
|
|
327
|
-
this.
|
|
363
|
+
private async exitPrivateState() {
|
|
364
|
+
if (this.state.name != 'PRIVATE') {
|
|
365
|
+
throw new Error(`Expected to be in state 'PRIVATE', but got '${this.state.name}' instead`);
|
|
366
|
+
}
|
|
328
367
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
368
|
+
this.logger.debug('Exiting Private state, building block with collected side effects', {
|
|
369
|
+
blockNumber: this.state.nextBlockGlobalVariables.blockNumber,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
373
|
+
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
374
|
+
const txEffect = await makeTxEffect(
|
|
375
|
+
this.state.noteCache,
|
|
376
|
+
this.state.txRequestHash,
|
|
377
|
+
this.state.nextBlockGlobalVariables.blockNumber,
|
|
378
|
+
);
|
|
332
379
|
|
|
333
|
-
|
|
334
|
-
this.
|
|
380
|
+
// We build a block holding just this transaction
|
|
381
|
+
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
382
|
+
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
335
383
|
|
|
336
|
-
const block =
|
|
384
|
+
const block = new L2Block(
|
|
385
|
+
makeAppendOnlyTreeSnapshot(),
|
|
386
|
+
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
387
|
+
new Body([txEffect]),
|
|
388
|
+
);
|
|
337
389
|
await this.stateMachine.handleL2Block(block);
|
|
338
|
-
}
|
|
339
390
|
|
|
340
|
-
|
|
341
|
-
this.assertState(SessionState.UTILITY);
|
|
342
|
-
}
|
|
391
|
+
await forkedWorldTrees.close();
|
|
343
392
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
393
|
+
this.logger.debug('Exited PublicContext with built block', {
|
|
394
|
+
blockNumber: block.number,
|
|
395
|
+
txEffects: block.body.txEffects,
|
|
396
|
+
});
|
|
348
397
|
}
|
|
349
398
|
|
|
350
|
-
private async
|
|
351
|
-
this.
|
|
399
|
+
private async exitPublicState() {
|
|
400
|
+
if (this.state.name != 'PUBLIC') {
|
|
401
|
+
throw new Error(`Expected to be in state 'PUBLIC', but got '${this.state.name}' instead`);
|
|
402
|
+
}
|
|
352
403
|
|
|
353
|
-
const
|
|
404
|
+
const block = await (this.oracleHandler as TXEOraclePublicContext).close();
|
|
405
|
+
await this.stateMachine.handleL2Block(block);
|
|
406
|
+
}
|
|
354
407
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
(
|
|
358
|
-
|
|
359
|
-
0,
|
|
360
|
-
);
|
|
408
|
+
private exitUtilityContext() {
|
|
409
|
+
if (this.state.name != 'UTILITY') {
|
|
410
|
+
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
411
|
+
}
|
|
361
412
|
}
|
|
362
413
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
|
|
3
|
+
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
|
|
4
|
+
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
5
|
+
|
|
6
|
+
export async function makeTxEffect(
|
|
7
|
+
noteCache: ExecutionNoteCache,
|
|
8
|
+
txRequestHash: Fr,
|
|
9
|
+
txBlockNumber: number,
|
|
10
|
+
): Promise<TxEffect> {
|
|
11
|
+
const txEffect = TxEffect.empty();
|
|
12
|
+
|
|
13
|
+
const { usedTxRequestHashForNonces } = noteCache.finish();
|
|
14
|
+
const nonceGenerator = usedTxRequestHashForNonces ? txRequestHash : noteCache.getAllNullifiers()[0];
|
|
15
|
+
|
|
16
|
+
txEffect.noteHashes = await Promise.all(
|
|
17
|
+
noteCache
|
|
18
|
+
.getAllNotes()
|
|
19
|
+
.map(async (pendingNote, i) =>
|
|
20
|
+
computeUniqueNoteHash(
|
|
21
|
+
await computeNoteHashNonce(nonceGenerator, i),
|
|
22
|
+
await siloNoteHash(pendingNote.note.contractAddress, pendingNote.noteHashForConsumption),
|
|
23
|
+
),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// Nullifiers are already siloed
|
|
28
|
+
txEffect.nullifiers = noteCache.getAllNullifiers();
|
|
29
|
+
|
|
30
|
+
if (usedTxRequestHashForNonces) {
|
|
31
|
+
txEffect.nullifiers.unshift(txRequestHash);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
txEffect.txHash = new TxHash(new Fr(txBlockNumber));
|
|
35
|
+
|
|
36
|
+
return txEffect;
|
|
37
|
+
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { Fr, Point } from '@aztec/foundation/fields';
|
|
3
|
-
import { PXEOracleInterface } from '@aztec/pxe/server';
|
|
4
|
-
import { ExecutionNoteCache, type IPrivateExecutionOracle, type IUtilityExecutionOracle, MessageLoadOracleInputs, type NoteData, UtilityContext } from '@aztec/pxe/simulator';
|
|
5
|
-
import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
6
|
-
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
|
-
import { L2Block } from '@aztec/stdlib/block';
|
|
8
|
-
import type { ContractInstance } from '@aztec/stdlib/contract';
|
|
9
|
-
import type { MerkleTreeWriteOperations } from '@aztec/stdlib/interfaces/server';
|
|
10
|
-
import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
|
|
11
|
-
import { ContractClassLog, IndexedTaggingSecret } from '@aztec/stdlib/logs';
|
|
12
|
-
import { type NoteStatus } from '@aztec/stdlib/note';
|
|
13
|
-
import { MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
|
|
14
|
-
import { BlockHeader, GlobalVariables } from '@aztec/stdlib/tx';
|
|
15
|
-
export declare class TXE implements IUtilityExecutionOracle, IPrivateExecutionOracle {
|
|
16
|
-
private contractAddress;
|
|
17
|
-
private pxeOracleInterface;
|
|
18
|
-
private forkedWorldTrees;
|
|
19
|
-
private anchorBlockGlobalVariables;
|
|
20
|
-
private nextBlockGlobalVariables;
|
|
21
|
-
private txRequestHash;
|
|
22
|
-
isMisc: true;
|
|
23
|
-
isUtility: true;
|
|
24
|
-
isPrivate: true;
|
|
25
|
-
private logger;
|
|
26
|
-
private executionCache;
|
|
27
|
-
private senderForTags?;
|
|
28
|
-
noteCache: ExecutionNoteCache;
|
|
29
|
-
private constructor();
|
|
30
|
-
static create(contractAddress: AztecAddress, pxeOracleInterface: PXEOracleInterface, forkedWorldTrees: MerkleTreeWriteOperations, anchorBlockGlobalVariables: GlobalVariables, nextBlockGlobalVariables: GlobalVariables, txRequestHash: Fr): Promise<TXE>;
|
|
31
|
-
checkNullifiersNotInTree(contractAddress: AztecAddress, nullifiers: Fr[]): Promise<void>;
|
|
32
|
-
utilityGetRandomField(): Fr;
|
|
33
|
-
utilityGetUtilityContext(): Promise<UtilityContext>;
|
|
34
|
-
privateStoreInExecutionCache(values: Fr[], hash: Fr): void;
|
|
35
|
-
privateLoadFromExecutionCache(hash: Fr): Promise<Fr[]>;
|
|
36
|
-
utilityGetKeyValidationRequest(pkMHash: Fr): Promise<KeyValidationRequest>;
|
|
37
|
-
utilityGetContractInstance(address: AztecAddress): Promise<ContractInstance>;
|
|
38
|
-
utilityGetMembershipWitness(blockNumber: number, treeId: MerkleTreeId, leafValue: Fr): Promise<Fr[] | undefined>;
|
|
39
|
-
utilityGetNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
40
|
-
utilityGetPublicDataWitness(blockNumber: number, leafSlot: Fr): Promise<PublicDataWitness | undefined>;
|
|
41
|
-
utilityGetLowNullifierMembershipWitness(blockNumber: number, nullifier: Fr): Promise<NullifierMembershipWitness | undefined>;
|
|
42
|
-
utilityGetBlockHeader(blockNumber: number): Promise<BlockHeader | undefined>;
|
|
43
|
-
utilityGetPublicKeysAndPartialAddress(account: AztecAddress): Promise<import("@aztec/stdlib/contract").CompleteAddress>;
|
|
44
|
-
utilityGetNotes(storageSlot: Fr, numSelects: number, selectByIndexes: number[], selectByOffsets: number[], selectByLengths: number[], selectValues: Fr[], selectComparators: number[], sortByIndexes: number[], sortByOffsets: number[], sortByLengths: number[], sortOrder: number[], limit: number, offset: number, status: NoteStatus): Promise<NoteData[]>;
|
|
45
|
-
privateNotifyCreatedNote(storageSlot: Fr, _noteTypeId: NoteSelector, noteItems: Fr[], noteHash: Fr, counter: number): void;
|
|
46
|
-
privateNotifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, _counter: number): Promise<void>;
|
|
47
|
-
privateNotifyCreatedNullifier(innerNullifier: Fr): Promise<void>;
|
|
48
|
-
utilityCheckNullifierExists(innerNullifier: Fr): Promise<boolean>;
|
|
49
|
-
utilityStorageRead(contractAddress: AztecAddress, startStorageSlot: Fr, blockNumber: number, numberOfElements: number): Promise<Fr[]>;
|
|
50
|
-
utilityDebugLog(message: string, fields: Fr[]): void;
|
|
51
|
-
privateIncrementAppTaggingSecretIndexAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<void>;
|
|
52
|
-
utilityGetIndexedTaggingSecretAsSender(sender: AztecAddress, recipient: AztecAddress): Promise<IndexedTaggingSecret>;
|
|
53
|
-
utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot: Fr): Promise<void>;
|
|
54
|
-
utilityValidateEnqueuedNotesAndEvents(contractAddress: AztecAddress, noteValidationRequestsArrayBaseSlot: Fr, eventValidationRequestsArrayBaseSlot: Fr): Promise<void>;
|
|
55
|
-
utilityBulkRetrieveLogs(contractAddress: AztecAddress, logRetrievalRequestsArrayBaseSlot: Fr, logRetrievalResponsesArrayBaseSlot: Fr): Promise<void>;
|
|
56
|
-
utilityStoreCapsule(contractAddress: AztecAddress, slot: Fr, capsule: Fr[]): Promise<void>;
|
|
57
|
-
utilityLoadCapsule(contractAddress: AztecAddress, slot: Fr): Promise<Fr[] | null>;
|
|
58
|
-
utilityDeleteCapsule(contractAddress: AztecAddress, slot: Fr): Promise<void>;
|
|
59
|
-
utilityCopyCapsule(contractAddress: AztecAddress, srcSlot: Fr, dstSlot: Fr, numEntries: number): Promise<void>;
|
|
60
|
-
utilityAes128Decrypt(ciphertext: Buffer, iv: Buffer, symKey: Buffer): Promise<Buffer>;
|
|
61
|
-
utilityGetSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
|
|
62
|
-
privateGetSenderForTags(): Promise<AztecAddress | undefined>;
|
|
63
|
-
privateSetSenderForTags(senderForTags: AztecAddress): Promise<void>;
|
|
64
|
-
close(): Promise<L2Block>;
|
|
65
|
-
private makeTxEffect;
|
|
66
|
-
utilityAssertCompatibleOracleVersion(_version: number): void;
|
|
67
|
-
utilityGetAuthWitness(_messageHash: Fr): Promise<Fr[] | undefined>;
|
|
68
|
-
utilityGetL1ToL2MembershipWitness(_contractAddress: AztecAddress, _messageHash: Fr, _secret: Fr): Promise<MessageLoadOracleInputs<typeof L1_TO_L2_MSG_TREE_HEIGHT>>;
|
|
69
|
-
utilityEmitOffchainEffect(_data: Fr[]): Promise<void>;
|
|
70
|
-
privateNotifyCreatedContractClassLog(_log: ContractClassLog, _counter: number): void;
|
|
71
|
-
privateCallPrivateFunction(_targetContractAddress: AztecAddress, _functionSelector: FunctionSelector, _argsHash: Fr, _sideEffectCounter: number, _isStaticCall: boolean): Promise<{
|
|
72
|
-
endSideEffectCounter: Fr;
|
|
73
|
-
returnsHash: Fr;
|
|
74
|
-
}>;
|
|
75
|
-
privateNotifyEnqueuedPublicFunctionCall(_targetContractAddress: AztecAddress, _calldataHash: Fr, _sideEffectCounter: number, _isStaticCall: boolean): Promise<void>;
|
|
76
|
-
privateNotifySetPublicTeardownFunctionCall(_targetContractAddress: AztecAddress, _calldataHash: Fr, _sideEffectCounter: number, _isStaticCall: boolean): Promise<void>;
|
|
77
|
-
privateNotifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): Promise<void>;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=txe_oracle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_oracle.d.ts","sourceRoot":"","sources":["../../src/oracle/txe_oracle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAErD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,kBAAkB,EAElB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,uBAAuB,EACvB,KAAK,QAAQ,EACb,cAAc,EAEf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,YAAY,EA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