@aztec/txe 0.0.1-commit.2ed92850 → 0.0.1-commit.3100065

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 (174) hide show
  1. package/dest/AuthRegistry-FSRZIMX6.js +3 -0
  2. package/dest/AuthRegistry-FSRZIMX6.js.map +7 -0
  3. package/dest/ContractClassRegistry-N6NA3SFA.js +3 -0
  4. package/dest/ContractClassRegistry-N6NA3SFA.js.map +7 -0
  5. package/dest/ContractInstanceRegistry-NADDSLGL.js +3 -0
  6. package/dest/ContractInstanceRegistry-NADDSLGL.js.map +7 -0
  7. package/dest/FeeJuice-QBH5JWJV.js +3 -0
  8. package/dest/FeeJuice-QBH5JWJV.js.map +7 -0
  9. package/dest/HandshakeRegistry-KKUEU7XW.js +3 -0
  10. package/dest/HandshakeRegistry-KKUEU7XW.js.map +7 -0
  11. package/dest/MultiCallEntrypoint-TGICA67H.js +3 -0
  12. package/dest/MultiCallEntrypoint-TGICA67H.js.map +7 -0
  13. package/dest/SchnorrAccount-J5T6OKR3.js +3 -0
  14. package/dest/SchnorrAccount-J5T6OKR3.js.map +7 -0
  15. package/dest/SchnorrInitializerlessAccount-OOES6Q4F.js +3 -0
  16. package/dest/SchnorrInitializerlessAccount-OOES6Q4F.js.map +7 -0
  17. package/dest/bin/check_txe_oracle_version.d.ts +2 -0
  18. package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
  19. package/dest/bin/check_txe_oracle_version.js +61 -0
  20. package/dest/bin/index.js +3 -30
  21. package/dest/bin/index.js.map +7 -0
  22. package/dest/bin/oracle_test_server.d.ts +3 -0
  23. package/dest/bin/oracle_test_server.d.ts.map +1 -0
  24. package/dest/bin/oracle_test_server.js +41 -0
  25. package/dest/chunk-BJVAAXNA.js +3 -0
  26. package/dest/chunk-BJVAAXNA.js.map +7 -0
  27. package/dest/chunk-PDOEF22H.js +304 -0
  28. package/dest/chunk-PDOEF22H.js.map +7 -0
  29. package/dest/chunk-YP4ODNMQ.js +268 -0
  30. package/dest/chunk-YP4ODNMQ.js.map +7 -0
  31. package/dest/constants.d.ts +5 -1
  32. package/dest/constants.d.ts.map +1 -1
  33. package/dest/constants.js +9 -1
  34. package/dest/dispatcher_pool.d.ts +67 -0
  35. package/dest/dispatcher_pool.d.ts.map +1 -0
  36. package/dest/dispatcher_pool.js +286 -0
  37. package/dest/index.d.ts +51 -7
  38. package/dest/index.d.ts.map +1 -1
  39. package/dest/index.js +73 -157
  40. package/dest/metafile.json +39883 -0
  41. package/dest/msgpackr_fr_extension.d.ts +2 -0
  42. package/dest/msgpackr_fr_extension.d.ts.map +1 -0
  43. package/dest/msgpackr_fr_extension.js +21 -0
  44. package/dest/oracle/interfaces.d.ts +65 -30
  45. package/dest/oracle/interfaces.d.ts.map +1 -1
  46. package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
  47. package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
  48. package/dest/oracle/tagging_secret_strategy.js +12 -0
  49. package/dest/oracle/test-resolver/default_fixtures.d.ts +9 -0
  50. package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
  51. package/dest/oracle/test-resolver/default_fixtures.js +207 -0
  52. package/dest/oracle/test-resolver/index.d.ts +9 -0
  53. package/dest/oracle/test-resolver/index.d.ts.map +1 -0
  54. package/dest/oracle/test-resolver/index.js +32 -0
  55. package/dest/oracle/test-resolver/resolver.d.ts +48 -0
  56. package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
  57. package/dest/oracle/test-resolver/resolver.js +181 -0
  58. package/dest/oracle/txe_oracle_public_context.d.ts +38 -14
  59. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  60. package/dest/oracle/txe_oracle_public_context.js +63 -16
  61. package/dest/oracle/txe_oracle_registry.d.ts +170 -0
  62. package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
  63. package/dest/oracle/txe_oracle_registry.js +749 -0
  64. package/dest/oracle/txe_oracle_top_level_context.d.ts +56 -29
  65. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  66. package/dest/oracle/txe_oracle_top_level_context.js +330 -103
  67. package/dest/oracle/txe_oracle_version.d.ts +17 -0
  68. package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
  69. package/dest/oracle/txe_oracle_version.js +14 -0
  70. package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
  71. package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
  72. package/dest/oracle/txe_private_execution_oracle.js +15 -0
  73. package/dest/rpc_server.d.ts +14 -0
  74. package/dest/rpc_server.d.ts.map +1 -0
  75. package/dest/rpc_server.js +78 -0
  76. package/dest/rpc_translator.d.ts +113 -228
  77. package/dest/rpc_translator.d.ts.map +1 -1
  78. package/dest/rpc_translator.js +885 -613
  79. package/dest/server.bundle.js +3 -0
  80. package/dest/server.bundle.js.map +7 -0
  81. package/dest/state_machine/archiver.d.ts +6 -5
  82. package/dest/state_machine/archiver.d.ts.map +1 -1
  83. package/dest/state_machine/archiver.js +30 -20
  84. package/dest/state_machine/dummy_p2p_client.d.ts +29 -16
  85. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  86. package/dest/state_machine/dummy_p2p_client.js +53 -20
  87. package/dest/state_machine/global_variable_builder.d.ts +10 -6
  88. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  89. package/dest/state_machine/global_variable_builder.js +8 -5
  90. package/dest/state_machine/index.d.ts +13 -7
  91. package/dest/state_machine/index.d.ts.map +1 -1
  92. package/dest/state_machine/index.js +60 -15
  93. package/dest/state_machine/mock_epoch_cache.d.ts +18 -3
  94. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  95. package/dest/state_machine/mock_epoch_cache.js +33 -2
  96. package/dest/state_machine/synchronizer.d.ts +9 -6
  97. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  98. package/dest/state_machine/synchronizer.js +10 -6
  99. package/dest/txe_session.d.ts +89 -16
  100. package/dest/txe_session.d.ts.map +1 -1
  101. package/dest/txe_session.js +363 -56
  102. package/dest/utils/block_creation.d.ts +2 -2
  103. package/dest/utils/block_creation.d.ts.map +1 -1
  104. package/dest/utils/block_creation.js +5 -3
  105. package/dest/utils/encoding.d.ts +192 -0
  106. package/dest/utils/encoding.d.ts.map +1 -0
  107. package/dest/{util → utils}/encoding.js +7 -2
  108. package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
  109. package/dest/utils/expected_failure_error.d.ts.map +1 -0
  110. package/dest/utils/tx_effect_creation.d.ts +1 -1
  111. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  112. package/dest/utils/tx_effect_creation.js +0 -1
  113. package/dest/{util → utils}/txe_account_store.d.ts +1 -1
  114. package/dest/utils/txe_account_store.d.ts.map +1 -0
  115. package/dest/utils/txe_artifact_resolver.d.ts +37 -0
  116. package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
  117. package/dest/utils/txe_artifact_resolver.js +161 -0
  118. package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
  119. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
  120. package/dest/utils/txe_public_contract_data_source.js +51 -0
  121. package/dest/worker.bundle.js +3 -0
  122. package/dest/worker.bundle.js.map +7 -0
  123. package/dest/worker.d.ts +2 -0
  124. package/dest/worker.d.ts.map +1 -0
  125. package/dest/worker.js +92 -0
  126. package/package.json +38 -21
  127. package/src/bin/check_txe_oracle_version.ts +70 -0
  128. package/src/bin/index.ts +11 -2
  129. package/src/bin/oracle_test_server.ts +51 -0
  130. package/src/constants.ts +11 -1
  131. package/src/dispatcher_pool.ts +317 -0
  132. package/src/index.ts +99 -190
  133. package/src/msgpackr_fr_extension.ts +23 -0
  134. package/src/oracle/interfaces.ts +71 -35
  135. package/src/oracle/tagging_secret_strategy.ts +25 -0
  136. package/src/oracle/test-resolver/default_fixtures.ts +282 -0
  137. package/src/oracle/test-resolver/index.ts +44 -0
  138. package/src/oracle/test-resolver/resolver.ts +245 -0
  139. package/src/oracle/txe_oracle_public_context.ts +76 -16
  140. package/src/oracle/txe_oracle_registry.ts +539 -0
  141. package/src/oracle/txe_oracle_top_level_context.ts +440 -168
  142. package/src/oracle/txe_oracle_version.ts +17 -0
  143. package/src/oracle/txe_private_execution_oracle.ts +30 -0
  144. package/src/rpc_server.ts +87 -0
  145. package/src/rpc_translator.ts +1098 -988
  146. package/src/state_machine/archiver.ts +43 -20
  147. package/src/state_machine/dummy_p2p_client.ts +83 -32
  148. package/src/state_machine/global_variable_builder.ts +12 -11
  149. package/src/state_machine/index.ts +84 -33
  150. package/src/state_machine/mock_epoch_cache.ts +43 -3
  151. package/src/state_machine/synchronizer.ts +13 -7
  152. package/src/txe_session.ts +603 -128
  153. package/src/utils/block_creation.ts +5 -2
  154. package/src/{util → utils}/encoding.ts +8 -2
  155. package/src/utils/tx_effect_creation.ts +0 -2
  156. package/src/utils/txe_artifact_resolver.ts +217 -0
  157. package/src/utils/txe_public_contract_data_source.ts +60 -0
  158. package/src/worker.ts +98 -0
  159. package/dest/util/encoding.d.ts +0 -720
  160. package/dest/util/encoding.d.ts.map +0 -1
  161. package/dest/util/expected_failure_error.d.ts.map +0 -1
  162. package/dest/util/txe_account_store.d.ts.map +0 -1
  163. package/dest/util/txe_contract_store.d.ts +0 -12
  164. package/dest/util/txe_contract_store.d.ts.map +0 -1
  165. package/dest/util/txe_contract_store.js +0 -22
  166. package/dest/util/txe_public_contract_data_source.d.ts +0 -21
  167. package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
  168. package/dest/util/txe_public_contract_data_source.js +0 -67
  169. package/src/util/txe_contract_store.ts +0 -36
  170. package/src/util/txe_public_contract_data_source.ts +0 -86
  171. /package/dest/{util → utils}/expected_failure_error.js +0 -0
  172. /package/dest/{util → utils}/txe_account_store.js +0 -0
  173. /package/src/{util → utils}/expected_failure_error.ts +0 -0
  174. /package/src/{util → utils}/txe_account_store.ts +0 -0
