@aztec/txe 0.0.1-commit.6d3c34e → 0.0.1-commit.7cf39cb55

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 (52) hide show
  1. package/dest/constants.d.ts +1 -2
  2. package/dest/constants.d.ts.map +1 -1
  3. package/dest/constants.js +0 -1
  4. package/dest/oracle/interfaces.d.ts +3 -3
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +6 -6
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +4 -3
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +102 -35
  12. package/dest/rpc_translator.d.ts +19 -13
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +75 -50
  15. package/dest/state_machine/archiver.d.ts +20 -69
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +36 -178
  18. package/dest/state_machine/dummy_p2p_client.d.ts +11 -8
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +21 -12
  21. package/dest/state_machine/index.d.ts +5 -5
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +34 -11
  24. package/dest/state_machine/mock_epoch_cache.d.ts +8 -6
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +11 -7
  27. package/dest/state_machine/synchronizer.d.ts +3 -3
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/txe_session.d.ts +5 -3
  30. package/dest/txe_session.d.ts.map +1 -1
  31. package/dest/txe_session.js +90 -17
  32. package/dest/util/encoding.d.ts +17 -17
  33. package/dest/utils/block_creation.d.ts +4 -4
  34. package/dest/utils/block_creation.d.ts.map +1 -1
  35. package/dest/utils/block_creation.js +18 -4
  36. package/dest/utils/tx_effect_creation.d.ts +2 -3
  37. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  38. package/dest/utils/tx_effect_creation.js +3 -6
  39. package/package.json +16 -16
  40. package/src/constants.ts +0 -1
  41. package/src/oracle/interfaces.ts +2 -2
  42. package/src/oracle/txe_oracle_public_context.ts +6 -8
  43. package/src/oracle/txe_oracle_top_level_context.ts +123 -82
  44. package/src/rpc_translator.ts +78 -52
  45. package/src/state_machine/archiver.ts +37 -234
  46. package/src/state_machine/dummy_p2p_client.ts +29 -15
  47. package/src/state_machine/index.ts +48 -11
  48. package/src/state_machine/mock_epoch_cache.ts +11 -11
  49. package/src/state_machine/synchronizer.ts +2 -2
  50. package/src/txe_session.ts +93 -73
  51. package/src/utils/block_creation.ts +19 -16
  52. package/src/utils/tx_effect_creation.ts +3 -11
@@ -78,13 +78,11 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
78
78
  this.transientUniqueNoteHashes.push(siloedNoteHash);
79
79
  }
80
80
 
81
- async avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise<boolean> {
82
- const nullifier = await siloNullifier(targetAddress, innerNullifier!);
83
-
81
+ async avmOpcodeNullifierExists(siloedNullifier: Fr): Promise<boolean> {
84
82
  const treeIndex = (
85
- await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [nullifier.toBuffer()])
83
+ await this.forkedWorldTrees.findLeafIndices(MerkleTreeId.NULLIFIER_TREE, [siloedNullifier.toBuffer()])
86
84
  )[0];
87
- const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(nullifier));
85
+ const transientIndex = this.transientSiloedNullifiers.find(n => n.equals(siloedNullifier));
88
86
 
89
87
  return treeIndex !== undefined || transientIndex !== undefined;
90
88
  }
@@ -101,8 +99,8 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
101
99
  ]);
102
100
  }
103
101
 
104
- async avmOpcodeStorageRead(slot: Fr): Promise<Fr> {
105
- const leafSlot = await computePublicDataTreeLeafSlot(this.contractAddress, slot);
102
+ async avmOpcodeStorageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr> {
103
+ const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, slot);
106
104
 
107
105
  const lowLeafResult = await this.forkedWorldTrees.getPreviousValueIndex(
108
106
  MerkleTreeId.PUBLIC_DATA_TREE,
@@ -119,7 +117,7 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
119
117
  )) as PublicDataTreeLeafPreimage
120
118
  ).leaf.value;
121
119
 
122
- this.logger.debug('AVM storage read', { slot, value });
120
+ this.logger.debug('AVM storage read', { slot, contractAddress, value });
123
121
 
124
122
  return value;
125
123
  }
