@aztec/txe 0.0.1-commit.7d4e6cd → 0.0.1-commit.9372f48

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 (48) 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 +3 -2
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +30 -22
  12. package/dest/rpc_translator.d.ts +16 -10
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +53 -40
  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 +34 -178
  18. package/dest/state_machine/index.d.ts +1 -1
  19. package/dest/state_machine/index.d.ts.map +1 -1
  20. package/dest/state_machine/index.js +22 -4
  21. package/dest/state_machine/mock_epoch_cache.d.ts +6 -6
  22. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  23. package/dest/state_machine/mock_epoch_cache.js +7 -7
  24. package/dest/state_machine/synchronizer.d.ts +3 -3
  25. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  26. package/dest/txe_session.d.ts +5 -3
  27. package/dest/txe_session.d.ts.map +1 -1
  28. package/dest/txe_session.js +31 -15
  29. package/dest/util/encoding.d.ts +17 -17
  30. package/dest/utils/block_creation.d.ts +4 -4
  31. package/dest/utils/block_creation.d.ts.map +1 -1
  32. package/dest/utils/block_creation.js +16 -4
  33. package/dest/utils/tx_effect_creation.d.ts +2 -3
  34. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  35. package/dest/utils/tx_effect_creation.js +3 -6
  36. package/package.json +16 -16
  37. package/src/constants.ts +0 -1
  38. package/src/oracle/interfaces.ts +2 -2
  39. package/src/oracle/txe_oracle_public_context.ts +6 -8
  40. package/src/oracle/txe_oracle_top_level_context.ts +50 -24
  41. package/src/rpc_translator.ts +62 -47
  42. package/src/state_machine/archiver.ts +35 -234
  43. package/src/state_machine/index.ts +26 -4
  44. package/src/state_machine/mock_epoch_cache.ts +6 -11
  45. package/src/state_machine/synchronizer.ts +2 -2
  46. package/src/txe_session.ts +38 -24
  47. package/src/utils/block_creation.ts +17 -16
  48. 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
  }
@@ -22,6 +22,7 @@ import {
22
22
  SenderAddressBookStore,
23
23
  SenderTaggingStore,
24
24
  enrichPublicSimulationError,
25
+ syncState,
25
26
  } from '@aztec/pxe/server';
26
27
  import {
27
28
  ExecutionNoteCache,
@@ -80,7 +81,7 @@ import {
80
81
  import type { UInt64 } from '@aztec/stdlib/types';
81
82
  import { ForkCheckpoint } from '@aztec/world-state';
82
83
 
83
- import { DEFAULT_ADDRESS, TXE_JOB_ID } from '../constants.js';
84
+ import { DEFAULT_ADDRESS } from '../constants.js';
84
85
  import type { TXEStateMachine } from '../state_machine/index.js';
85
86
  import type { TXEAccountStore } from '../util/txe_account_store.js';
86
87
  import type { TXEContractStore } from '../util/txe_contract_store.js';
@@ -106,6 +107,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
106
107
  private senderAddressBookStore: SenderAddressBookStore,
107
108
  private capsuleStore: CapsuleStore,
108
109
  private privateEventStore: PrivateEventStore,
110
+ private jobId: string,
109
111
  private nextBlockTimestamp: bigint,
110
112
  private version: Fr,
111
113
  private chainId: Fr,
@@ -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
@@ -299,7 +302,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
299
302
  await this.executeUtilityCall(call);
300
303
  };
301
304
 
302
- await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, utilityExecutor);
305
+ await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
303
306
 
304
307
  const blockNumber = await this.txeGetNextBlockNumber();
305
308
 
@@ -315,6 +318,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
315
318
 
316
319
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
317
320
  const noteCache = new ExecutionNoteCache(protocolNullifier);
321
+ // In production, the account contract sets the min revertible counter before calling the app function.
322
+ // Since TXE bypasses the account contract, we simulate this by setting minRevertibleSideEffectCounter to 1,
323
+ // marking all side effects as revertible.
324
+ const minRevertibleSideEffectCounter = 1;
325
+ await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
318
326
  const taggingIndexCache = new ExecutionTaggingIndexCache();
319
327
 
320
328
  const simulator = new WASMSimulator();
@@ -338,15 +346,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
338
346
  this.keyStore,
339
347
  this.addressStore,
340
348
  this.stateMachine.node,
341
- this.stateMachine.anchorBlockStore,
342
349
  this.senderTaggingStore,
