@aztec/txe 0.0.1-commit.c80b6263 → 0.0.1-commit.cd76b27

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.
Files changed (36) hide show
  1. package/dest/oracle/interfaces.d.ts +2 -2
  2. package/dest/oracle/interfaces.d.ts.map +1 -1
  3. package/dest/oracle/txe_oracle_top_level_context.d.ts +3 -3
  4. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  5. package/dest/oracle/txe_oracle_top_level_context.js +83 -24
  6. package/dest/rpc_translator.d.ts +8 -8
  7. package/dest/rpc_translator.d.ts.map +1 -1
  8. package/dest/rpc_translator.js +39 -27
  9. package/dest/state_machine/archiver.d.ts +1 -1
  10. package/dest/state_machine/archiver.d.ts.map +1 -1
  11. package/dest/state_machine/archiver.js +2 -0
  12. package/dest/state_machine/dummy_p2p_client.d.ts +15 -11
  13. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  14. package/dest/state_machine/dummy_p2p_client.js +27 -15
  15. package/dest/state_machine/index.d.ts +5 -5
  16. package/dest/state_machine/index.d.ts.map +1 -1
  17. package/dest/state_machine/index.js +15 -10
  18. package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
  19. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  20. package/dest/state_machine/mock_epoch_cache.js +4 -0
  21. package/dest/txe_session.d.ts +1 -1
  22. package/dest/txe_session.d.ts.map +1 -1
  23. package/dest/txe_session.js +68 -9
  24. package/dest/utils/block_creation.d.ts +1 -1
  25. package/dest/utils/block_creation.d.ts.map +1 -1
  26. package/dest/utils/block_creation.js +3 -1
  27. package/package.json +15 -15
  28. package/src/oracle/interfaces.ts +1 -1
  29. package/src/oracle/txe_oracle_top_level_context.ts +86 -76
  30. package/src/rpc_translator.ts +41 -22
  31. package/src/state_machine/archiver.ts +2 -0
  32. package/src/state_machine/dummy_p2p_client.ts +39 -21
  33. package/src/state_machine/index.ts +25 -9
  34. package/src/state_machine/mock_epoch_cache.ts +5 -0
  35. package/src/txe_session.ts +70 -66
  36. package/src/utils/block_creation.ts +3 -1
@@ -4,8 +4,10 @@ import { type Logger, createLogger } from '@aztec/foundation/log';
4
4
  import { KeyStore } from '@aztec/key-store';
5
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
6
6
  import type { ProtocolContract } from '@aztec/protocol-contracts';