@@ -80,7 +80,7 @@ import {
80
80
  import type { UInt64 } from '@aztec/stdlib/types';
81
81
  import { ForkCheckpoint } from '@aztec/world-state';
82
82
 
83
- import { DEFAULT_ADDRESS, TXE_JOB_ID } from '../constants.js';
83
+ import { DEFAULT_ADDRESS } from '../constants.js';
84
84
  import type { TXEStateMachine } from '../state_machine/index.js';
85
85
  import type { TXEAccountStore } from '../util/txe_account_store.js';
86
86
  import type { TXEContractStore } from '../util/txe_contract_store.js';
@@ -106,6 +106,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
106
106
  private senderAddressBookStore: SenderAddressBookStore,
107
107
  private capsuleStore: CapsuleStore,
108
108
  private privateEventStore: PrivateEventStore,
109
+ private jobId: string,
109
110
  private nextBlockTimestamp: bigint,
110
111
  private version: Fr,
111
112
  private chainId: Fr,
@@ -130,13 +131,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
130
131
  }
131
132
 
132
133
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
133
- utilityDebugLog(level: number, message: string, fields: Fr[]): void {
134
+ utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
134
135
  if (!LogLevels[level]) {
135
- throw new Error(`Invalid debug log level: ${level}`);
136
+ throw new Error(`Invalid log level: ${level}`);
136
137
  }
137
138
  const levelName = LogLevels[level];
138
139
 
139
140
  this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
141
+ return Promise.resolve();
140
142
  }
141
143
 
142
144
  txeGetDefaultAddress(): AztecAddress {
@@ -156,7 +158,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
156
158
  }
157
159
 
158
160
  async txeGetLastTxEffects() {
159
- const block = await this.stateMachine.archiver.getL2Block('latest');
161
+ const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
162
+ const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
160
163
 
161
164
  if (block!.body.txEffects.length != 1) {
162
165
  // Note that calls like env.mine() will result in blocks with no transactions, hitting this
@@ -294,12 +297,24 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
294
297
  throw new Error(message);
295
298
  }
296
299
 
300
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
301
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
302
+ const effectiveScopes = from.isZero() ? [] : [from];
303
+
297
304
  // Sync notes before executing private function to discover notes from previous transactions
298
- const utilityExecutor = async (call: FunctionCall) => {
299
- await this.executeUtilityCall(call);
305
+ const utilityExecutor = async (call: FunctionCall, execScopes: undefined | AztecAddress[]) => {
306
+ await this.executeUtilityCall(call, execScopes);
300
307
  };
301
308
 
302
- await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, utilityExecutor);
309
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
310
+ await this.stateMachine.contractSyncService.ensureContractSynced(
311
+ targetContractAddress,
312
+ functionSelector,
313
+ utilityExecutor,
314
+ blockHeader,
315
+ this.jobId,
316
+ effectiveScopes,
317
+ );
303
318
 
304
319
  const blockNumber = await this.txeGetNextBlockNumber();
305
320
 
@@ -311,51 +326,48 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
311
326
 
312
327
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
313
328
 
314
- const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
315
-
316
329
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
317
330
  const noteCache = new ExecutionNoteCache(protocolNullifier);
331
+ // In production, the account contract sets the min revertible counter before calling the app function.
332
+ // Since TXE bypasses the account contract, we simulate this by setting minRevertibleSideEffectCounter to 1,
333
+ // marking all side effects as revertible.
334
+ const minRevertibleSideEffectCounter = 1;
335
+ await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
318
336
  const taggingIndexCache = new ExecutionTaggingIndexCache();
319
337
 
320
338
  const simulator = new WASMSimulator();
321
339
 
322
- const privateExecutionOracle = new PrivateExecutionOracle(
340
+ const privateExecutionOracle = new PrivateExecutionOracle({
323
341
  argsHash,
324
342
  txContext,
325
343
  callContext,
326
- /** Header of a block whose state is used during private execution (not the block the transaction is included in). */
327
- blockHeader,
344
+ anchorBlockHeader: blockHeader,
328
345
  utilityExecutor,
329
- /** List of transient auth witnesses to be used during this simulation */
330
- Array.from(this.authwits.values()),
331
- /** List of transient auth witnesses to be used during this simulation */
332
- [],
333
- HashedValuesCache.create([new HashedValues(args, argsHash)]),
346
+ authWitnesses: Array.from(this.authwits.values()),
347
+ capsules: [],
348
+ executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
334
349
  noteCache,
335
350
  taggingIndexCache,
336
- this.contractStore,
337
- this.noteStore,
338
- this.keyStore,
339
- this.addressStore,
340
- this.stateMachine.node,
341
- this.stateMachine.anchorBlockStore,
342
- this.senderTaggingStore,
343
- this.recipientTaggingStore,
344
- this.senderAddressBookStore,
345
- this.capsuleStore,
346
- this.privateEventStore,
347
- TXE_JOB_ID,
348
- 0,
349
- 1,
350
- undefined, // log
351
- undefined, // scopes
352
- /**
353
- * In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
354
- * contract would perform, including setting senderForTags.
355
- */
356
- from,
351
+ contractStore: this.contractStore,
352
+ noteStore: this.noteStore,
353
+ keyStore: this.keyStore,
354
+ addressStore: this.addressStore,
355
+ aztecNode: this.stateMachine.node,
356
+ senderTaggingStore: this.senderTaggingStore,
357
+ recipientTaggingStore: this.recipientTaggingStore,
358
+ senderAddressBookStore: this.senderAddressBookStore,
359
+ capsuleStore: this.capsuleStore,
360
+ privateEventStore: this.privateEventStore,
361
+ contractSyncService: this.stateMachine.contractSyncService,
362
+ jobId: this.jobId,
363
+ totalPublicCalldataCount: 0,
364
+ sideEffectCounter: minRevertibleSideEffectCounter,
365
+ scopes: effectiveScopes,
366
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
367
+ // contract would perform, including setting senderForTags.
368
+ senderForTags: from,
357
369
  simulator,
358
- );
370
+ });
359
371
 
360
372
  // Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
361
373
  let result: PrivateExecutionResult;
@@ -382,19 +394,22 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
382
394
  }),
