@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701

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 (73) hide show
  1. package/dest/constants.d.ts +3 -0
  2. package/dest/constants.d.ts.map +1 -0
  3. package/dest/constants.js +2 -0
  4. package/dest/oracle/interfaces.d.ts +2 -2
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +2 -2
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +3 -2
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +16 -13
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +77 -61
  12. package/dest/rpc_translator.d.ts +15 -9
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +49 -35
  15. package/dest/state_machine/archiver.d.ts +20 -67
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +57 -178
  18. package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +13 -10
  21. package/dest/state_machine/global_variable_builder.d.ts +2 -2
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +1 -1
  24. package/dest/state_machine/index.d.ts +4 -4
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +28 -10
  27. package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +10 -7
  30. package/dest/state_machine/synchronizer.d.ts +3 -3
  31. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  32. package/dest/txe_session.d.ts +17 -14
  33. package/dest/txe_session.d.ts.map +1 -1
  34. package/dest/txe_session.js +86 -48
  35. package/dest/util/encoding.d.ts +17 -17
  36. package/dest/util/txe_account_store.d.ts +10 -0
  37. package/dest/util/txe_account_store.d.ts.map +1 -0
  38. package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
  39. package/dest/util/txe_contract_store.d.ts +12 -0
  40. package/dest/util/txe_contract_store.d.ts.map +1 -0
  41. package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
  42. package/dest/util/txe_public_contract_data_source.d.ts +4 -4
  43. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  44. package/dest/util/txe_public_contract_data_source.js +10 -10
  45. package/dest/utils/block_creation.d.ts +4 -4
  46. package/dest/utils/block_creation.d.ts.map +1 -1
  47. package/dest/utils/block_creation.js +16 -5
  48. package/dest/utils/tx_effect_creation.d.ts +2 -3
  49. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  50. package/dest/utils/tx_effect_creation.js +3 -6
  51. package/package.json +16 -16
  52. package/src/constants.ts +3 -0
  53. package/src/index.ts +1 -1
  54. package/src/oracle/interfaces.ts +1 -1
  55. package/src/oracle/txe_oracle_public_context.ts +3 -3
  56. package/src/oracle/txe_oracle_top_level_context.ts +110 -78
  57. package/src/rpc_translator.ts +53 -45
  58. package/src/state_machine/archiver.ts +52 -220
  59. package/src/state_machine/dummy_p2p_client.ts +18 -13
  60. package/src/state_machine/global_variable_builder.ts +1 -1
  61. package/src/state_machine/index.ts +30 -8
  62. package/src/state_machine/mock_epoch_cache.ts +10 -11
  63. package/src/state_machine/synchronizer.ts +2 -2
  64. package/src/txe_session.ts +165 -86
  65. package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
  66. package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
  67. package/src/util/txe_public_contract_data_source.ts +9 -9
  68. package/src/utils/block_creation.ts +17 -16
  69. package/src/utils/tx_effect_creation.ts +3 -11
  70. package/dest/util/txe_account_data_provider.d.ts +0 -10
  71. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  72. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  73. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"block_creation.d.ts","sourceRoot":"","sources":["../../src/utils/block_creation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAQ,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAwC,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAExE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,aAAa,CAAC,CAcxB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,OAAO,CAAC,CAWlB"}