@@ -2,31 +2,44 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { KeyStore } from '@aztec/key-store';
5
- import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
6
- import { AddressStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
7
- import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
5
+ import { openEphemeralStore } from '@aztec/kv-store/lmdb-v2';
6
+ import { AddressStore, AnchorBlockStore, AnchoredContractData, CapsuleService, CapsuleStore, FactService, FactStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderTaggingStore, TaggingSecretSourcesStore, composeHooks } from '@aztec/pxe/server';
7
+ import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, LEGACY_ORACLE_REGISTRY, TransientArrayService, UtilityExecutionOracle, buildACIRCallback } from '@aztec/pxe/simulator';
8
8
  import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
9
+ import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec/standard-contracts/auth-registry/constants';
9
10
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
10
11
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
11
- import { GasSettings } from '@aztec/stdlib/gas';
12
12
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
13
13
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
14
- import { CallContext, TxContext } from '@aztec/stdlib/tx';
14
+ import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
15
15
  import { z } from 'zod';
16
- import { DEFAULT_ADDRESS } from './constants.js';
16
+ import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
17
+ import { makeResolveTaggingSecretStrategyHook } from './oracle/tagging_secret_strategy.js';
17
18
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
19
+ import { callTxeLegacyHandler } from './oracle/txe_oracle_registry.js';
18
20
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
19
- import { RPCTranslator } from './rpc_translator.js';
21
+ import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './oracle/txe_oracle_version.js';
22
+ import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
23
+ import { RPCTranslator, UnavailableOracleError } from './rpc_translator.js';
24
+ import { TXEArchiver } from './state_machine/archiver.js';
20
25
  import { TXEStateMachine } from './state_machine/index.js';