383
395
  );
384
396
 
385
- // TXE's top level context does not track side effect counters, and as such, minRevertibleSideEffectCounter is always 0.
386
- // This has the unfortunate consequence of always producing revertible nullifiers, which means we
387
- // must set the firstNullifierHint to Fr.ZERO so the txRequestHash is always used as nonce generator
388
- result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
397
+ noteCache.finish();
398
+ const nonceGenerator = noteCache.getNonceGenerator();
399
+ result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
389
400
  } catch (err) {
390
401
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
391
402
  }
392
403
 
393
- // According to the protocol rules, the nonce generator for the note hashes
394
- // can either be the first nullifier in the tx or the hash of the initial tx request
395
- // if there are none.
396
- const nonceGenerator = result.firstNullifier.equals(Fr.ZERO) ? protocolNullifier : result.firstNullifier;
397
- const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractStore);
404
+ // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
405
+ // the nonce generator for the note hashes.
406
+ // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
407
+ const { publicInputs } = await generateSimulatedProvingResult(
408
+ result,
409
+ (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
410
+ this.stateMachine.node,
411
+ minRevertibleSideEffectCounter,
412
+ );
398
413
 
399
414
  const globals = makeGlobalVariables();
400
415
  globals.blockNumber = blockNumber;
@@ -405,7 +420,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
405
420
 
406
421
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
407
422
 
408
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
423
+ const bindings = this.logger.getBindings();
424
+ const contractsDB = new PublicContractsDB(
425
+ new TXEPublicContractDataSource(blockNumber, this.contractStore),
426
+ bindings,
427
+ );
409
428
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
410
429
  const config = PublicSimulatorConfig.from({
411
430
  skipFeeEnforcement: true,
@@ -418,8 +437,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
418
437
  globals,
419
438
  guardedMerkleTrees,
420
439
  contractsDB,
421
- new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config),
440
+ new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings),
422
441
  new TestDateProvider(),
442
+ undefined,
443
+ createLogger('simulator:public-processor', bindings),
423
444
  );
424
445
 