1
+ {"version":3,"file":"block_creation.d.ts","sourceRoot":"","sources":["../../src/utils/block_creation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAA2C,MAAM,iCAAiC,CAAC;AAEvG,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAQ,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAwC,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAExE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,OAAO,CAAC,CAelB"}
@@ -1,9 +1,10 @@
1
1
  import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
3
  import { padArrayEnd } from '@aztec/foundation/collection';
3
4
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { Body, L2Block, L2BlockHeader } from '@aztec/stdlib/block';
5
- import { makeContentCommitment } from '@aztec/stdlib/testing';
5
+ import { Body, L2Block } from '@aztec/stdlib/block';
6
6
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
7
+ import { BlockHeader } from '@aztec/stdlib/tx';
7
8
  /**
8
9
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
9
10
  * @param blockNumber The number for the block in which there is a single transaction.
@@ -20,7 +21,14 @@ export async function insertTxEffectIntoWorldTrees(txEffect, worldTrees) {
20
21
  export async function makeTXEBlockHeader(worldTrees, globalVariables) {
21
22
  const stateReference = await worldTrees.getStateReference();
22
23
  const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
23
- return new L2BlockHeader(new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, globalVariables, Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO);
24
+ return BlockHeader.from({
25
+ lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
26
+ spongeBlobHash: Fr.ZERO,
27
+ state: stateReference,
28
+ globalVariables,
29
+ totalFees: Fr.ZERO,
30
+ totalManaUsed: Fr.ZERO
31
+ });
24
32
  }
25
33
  /**
26
34
  * Creates an L2Block with proper archive chaining.
@@ -37,9 +45,12 @@ export async function makeTXEBlockHeader(worldTrees, globalVariables) {
37
45
  */ export async function makeTXEBlock(worldTrees, globalVariables, txEffects) {
38
46
  const header = await makeTXEBlockHeader(worldTrees, globalVariables);
39
47
  // Update the archive tree with this block's header hash
40
- await worldTrees.updateArchive(header.toBlockHeader());
48
+ await worldTrees.updateArchive(header);
41
49
  // Get the new archive state after updating
42
50
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
43
51
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
44
- return new L2Block(newArchive, header, new Body(txEffects));
52
+ // L2Block requires checkpointNumber and indexWithinCheckpoint
53
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
54
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
55
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
45
56
  }
@@ -1,6 +1,5 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
- import { Fr } from '@aztec/foundation/curves/bn254';
3
2
  import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
4
3
  import { TxEffect } from '@aztec/stdlib/tx';
5
- export declare function makeTxEffect(noteCache: ExecutionNoteCache, protocolNullifier: Fr, txBlockNumber: BlockNumber): Promise<TxEffect>;
6
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfZWZmZWN0X2NyZWF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvdHhfZWZmZWN0X2NyZWF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUM5RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsTUFBTSxzQkFBc0IsQ0FBQztBQUUvRCxPQUFPLEVBQUUsUUFBUSxFQUFVLE1BQU0sa0JBQWtCLENBQUM7QUFFcEQsd0JBQXNCLFlBQVksQ0FDaEMsU0FBUyxFQUFFLGtCQUFrQixFQUM3QixpQkFBaUIsRUFBRSxFQUFFLEVBQ3JCLGFBQWEsRUFBRSxXQUFXLEdBQ3pCLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0EyQm5CIn0=
4
+ export declare function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect>;
5
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhfZWZmZWN0X2NyZWF0aW9uLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvdHhfZWZmZWN0X2NyZWF0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU5RCxPQUFPLEtBQUssRUFBRSxrQkFBa0IsRUFBRSxNQUFNLHNCQUFzQixDQUFDO0FBRS9ELE9BQU8sRUFBRSxRQUFRLEVBQVUsTUFBTSxrQkFBa0IsQ0FBQztBQUVwRCx3QkFBc0IsWUFBWSxDQUFDLFNBQVMsRUFBRSxrQkFBa0IsRUFBRSxhQUFhLEVBQUUsV0FBVyxHQUFHLE9BQU8sQ0FBQyxRQUFRLENBQUMsQ0F1Qi9HIn0=
@@ -1 +1 @@
1
- {"version":3,"file":"tx_effect_creation.d.ts","sourceRoot":"","sources":["../../src/utils/tx_effect_creation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAU,MAAM,kBAAkB,CAAC;AAEpD,wBAAsB,YAAY,CAChC,SAAS,EAAE,kBAAkB,EAC7B,iBAAiB,EAAE,EAAE,EACrB,aAAa,EAAE,WAAW,GACzB,OAAO,CAAC,QAAQ,CAAC,CA2BnB"}
1
+ {"version":3,"file":"tx_effect_creation.d.ts","sourceRoot":"","sources":["../../src/utils/tx_effect_creation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAU,MAAM,kBAAkB,CAAC;AAEpD,wBAAsB,YAAY,CAAC,SAAS,EAAE,kBAAkB,EAAE,aAAa,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAuB/G"}
@@ -1,16 +1,13 @@
1
1
  import { Fr } from '@aztec/foundation/curves/bn254';
2
2
  import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
3
3
  import { TxEffect, TxHash } from '@aztec/stdlib/tx';
4
- export async function makeTxEffect(noteCache, protocolNullifier, txBlockNumber) {
4
+ export async function makeTxEffect(noteCache, txBlockNumber) {
5
5
  const txEffect = TxEffect.empty();
6
- const { usedProtocolNullifierForNonces } = noteCache.finish();
7
- const nonceGenerator = usedProtocolNullifierForNonces ? protocolNullifier : noteCache.getAllNullifiers()[0];
6
+ noteCache.finish();
7
+ const nonceGenerator = noteCache.getNonceGenerator();
8
8
  txEffect.noteHashes = await Promise.all(noteCache.getAllNotes().map(async (pendingNote, i)=>computeUniqueNoteHash(await computeNoteHashNonce(nonceGenerator, i), await siloNoteHash(pendingNote.note.contractAddress, pendingNote.noteHashForConsumption))));
9
9
  // Nullifiers are already siloed
10
10
  txEffect.nullifiers = noteCache.getAllNullifiers();
11
- if (usedProtocolNullifierForNonces) {
12
- txEffect.nullifiers.unshift(protocolNullifier);
13
- }
14
11
  txEffect.txHash = new TxHash(new Fr(txBlockNumber));
15
12
  return txEffect;
16
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "0.0.1-commit.03f7ef2",
3
+ "version": "0.0.1-commit.0b941701",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "bin": "./dest/bin/index.js",
@@ -61,27 +61,27 @@
61
61
  ]
62
62
  },
63
63
  "dependencies": {
64
- "@aztec/accounts": "0.0.1-commit.03f7ef2",
65
- "@aztec/archiver": "0.0.1-commit.03f7ef2",
66
- "@aztec/aztec-node": "0.0.1-commit.03f7ef2",
67
- "@aztec/aztec.js": "0.0.1-commit.03f7ef2",
68
- "@aztec/bb-prover": "0.0.1-commit.03f7ef2",
69
- "@aztec/constants": "0.0.1-commit.03f7ef2",
70
- "@aztec/foundation": "0.0.1-commit.03f7ef2",
71
- "@aztec/key-store": "0.0.1-commit.03f7ef2",
72
- "@aztec/kv-store": "0.0.1-commit.03f7ef2",
73
- "@aztec/protocol-contracts": "0.0.1-commit.03f7ef2",
74
- "@aztec/pxe": "0.0.1-commit.03f7ef2",
75
- "@aztec/simulator": "0.0.1-commit.03f7ef2",
76
- "@aztec/stdlib": "0.0.1-commit.03f7ef2",
77
- "@aztec/world-state": "0.0.1-commit.03f7ef2",
64
+ "@aztec/accounts": "0.0.1-commit.0b941701",
65
+ "@aztec/archiver": "0.0.1-commit.0b941701",
66
+ "@aztec/aztec-node": "0.0.1-commit.0b941701",
67
+ "@aztec/aztec.js": "0.0.1-commit.0b941701",
68
+ "@aztec/bb-prover": "0.0.1-commit.0b941701",
69
+ "@aztec/constants": "0.0.1-commit.0b941701",
70
+ "@aztec/foundation": "0.0.1-commit.0b941701",
71
+ "@aztec/key-store": "0.0.1-commit.0b941701",
72
+ "@aztec/kv-store": "0.0.1-commit.0b941701",
73
+ "@aztec/protocol-contracts": "0.0.1-commit.0b941701",
74
+ "@aztec/pxe": "0.0.1-commit.0b941701",
75
+ "@aztec/simulator": "0.0.1-commit.0b941701",
76
+ "@aztec/stdlib": "0.0.1-commit.0b941701",
77
+ "@aztec/world-state": "0.0.1-commit.0b941701",
78
78
  "zod": "^3.23.8"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@jest/globals": "^30.0.0",
82
82
  "@types/jest": "^30.0.0",
83
83
  "@types/node": "^22.15.17",
84
- "@typescript/native-preview": "7.0.0-dev.20251126.1",
84
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
85
85
  "jest": "^30.0.0",
86
86
  "jest-mock-extended": "^4.0.0",
87
87
  "ts-node": "^10.9.1",
@@ -0,0 +1,3 @@
1
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+
3
+ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
package/src/index.ts CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  fromSingle,
34
34
  toSingle,
35
35
  } from './util/encoding.js';
36
- import type { ContractArtifactWithHash } from './util/txe_contract_data_provider.js';
36
+ import type { ContractArtifactWithHash } from './util/txe_contract_store.js';
37
37
 
38
38
  const sessions = new Map<number, TXESession>();
39
39
 
@@ -35,7 +35,7 @@ export interface IAvmExecutionOracle {
35
35
  avmOpcodeEmitNoteHash(noteHash: Fr): Promise<void>;
36
36
  avmOpcodeNullifierExists(innerNullifier: Fr, targetAddress: AztecAddress): Promise<boolean>;
37
37
  avmOpcodeStorageWrite(slot: Fr, value: Fr): Promise<void>;
38
- avmOpcodeStorageRead(slot: Fr): Promise<Fr>;
38
+ avmOpcodeStorageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr>;
39
39
  }
40
40
 
41
41
  /**
@@ -101,8 +101,8 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
101
101
  ]);
102
102
  }
103
103
 
104
- async avmOpcodeStorageRead(slot: Fr): Promise<Fr> {
105
- const leafSlot = await computePublicDataTreeLeafSlot(this.contractAddress, slot);
104
+ async avmOpcodeStorageRead(slot: Fr, contractAddress: AztecAddress): Promise<Fr> {
105
+ const leafSlot = await computePublicDataTreeLeafSlot(contractAddress, slot);
106
106
 
107
107
  const lowLeafResult = await this.forkedWorldTrees.getPreviousValueIndex(
108
108
  MerkleTreeId.PUBLIC_DATA_TREE,
@@ -119,7 +119,7 @@ export class TXEOraclePublicContext implements IAvmExecutionOracle {
119
119
  )) as PublicDataTreeLeafPreimage
120
120
  ).leaf.value;
121
121
 
122
- this.logger.debug('AVM storage read', { slot, value });
122
+ this.logger.debug('AVM storage read', { slot, contractAddress, value });
123
123
 
124
124
  return value;
125
125
  }
@@ -13,14 +13,16 @@ import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@az
13
13
  import { TestDateProvider } from '@aztec/foundation/timer';
14
14
  import type { KeyStore } from '@aztec/key-store';
15
15
  import {
16
- AddressDataProvider,
17
- CapsuleDataProvider,
18
- NoteDataProvider,
16
+ AddressStore,
17
+ CapsuleStore,
18
+ NoteStore,
19
19
  ORACLE_VERSION,
20
- PrivateEventDataProvider,
21
- RecipientTaggingDataProvider,
22
- SenderTaggingDataProvider,
20
+ PrivateEventStore,
21
+ RecipientTaggingStore,
22
+ SenderAddressBookStore,
23
+ SenderTaggingStore,
23
24
  enrichPublicSimulationError,
25
+ syncState,
24
26
  } from '@aztec/pxe/server';
25
27
  import {
26
28
  ExecutionNoteCache,
@@ -48,7 +50,7 @@ import {
48
50
  PublicContractsDB,
49
51
  PublicProcessor,
50
52
  } from '@aztec/simulator/server';
51
- import { type ContractArtifact, EventSelector, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
53
+ import { type ContractArtifact, EventSelector, FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
52
54
  import { AuthWitness } from '@aztec/stdlib/auth-witness';
53
55
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
54
56
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
@@ -79,10 +81,10 @@ import {
79
81
  import type { UInt64 } from '@aztec/stdlib/types';
80
82
  import { ForkCheckpoint } from '@aztec/world-state';
81
83
 
84
+ import { DEFAULT_ADDRESS } from '../constants.js';
82
85
  import type { TXEStateMachine } from '../state_machine/index.js';
83
- import { DEFAULT_ADDRESS } from '../txe_session.js';
84
- import type { TXEAccountDataProvider } from '../util/txe_account_data_provider.js';
85
- import type { TXEContractDataProvider } from '../util/txe_contract_data_provider.js';
86
+ import type { TXEAccountStore } from '../util/txe_account_store.js';
87
+ import type { TXEContractStore } from '../util/txe_contract_store.js';
86
88
  import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
87
89
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
88
90
  import type { ITxeExecutionOracle } from './interfaces.js';
@@ -95,15 +97,17 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
95
97
 
96
98
  constructor(
97
99
  private stateMachine: TXEStateMachine,
98
- private contractDataProvider: TXEContractDataProvider,
99
- private noteDataProvider: NoteDataProvider,
100
+ private contractStore: TXEContractStore,
101
+ private noteStore: NoteStore,
100
102
  private keyStore: KeyStore,
101
- private addressDataProvider: AddressDataProvider,
102
- private accountDataProvider: TXEAccountDataProvider,
103
- private senderTaggingDataProvider: SenderTaggingDataProvider,
104
- private recipientTaggingDataProvider: RecipientTaggingDataProvider,
105
- private capsuleDataProvider: CapsuleDataProvider,
106
- private privateEventDataProvider: PrivateEventDataProvider,
103
+ private addressStore: AddressStore,
104
+ private accountStore: TXEAccountStore,
105
+ private senderTaggingStore: SenderTaggingStore,
106
+ private recipientTaggingStore: RecipientTaggingStore,
107
+ private senderAddressBookStore: SenderAddressBookStore,
108
+ private capsuleStore: CapsuleStore,
109
+ private privateEventStore: PrivateEventStore,
110
+ private jobId: string,
107
111
  private nextBlockTimestamp: bigint,
108
112
  private version: Fr,
109
113
  private chainId: Fr,
@@ -154,7 +158,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
154
158
  }
155
159
 
156
160
  async txeGetLastTxEffects() {
157
- 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);
158
163
 
159
164
  if (block!.body.txEffects.length != 1) {
160
165
  // Note that calls like env.mine() will result in blocks with no transactions, hitting this
@@ -168,7 +173,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
168
173
 
169
174
  async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
170
175
  return (
171
- await this.privateEventDataProvider.getPrivateEvents(selector, {
176
+ await this.privateEventStore.getPrivateEvents(selector, {
172
177
  contractAddress,
173
178
  scopes: [scope],
174
179
  fromBlock: 0,
@@ -204,8 +209,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
204
209
  if (!secret.equals(Fr.ZERO)) {
205
210
  await this.txeAddAccount(artifact, instance, secret);
206
211
  } else {
207
- await this.contractDataProvider.addContractInstance(instance);
208
- await this.contractDataProvider.addContractArtifact(instance.currentContractClassId, artifact);
212
+ await this.contractStore.addContractInstance(instance);
213
+ await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
209
214
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
210
215
  }
211
216
  }
@@ -214,12 +219,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
214
219
  const partialAddress = await computePartialAddress(instance);
215
220
 
216
221
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
217
- await this.contractDataProvider.addContractInstance(instance);
218
- await this.contractDataProvider.addContractArtifact(instance.currentContractClassId, artifact);
222
+ await this.contractStore.addContractInstance(instance);
223
+ await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
219
224
 
220
225
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
221
- await this.accountDataProvider.setAccount(completeAddress.address, completeAddress);
222
- await this.addressDataProvider.addCompleteAddress(completeAddress);
226
+ await this.accountStore.setAccount(completeAddress.address, completeAddress);
227
+ await this.addressStore.addCompleteAddress(completeAddress);
223
228
  this.logger.debug(`Created account ${completeAddress.address}`);
224
229
 
225
230
  return completeAddress;
@@ -228,15 +233,15 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
228
233
  async txeCreateAccount(secret: Fr) {
229
234
  // This is a foot gun !
230
235
  const completeAddress = await this.keyStore.addAccount(secret, secret);
231
- await this.accountDataProvider.setAccount(completeAddress.address, completeAddress);
232
- await this.addressDataProvider.addCompleteAddress(completeAddress);
236
+ await this.accountStore.setAccount(completeAddress.address, completeAddress);
237
+ await this.addressStore.addCompleteAddress(completeAddress);
233
238
  this.logger.debug(`Created account ${completeAddress.address}`);
234
239
 
235
240
  return completeAddress;
236
241
  }
237
242
 
238
243
  async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
239
- const account = await this.accountDataProvider.getAccount(address);
244
+ const account = await this.accountStore.getAccount(address);
240
245
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
241
246
 
242
247
  const schnorr = new Schnorr();
@@ -281,10 +286,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
281
286
  isStaticCall: boolean = false,
282
287
  ) {
283
288
  this.logger.verbose(
284
- `Executing external function ${await this.contractDataProvider.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
289
+ `Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
285
290
  );
286
291
 
287
- const artifact = await this.contractDataProvider.getFunctionArtifact(targetContractAddress, functionSelector);
292
+ const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
288
293
  if (!artifact) {
289
294
  const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)'))
290
295
  ? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.'
@@ -292,22 +297,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
292
297
  throw new Error(message);
293
298
  }
294
299
 
300
+ // Sync notes before executing private function to discover notes from previous transactions
301
+ const utilityExecutor = async (call: FunctionCall) => {
302
+ await this.executeUtilityCall(call);
303
+ };
304
+
305
+ await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
306
+
295
307
  const blockNumber = await this.txeGetNextBlockNumber();
296
308
 
297
309
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
298
310
 
299
311
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
300
-
301
312
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
302
-
303
313
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
304
314
 
305
315
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
306
316
 
307
- const blockHeader = await this.stateMachine.anchorBlockDataProvider.getBlockHeader();
317
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
308
318
 
309
319
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
310
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);
311
326
  const taggingIndexCache = new ExecutionTaggingIndexCache();
312
327
 
313
328
  const simulator = new WASMSimulator();
@@ -318,6 +333,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
318
333
  callContext,
319
334
  /** Header of a block whose state is used during private execution (not the block the transaction is included in). */
320
335
  blockHeader,
336
+ utilityExecutor,
321
337
  /** List of transient auth witnesses to be used during this simulation */
322
338
  Array.from(this.authwits.values()),
323
339
  /** List of transient auth witnesses to be used during this simulation */
@@ -325,18 +341,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
325
341
  HashedValuesCache.create([new HashedValues(args, argsHash)]),
326
342
  noteCache,
327
343
  taggingIndexCache,
328
- this.contractDataProvider,
329
- this.noteDataProvider,
344
+ this.contractStore,
345
+ this.noteStore,
330
346
  this.keyStore,
331
- this.addressDataProvider,
347
+ this.addressStore,
332
348
  this.stateMachine.node,
333
- this.stateMachine.anchorBlockDataProvider,
334
- this.senderTaggingDataProvider,
335
- this.recipientTaggingDataProvider,
336
- this.capsuleDataProvider,
337
- this.privateEventDataProvider,
338
- 0,
339
- 1,
349
+ this.stateMachine.anchorBlockStore,
350
+ this.senderTaggingStore,
351
+ this.recipientTaggingStore,
352
+ this.senderAddressBookStore,
353
+ this.capsuleStore,
354
+ this.privateEventStore,
355
+ this.jobId,
356
+ 0, // totalPublicArgsCount
357
+ minRevertibleSideEffectCounter, // (start) sideEffectCounter
340
358
  undefined, // log
341
359
  undefined, // scopes
342
360
  /**
@@ -372,19 +390,21 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
372
390
  }),
373
391
  );
374
392
 
375
- // TXE's top level context does not track side effect counters, and as such, minRevertibleSideEffectCounter is always 0.
376
- // This has the unfortunate consequence of always producing revertible nullifiers, which means we
377
- // must set the firstNullifierHint to Fr.ZERO so the txRequestHash is always used as nonce generator
378
- result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
393
+ noteCache.finish();
394
+ const nonceGenerator = noteCache.getNonceGenerator();
395
+ result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
379
396
  } catch (err) {
380
397
  throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
381
398
  }
382
399
 
383
- // According to the protocol rules, the nonce generator for the note hashes
384
- // can either be the first nullifier in the tx or the hash of the initial tx request
385
- // if there are none.
386
- const nonceGenerator = result.firstNullifier.equals(Fr.ZERO) ? protocolNullifier : result.firstNullifier;
387
- const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractDataProvider);
400
+ // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
401
+ // the nonce generator for the note hashes.
402
+ // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
403
+ const { publicInputs } = await generateSimulatedProvingResult(
404
+ result,
405
+ this.contractStore,
406
+ minRevertibleSideEffectCounter,
407
+ );
388
408
 
389
409
  const globals = makeGlobalVariables();
390
410
  globals.blockNumber = blockNumber;
@@ -395,7 +415,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
395
415
 
396
416
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
397
417
 
398
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractDataProvider));
418
+ const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
399
419
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
400
420
  const config = PublicSimulatorConfig.from({
401
421
  skipFeeEnforcement: true,
@@ -434,7 +454,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
434
454
  } else if (!processedTx.revertCode.isOK()) {
435
455
  if (processedTx.revertReason) {
436
456
  try {
437
- await enrichPublicSimulationError(processedTx.revertReason, this.contractDataProvider, this.logger);
457
+ await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
438
458
  // eslint-disable-next-line no-empty
439
459
  } catch {}
440
460
  throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
@@ -479,7 +499,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
479
499
  isStaticCall: boolean,
480
500
  ) {
481
501
  this.logger.verbose(
482
- `Executing public function ${await this.contractDataProvider.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
502
+ `Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
483
503
  );
484
504
 
485
505
  const blockNumber = await this.txeGetNextBlockNumber();
@@ -492,7 +512,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
492
512
 
493
513
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
494
514
 
495
- const anchorBlockHeader = await this.stateMachine.anchorBlockDataProvider.getBlockHeader();
515
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
496
516
 
497
517
  const calldataHash = await computeCalldataHash(calldata);
498
518
  const calldataHashedValues = new HashedValues(calldata, calldataHash);
@@ -506,7 +526,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
506
526
 
507
527
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
508
528
 
509
- const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractDataProvider));
529
+ const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
510
530
  const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
511
531
  const config = PublicSimulatorConfig.from({
512
532
  skipFeeEnforcement: true,
@@ -574,7 +594,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
574
594
  } else if (!processedTx.revertCode.isOK()) {
575
595
  if (processedTx.revertReason) {
576
596
  try {
577
- await enrichPublicSimulationError(processedTx.revertReason, this.contractDataProvider, this.logger);
597
+ await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
578
598
  // eslint-disable-next-line no-empty
579
599
  } catch {}
580
600
  throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
@@ -620,21 +640,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
620
640
  functionSelector: FunctionSelector,
621
641
  args: Fr[],
622
642
  ) {
623
- const artifact = await this.contractDataProvider.getFunctionArtifact(targetContractAddress, functionSelector);
643
+ const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
624
644
  if (!artifact) {
625
645
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
626
646
  }
627
647
 
628
- const call = {
629
- name: artifact.name,
630
- selector: functionSelector,
631
- to: targetContractAddress,
632
- };
648
+ // Sync notes before executing utility function to discover notes from previous transactions
649
+ await syncState(targetContractAddress, this.contractStore, functionSelector, async call => {
650
+ await this.executeUtilityCall(call);
651
+ });
633
652
 
634
- const entryPointArtifact = await this.contractDataProvider.getFunctionArtifactWithDebugMetadata(
635
- call.to,
636
- call.selector,
653
+ const call = new FunctionCall(
654
+ artifact.name,
655
+ targetContractAddress,
656
+ functionSelector,
657
+ FunctionType.UTILITY,
658
+ false,
659
+ false,
660
+ args,
661
+ [],
637
662
  );
663
+
664
+ return this.executeUtilityCall(call);
665
+ }
666
+
667
+ private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
668
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
638
669
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
639
670
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
640
671
  }
@@ -645,25 +676,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
645
676
  });
646
677
 
647
678
  try {
648
- const anchorBlockHeader = await this.stateMachine.anchorBlockDataProvider.getBlockHeader();
679
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
649
680
  const oracle = new UtilityExecutionOracle(
650
681
  call.to,
651
682
  [],
652
683
  [],
653
684
  anchorBlockHeader,
654
- this.contractDataProvider,
655
- this.noteDataProvider,
685
+ this.contractStore,
686
+ this.noteStore,
656
687
  this.keyStore,
657
- this.addressDataProvider,
688
+ this.addressStore,
658
689
  this.stateMachine.node,
659
- this.stateMachine.anchorBlockDataProvider,
660
- this.senderTaggingDataProvider,
661
- this.recipientTaggingDataProvider,
662
- this.capsuleDataProvider,
663
- this.privateEventDataProvider,
690
+ this.stateMachine.anchorBlockStore,
691
+ this.recipientTaggingStore,
692
+ this.senderAddressBookStore,
693
+ this.capsuleStore,
694
+ this.privateEventStore,
695
+ this.jobId,
664
696
  );
665
697
  const acirExecutionResult = await new WASMSimulator()
666
- .executeUserCircuit(toACVMWitness(0, args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
698
+ .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
667
699
  .catch((err: Error) => {
668
700
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
669
701
  throw new ExecutionError(