21
- import { TXEAccountStore } from './util/txe_account_store.js';
22
- import { TXEContractStore } from './util/txe_contract_store.js';
23
26
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
24
27
  import { makeTxEffect } from './utils/tx_effect_creation.js';
28
+ import { TXEAccountStore } from './utils/txe_account_store.js';
29
+ function emptyLastCallState() {
30
+ return {
31
+ offchainEffects: [],
32
+ queried: false,
33
+ txHash: Fr.ZERO,
34
+ anchorBlockTimestamp: 0n
35
+ };
36
+ }
25
37
  /**
26
38
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
27
39
  * state, etc., independent of all other tests running in parallel.
28
40
  */ export class TXESession {
29
41
  logger;
42
+ sessionStore;
30
43
  stateMachine;
31
44
  oracleHandler;
32
45
  contractStore;
@@ -36,18 +49,27 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
36
49
  accountStore;
37
50
  senderTaggingStore;
38
51
  recipientTaggingStore;
39
- senderAddressBookStore;
52
+ taggingSecretSourcesStore;
40
53
  capsuleStore;
54
+ factStore;
41
55
  privateEventStore;
42
56
  jobCoordinator;
43
57
  currentJobId;
44
58
  chainId;
45
59
  version;
46
60
  nextBlockTimestamp;
61
+ artifactResolver;
62
+ rootPath;
63
+ packageName;
47
64
  state;
48
65
  authwits;
49
- constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
66
+ taggingSecretStrategies;
67
+ lastCallInfo;
68
+ txeOracleVersion;
69
+ disposed;
70
+ constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, artifactResolver, rootPath, packageName){
50
71
  this.logger = logger;
72
+ this.sessionStore = sessionStore;
51
73
  this.stateMachine = stateMachine;
52
74
  this.oracleHandler = oracleHandler;
53
75
  this.contractStore = contractStore;
@@ -57,53 +79,83 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
57
79
  this.accountStore = accountStore;
58
80
  this.senderTaggingStore = senderTaggingStore;
59
81
  this.recipientTaggingStore = recipientTaggingStore;
60
- this.senderAddressBookStore = senderAddressBookStore;
82
+ this.taggingSecretSourcesStore = taggingSecretSourcesStore;
61
83
  this.capsuleStore = capsuleStore;
84
+ this.factStore = factStore;
62
85
  this.privateEventStore = privateEventStore;
63
86
  this.jobCoordinator = jobCoordinator;
64
87
  this.currentJobId = currentJobId;
65
88
  this.chainId = chainId;
66
89
  this.version = version;
67
90
  this.nextBlockTimestamp = nextBlockTimestamp;
91
+ this.artifactResolver = artifactResolver;
92
+ this.rootPath = rootPath;
93
+ this.packageName = packageName;
68
94
  this.state = {
69
95
  name: 'TOP_LEVEL'
70
96
  };
71
97
  this.authwits = new Map();
98
+ this.taggingSecretStrategies = new Map();
99
+ this.lastCallInfo = emptyLastCallState();
100
+ this.disposed = false;
72
101
  }
