@aztec/txe 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a

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 (134) hide show
  1. package/dest/ContractClassRegistry-KKNT527R.js +3 -0
  2. package/dest/ContractClassRegistry-KKNT527R.js.map +7 -0
  3. package/dest/ContractInstanceRegistry-GSKBNL3Q.js +3 -0
  4. package/dest/ContractInstanceRegistry-GSKBNL3Q.js.map +7 -0
  5. package/dest/FeeJuice-GUJ5O6GB.js +3 -0
  6. package/dest/FeeJuice-GUJ5O6GB.js.map +7 -0
  7. package/dest/MultiCallEntrypoint-ZQPCKVKL.js +3 -0
  8. package/dest/MultiCallEntrypoint-ZQPCKVKL.js.map +7 -0
  9. package/dest/SchnorrAccount-QIXE5DXA.js +3 -0
  10. package/dest/SchnorrAccount-QIXE5DXA.js.map +7 -0
  11. package/dest/bin/check_txe_oracle_version.d.ts +2 -0
  12. package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
  13. package/dest/bin/check_txe_oracle_version.js +32 -0
  14. package/dest/bin/index.js +3 -30
  15. package/dest/bin/index.js.map +7 -0
  16. package/dest/chunk-BJVAAXNA.js +3 -0
  17. package/dest/chunk-BJVAAXNA.js.map +7 -0
  18. package/dest/chunk-DF6RMOC6.js +304 -0
  19. package/dest/chunk-DF6RMOC6.js.map +7 -0
  20. package/dest/chunk-PPJTNNUG.js +265 -0
  21. package/dest/chunk-PPJTNNUG.js.map +7 -0
  22. package/dest/constants.d.ts +3 -1
  23. package/dest/constants.d.ts.map +1 -1
  24. package/dest/constants.js +5 -0
  25. package/dest/dispatcher_pool.d.ts +67 -0
  26. package/dest/dispatcher_pool.d.ts.map +1 -0
  27. package/dest/dispatcher_pool.js +284 -0
  28. package/dest/index.d.ts +188 -7
  29. package/dest/index.d.ts.map +1 -1
  30. package/dest/index.js +148 -75
  31. package/dest/metafile.json +38147 -0
  32. package/dest/msgpackr_fr_extension.d.ts +2 -0
  33. package/dest/msgpackr_fr_extension.d.ts.map +1 -0
  34. package/dest/msgpackr_fr_extension.js +21 -0
  35. package/dest/oracle/interfaces.d.ts +40 -28
  36. package/dest/oracle/interfaces.d.ts.map +1 -1
  37. package/dest/oracle/txe_oracle_public_context.d.ts +18 -13
  38. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  39. package/dest/oracle/txe_oracle_public_context.js +27 -12
  40. package/dest/oracle/txe_oracle_top_level_context.d.ts +39 -24
  41. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  42. package/dest/oracle/txe_oracle_top_level_context.js +205 -78
  43. package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
  44. package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
  45. package/dest/oracle/txe_private_execution_oracle.js +15 -0
  46. package/dest/rpc_server.d.ts +14 -0
  47. package/dest/rpc_server.d.ts.map +1 -0
  48. package/dest/rpc_server.js +78 -0
  49. package/dest/rpc_translator.d.ts +140 -84
  50. package/dest/rpc_translator.d.ts.map +1 -1
  51. package/dest/rpc_translator.js +587 -239
  52. package/dest/server.bundle.js +3 -0
  53. package/dest/server.bundle.js.map +7 -0
  54. package/dest/state_machine/archiver.d.ts +4 -4
  55. package/dest/state_machine/archiver.d.ts.map +1 -1
  56. package/dest/state_machine/archiver.js +24 -20
  57. package/dest/state_machine/dummy_p2p_client.d.ts +26 -16
  58. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  59. package/dest/state_machine/dummy_p2p_client.js +44 -20
  60. package/dest/state_machine/global_variable_builder.d.ts +9 -4
  61. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  62. package/dest/state_machine/global_variable_builder.js +9 -3
  63. package/dest/state_machine/index.d.ts +10 -6
  64. package/dest/state_machine/index.d.ts.map +1 -1
  65. package/dest/state_machine/index.js +35 -12
  66. package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
  67. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  68. package/dest/state_machine/mock_epoch_cache.js +39 -2
  69. package/dest/state_machine/synchronizer.d.ts +5 -5
  70. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  71. package/dest/state_machine/synchronizer.js +4 -4
  72. package/dest/txe_oracle_version.d.ts +17 -0
  73. package/dest/txe_oracle_version.d.ts.map +1 -0
  74. package/dest/txe_oracle_version.js +14 -0
  75. package/dest/txe_session.d.ts +71 -10
  76. package/dest/txe_session.d.ts.map +1 -1
  77. package/dest/txe_session.js +227 -40
  78. package/dest/utils/block_creation.d.ts +1 -1
  79. package/dest/utils/block_creation.d.ts.map +1 -1
  80. package/dest/utils/block_creation.js +3 -1
  81. package/dest/utils/encoding.d.ts +191 -0
  82. package/dest/utils/encoding.d.ts.map +1 -0
  83. package/dest/{util → utils}/encoding.js +7 -2
  84. package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
  85. package/dest/utils/expected_failure_error.d.ts.map +1 -0
  86. package/dest/{util → utils}/txe_account_store.d.ts +1 -1
  87. package/dest/utils/txe_account_store.d.ts.map +1 -0
  88. package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
  89. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
  90. package/dest/{util → utils}/txe_public_contract_data_source.js +6 -25
  91. package/dest/worker.bundle.js +3 -0
  92. package/dest/worker.bundle.js.map +7 -0
  93. package/dest/worker.d.ts +2 -0
  94. package/dest/worker.d.ts.map +1 -0
  95. package/dest/worker.js +92 -0
  96. package/package.json +37 -21
  97. package/src/bin/check_txe_oracle_version.ts +37 -0
  98. package/src/bin/index.ts +11 -2
  99. package/src/constants.ts +6 -0
  100. package/src/dispatcher_pool.ts +316 -0
  101. package/src/index.ts +166 -80
  102. package/src/msgpackr_fr_extension.ts +23 -0
  103. package/src/oracle/interfaces.ts +48 -34
  104. package/src/oracle/txe_oracle_public_context.ts +42 -12
  105. package/src/oracle/txe_oracle_top_level_context.ts +231 -144
  106. package/src/oracle/txe_private_execution_oracle.ts +30 -0
  107. package/src/rpc_server.ts +87 -0
  108. package/src/rpc_translator.ts +662 -316
  109. package/src/state_machine/archiver.ts +35 -18
  110. package/src/state_machine/dummy_p2p_client.ts +70 -32
  111. package/src/state_machine/global_variable_builder.ts +18 -3
  112. package/src/state_machine/index.ts +48 -13
  113. package/src/state_machine/mock_epoch_cache.ts +51 -3
  114. package/src/state_machine/synchronizer.ts +5 -5
  115. package/src/txe_oracle_version.ts +17 -0
  116. package/src/txe_session.ts +324 -90
  117. package/src/utils/block_creation.ts +3 -1
  118. package/src/{util → utils}/encoding.ts +8 -2
  119. package/src/{util → utils}/txe_public_contract_data_source.ts +10 -38
  120. package/src/worker.ts +98 -0
  121. package/dest/util/encoding.d.ts +0 -720
  122. package/dest/util/encoding.d.ts.map +0 -1
  123. package/dest/util/expected_failure_error.d.ts.map +0 -1
  124. package/dest/util/txe_account_store.d.ts.map +0 -1
  125. package/dest/util/txe_contract_store.d.ts +0 -12
  126. package/dest/util/txe_contract_store.d.ts.map +0 -1
  127. package/dest/util/txe_contract_store.js +0 -22
  128. package/dest/util/txe_public_contract_data_source.d.ts +0 -21
  129. package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
  130. package/src/util/txe_contract_store.ts +0 -36
  131. /package/dest/{util → utils}/expected_failure_error.js +0 -0
  132. /package/dest/{util → utils}/txe_account_store.js +0 -0
  133. /package/src/{util → utils}/expected_failure_error.ts +0 -0
  134. /package/src/{util → utils}/txe_account_store.ts +0 -0
