@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04d373f

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 (141) 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 +5 -0
  23. package/dest/constants.d.ts.map +1 -0
  24. package/dest/constants.js +7 -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 +31 -16
  40. package/dest/oracle/txe_oracle_top_level_context.d.ts +49 -31
  41. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  42. package/dest/oracle/txe_oracle_top_level_context.js +265 -119
  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 +144 -82
  50. package/dest/rpc_translator.d.ts.map +1 -1
  51. package/dest/rpc_translator.js +599 -238
  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 +20 -67
  55. package/dest/state_machine/archiver.d.ts.map +1 -1
  56. package/dest/state_machine/archiver.js +65 -182
  57. package/dest/state_machine/dummy_p2p_client.d.ts +28 -17
  58. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  59. package/dest/state_machine/dummy_p2p_client.js +51 -24
  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 +10 -4
  63. package/dest/state_machine/index.d.ts +11 -7
  64. package/dest/state_machine/index.d.ts.map +1 -1
  65. package/dest/state_machine/index.js +57 -16
  66. package/dest/state_machine/mock_epoch_cache.d.ts +26 -8
  67. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  68. package/dest/state_machine/mock_epoch_cache.js +49 -9
  69. package/dest/state_machine/synchronizer.d.ts +6 -6
  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 +83 -19
  76. package/dest/txe_session.d.ts.map +1 -1
  77. package/dest/txe_session.js +291 -66
  78. package/dest/utils/block_creation.d.ts +4 -4
  79. package/dest/utils/block_creation.d.ts.map +1 -1
  80. package/dest/utils/block_creation.js +18 -5
  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/utils/tx_effect_creation.d.ts +2 -3
  87. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  88. package/dest/utils/tx_effect_creation.js +3 -6
  89. package/dest/utils/txe_account_store.d.ts +10 -0
  90. package/dest/utils/txe_account_store.d.ts.map +1 -0
  91. package/dest/{util/txe_account_data_provider.js → utils/txe_account_store.js} +1 -1
  92. package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
  93. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
  94. package/dest/utils/txe_public_contract_data_source.js +48 -0
  95. package/dest/worker.bundle.js +3 -0
  96. package/dest/worker.bundle.js.map +7 -0
  97. package/dest/worker.d.ts +2 -0
  98. package/dest/worker.d.ts.map +1 -0
  99. package/dest/worker.js +92 -0
  100. package/package.json +38 -22
  101. package/src/bin/check_txe_oracle_version.ts +37 -0
  102. package/src/bin/index.ts +11 -2
  103. package/src/constants.ts +9 -0
  104. package/src/dispatcher_pool.ts +316 -0
  105. package/src/index.ts +166 -80
  106. package/src/msgpackr_fr_extension.ts +23 -0
  107. package/src/oracle/interfaces.ts +48 -34
  108. package/src/oracle/txe_oracle_public_context.ts +46 -18
  109. package/src/oracle/txe_oracle_top_level_context.ts +322 -169
  110. package/src/oracle/txe_private_execution_oracle.ts +30 -0
  111. package/src/rpc_server.ts +87 -0
  112. package/src/rpc_translator.ts +687 -326
  113. package/src/state_machine/archiver.ts +69 -220
  114. package/src/state_machine/dummy_p2p_client.ts +80 -37
  115. package/src/state_machine/global_variable_builder.ts +19 -4
  116. package/src/state_machine/index.ts +73 -16
  117. package/src/state_machine/mock_epoch_cache.ts +61 -14
  118. package/src/state_machine/synchronizer.ts +6 -6
  119. package/src/txe_oracle_version.ts +17 -0
  120. package/src/txe_session.ts +439 -132
  121. package/src/utils/block_creation.ts +19 -16
  122. package/src/{util → utils}/encoding.ts +8 -2
  123. package/src/utils/tx_effect_creation.ts +3 -11
  124. package/src/{util/txe_account_data_provider.ts → utils/txe_account_store.ts} +1 -1
  125. package/src/utils/txe_public_contract_data_source.ts +58 -0
  126. package/src/worker.ts +98 -0
  127. package/dest/util/encoding.d.ts +0 -720
  128. package/dest/util/encoding.d.ts.map +0 -1
  129. package/dest/util/expected_failure_error.d.ts.map +0 -1
  130. package/dest/util/txe_account_data_provider.d.ts +0 -10
  131. package/dest/util/txe_account_data_provider.d.ts.map +0 -1
  132. package/dest/util/txe_contract_data_provider.d.ts +0 -12
  133. package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
  134. package/dest/util/txe_contract_data_provider.js +0 -22
  135. package/dest/util/txe_public_contract_data_source.d.ts +0 -21
  136. package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
  137. package/dest/util/txe_public_contract_data_source.js +0 -67
  138. package/src/util/txe_contract_data_provider.ts +0 -36
  139. package/src/util/txe_public_contract_data_source.ts +0 -86
  140. /package/dest/{util → utils}/expected_failure_error.js +0 -0
  141. /package/src/{util → utils}/expected_failure_error.ts +0 -0