73
- static async init(protocolContracts) {
74
- const store = await openTmpStore('txe-session');
102
+ /**
103
+ * Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
104
+ * Called via IPC when the dispatcher detects the end of a test. Idempotent.
105
+ */ async dispose() {
106
+ if (this.disposed) {
107
+ return;
108
+ }
109
+ this.disposed = true;
110
+ try {
111
+ await this.stateMachine.synchronizer.nativeWorldStateService.close();
112
+ } catch (err) {
113
+ this.logger.warn(`Error closing native world state during session dispose`, err);
114
+ }
115
+ try {
116
+ await this.sessionStore.close();
117
+ } catch (err) {
118
+ this.logger.warn(`Error closing session LMDB during dispose`, err);
119
+ }
120
+ }
121
+ static async init(contractStore, artifactResolver, rootPath, packageName) {
122
+ // Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
123
+ // HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
124
+ // slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
125
+ // entry per session.
126
+ const store = await openEphemeralStore('txe-session', undefined, 2);
75
127
  const addressStore = new AddressStore(store);
76
128
  const privateEventStore = new PrivateEventStore(store);
77
- const contractStore = new TXEContractStore(store);
78
129
  const noteStore = new NoteStore(store);
79
130
  const senderTaggingStore = new SenderTaggingStore(store);
80
131
  const recipientTaggingStore = new RecipientTaggingStore(store);
81
- const senderAddressBookStore = new SenderAddressBookStore(store);
132
+ const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
82
133
  const capsuleStore = new CapsuleStore(store);
134
+ const factStore = new FactStore(store);
83
135
  const keyStore = new KeyStore(store);
84
136
  const accountStore = new TXEAccountStore(store);
85
- // Create job coordinator and register staged stores
86
137
  const jobCoordinator = new JobCoordinator(store);
87
138
  jobCoordinator.registerStores([
88
139
  capsuleStore,
140
+ factStore,
89
141
  senderTaggingStore,
90
142
  recipientTaggingStore,
91
143
  privateEventStore,
92
144
  noteStore
93
145
  ]);
94
- // Register protocol contracts.
95
- for (const { contractClass, instance, artifact } of protocolContracts){
96
- await contractStore.addContractArtifact(contractClass.id, artifact);
97
- await contractStore.addContractInstance(instance);
98
- }
99
- const stateMachine = await TXEStateMachine.create(store);
146
+ const archiver = new TXEArchiver(store);
147
+ const anchorBlockStore = new AnchorBlockStore(store);
148
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
100
149
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
101
150
  const version = new Fr(await stateMachine.node.getVersion());
102
151
  const chainId = new Fr(await stateMachine.node.getChainId());
103
152
  const initialJobId = jobCoordinator.beginJob();
104
- const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, initialJobId, nextBlockTimestamp, version, chainId, new Map());
105
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
106
- return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
153
+ const logger = createLogger('txe:session');
154
+ const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map(), new Map(), artifactResolver, rootPath, packageName);
155
+ await topLevelOracleHandler.mineDeploymentNullifiers([
156
+ STANDARD_AUTH_REGISTRY_ADDRESS
157
+ ]);
158
+ return new TXESession(logger, store, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp, artifactResolver, rootPath, packageName);
107
159
  }