@@ -2,31 +2,42 @@ 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, CapsuleService, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
7
+ import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, UtilityExecutionOracle } 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
17
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
18
18
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
19
+ import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
19
20
  import { RPCTranslator } from './rpc_translator.js';
21
+ import { TXEArchiver } from './state_machine/archiver.js';
20
22
  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
+ import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './txe_oracle_version.js';
23
24
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
24
25
  import { makeTxEffect } from './utils/tx_effect_creation.js';
26
+ import { TXEAccountStore } from './utils/txe_account_store.js';
27
+ function emptyLastCallState() {
28
+ return {
29
+ offchainEffects: [],
30
+ queried: false,
31
+ txHash: Fr.ZERO,
32
+ anchorBlockTimestamp: 0n
33
+ };
34
+ }
25
35
  /**
26
36
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
27
37
  * state, etc., independent of all other tests running in parallel.
28
38
  */ export class TXESession {
29
39
  logger;
40
+ sessionStore;
30
41
  stateMachine;
31
42
  oracleHandler;
32
43
  contractStore;
@@ -46,8 +57,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
46
57
  nextBlockTimestamp;
47
58
  state;
48
59
  authwits;
49
- constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
60
+ lastCallInfo;
61
+ txeOracleVersion;
62
+ disposed;
63
+ constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
50
64
  this.logger = logger;
65
+ this.sessionStore = sessionStore;
51
66
  this.stateMachine = stateMachine;
52
67
  this.oracleHandler = oracleHandler;
53
68
  this.contractStore = contractStore;
@@ -69,12 +84,36 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
69
84
  name: 'TOP_LEVEL'
70
85
  };