@@ -2,59 +2,81 @@ 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 { AddressDataProvider, CapsuleDataProvider, NoteDataProvider, NoteService, PrivateEventDataProvider, RecipientTaggingDataProvider, SenderTaggingDataProvider } from '@aztec/pxe/server';
7
- import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
8
- import { FunctionSelector } from '@aztec/stdlib/abi';
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
+ import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
9
+ import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec/standard-contracts/auth-registry/constants';
10
+ import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
9
11
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
10
- import { GasSettings } from '@aztec/stdlib/gas';
11
12
  import { computeProtocolNullifier } from '@aztec/stdlib/hash';
12
13
  import { makeGlobalVariables } from '@aztec/stdlib/testing';
13
- import { CallContext, TxContext } from '@aztec/stdlib/tx';
14
+ import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
14
15
  import { z } from 'zod';
16
+ import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
15
17
  import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
16
18
  import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
19
+ import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
17
20
  import { RPCTranslator } from './rpc_translator.js';
21
+ import { TXEArchiver } from './state_machine/archiver.js';
18
22
  import { TXEStateMachine } from './state_machine/index.js';
19
- import { TXEAccountDataProvider } from './util/txe_account_data_provider.js';
20
- import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
23
+ import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './txe_oracle_version.js';
21
24
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
22
25
  import { makeTxEffect } from './utils/tx_effect_creation.js';
23
- export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
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
+ }
24
35
  /**
25
36
  * A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
26
37
  * state, etc., independent of all other tests running in parallel.
27
38
  */ export class TXESession {
28
39
  logger;
40
+ sessionStore;
29
41
  stateMachine;
30
42
  oracleHandler;
31
- contractDataProvider;
32
- noteDataProvider;
43
+ contractStore;
44
+ noteStore;
33
45
  keyStore;
34
- addressDataProvider;
35
- accountDataProvider;
36
- senderTaggingDataProvider;
37
- recipientTaggingDataProvider;
38
- capsuleDataProvider;
39
- privateEventDataProvider;
46
+ addressStore;
47
+ accountStore;
48
+ senderTaggingStore;
49
+ recipientTaggingStore;
50
+ senderAddressBookStore;
51
+ capsuleStore;
52
+ privateEventStore;
53
+ jobCoordinator;
54
+ currentJobId;
40
55
  chainId;
41
56
  version;
42
57
  nextBlockTimestamp;
43
58
  state;
44
59
  authwits;
45
- constructor(logger, stateMachine, oracleHandler, contractDataProvider, noteDataProvider, keyStore, addressDataProvider, accountDataProvider, senderTaggingDataProvider, recipientTaggingDataProvider, capsuleDataProvider, privateEventDataProvider, 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){
46
64
  this.logger = logger;
65
+ this.sessionStore = sessionStore;
47
66
  this.stateMachine = stateMachine;
48
67
  this.oracleHandler = oracleHandler;
49
- this.contractDataProvider = contractDataProvider;
50
- this.noteDataProvider = noteDataProvider;
68
+ this.contractStore = contractStore;
69
+ this.noteStore = noteStore;
51
70
  this.keyStore = keyStore;
52
- this.addressDataProvider = addressDataProvider;
53
- this.accountDataProvider = accountDataProvider;
54
- this.senderTaggingDataProvider = senderTaggingDataProvider;
55
- this.recipientTaggingDataProvider = recipientTaggingDataProvider;
56
- this.capsuleDataProvider = capsuleDataProvider;
57
- this.privateEventDataProvider = privateEventDataProvider;
71
+ this.addressStore = addressStore;
72
+ this.accountStore = accountStore;
73
+ this.senderTaggingStore = senderTaggingStore;
74
+ this.recipientTaggingStore = recipientTaggingStore;
75
+ this.senderAddressBookStore = senderAddressBookStore;
76
+ this.capsuleStore = capsuleStore;
77
+ this.privateEventStore = privateEventStore;
78
+ this.jobCoordinator = jobCoordinator;
79
+ this.currentJobId = currentJobId;
58
80
  this.chainId = chainId;
59
81
  this.version = version;
60
82
  this.nextBlockTimestamp = nextBlockTimestamp;
@@ -62,30 +84,64 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
62
84
  name: 'TOP_LEVEL'
63
85
  };
64
86
  this.authwits = new Map();
87
+ this.lastCallInfo = emptyLastCallState();
88
+ this.disposed = false;
65
89
  }