108
160
  /**
109
161
  * Processes an oracle function invoked by the Noir test associated to this session.
@@ -112,13 +164,28 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
112
164
  * @returns The oracle return values.
113
165
  */ processFunction(functionName, inputs) {
114
166
  try {
167
+ // Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
168
+ // buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
169
+ // Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
170
+ // them into the legacy path instead of letting them fall through to the unknown-oracle error.
171
+ if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
172
+ return callTxeLegacyHandler(functionName, inputs, this.oracleHandler);
173
+ }
115
174
  const translator = new RPCTranslator(this, this.oracleHandler);
116
175
  // We perform a runtime validation to check that the function name corresponds to a real oracle handler.
117
176
  const validatedFunctionName = z.string().refine((fn)=>typeof translator[fn] === 'function' && !fn.startsWith('handlerAs') && fn !== 'constructor').parse(functionName);
118
177
  return translator[validatedFunctionName](...inputs);
119
178
  } catch (error) {
120
179
  if (error instanceof z.ZodError) {
121
- throw new Error(`${functionName} does not correspond to any oracle handler available on RPCTranslator`);
180
+ let versionHint;
181
+ if (!this.txeOracleVersion) {
182
+ versionHint = ' The test appears to use an older version of Aztec.nr that does not' + ' support test environment oracle versioning. Update Aztec.nr to a compatible version.' + ' See https://docs.aztec.network/errors/12';
183
+ } else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
184
+ versionHint = ` The test uses Aztec.nr test oracle version` + ` ${this.txeOracleVersion.major}.${this.txeOracleVersion.minor}, but this test environment` + ` only supports up to ${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}.` + ` Upgrade the Aztec CLI to a compatible version.` + ` See https://docs.aztec.network/errors/12`;
185
+ } else {
186
+ versionHint = ` The test's oracle version (${this.txeOracleVersion.major}.${this.txeOracleVersion.minor})` + ` is compatible with this test environment` + ` (${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}), so this oracle should be` + ` available. This is an unexpected error, please report it.` + ` See https://docs.aztec.network/errors/13`;
187
+ }
188
+ throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
122
189
  } else if (error instanceof Error) {
123
190
  throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
124
191
  } else {
@@ -126,6 +193,132 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
126
193
  }
127
194
  }
128
195
  }