71
86
  this.authwits = new Map();
87
+ this.lastCallInfo = emptyLastCallState();
88
+ this.disposed = false;
72
89
  }
73
- static async init(protocolContracts) {
74
- const store = await openTmpStore('txe-session');
90
+ /**
91
+ * Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
92
+ * Called via IPC when the dispatcher detects the end of a test. Idempotent.
93
+ */ async dispose() {
94
+ if (this.disposed) {
95
+ return;
96
+ }
97
+ this.disposed = true;
98
+ try {
99
+ await this.stateMachine.synchronizer.nativeWorldStateService.close();
100
+ } catch (err) {
101
+ this.logger.warn(`Error closing native world state during session dispose`, err);
102
+ }
103
+ try {
104
+ await this.sessionStore.close();
105
+ } catch (err) {
106
+ this.logger.warn(`Error closing session LMDB during dispose`, err);
107
+ }
108
+ }
109
+ static async init(contractStore) {
110
+ // Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
111
+ // HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
112
+ // slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
113
+ // entry per session.
114
+ const store = await openEphemeralStore('txe-session', undefined, 2);
75
115
  const addressStore = new AddressStore(store);
76
116
  const privateEventStore = new PrivateEventStore(store);
77
- const contractStore = new TXEContractStore(store);
78
117
  const noteStore = new NoteStore(store);
79
118
  const senderTaggingStore = new SenderTaggingStore(store);
80
119
  const recipientTaggingStore = new RecipientTaggingStore(store);
@@ -82,7 +121,6 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
82
121
  const capsuleStore = new CapsuleStore(store);
83
122
  const keyStore = new KeyStore(store);
84
123
  const accountStore = new TXEAccountStore(store);
85
- // Create job coordinator and register staged stores
86
124
  const jobCoordinator = new JobCoordinator(store);
87
125
  jobCoordinator.registerStores([
88
126
  capsuleStore,
@@ -91,19 +129,19 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
91
129
  privateEventStore,
92
130
  noteStore
93
131
  ]);
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);
132
+ const archiver = new TXEArchiver(store);
133
+ const anchorBlockStore = new AnchorBlockStore(store);
134
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
100
135
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
101
136
  const version = new Fr(await stateMachine.node.getVersion());
102
137
  const chainId = new Fr(await stateMachine.node.getChainId());
103
138
  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);