66
- static async init(protocolContracts) {
67
- const store = await openTmpStore('txe-session');
68
- const addressDataProvider = new AddressDataProvider(store);
69
- const privateEventDataProvider = new PrivateEventDataProvider(store);
70
- const contractDataProvider = new TXEContractDataProvider(store);
71
- const noteDataProvider = await NoteDataProvider.create(store);
72
- const senderTaggingDataProvider = new SenderTaggingDataProvider(store);
73
- const recipientTaggingDataProvider = new RecipientTaggingDataProvider(store);
74
- const capsuleDataProvider = new CapsuleDataProvider(store);
75
- const keyStore = new KeyStore(store);
76
- const accountDataProvider = new TXEAccountDataProvider(store);
77
- // Register protocol contracts.
78
- for (const { contractClass, instance, artifact } of protocolContracts){
79
- await contractDataProvider.addContractArtifact(contractClass.id, artifact);
80
- await contractDataProvider.addContractInstance(instance);
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);
81
102
  }
82
- const stateMachine = await TXEStateMachine.create(store);
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);
115
+ const addressStore = new AddressStore(store);
116
+ const privateEventStore = new PrivateEventStore(store);
117
+ const noteStore = new NoteStore(store);
118
+ const senderTaggingStore = new SenderTaggingStore(store);
119
+ const recipientTaggingStore = new RecipientTaggingStore(store);
120
+ const senderAddressBookStore = new SenderAddressBookStore(store);
121
+ const capsuleStore = new CapsuleStore(store);
122
+ const keyStore = new KeyStore(store);
123
+ const accountStore = new TXEAccountStore(store);
124
+ const jobCoordinator = new JobCoordinator(store);
125
+ jobCoordinator.registerStores([
126
+ capsuleStore,
127
+ senderTaggingStore,
128
+ recipientTaggingStore,
129
+ privateEventStore,
130
+ noteStore
131
+ ]);
132
+ const archiver = new TXEArchiver(store);
133
+ const anchorBlockStore = new AnchorBlockStore(store);
134
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
83
135
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
84
136
  const version = new Fr(await stateMachine.node.getVersion());
85
137
  const chainId = new Fr(await stateMachine.node.getChainId());
86
- const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractDataProvider, noteDataProvider, keyStore, addressDataProvider, accountDataProvider, senderTaggingDataProvider, recipientTaggingDataProvider, capsuleDataProvider, privateEventDataProvider, nextBlockTimestamp, version, chainId, new Map());
87
- await topLevelOracleHandler.txeAdvanceBlocksBy(1);
88
- return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractDataProvider, noteDataProvider, keyStore, addressDataProvider, accountDataProvider, senderTaggingDataProvider, recipientTaggingDataProvider, capsuleDataProvider, privateEventDataProvider, version, chainId, nextBlockTimestamp);
138
+ const initialJobId = jobCoordinator.beginJob();
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);
89
145
  }