196
+ /** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
197
+ await this.jobCoordinator.commitJob(this.currentJobId);
198
+ this.currentJobId = this.jobCoordinator.beginJob();
199
+ return this.currentJobId;
200
+ }
201
+ resetLastCall() {
202
+ const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
203
+ if (notQueriedMessageCount > 0) {
204
+ this.logger.warn(`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` + `To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` + `\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` + `to \`let _ = env.offchain_messages()\` to silence this warning.`);
205
+ }
206
+ this.lastCallInfo = emptyLastCallState();
207
+ }
208
+ recordOffchainEffect(data) {
209
+ this.lastCallInfo.offchainEffects.push(data);
210
+ }
211
+ setLastCallContext(txHash, anchorBlockTimestamp) {
212
+ this.lastCallInfo.txHash = txHash;
213
+ this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
214
+ }
215
+ async withTopLevelCallTracking(work) {
216
+ this.resetLastCall();
217
+ // Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
218
+ // side effect, and that block's timestamp should not be attributed to this call's anchor.
219
+ const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
220
+ const { result, txHash } = await work();
221
+ this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
222
+ return result;
223
+ }
224
+ getLastCallOffchainEffects() {
225
+ this.lastCallInfo.queried = true;
226
+ const effects = this.lastCallInfo.offchainEffects;
227
+ if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
228
+ throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
229
+ }
230
+ if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
231
+ throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
232
+ }
233
+ return {
234
+ effects
235
+ };
236
+ }
237
+ getLastCallContext() {
238
+ const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
239
+ return {
240
+ txHash,
241
+ anchorBlockTimestamp
242
+ };
243
+ }
244
+ async executePrivateCall(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, authorizedUtilityCallTargets, gasSettings) {
245
+ const handler = this.handlerAsTxe();
246
+ return await this.withTopLevelCallTracking(async ()=>{
247
+ const { returnValues, offchainEffects } = await handler.privateCallNewFlow(from?.value, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, this.currentJobId, authorizedUtilityCallTargets, gasSettings);
248
+ // Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
249
+ // them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
250
+ // from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
251
+ // them.
252
+ for (const data of offchainEffects){
253
+ this.recordOffchainEffect(data);
254
+ }
255
+ await this.cycleJob();
256
+ if (isStaticCall) {
257
+ // Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
258
+ // with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
259
+ return {
260
+ result: returnValues
261
+ };
262
+ }
263
+ const { txHash } = await handler.getLastTxEffects();
264
+ return {
265
+ result: returnValues,
266
+ txHash: txHash.hash
267
+ };
268
+ });
269
+ }
270
+ async executeUtilityFunction(from, targetContractAddress, functionSelector, args, authorizedUtilityCallTargets) {
271
+ const handler = this.handlerAsTxe();
272
+ return await this.withTopLevelCallTracking(async ()=>{
273
+ const returnValues = await handler.executeUtilityFunction(from?.value, targetContractAddress, functionSelector, args, this.currentJobId, authorizedUtilityCallTargets);
274
+ await this.cycleJob();
275
+ return {
276
+ result: returnValues
277
+ };
278
+ });
279
+ }
280
+ async executePublicCall(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
281
+ const handler = this.handlerAsTxe();
282
+ return await this.withTopLevelCallTracking(async ()=>{
283
+ const returnValues = await handler.publicCallNewFlow(from?.value, targetContractAddress, calldata, isStaticCall, gasSettings);
284
+ await this.cycleJob();
285
+ if (isStaticCall) {
286
+ // See the equivalent branch in `executePrivateCall`.
287
+ return {
288
+ result: returnValues
289
+ };
290
+ }
291
+ const { txHash } = await handler.getLastTxEffects();
292
+ return {
293
+ result: returnValues,
294
+ txHash: txHash.hash
295
+ };
296
+ });
297
+ }
298
+ async getPrivateEvents(selector, contractAddress, scope) {
299
+ const handler = this.handlerAsTxe();
300
+ await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
301
+ // Cycle the job to commit the stores after the contract sync.
302
+ await this.cycleJob();
303
+ return handler.getPrivateEvents(selector, contractAddress, scope);
304
+ }
305
+ handlerAsTxe() {
306
+ if (!('isTxe' in this.oracleHandler)) {
307
+ throw new UnavailableOracleError('Txe');
308
+ }
309
+ return this.oracleHandler;
310
+ }
311
+ setTxeOracleVersion(major, minor) {
312
+ if (major !== TXE_ORACLE_VERSION_MAJOR) {
313
+ const hint = major > TXE_ORACLE_VERSION_MAJOR ? 'The test was compiled with a newer version of Aztec.nr than your test environment supports. Upgrade your test environment to a compatible version.' : 'The test was compiled with an older version of Aztec.nr than your test environment supports. Recompile the test with a compatible version of Aztec.nr.';
314
+ throw new Error(`Incompatible test environment version: ${hint} See https://docs.aztec.network/errors/12 (expected test oracle major version ${TXE_ORACLE_VERSION_MAJOR}, got ${major})`);
315
+ }
316
+ this.txeOracleVersion = {
317
+ major,
318
+ minor
319
+ };
320
+ this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
321
+ }
129
322
  async enterTopLevelState() {
130
323
  switch(this.state.name){
131
324
  case 'PRIVATE':
@@ -153,22 +346,24 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
153
346
  }
154
347
  }
155
348
  // Commit all staged stores from the job that was just completed, then begin a new job
156
- await this.jobCoordinator.commitJob(this.currentJobId);
157
- this.currentJobId = this.jobCoordinator.beginJob();
158
- this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
349
+ await this.cycleJob();
350
+ this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.taggingSecretSourcesStore, this.capsuleStore, this.factStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits, this.taggingSecretStrategies, this.artifactResolver, this.rootPath, this.packageName);
159
351
  this.state = {
160
352
  name: 'TOP_LEVEL'
161
353
  };
162
354
  this.logger.debug(`Entered state ${this.state.name}`);
163
355
  }
164
- async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
356
+ async enterPrivateState(contractAddressOpt, anchorBlockNumberOpt, gasSettings) {
357
+ const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
358
+ const anchorBlockNumber = anchorBlockNumberOpt?.value;
165
359
  this.exitTopLevelState();
166
- await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.currentJobId).syncNoteNullifiers(contractAddress);
360
+ this.resetLastCall();
167
361
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
168
362
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
169
363
  // a single transaction with the effects of what was done in the test.
170
- const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
171
- const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
364
+ const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
365
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
366
+ const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
172
367
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
173
368
  blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
174
369
  timestamp: this.nextBlockTimestamp,
@@ -180,7 +375,42 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
180
375
  const noteCache = new ExecutionNoteCache(protocolNullifier);
181
376
  const taggingIndexCache = new ExecutionTaggingIndexCache();
182
377
  const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
183
- this.oracleHandler = new PrivateExecutionOracle(Fr.ZERO, new TxContext(this.chainId, this.version, GasSettings.empty()), new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false), anchorBlock, utilityExecutor, [], [], new HashedValuesCache(), noteCache, taggingIndexCache, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
378
+ const transientArrayService = new TransientArrayService();
379
+ const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
380
+ this.oracleHandler = new TXEPrivateExecutionOracle({
381
+ argsHash: Fr.ZERO,
382
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
383
+ txRequestSalt: Fr.ZERO,
384
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
385
+ anchorBlockHeader: anchorBlock,
386
+ utilityExecutor,
387
+ authWitnesses: [],
388
+ capsules: [],
389
+ executionCache: new HashedValuesCache(),
390
+ noteCache,
391
+ taggingIndexCache,
392
+ anchoredContractData,
393
+ noteStore: this.noteStore,
394
+ keyStore: this.keyStore,
395
+ addressStore: this.addressStore,
396
+ aztecNode: this.stateMachine.node,
397
+ senderTaggingStore: this.senderTaggingStore,
398
+ recipientTaggingStore: this.recipientTaggingStore,
399
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
400
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
401
+ factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
402
+ privateEventStore: this.privateEventStore,
403
+ contractSyncService: this.stateMachine.contractSyncService,
404
+ l2TipsStore: this.stateMachine.l2TipsProvider,
405
+ jobId: this.currentJobId,
406
+ scopes: await this.keyStore.getAccounts(),
407
+ txResolver: this.stateMachine.txResolver,
408
+ simulator: new WASMSimulator(),
409
+ hooks: composeHooks({
410
+ resolveTaggingSecretStrategy: makeResolveTaggingSecretStrategyHook(this.taggingSecretStrategies)
411
+ }),
412
+ transientArrayService
413
+ });
184
414
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
185
415
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
186
416
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -193,54 +423,97 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
193
423
  taggingIndexCache
194
424
  };
195
425
  this.logger.debug(`Entered state ${this.state.name}`);
426
+ // Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
427
+ // via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
428
+ this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
196
429
  return this.oracleHandler.getPrivateContextInputs();
197
430
  }
198
- async enterPublicState(contractAddress) {
431
+ async enterPublicState(contractAddressOpt) {
432
+ const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
199
433
  this.exitTopLevelState();
434
+ this.resetLastCall();
200
435
  // The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
201
436
  // the test. The block therefore gets the *next* block number and timestamp.
202
- const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
437
+ const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
203
438
  const globalVariables = makeGlobalVariables(undefined, {
204
- blockNumber: BlockNumber(latestBlockNumber + 1),
439
+ blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
205
440
  timestamp: this.nextBlockTimestamp,
206
441
  version: this.version,
207
442
  chainId: this.chainId
208
443
  });
209
- this.oracleHandler = new TXEOraclePublicContext(contractAddress ?? DEFAULT_ADDRESS, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables);
444
+ this.oracleHandler = new TXEOraclePublicContext(contractAddress, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables, this.contractStore);
210
445
  this.state = {
211
446
  name: 'PUBLIC'
212
447
  };
213
448
  this.logger.debug(`Entered state ${this.state.name}`);
449
+ // Public state is anchored at the latest block.
450
+ this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
214
451
  }
215
- async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
452
+ async enterUtilityState(contractAddressOpt) {
453
+ const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
216
454
  this.exitTopLevelState();
455
+ this.resetLastCall();
456
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
217
457
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
218
458
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
219
459
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
220
460
  // be removed from the database.
221
461
  // TODO(#12553): make the synchronizer sync here instead and remove this
222
- await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.currentJobId).syncNoteNullifiers(contractAddress);
223
- const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
224
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], anchorBlockHeader, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
462
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
463
+ this.oracleHandler = new UtilityExecutionOracle({
464
+ callContext: CallContext.from({
465
+ msgSender: AztecAddress.NULL_MSG_SENDER,
466
+ contractAddress,
467
+ // No specific function is being executed in this inlined utility context, hence the empty selector.
468
+ functionSelector: FunctionSelector.empty(),
469
+ isStaticCall: true
470
+ }),
471
+ authWitnesses: [],
472
+ capsules: [],
473
+ anchorBlockHeader,
474
+ anchoredContractData: new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader),
475
+ noteStore: this.noteStore,
476
+ keyStore: this.keyStore,
477
+ addressStore: this.addressStore,
478
+ aztecNode: this.stateMachine.node,
479
+ recipientTaggingStore: this.recipientTaggingStore,
480
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
481
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
482
+ factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
483
+ privateEventStore: this.privateEventStore,
484
+ txResolver: this.stateMachine.txResolver,
485
+ contractSyncService: this.stateMachine.contractSyncService,
486
+ l2TipsStore: this.stateMachine.l2TipsProvider,
487
+ jobId: this.currentJobId,
488
+ scopes: await this.keyStore.getAccounts(),
489
+ simulator: new WASMSimulator(),
490
+ utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
491
+ // Execution-tree root (top-level utility run): own store; nested frames inherit it.
492
+ transientArrayService: new TransientArrayService()
493
+ });
225
494
  this.state = {
226
495
  name: 'UTILITY'
227
496
  };
228
497
  this.logger.debug(`Entered state ${this.state.name}`);
498
+ // Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
499
+ this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
229
500
  }
230
501
  exitTopLevelState() {
231
502
  if (this.state.name != 'TOP_LEVEL') {
232
503
  throw new Error(`Expected to be in state 'TOP_LEVEL', but got '${this.state.name}' instead`);
233
504
  }
234
505
  // Note that while all public and private contexts do is build a single block that we then process when exiting
235
- // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
236
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
237
- // `txePrivateCallNewFlow` and `txePublicCallNewFlow`, add accounts to PXE via `txeAddAccount`, etc. This is a
238
- // slight inconsistency in the working model of this class, but is not too bad.
239
- // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
240
- // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
241
- // the authwits if not persisted, so we'd not be able to pass more than one per execution.
242
- // Ideally authwits would be passed alongside a contract call instead of pre-seeded.
243
- [this.nextBlockTimestamp, this.authwits] = this.oracleHandler.close();
506
+ // them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
507
+ // and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
508
+ // accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
509
+ // is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
510
+ // sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
511
+ // `addAuthWitness`, `setTaggingSecretStrategies`). The oracle handler is discarded on every state transition,
512
+ // so the session must seed these values into the contexts it creates later.
513
+ // TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
514
+ // otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
515
+ // alongside a contract call instead of pre-seeded.
516
+ [this.nextBlockTimestamp, this.authwits, this.taggingSecretStrategies] = this.oracleHandler.close();
244
517
  }
245
518
  async exitPrivateState() {
246
519
  if (this.state.name != 'PRIVATE') {
@@ -278,14 +551,48 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
278
551
  }
279
552
  }
280
553
  utilityExecutorForContractSync(anchorBlock) {
281
- return async (call)=>{
282
- const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
554
+ return async (call, scopes)=>{
555
+ const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
556
+ const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
557
+ if (!entryPointArtifact) {
558
+ throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
559
+ }
283
560
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
284
561
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
285
562
  }
286
563
  try {
287
- const oracle = new UtilityExecutionOracle(call.to, [], [], anchorBlock, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
288
- await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
564
+ const simulator = new WASMSimulator();
565
+ const oracle = new UtilityExecutionOracle({
566
+ callContext: CallContext.from({
567
+ msgSender: AztecAddress.NULL_MSG_SENDER,
568
+ contractAddress: call.to,
569
+ functionSelector: call.selector,
570
+ isStaticCall: true
571
+ }),
572
+ authWitnesses: [],
573
+ capsules: [],
574
+ anchorBlockHeader: anchorBlock,
575
+ anchoredContractData,
576
+ noteStore: this.noteStore,
577
+ keyStore: this.keyStore,
578
+ addressStore: this.addressStore,
579
+ aztecNode: this.stateMachine.node,
580
+ recipientTaggingStore: this.recipientTaggingStore,
581
+ taggingSecretSourcesStore: this.taggingSecretSourcesStore,
582
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
583
+ factService: new FactService(this.factStore, scopes),
584
+ privateEventStore: this.privateEventStore,
585
+ txResolver: this.stateMachine.txResolver,
586
+ contractSyncService: this.stateMachine.contractSyncService,
587
+ l2TipsStore: this.stateMachine.l2TipsProvider,
588
+ jobId: this.currentJobId,
589
+ scopes,
590
+ simulator,
591
+ utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
592
+ // Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
593
+ transientArrayService: new TransientArrayService()
594
+ });
595
+ await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
289
596
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
290
597
  throw new ExecutionError(err.message, {
291
598
  contractAddress: call.to,
@@ -9,7 +9,7 @@ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
9
9
  * @returns The transaction request hash.
10
10
  */