425
446
  const tx = await Tx.create({
@@ -516,7 +537,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
516
537
 
517
538
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
518
539
 
519
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
540
+ const bindings2 = this.logger.getBindings();
541
+ const contractsDB = new PublicContractsDB(
542
+ new TXEPublicContractDataSource(blockNumber, this.contractStore),
543
+ bindings2,
544
+ );
520
545
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
521
546
  const config = PublicSimulatorConfig.from({
522
547
  skipFeeEnforcement: true,
@@ -525,8 +550,16 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
525
550
  collectStatistics: false,
526
551
  collectCallMetadata: true,
527
552
  });
528
- const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
529
- const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
553
+ const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
554
+ const processor = new PublicProcessor(
555
+ globals,
556
+ guardedMerkleTrees,
557
+ contractsDB,
558
+ simulator,
559
+ new TestDateProvider(),
560
+ undefined,
561
+ createLogger('simulator:public-processor', bindings2),
562
+ );
530
563
 
531
564
  // We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
532
565
  // kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
@@ -636,25 +669,33 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
636
669
  }
637
670
 
638
671
  // Sync notes before executing utility function to discover notes from previous transactions
639
- await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, async call => {
640
- await this.executeUtilityCall(call);
641
- });
642
-
643
- const call = new FunctionCall(
644
- artifact.name,
672
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
673
+ await this.stateMachine.contractSyncService.ensureContractSynced(
645
674
  targetContractAddress,
646
675
  functionSelector,
647
- FunctionType.UTILITY,
648
- false,
649
- false,
650
- args,
651
- [],
676
+ async (call, execScopes) => {
677
+ await this.executeUtilityCall(call, execScopes);
678
+ },
679
+ blockHeader,
680
+ this.jobId,
681
+ undefined,
652
682
  );
653
683
 
654
- return this.executeUtilityCall(call);
684
+ const call = FunctionCall.from({
685
+ name: artifact.name,
686
+ to: targetContractAddress,
687
+ selector: functionSelector,
688
+ type: FunctionType.UTILITY,
689
+ hideMsgSender: false,
690
+ isStatic: false,
691
+ args,
692
+ returnTypes: [],
693
+ });
694
+
695
+ return this.executeUtilityCall(call, undefined);
655
696
  }
656
697
 