90
146
  /**
91
147
  * Processes an oracle function invoked by the Noir test associated to this session.
@@ -100,7 +156,15 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
100
156
  return translator[validatedFunctionName](...inputs);
101
157
  } catch (error) {
102
158
  if (error instanceof z.ZodError) {
103
- 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}`);
104
168
  } else if (error instanceof Error) {
105
169
  throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
106
170
  } else {
@@ -108,6 +172,68 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
108
172
  }
109
173
  }
110
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
+ }
111
237
  async enterTopLevelState() {
112
238
  switch(this.state.name){
113
239
  case 'PRIVATE':
@@ -134,25 +260,23 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
134
260
  this.state;
135
261
  }
136
262
  }
137
- this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractDataProvider, this.noteDataProvider, this.keyStore, this.addressDataProvider, this.accountDataProvider, this.senderTaggingDataProvider, this.recipientTaggingDataProvider, this.capsuleDataProvider, this.privateEventDataProvider, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
263
+ // Commit all staged stores from the job that was just completed, then begin a new job
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);
138
266
  this.state = {
139
267
  name: 'TOP_LEVEL'
140
268
  };
141
269
  this.logger.debug(`Entered state ${this.state.name}`);
142
270
  }
143
- async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
271
+ async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber, gasSettings) {
144
272
  this.exitTopLevelState();
145
- // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
146
- // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
147
- // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
148
- // be removed from the database.
149
- // TODO(#12553): make the synchronizer sync here instead and remove this
150
- await new NoteService(this.noteDataProvider, this.stateMachine.node, this.stateMachine.anchorBlockDataProvider).syncNoteNullifiers(contractAddress);
273
+ this.resetLastCall();
151
274
  // Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
152
275
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
153
276
  // a single transaction with the effects of what was done in the test.
154
- const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
155
- 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);
156
280
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
157
281
  blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
158
282
  timestamp: this.nextBlockTimestamp,
@@ -163,7 +287,35 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
163
287
  const protocolNullifier = await computeProtocolNullifier(txRequestHash);
164
288
  const noteCache = new ExecutionNoteCache(protocolNullifier);
165
289
  const taggingIndexCache = new ExecutionTaggingIndexCache();
166
- this.oracleHandler = new PrivateExecutionOracle(Fr.ZERO, new TxContext(this.chainId, this.version, GasSettings.empty()), new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false), anchorBlock, [], [], new HashedValuesCache(), noteCache, taggingIndexCache, this.contractDataProvider, this.noteDataProvider, this.keyStore, this.addressDataProvider, this.stateMachine.node, this.stateMachine.anchorBlockDataProvider, this.senderTaggingDataProvider, this.recipientTaggingDataProvider, this.capsuleDataProvider, this.privateEventDataProvider);
290
+ const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
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
+ });
167
319
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
168
320
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
169
321
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -172,20 +324,23 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
172
324
  this.state = {
173
325
  name: 'PRIVATE',
174
326
  nextBlockGlobalVariables,
175
- protocolNullifier,
176
327
  noteCache,
177
328
  taggingIndexCache
178
329
  };
179
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);
180
334
  return this.oracleHandler.getPrivateContextInputs();
181
335
  }
182
336
  async enterPublicState(contractAddress) {
183
337
  this.exitTopLevelState();
338
+ this.resetLastCall();
184
339
  // The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
185
340
  // the test. The block therefore gets the *next* block number and timestamp.
186
- const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
341
+ const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
187
342
  const globalVariables = makeGlobalVariables(undefined, {
188
- blockNumber: BlockNumber(latestBlockNumber + 1),
343
+ blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
189
344
  timestamp: this.nextBlockTimestamp,
190
345
  version: this.version,
191
346
  chainId: this.chainId
@@ -195,21 +350,47 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
195
350
  name: 'PUBLIC'
196
351
  };
197
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);
198
355
  }
199
356
  async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
200
357
  this.exitTopLevelState();
358
+ this.resetLastCall();
359
+ const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
201
360
  // There is no automatic message discovery and contract-driven syncing process in inlined private or utility
202
361
  // contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
203
362
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
204
363
  // be removed from the database.
205
364
  // TODO(#12553): make the synchronizer sync here instead and remove this
206
- await new NoteService(this.noteDataProvider, this.stateMachine.node, this.stateMachine.anchorBlockDataProvider).syncNoteNullifiers(contractAddress);
207
- const anchorBlockHeader = await this.stateMachine.anchorBlockDataProvider.getBlockHeader();
208
- this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], anchorBlockHeader, this.contractDataProvider, this.noteDataProvider, this.keyStore, this.addressDataProvider, this.stateMachine.node, this.stateMachine.anchorBlockDataProvider, this.senderTaggingDataProvider, this.recipientTaggingDataProvider, this.capsuleDataProvider, this.privateEventDataProvider);
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
+ });
209
388
  this.state = {
210
389
  name: 'UTILITY'
211
390
  };
212
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);
213
394
  }
214
395
  exitTopLevelState() {
215
396
  if (this.state.name != 'TOP_LEVEL') {
@@ -217,8 +398,8 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
217
398
  }
218
399
  // Note that while all public and private contexts do is build a single block that we then process when exiting
219
400
  // those, the top level context performs a large number of actions not captured in the following 'close' call. Among
220
- // others, it will create empty blocks (via `txeAdvanceBlocksBy` and `deploy`), create blocks with transactions via
221
- // `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
222
403
  // slight inconsistency in the working model of this class, but is not too bad.
223
404
  // TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
224
405
  // level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
@@ -235,7 +416,7 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
235
416
  });
236
417
  // We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
237
418
  // logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
238
- const txEffect = await makeTxEffect(this.state.noteCache, this.state.protocolNullifier, this.state.nextBlockGlobalVariables.blockNumber);
419
+ const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
239
420
  // We build a block holding just this transaction
240
421
  const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
241
422
  await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
@@ -261,4 +442,48 @@ export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
261
442
  throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
262
443
  }
263
444
  }
445
+ utilityExecutorForContractSync(anchorBlock) {
446
+ return async (call, scopes)=>{
447
+ const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
448
+ if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
449
+ throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
450
+ }
451
+ try {
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)=>{
476
+ err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
477
+ throw new ExecutionError(err.message, {
478
+ contractAddress: call.to,
479
+ functionSelector: call.selector
480
+ }, extractCallStack(err, entryPointArtifact.debug), {
481
+ cause: err
482
+ });
483
+ });
484
+ } catch (err) {
485
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
486
+ }
487
+ };
488
+ }
264
489
  }
@@ -1,8 +1,8 @@
1
1
  import { BlockNumber } from '@aztec/foundation/branded-types';
2
2
  import { Fr } from '@aztec/foundation/curves/bn254';
3
- import { L2Block, L2BlockHeader } from '@aztec/stdlib/block';
3
+ import { L2Block } from '@aztec/stdlib/block';
4
4
  import { type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
5
- import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
5
+ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
6
6
  /**
7
7
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
8
8
  * @param blockNumber The number for the block in which there is a single transaction.
@@ -10,7 +10,7 @@ import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
10
10
  */