11
11
  export declare function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr;
12
- export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations): Promise<void>;
12
+ export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations, l1ToL2Messages?: Fr[]): Promise<void>;
13
13
  export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables): Promise<BlockHeader>;
14
14
  /**
15
15
  * Creates an L2Block with proper archive chaining.
@@ -25,4 +25,4 @@ export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations
25
25
  * @returns The created L2Block with proper archive chaining
26
26
  */
27
27
  export declare function makeTXEBlock(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables, txEffects: TxEffect[]): Promise<L2Block>;
28
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFFLFdBQVcsRUFBRSxlQUFlLEVBQUUsUUFBUSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFMUU7Ozs7R0FJRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLEVBQUUsQ0FFeEU7QUFFRCx3QkFBc0IsNEJBQTRCLENBQ2hELFFBQVEsRUFBRSxRQUFRLEVBQ2xCLFVBQVUsRUFBRSx5QkFBeUIsR0FDcEMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWtCZjtBQUVELHdCQUFzQixrQkFBa0IsQ0FDdEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxHQUMvQixPQUFPLENBQUMsV0FBVyxDQUFDLENBWXRCO0FBRUQ7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gsd0JBQXNCLFlBQVksQ0FDaEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxFQUNoQyxTQUFTLEVBQUUsUUFBUSxFQUFFLEdBQ3BCLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FlbEIifQ==
28
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFFLFdBQVcsRUFBRSxlQUFlLEVBQUUsUUFBUSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFMUU7Ozs7R0FJRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLEVBQUUsQ0FFeEU7QUFFRCx3QkFBc0IsNEJBQTRCLENBQ2hELFFBQVEsRUFBRSxRQUFRLEVBQ2xCLFVBQVUsRUFBRSx5QkFBeUIsRUFDckMsY0FBYyxHQUFFLEVBQUUsRUFBTyxHQUN4QixPQUFPLENBQUMsSUFBSSxDQUFDLENBa0JmO0FBRUQsd0JBQXNCLGtCQUFrQixDQUN0QyxVQUFVLEVBQUUseUJBQXlCLEVBQ3JDLGVBQWUsRUFBRSxlQUFlLEdBQy9CLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FZdEI7QUFFRDs7Ozs7Ozs7Ozs7O0dBWUc7QUFDSCx3QkFBc0IsWUFBWSxDQUNoQyxVQUFVLEVBQUUseUJBQXlCLEVBQ3JDLGVBQWUsRUFBRSxlQUFlLEVBQ2hDLFNBQVMsRUFBRSxRQUFRLEVBQUUsR0FDcEIsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQWlCbEIifQ==
@@ -1 +1 @@
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
+ {"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,EACrC,cAAc,GAAE,EAAE,EAAO,GACxB,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,CAiBlB"}