657
- private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
698
+ private async executeUtilityCall(call: FunctionCall, scopes: undefined | AztecAddress[]): Promise<Fr[]> {
658
699
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
659
700
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
660
701
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -667,23 +708,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
667
708
 
668
709
  try {
669
710
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
670
- const oracle = new UtilityExecutionOracle(
671
- call.to,
672
- [],
673
- [],
711
+ const oracle = new UtilityExecutionOracle({
712
+ contractAddress: call.to,
713
+ authWitnesses: [],
714
+ capsules: [],
674
715
  anchorBlockHeader,
675
- this.contractStore,
676
- this.noteStore,
677
- this.keyStore,
678
- this.addressStore,
679
- this.stateMachine.node,
680
- this.stateMachine.anchorBlockStore,
681
- this.recipientTaggingStore,
682
- this.senderAddressBookStore,
683
- this.capsuleStore,
684
- this.privateEventStore,
685
- TXE_JOB_ID,
686
- );
716
+ contractStore: this.contractStore,
717
+ noteStore: this.noteStore,
718
+ keyStore: this.keyStore,
719
+ addressStore: this.addressStore,
720
+ aztecNode: this.stateMachine.node,
721
+ recipientTaggingStore: this.recipientTaggingStore,
722
+ senderAddressBookStore: this.senderAddressBookStore,
723
+ capsuleStore: this.capsuleStore,
724
+ privateEventStore: this.privateEventStore,
725
+ jobId: this.jobId,
726
+ scopes,
727
+ });
687
728
  const acirExecutionResult = await new WASMSimulator()
688
729
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
689
730
  .catch((err: Error) => {
@@ -6,11 +6,11 @@ import {
6
6
  type IMiscOracle,
7
7
  type IPrivateExecutionOracle,
8
8
  type IUtilityExecutionOracle,
9
- packAsRetrievedNote,
9
+ packAsHintedNote,
10
10
  } from '@aztec/pxe/simulator';
11
11
  import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
12
12
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
13
- import { MerkleTreeId } from '@aztec/stdlib/trees';
13
+ import { BlockHash } from '@aztec/stdlib/block';
14
14
 
15
15
  import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
16
16
  import type { TXESessionStateHandler } from './txe_session.js';
@@ -328,7 +328,7 @@ export class RPCTranslator {
328
328
 
329
329
  // When the argument is a slice, noir automatically adds a length field to oracle call.
330
330
  // When the argument is an array, we add the field length manually to the signature.
331
- utilityDebugLog(
331
+ async utilityLog(
332
332
  foreignLevel: ForeignCallSingle,
333
333
  foreignMessage: ForeignCallArray,
334
334
  _foreignLength: ForeignCallSingle,
@@ -340,40 +340,40 @@ export class RPCTranslator {
340
340
  .join('');
341
341
  const fields = fromArray(foreignFields);
342
342
 
343
- this.handlerAsMisc().utilityDebugLog(level, message, fields);
343
+ await this.handlerAsMisc().utilityLog(level, message, fields);
344
344
 
345
345
  return toForeignCallResult([]);
346
346
  }
347
347
 
348
348
  async utilityStorageRead(
349
+ foreignBlockHash: ForeignCallSingle,
349
350
  foreignContractAddress: ForeignCallSingle,
350
351
  foreignStartStorageSlot: ForeignCallSingle,
351
- foreignBlockNumber: ForeignCallSingle,
352
352
  foreignNumberOfElements: ForeignCallSingle,
353
353
  ) {
354
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
354
355
  const contractAddress = addressFromSingle(foreignContractAddress);
355
356
  const startStorageSlot = fromSingle(foreignStartStorageSlot);
356
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
357
357
  const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
358
358
 
359
359
  const values = await this.handlerAsUtility().utilityStorageRead(
360
+ blockHash,
360
361
  contractAddress,
361
362
  startStorageSlot,
362
- blockNumber,
363
363
  numberOfElements,
364
364
  );
365
365
 
366
366
  return toForeignCallResult([toArray(values)]);
367
367
  }
368
368
 
369
- async utilityGetPublicDataWitness(foreignBlockNumber: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
370
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
369
+ async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
370
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
371
371
  const leafSlot = fromSingle(foreignLeafSlot);
372
372
 
373
- const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
373
+ const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
374
374
 
375
375
  if (!witness) {
376
- throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
376
+ throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
377
377
  }
378
378
  return toForeignCallResult(witness.toNoirRepresentation());
379
379
  }
@@ -396,7 +396,7 @@ export class RPCTranslator {
396
396
  foreignOffset: ForeignCallSingle,
397
397
  foreignStatus: ForeignCallSingle,
398
398
  foreignMaxNotes: ForeignCallSingle,
399
- foreignPackedRetrievedNoteLength: ForeignCallSingle,
399
+ foreignPackedHintedNoteLength: ForeignCallSingle,
400
400
  ) {
401
401
  // Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
402
402
  const owner = fromSingle(foreignOwnerIsSome).toBool()
@@ -417,7 +417,7 @@ export class RPCTranslator {
417
417
  const offset = fromSingle(foreignOffset).toNumber();
418
418
  const status = fromSingle(foreignStatus).toNumber();
419
419
  const maxNotes = fromSingle(foreignMaxNotes).toNumber();
420
- const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
420
+ const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
421
421
 
422
422
  const noteDatas = await this.handlerAsUtility().utilityGetNotes(
423
423
  owner,
@@ -438,13 +438,13 @@ export class RPCTranslator {
438
438
  );
439
439
 
440
440
  const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
441
- packAsRetrievedNote({
441
+ packAsHintedNote({
442
442
  contractAddress: noteData.contractAddress,
443
443
  owner: noteData.owner,
444
444
  randomness: noteData.randomness,
445
445
  storageSlot: noteData.storageSlot,
446
446
  noteNonce: noteData.noteNonce,
447
- index: noteData.index,
447
+ isPending: noteData.isPending,
448
448
  note: noteData.note,
449
449
  }),
450
450
  );
@@ -456,11 +456,7 @@ export class RPCTranslator {
456
456
 
457
457
  // At last we convert the array of arrays to a bounded vec of arrays
458
458
  return toForeignCallResult(
459
- arrayOfArraysToBoundedVecOfArrays(
460
- returnDataAsArrayOfForeignCallSingleArrays,
461
- maxNotes,
462
- packedRetrievedNoteLength,
463
- ),
459
+ arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
464
460
  );
465
461
  }
466
462
 
@@ -516,6 +512,15 @@ export class RPCTranslator {
516
512
  return toForeignCallResult([]);
517
513
  }
518
514
 
515
+ async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
516
+ const innerNullifier = fromSingle(foreignInnerNullifier);
517
+ const contractAddress = addressFromSingle(foreignContractAddress);
518
+
519
+ const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
520
+
521
+ return toForeignCallResult([toSingle(new Fr(isPending))]);
522
+ }
523
+
519
524
  async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
520
525
  const innerNullifier = fromSingle(foreignInnerNullifier);
521
526
 
@@ -540,12 +545,23 @@ export class RPCTranslator {
540
545
  );
541
546
  }
542
547
 
543
- async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
548
+ async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
544
549
  const address = addressFromSingle(foreignAddress);
545
550
 
546
- const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
551
+ const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
547
552
 
548
- return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
553
+ // We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
554
+ // with two fields: `some` (a boolean) and `value` (a field array in this case).
555
+ if (result === undefined) {
556
+ // No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
557
+ return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
558
+ } else {
559
+ // Data was found so we set `some` to 1 and return it along with `value`.
560
+ return toForeignCallResult([
561
+ toSingle(new Fr(1)),
562
+ toArray([...result.publicKeys.toFields(), result.partialAddress]),
563
+ ]);
564
+ }
549
565
  }
550
566
 
551
567
  async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
@@ -568,17 +584,14 @@ export class RPCTranslator {
568
584
  );
569
585
  }
570
586
 
571
- async utilityGetNullifierMembershipWitness(
572
- foreignBlockNumber: ForeignCallSingle,
573
- foreignNullifier: ForeignCallSingle,
574
- ) {
575
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
587
+ async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
588
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
576
589
  const nullifier = fromSingle(foreignNullifier);
577
590
 
578
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
591
+ const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
579
592
 
580
593
  if (!witness) {
581
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
594
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
582
595
  }
583
596
  return toForeignCallResult(witness.toNoirRepresentation());
584
597
  }
@@ -639,36 +652,49 @@ export class RPCTranslator {
639
652
  return toForeignCallResult(header.toFields().map(toSingle));
640
653
  }
641
654
 
642
- async utilityGetMembershipWitness(
643
- foreignBlockNumber: ForeignCallSingle,
644
- foreignTreeId: ForeignCallSingle,
645
- foreignLeafValue: ForeignCallSingle,
655
+ async utilityGetNoteHashMembershipWitness(
656
+ foreignAnchorBlockHash: ForeignCallSingle,
657
+ foreignNoteHash: ForeignCallSingle,
646
658
  ) {
647
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
648
- const treeId = fromSingle(foreignTreeId).toNumber();
649
- const leafValue = fromSingle(foreignLeafValue);
659
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
660
+ const noteHash = fromSingle(foreignNoteHash);
661
+
662
+ const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
663
+
664
+ if (!witness) {
665
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
666
+ }
667
+ return toForeignCallResult(witness.toNoirRepresentation());
668
+ }
669
+
670
+ async utilityGetBlockHashMembershipWitness(
671
+ foreignAnchorBlockHash: ForeignCallSingle,
672
+ foreignBlockHash: ForeignCallSingle,
673
+ ) {
674
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
675
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
650
676
 
651
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
677
+ const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
652
678
 
653
679
  if (!witness) {
654
680
  throw new Error(
655
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
681
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
656
682
  );
657
683
  }
658
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
684
+ return toForeignCallResult(witness.toNoirRepresentation());
659
685
  }
660
686
 
661
687
  async utilityGetLowNullifierMembershipWitness(
662
- foreignBlockNumber: ForeignCallSingle,
688
+ foreignBlockHash: ForeignCallSingle,
663
689
  foreignNullifier: ForeignCallSingle,
664
690
  ) {
665
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
691
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
666
692
  const nullifier = fromSingle(foreignNullifier);
667
693
 
668
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
694
+ const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
669
695
 
670
696
  if (!witness) {
671
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
697
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
672
698
  }
673
699
  return toForeignCallResult(witness.toNoirRepresentation());
674
700
  }
@@ -681,7 +707,7 @@ export class RPCTranslator {
681
707
  return toForeignCallResult([]);
682
708
  }
683
709
 
684
- public async utilityValidateEnqueuedNotesAndEvents(
710
+ public async utilityValidateAndStoreEnqueuedNotesAndEvents(
685
711
  foreignContractAddress: ForeignCallSingle,
686
712
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
687
713
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
@@ -690,7 +716,7 @@ export class RPCTranslator {
690
716
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
691
717
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
692
718
 
693
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
719
+ await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
694
720
  contractAddress,
695
721
  noteValidationRequestsArrayBaseSlot,
696
722
  eventValidationRequestsArrayBaseSlot,
@@ -828,10 +854,11 @@ export class RPCTranslator {
828
854
  return toForeignCallResult([]);
829
855
  }
830
856
 
831
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
857
+ async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
832
858
  const slot = fromSingle(foreignSlot);
859
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
833
860
 
834
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
861
+ const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
835
862
 
836
863
  return toForeignCallResult([toSingle(new Fr(value))]);
837
864
  }
@@ -903,11 +930,10 @@ export class RPCTranslator {
903
930
  return toForeignCallResult([]);
904
931
  }
905
932
 
906
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
907
- const innerNullifier = fromSingle(foreignInnerNullifier);
908
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
933
+ async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
934
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
909
935
 
910
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
936
+ const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
911
937
 
912
938
  return toForeignCallResult([toSingle(new Fr(exists))]);
913
939
  }