139
+ const logger = createLogger('txe:session');
140
+ const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map());
141
+ await topLevelOracleHandler.mineDeploymentNullifiers([
142
+ STANDARD_AUTH_REGISTRY_ADDRESS
143
+ ]);
144
+ return new TXESession(logger, store, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
107
145
  }
108
146
  /**
109
147
  * Processes an oracle function invoked by the Noir test associated to this session.
@@ -118,7 +156,15 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
118
156
  return translator[validatedFunctionName](...inputs);
119
157
  } catch (error) {
120
158
  if (error instanceof z.ZodError) {
121
- throw new Error(`${functionName} does not correspond to any oracle handler available on RPCTranslator`);
159
+ let versionHint;
160
+ if (!this.txeOracleVersion) {
161
+ 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';
162
+ } else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
163
+ 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`;
164
+ } else {
165
+ 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`;
166
+ }
167
+ throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
122
168
  } else if (error instanceof Error) {
123
169
  throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
124
170
  } else {
@@ -126,6 +172,68 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
126
172
  }
127
173
  }
128
174
  }
175
+ getCurrentJob() {
176
+ return this.currentJobId;
177
+ }
178
+ /** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
179
+ await this.jobCoordinator.commitJob(this.currentJobId);
180
+ this.currentJobId = this.jobCoordinator.beginJob();
181
+ return this.currentJobId;
182
+ }
183
+ resetLastCall() {
184
+ const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
185
+ if (notQueriedMessageCount > 0) {
186
+ 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.`);
187
+ }
188
+ this.lastCallInfo = emptyLastCallState();
189
+ }
190
+ recordOffchainEffect(data) {
191
+ this.lastCallInfo.offchainEffects.push(data);
192
+ }
193
+ setLastCallContext(txHash, anchorBlockTimestamp) {
194
+ this.lastCallInfo.txHash = txHash;
195
+ this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
196
+ }
197
+ async withTopLevelCallTracking(work) {
198
+ this.resetLastCall();
199
+ // Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
200
+ // side effect, and that block's timestamp should not be attributed to this call's anchor.
201
+ const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
202
+ const { result, txHash } = await work();
203
+ this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
204
+ return result;
205
+ }
206
+ getLastCallOffchainEffects() {
207
+ this.lastCallInfo.queried = true;
208
+ const effects = this.lastCallInfo.offchainEffects;
209
+ if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
210
+ throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
211
+ }
212
+ if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
213
+ throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
214
+ }
215
+ return {
216
+ effects
217
+ };
218
+ }
219
+ getLastCallContext() {
220
+ const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
221
+ return {
222
+ txHash,
223
+ anchorBlockTimestamp
224
+ };
225
+ }
226
+ setTxeOracleVersion(major, minor) {
227
+ if (major !== TXE_ORACLE_VERSION_MAJOR) {
228
+ 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.';
229
+ 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})`);
230
+ }
231
+ this.txeOracleVersion = {
232
+ major,
233
+ minor
234
+ };
235
+ this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
236
+ }
129
237
  async enterTopLevelState() {
130
238
  switch(this.state.name){
131
239
  case 'PRIVATE':
@@ -153,22 +261,22 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
153
261
  }
154
262
  }
155
263
  // 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);
264
+ await this.cycleJob();
265
+ 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.nextBlockTimestamp, this.version, this.chainId, this.authwits);
159
266
  this.state = {
160
267
  name: 'TOP_LEVEL'
161
268
  };
162
269
  this.logger.debug(`Entered state ${this.state.name}`);
163
270
  }
164
- async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
271
+ async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber, gasSettings) {
165
272
  this.exitTopLevelState();
273
+ this.resetLastCall();
166
274
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
167
275
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
168
276
  // a single transaction with the effects of what was done in the test.
169
- const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
170
- await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress);
171
- const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
277
+ const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
278
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
279
+ const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
172
280
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
173
281
  blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
174
282
  timestamp: this.nextBlockTimestamp,
@@ -180,7 +288,34 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
180
288
  const noteCache = new ExecutionNoteCache(protocolNullifier);
181
289
  const taggingIndexCache = new ExecutionTaggingIndexCache();
182
290
  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.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
291
+ this.oracleHandler = new TXEPrivateExecutionOracle({
292
+ argsHash: Fr.ZERO,
293
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
294
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
295
+ anchorBlockHeader: anchorBlock,
296
+ utilityExecutor,
297
+ authWitnesses: [],
298
+ capsules: [],
299
+ executionCache: new HashedValuesCache(),
300
+ noteCache,
301
+ taggingIndexCache,
302
+ contractStore: this.contractStore,
303
+ noteStore: this.noteStore,
304
+ keyStore: this.keyStore,
305
+ addressStore: this.addressStore,
306
+ aztecNode: this.stateMachine.node,
307
+ senderTaggingStore: this.senderTaggingStore,
308
+ recipientTaggingStore: this.recipientTaggingStore,
309
+ senderAddressBookStore: this.senderAddressBookStore,
310
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
311
+ privateEventStore: this.privateEventStore,
312
+ contractSyncService: this.stateMachine.contractSyncService,
313
+ l2TipsStore: this.stateMachine.l2TipsProvider,
314
+ jobId: this.currentJobId,
315
+ scopes: await this.keyStore.getAccounts(),
316
+ messageContextService: this.stateMachine.messageContextService,
317
+ simulator: new WASMSimulator()
318
+ });
184
319
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
185
320
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
186
321
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -193,15 +328,19 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
193
328
  taggingIndexCache
194
329
  };
195
330
  this.logger.debug(`Entered state ${this.state.name}`);
331
+ // Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
332
+ // via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
333
+ this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
196
334
  return this.oracleHandler.getPrivateContextInputs();
197
335
  }
198
336
  async enterPublicState(contractAddress) {
199
337
  this.exitTopLevelState();
338
+ this.resetLastCall();
200
339
  // The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
201
340
  // the test. The block therefore gets the *next* block number and timestamp.
202
- const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
341
+ const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
203
342
  const globalVariables = makeGlobalVariables(undefined, {
204
- blockNumber: BlockNumber(latestBlockNumber + 1),
343
+ blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
205
344
  timestamp: this.nextBlockTimestamp,
206
345
  version: this.version,
207
346
  chainId: this.chainId
@@ -211,21 +350,47 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
211
350
  name: 'PUBLIC'
212
351
  };
213
352
  this.logger.debug(`Entered state ${this.state.name}`);
353
+ // Public state is anchored at the latest block.
354
+ this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
214
355
  }
215
356
  async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
216
357
  this.exitTopLevelState();
358
+ this.resetLastCall();
217
359
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
218
360
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
219
361
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
220
362
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
221
363
  // be removed from the database.
222
364
  // TODO(#12553): make the synchronizer sync here instead and remove this
223
- await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress);
224
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], anchorBlockHeader, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
365
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
366
+ this.oracleHandler = new UtilityExecutionOracle({
367
+ contractAddress,
368
+ authWitnesses: [],
369
+ capsules: [],
370
+ anchorBlockHeader,
371
+ contractStore: this.contractStore,
372
+ noteStore: this.noteStore,
373
+ keyStore: this.keyStore,
374
+ addressStore: this.addressStore,
375
+ aztecNode: this.stateMachine.node,
376
+ recipientTaggingStore: this.recipientTaggingStore,
377
+ senderAddressBookStore: this.senderAddressBookStore,
378
+ capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
379
+ privateEventStore: this.privateEventStore,
380
+ messageContextService: this.stateMachine.messageContextService,
381
+ contractSyncService: this.stateMachine.contractSyncService,
382
+ l2TipsStore: this.stateMachine.l2TipsProvider,
383
+ jobId: this.currentJobId,
384
+ scopes: await this.keyStore.getAccounts(),
385
+ simulator: new WASMSimulator(),
386
+ utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader)
387
+ });
225
388
  this.state = {
226
389
  name: 'UTILITY'
227
390
  };
228
391
  this.logger.debug(`Entered state ${this.state.name}`);
392
+ // Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
393
+ this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
229
394
  }
230
395
  exitTopLevelState() {
231
396
  if (this.state.name != 'TOP_LEVEL') {
@@ -233,8 +398,8 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
233
398
  }
234
399
  // Note that while all public and private contexts do is build a single block that we then process when exiting
235
400
  // 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
401
+ // others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
402
+ // `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
238
403
  // slight inconsistency in the working model of this class, but is not too bad.
239
404
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
240
405
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -278,14 +443,36 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
278
443
  }
279
444
  }
280
445
  utilityExecutorForContractSync(anchorBlock) {
281
- return async (call)=>{
446
+ return async (call, scopes)=>{
282
447
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
283
448
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
284
449
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
285
450
  }
286
451
  try {
287
- const oracle = new UtilityExecutionOracle(call.to, [], [], anchorBlock, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, 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)=>{
452
+ const simulator = new WASMSimulator();
453
+ const oracle = new UtilityExecutionOracle({
454
+ contractAddress: call.to,
455
+ authWitnesses: [],
456
+ capsules: [],
457
+ anchorBlockHeader: anchorBlock,
458
+ contractStore: this.contractStore,
459
+ noteStore: this.noteStore,
460
+ keyStore: this.keyStore,
461
+ addressStore: this.addressStore,
462
+ aztecNode: this.stateMachine.node,
463
+ recipientTaggingStore: this.recipientTaggingStore,
464
+ senderAddressBookStore: this.senderAddressBookStore,
465
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
466
+ privateEventStore: this.privateEventStore,
467
+ messageContextService: this.stateMachine.messageContextService,
468
+ contractSyncService: this.stateMachine.contractSyncService,
469
+ l2TipsStore: this.stateMachine.l2TipsProvider,
470
+ jobId: this.currentJobId,
471
+ scopes,
472
+ simulator,
473
+ utilityExecutor: this.utilityExecutorForContractSync(anchorBlock)
474
+ });
475
+ await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
289
476
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
290
477
  throw new ExecutionError(err.message, {
291
478
  contractAddress: call.to,
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFFLFdBQVcsRUFBRSxlQUFlLEVBQUUsUUFBUSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFMUU7Ozs7R0FJRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLEVBQUUsQ0FFeEU7QUFFRCx3QkFBc0IsNEJBQTRCLENBQ2hELFFBQVEsRUFBRSxRQUFRLEVBQ2xCLFVBQVUsRUFBRSx5QkFBeUIsR0FDcEMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWtCZjtBQUVELHdCQUFzQixrQkFBa0IsQ0FDdEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxHQUMvQixPQUFPLENBQUMsV0FBVyxDQUFDLENBWXRCO0FBRUQ7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gsd0JBQXNCLFlBQVksQ0FDaEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxFQUNoQyxTQUFTLEVBQUUsUUFBUSxFQUFFLEdBQ3BCLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FpQmxCIn0=
@@ -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,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,CAiBlB"}
@@ -49,7 +49,9 @@ export async function makeTXEBlockHeader(worldTrees, globalVariables) {
49
49
  // Get the new archive state after updating
50
50
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
51
51
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
52
- // L2Block requires checkpointNumber and indexWithinCheckpoint
52
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
53
+ // TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
54
+ // This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
53
55
  const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
54
56
  const indexWithinCheckpoint = IndexWithinCheckpoint(0);
55
57
  return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);