11
11
  export declare function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr;
12
12
  export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations): Promise<void>;
13
- export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables): Promise<L2BlockHeader>;
13
+ export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables): Promise<BlockHeader>;
14
14
  /**
15
15
  * Creates an L2Block with proper archive chaining.
16
16
  * This function:
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFFOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sRUFBUSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFFbkUsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFF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_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
2
3
  import { padArrayEnd } from '@aztec/foundation/collection';
3
4
  import { Fr } from '@aztec/foundation/curves/bn254';
4
- import { Body, L2Block, L2BlockHeader } from '@aztec/stdlib/block';
5
- import { makeContentCommitment } from '@aztec/stdlib/testing';
5
+ import { Body, L2Block } from '@aztec/stdlib/block';
6
6
  import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
7
+ import { BlockHeader } from '@aztec/stdlib/tx';
7
8
  /**
8
9
  * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
9
10
  * @param blockNumber The number for the block in which there is a single transaction.
@@ -20,7 +21,14 @@ export async function insertTxEffectIntoWorldTrees(txEffect, worldTrees) {
20
21
  export async function makeTXEBlockHeader(worldTrees, globalVariables) {
21
22
  const stateReference = await worldTrees.getStateReference();
22
23
  const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
23
- return new L2BlockHeader(new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)), makeContentCommitment(), stateReference, globalVariables, Fr.ZERO, Fr.ZERO, Fr.ZERO, Fr.ZERO);
24
+ return BlockHeader.from({
25
+ lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
26
+ spongeBlobHash: Fr.ZERO,
27
+ state: stateReference,
28
+ globalVariables,
29
+ totalFees: Fr.ZERO,
30
+ totalManaUsed: Fr.ZERO
31
+ });
24
32
  }
25
33
  /**
26
34
  * Creates an L2Block with proper archive chaining.
@@ -37,9 +45,14 @@ export async function makeTXEBlockHeader(worldTrees, globalVariables) {
37
45
  */ export async function makeTXEBlock(worldTrees, globalVariables, txEffects) {
38
46
  const header = await makeTXEBlockHeader(worldTrees, globalVariables);
39
47
  // Update the archive tree with this block's header hash
40
- await worldTrees.updateArchive(header.toBlockHeader());
48
+ await worldTrees.updateArchive(header);
41
49
  // Get the new archive state after updating
42
50
  const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
43
51
  const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
44
- return new L2Block(newArchive, header, new Body(txEffects));
52
+ // L2Block requires checkpointNumber and indexWithinCheckpoint.
53
+ // 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.
55
+ const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
56
+ const indexWithinCheckpoint = IndexWithinCheckpoint(0);
57
+ return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
45
58
  }