7
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
7
8
  import {
8
9
  AddressStore,
10
+ AnchorBlockStore,
9
11
  CapsuleStore,
10
12
  JobCoordinator,
11
13
  NoteService,
@@ -49,6 +51,7 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
49
51
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
50
52
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
51
53
  import { RPCTranslator } from './rpc_translator.js';
54
+ import { TXEArchiver } from './state_machine/archiver.js';
52
55
  import { TXEStateMachine } from './state_machine/index.js';
53
56
  import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
54
57
  import { TXEAccountStore } from './util/txe_account_store.js';
@@ -176,7 +179,9 @@ export class TXESession implements TXESessionStateHandler {
176
179
  await contractStore.addContractInstance(instance);
177
180
  }
178
181
 
179
- const stateMachine = await TXEStateMachine.create(store);
182
+ const archiver = new TXEArchiver(store);
183
+ const anchorBlockStore = new AnchorBlockStore(store);
184
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
180
185
 
181
186
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
182
187
  const version = new Fr(await stateMachine.node.getVersion());
@@ -312,17 +317,15 @@ export class TXESession implements TXESessionStateHandler {
312
317
  ): Promise<PrivateContextInputs> {
313
318
  this.exitTopLevelState();
314
319
 
315
- await new NoteService(
316
- this.noteStore,
317
- this.stateMachine.node,
318
- this.stateMachine.anchorBlockStore,
319
- this.currentJobId,
320
- ).syncNoteNullifiers(contractAddress);
321
-
322
320
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
323
321
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
324
322
  // a single transaction with the effects of what was done in the test.
325
323
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
324
+
325
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
326
+ contractAddress,
327
+ 'ALL_SCOPES',
328
+ );
326
329
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
327
330
 
328
331
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
@@ -338,30 +341,31 @@ export class TXESession implements TXESessionStateHandler {
338
341
  const taggingIndexCache = new ExecutionTaggingIndexCache();
339
342
 
340
343
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
341
- this.oracleHandler = new PrivateExecutionOracle(
342
- Fr.ZERO,
343
- new TxContext(this.chainId, this.version, GasSettings.empty()),
344
- new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
345
- anchorBlock!,
344
+ this.oracleHandler = new PrivateExecutionOracle({
345
+ argsHash: Fr.ZERO,
346
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
347
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
348
+ anchorBlockHeader: anchorBlock!,
346
349
  utilityExecutor,
347
- [],
348
- [],
349
- new HashedValuesCache(),
350
+ authWitnesses: [],
351
+ capsules: [],
352
+ executionCache: new HashedValuesCache(),
350
353
  noteCache,
351
354
  taggingIndexCache,
352
- this.contractStore,
353
- this.noteStore,
354
- this.keyStore,
355
- this.addressStore,
356
- this.stateMachine.node,
357
- this.stateMachine.anchorBlockStore,
358
- this.senderTaggingStore,
359
- this.recipientTaggingStore,
360
- this.senderAddressBookStore,
361
- this.capsuleStore,
362
- this.privateEventStore,
363
- this.currentJobId,
364
- );
355
+ contractStore: this.contractStore,
356
+ noteStore: this.noteStore,
357
+ keyStore: this.keyStore,
358
+ addressStore: this.addressStore,
359
+ aztecNode: this.stateMachine.node,
360
+ senderTaggingStore: this.senderTaggingStore,
361
+ recipientTaggingStore: this.recipientTaggingStore,
362
+ senderAddressBookStore: this.senderAddressBookStore,
363
+ capsuleStore: this.capsuleStore,
364
+ privateEventStore: this.privateEventStore,
365
+ contractSyncService: this.stateMachine.contractSyncService,
366
+ jobId: this.currentJobId,
367
+ scopes: 'ALL_SCOPES',
368
+ });
365
369
 
366
370
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
367
371
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
@@ -401,6 +405,8 @@ export class TXESession implements TXESessionStateHandler {
401
405
  async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
402
406
  this.exitTopLevelState();
403
407
 
408
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
409
+
404
410
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
405
411
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
406
412
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
@@ -409,29 +415,27 @@ export class TXESession implements TXESessionStateHandler {
409
415
  await new NoteService(
410
416
  this.noteStore,
411
417
  this.stateMachine.node,
412
- this.stateMachine.anchorBlockStore,
418
+ anchorBlockHeader,
413
419
  this.currentJobId,
414
- ).syncNoteNullifiers(contractAddress);
415
-
416
- const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
420
+ ).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
417
421
 
418
- this.oracleHandler = new UtilityExecutionOracle(
422
+ this.oracleHandler = new UtilityExecutionOracle({
419
423
  contractAddress,
420
- [],
421
- [],
424
+ authWitnesses: [],
425
+ capsules: [],
422
426
  anchorBlockHeader,
423
- this.contractStore,
424
- this.noteStore,
425
- this.keyStore,
426
- this.addressStore,
427
- this.stateMachine.node,
428
- this.stateMachine.anchorBlockStore,
429
- this.recipientTaggingStore,
430
- this.senderAddressBookStore,
431
- this.capsuleStore,
432
- this.privateEventStore,
433
- this.currentJobId,
434
- );
427
+ contractStore: this.contractStore,
428
+ noteStore: this.noteStore,
429
+ keyStore: this.keyStore,
430
+ addressStore: this.addressStore,
431
+ aztecNode: this.stateMachine.node,
432
+ recipientTaggingStore: this.recipientTaggingStore,
433
+ senderAddressBookStore: this.senderAddressBookStore,
434
+ capsuleStore: this.capsuleStore,
435
+ privateEventStore: this.privateEventStore,
436
+ jobId: this.currentJobId,
437
+ scopes: 'ALL_SCOPES',
438
+ });
435
439
 
436
440
  this.state = { name: 'UTILITY' };
437
441
  this.logger.debug(`Entered state ${this.state.name}`);
@@ -499,30 +503,30 @@ export class TXESession implements TXESessionStateHandler {
499
503
  }
500
504
 
501
505
  private utilityExecutorForContractSync(anchorBlock: any) {
502
- return async (call: FunctionCall) => {
506
+ return async (call: FunctionCall, scopes: AccessScopes) => {
503
507
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
504
508
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
505
509
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
506
510
  }
507
511
 
508
512
  try {
509
- const oracle = new UtilityExecutionOracle(
510
- call.to,
511
- [],
512
- [],
513
- anchorBlock!,
514
- this.contractStore,
515
- this.noteStore,
516
- this.keyStore,
517
- this.addressStore,
518
- this.stateMachine.node,
519
- this.stateMachine.anchorBlockStore,
520
- this.recipientTaggingStore,
521
- this.senderAddressBookStore,
522
- this.capsuleStore,
523
- this.privateEventStore,
524
- this.currentJobId,
525
- );
513
+ const oracle = new UtilityExecutionOracle({
514
+ contractAddress: call.to,
515
+ authWitnesses: [],
516
+ capsules: [],
517
+ anchorBlockHeader: anchorBlock!,
518
+ contractStore: this.contractStore,
519
+ noteStore: this.noteStore,
520
+ keyStore: this.keyStore,
521
+ addressStore: this.addressStore,
522
+ aztecNode: this.stateMachine.node,
523
+ recipientTaggingStore: this.recipientTaggingStore,
524
+ senderAddressBookStore: this.senderAddressBookStore,
525
+ capsuleStore: this.capsuleStore,
526
+ privateEventStore: this.privateEventStore,
527
+ jobId: this.currentJobId,
528
+ scopes,
529
+ });
526
530
  await new WASMSimulator()
527
531
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
528
532
  .catch((err: Error) => {
@@ -87,7 +87,9 @@ export async function makeTXEBlock(
87
87
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
88
88
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
89
89
 
90
- // L2Block requires checkpointNumber and indexWithinCheckpoint
90
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
91
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
92
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
91
93
  const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
92
94
  const indexWithinCheckpoint = IndexWithinCheckpoint(0);
93
95