343
350
  this.recipientTaggingStore,
344
351
  this.senderAddressBookStore,
345
352
  this.capsuleStore,
346
353
  this.privateEventStore,
347
- TXE_JOB_ID,
348
- 0,
349
- 1,
354
+ this.jobId,
355
+ 0, // totalPublicArgsCount
356
+ minRevertibleSideEffectCounter, // (start) sideEffectCounter
350
357
  undefined, // log
351
358
  undefined, // scopes
352
359
  /**
@@ -382,19 +389,21 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
382
389
  }),
383
390
  );
384
391
 
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);
392
+ noteCache.finish();
393
+ const nonceGenerator = noteCache.getNonceGenerator();
394
+ result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
389
395
  } catch (err) {
390
396
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
391
397
  }
392
398
 
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);
399
+ // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
400
+ // the nonce generator for the note hashes.
401
+ // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
402
+ const { publicInputs } = await generateSimulatedProvingResult(
403
+ result,
404
+ this.contractStore,
405
+ minRevertibleSideEffectCounter,
406
+ );
398
407
 
399
408
  const globals = makeGlobalVariables();
400
409
  globals.blockNumber = blockNumber;
@@ -405,7 +414,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
405
414
 
406
415
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
407
416
 
408
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
417
+ const bindings = this.logger.getBindings();
418
+ const contractsDB = new PublicContractsDB(
419
+ new TXEPublicContractDataSource(blockNumber, this.contractStore),
420
+ bindings,
421
+ );
409
422
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
410
423
  const config = PublicSimulatorConfig.from({
411
424
  skipFeeEnforcement: true,
@@ -418,8 +431,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
418
431
  globals,
419
432
  guardedMerkleTrees,
420
433
  contractsDB,
421
- new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config),
434
+ new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings),
422
435
  new TestDateProvider(),
436
+ undefined,
437
+ createLogger('simulator:public-processor', bindings),
423
438
  );
424
439
 
425
440
  const tx = await Tx.create({
@@ -516,7 +531,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
516
531
 
517
532
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
518
533
 
519
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
534
+ const bindings2 = this.logger.getBindings();
535
+ const contractsDB = new PublicContractsDB(
536
+ new TXEPublicContractDataSource(blockNumber, this.contractStore),
537
+ bindings2,
538
+ );
520
539
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
521
540
  const config = PublicSimulatorConfig.from({
522
541
  skipFeeEnforcement: true,
@@ -525,8 +544,16 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
525
544
  collectStatistics: false,
526
545
  collectCallMetadata: true,
527
546
  });
528
- const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
529
- const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
547
+ const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
548
+ const processor = new PublicProcessor(
549
+ globals,
550
+ guardedMerkleTrees,
551
+ contractsDB,
552
+ simulator,
553
+ new TestDateProvider(),
554
+ undefined,
555
+ createLogger('simulator:public-processor', bindings2),
556
+ );
530
557
 
531
558
  // We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
532
559
  // kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
@@ -636,7 +663,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
636
663
  }
637
664
 
638
665
  // Sync notes before executing utility function to discover notes from previous transactions
639
- await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, async call => {
666
+ await syncState(targetContractAddress, this.contractStore, functionSelector, async call => {
640
667
  await this.executeUtilityCall(call);
641
668
  });
642
669
 
@@ -677,12 +704,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
677
704
  this.keyStore,
678
705
  this.addressStore,
679
706
  this.stateMachine.node,
680
- this.stateMachine.anchorBlockStore,
681
707
  this.recipientTaggingStore,
682
708
  this.senderAddressBookStore,
683
709
  this.capsuleStore,
684
710
  this.privateEventStore,
685
- TXE_JOB_ID,
711
+ this.jobId,
686
712
  );
687
713
  const acirExecutionResult = await new WASMSimulator()
688
714
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
@@ -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';
@@ -346,34 +346,34 @@ export class RPCTranslator {
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
 
@@ -568,17 +573,14 @@ export class RPCTranslator {
568
573
  );
569
574
  }
570
575
 
571
- async utilityGetNullifierMembershipWitness(
572
- foreignBlockNumber: ForeignCallSingle,
573
- foreignNullifier: ForeignCallSingle,
574
- ) {
575
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
576
+ async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
577
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
576
578
  const nullifier = fromSingle(foreignNullifier);
577
579
 
578
- const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
580
+ const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
579
581
 
580
582
  if (!witness) {
581
- throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
583
+ throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
582
584
  }
583
585
  return toForeignCallResult(witness.toNoirRepresentation());
584
586
  }
@@ -639,36 +641,49 @@ export class RPCTranslator {
639
641
  return toForeignCallResult(header.toFields().map(toSingle));
640
642
  }
641
643
 
642
- async utilityGetMembershipWitness(
643
- foreignBlockNumber: ForeignCallSingle,
644
- foreignTreeId: ForeignCallSingle,
645
- foreignLeafValue: ForeignCallSingle,
644
+ async utilityGetNoteHashMembershipWitness(
645
+ foreignAnchorBlockHash: ForeignCallSingle,
646
+ foreignNoteHash: ForeignCallSingle,
646
647
  ) {
647
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
648
- const treeId = fromSingle(foreignTreeId).toNumber();
649
- const leafValue = fromSingle(foreignLeafValue);
648
+ const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
649
+ const noteHash = fromSingle(foreignNoteHash);
650
650
 
651
- const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
651
+ const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
652
+
653
+ if (!witness) {
654
+ throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
655
+ }
656
+ return toForeignCallResult(witness.toNoirRepresentation());
657
+ }
658
+
659
+ async utilityGetBlockHashMembershipWitness(
660
+ foreignAnchorBlockHash: ForeignCallSingle,
661
+ foreignBlockHash: ForeignCallSingle,
662
+ ) {
663
+ const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
664
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
665
+
666
+ const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
652
667
 
653
668
  if (!witness) {
654
669
  throw new Error(
655
- `Membership witness in tree ${MerkleTreeId[treeId]} not found for value ${leafValue} at block ${blockNumber}.`,
670
+ `Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
656
671
  );
657
672
  }
658
- return toForeignCallResult([toSingle(witness[0]), toArray(witness.slice(1))]);
673
+ return toForeignCallResult(witness.toNoirRepresentation());
659
674
  }
660
675
 
661
676
  async utilityGetLowNullifierMembershipWitness(
662
- foreignBlockNumber: ForeignCallSingle,
677
+ foreignBlockHash: ForeignCallSingle,
663
678
  foreignNullifier: ForeignCallSingle,
664
679
  ) {
665
- const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
680
+ const blockHash = new BlockHash(fromSingle(foreignBlockHash));
666
681
  const nullifier = fromSingle(foreignNullifier);
667
682
 
668
- const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
683
+ const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
669
684
 
670
685
  if (!witness) {
671
- throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
686
+ throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
672
687
  }
673
688
  return toForeignCallResult(witness.toNoirRepresentation());
674
689
  }
@@ -681,7 +696,7 @@ export class RPCTranslator {
681
696
  return toForeignCallResult([]);
682
697
  }
683
698
 
684
- public async utilityValidateEnqueuedNotesAndEvents(
699
+ public async utilityValidateAndStoreEnqueuedNotesAndEvents(
685
700
  foreignContractAddress: ForeignCallSingle,
686
701
  foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
687
702
  foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
@@ -690,7 +705,7 @@ export class RPCTranslator {
690
705
  const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
691
706
  const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
692
707
 
693
- await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
708
+ await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
694
709
  contractAddress,
695
710
  noteValidationRequestsArrayBaseSlot,
696
711
  eventValidationRequestsArrayBaseSlot,
@@ -828,10 +843,11 @@ export class RPCTranslator {
828
843
  return toForeignCallResult([]);
829
844
  }
830
845
 
831
- async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
846
+ async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
832
847
  const slot = fromSingle(foreignSlot);
848
+ const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
833
849
 
834
- const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
850
+ const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
835
851
 
836
852
  return toForeignCallResult([toSingle(new Fr(value))]);
837
853
  }
@@ -903,11 +919,10 @@ export class RPCTranslator {
903
919
  return toForeignCallResult([]);
904
920
  }
905
921
 
906
- async avmOpcodeNullifierExists(foreignInnerNullifier: ForeignCallSingle, foreignTargetAddress: ForeignCallSingle) {
907
- const innerNullifier = fromSingle(foreignInnerNullifier);
908
- const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
922
+ async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
923
+ const siloedNullifier = fromSingle(foreignSiloedNullifier);
909
924
 
910
- const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
925
+ const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
911
926
 
912
927
  return toForeignCallResult([toSingle(new Fr(exists))]);
913
928
  }