@aztec/txe 0.0.1-commit.6230a0c → 0.0.1-commit.643667a5cb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +82 -50
  4. package/dest/oracle/interfaces.d.ts +2 -2
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_top_level_context.d.ts +5 -6
  7. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_top_level_context.js +84 -26
  9. package/dest/rpc_translator.d.ts +5 -5
  10. package/dest/rpc_translator.d.ts.map +1 -1
  11. package/dest/rpc_translator.js +5 -5
  12. package/dest/state_machine/archiver.d.ts +1 -1
  13. package/dest/state_machine/archiver.d.ts.map +1 -1
  14. package/dest/state_machine/archiver.js +2 -0
  15. package/dest/state_machine/dummy_p2p_client.d.ts +15 -11
  16. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  17. package/dest/state_machine/dummy_p2p_client.js +27 -15
  18. package/dest/state_machine/index.d.ts +5 -5
  19. package/dest/state_machine/index.d.ts.map +1 -1
  20. package/dest/state_machine/index.js +15 -10
  21. package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
  22. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  23. package/dest/state_machine/mock_epoch_cache.js +4 -0
  24. package/dest/txe_session.d.ts +4 -6
  25. package/dest/txe_session.d.ts.map +1 -1
  26. package/dest/txe_session.js +68 -16
  27. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  28. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  29. package/dest/util/txe_public_contract_data_source.js +5 -22
  30. package/dest/utils/block_creation.d.ts +1 -1
  31. package/dest/utils/block_creation.d.ts.map +1 -1
  32. package/dest/utils/block_creation.js +3 -1
  33. package/package.json +15 -15
  34. package/src/index.ts +83 -49
  35. package/src/oracle/interfaces.ts +1 -1
  36. package/src/oracle/txe_oracle_top_level_context.ts +77 -83
  37. package/src/rpc_translator.ts +5 -5
  38. package/src/state_machine/archiver.ts +2 -0
  39. package/src/state_machine/dummy_p2p_client.ts +39 -21
  40. package/src/state_machine/index.ts +25 -9
  41. package/src/state_machine/mock_epoch_cache.ts +5 -0
  42. package/src/txe_session.ts +66 -64
  43. package/src/util/txe_public_contract_data_source.ts +10 -36
  44. package/src/utils/block_creation.ts +3 -1
  45. package/dest/util/txe_contract_store.d.ts +0 -12
  46. package/dest/util/txe_contract_store.d.ts.map +0 -1
  47. package/dest/util/txe_contract_store.js +0 -22
  48. package/src/util/txe_contract_store.ts +0 -36
@@ -3,7 +3,7 @@ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import { createLogger } from '@aztec/foundation/log';
4
4
  import { KeyStore } from '@aztec/key-store';
5
5
  import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
6
- import { AddressStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
6
+ import { AddressStore, AnchorBlockStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
7
7
  import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
8
8
  import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
9
9
  import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
@@ -17,9 +17,9 @@ import { DEFAULT_ADDRESS } 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
19
  import { RPCTranslator } from './rpc_translator.js';
20
+ import { TXEArchiver } from './state_machine/archiver.js';
20
21
  import { TXEStateMachine } from './state_machine/index.js';
21
22
  import { TXEAccountStore } from './util/txe_account_store.js';
22
- import { TXEContractStore } from './util/txe_contract_store.js';
23
23
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
24
24
  import { makeTxEffect } from './utils/tx_effect_creation.js';
25
25
  /**
@@ -70,11 +70,10 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
70
70
  };
71
71
  this.authwits = new Map();
72
72
  }
73
- static async init(protocolContracts) {
73
+ static async init(contractStore) {
74
74
  const store = await openTmpStore('txe-session');
75
75
  const addressStore = new AddressStore(store);
76
76
  const privateEventStore = new PrivateEventStore(store);
77
- const contractStore = new TXEContractStore(store);
78
77
  const noteStore = new NoteStore(store);
79
78
  const senderTaggingStore = new SenderTaggingStore(store);
80
79
  const recipientTaggingStore = new RecipientTaggingStore(store);
@@ -91,12 +90,9 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
91
90
  privateEventStore,
92
91
  noteStore
93
92
  ]);
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);
93
+ const archiver = new TXEArchiver(store);
94
+ const anchorBlockStore = new AnchorBlockStore(store);
95
+ const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
100
96
  const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
101
97
  const version = new Fr(await stateMachine.node.getVersion());
102
98
  const chainId = new Fr(await stateMachine.node.getChainId());
@@ -167,7 +163,7 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
167
163
  // build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
168
164
  // a single transaction with the effects of what was done in the test.
169
165
  const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
170
- await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress);
166
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
171
167
  const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
172
168
  const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
173
169
  blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
@@ -180,7 +176,31 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
180
176
  const noteCache = new ExecutionNoteCache(protocolNullifier);
181
177
  const taggingIndexCache = new ExecutionTaggingIndexCache();
182
178
  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);
179
+ this.oracleHandler = new PrivateExecutionOracle({
180
+ argsHash: Fr.ZERO,
181
+ txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
182
+ callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
183
+ anchorBlockHeader: anchorBlock,
184
+ utilityExecutor,
185
+ authWitnesses: [],
186
+ capsules: [],
187
+ executionCache: new HashedValuesCache(),
188
+ noteCache,
189
+ taggingIndexCache,
190
+ contractStore: this.contractStore,
191
+ noteStore: this.noteStore,
192
+ keyStore: this.keyStore,
193
+ addressStore: this.addressStore,
194
+ aztecNode: this.stateMachine.node,
195
+ senderTaggingStore: this.senderTaggingStore,
196
+ recipientTaggingStore: this.recipientTaggingStore,
197
+ senderAddressBookStore: this.senderAddressBookStore,
198
+ capsuleStore: this.capsuleStore,
199
+ privateEventStore: this.privateEventStore,
200
+ contractSyncService: this.stateMachine.contractSyncService,
201
+ jobId: this.currentJobId,
202
+ scopes: 'ALL_SCOPES'
203
+ });
184
204
  // We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
185
205
  // data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
186
206
  // difference resides in that the simulator has all information needed in order to run the simulation, while ours
@@ -220,8 +240,24 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
220
240
  // we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
221
241
  // be removed from the database.
222
242
  // 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);
243
+ await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
244
+ this.oracleHandler = new UtilityExecutionOracle({
245
+ contractAddress,
246
+ authWitnesses: [],
247
+ capsules: [],
248
+ anchorBlockHeader,
249
+ contractStore: this.contractStore,
250
+ noteStore: this.noteStore,
251
+ keyStore: this.keyStore,
252
+ addressStore: this.addressStore,
253
+ aztecNode: this.stateMachine.node,
254
+ recipientTaggingStore: this.recipientTaggingStore,
255
+ senderAddressBookStore: this.senderAddressBookStore,
256
+ capsuleStore: this.capsuleStore,
257
+ privateEventStore: this.privateEventStore,
258
+ jobId: this.currentJobId,
259
+ scopes: 'ALL_SCOPES'
260
+ });
225
261
  this.state = {
226
262
  name: 'UTILITY'
227
263
  };
@@ -278,13 +314,29 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
278
314
  }
279
315
  }
280
316
  utilityExecutorForContractSync(anchorBlock) {
281
- return async (call)=>{
317
+ return async (call, scopes)=>{
282
318
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
283
319
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
284
320
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
285
321
  }
286
322
  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);
323
+ const oracle = new UtilityExecutionOracle({
324
+ contractAddress: call.to,
325
+ authWitnesses: [],
326
+ capsules: [],
327
+ anchorBlockHeader: anchorBlock,
328
+ contractStore: this.contractStore,
329
+ noteStore: this.noteStore,
330
+ keyStore: this.keyStore,
331
+ addressStore: this.addressStore,
332
+ aztecNode: this.stateMachine.node,
333
+ recipientTaggingStore: this.recipientTaggingStore,
334
+ senderAddressBookStore: this.senderAddressBookStore,
335
+ capsuleStore: this.capsuleStore,
336
+ privateEventStore: this.privateEventStore,
337
+ jobId: this.currentJobId,
338
+ scopes
339
+ });
288
340
  await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
289
341
  err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
290
342
  throw new ExecutionError(err.message, {
@@ -3,9 +3,8 @@ import { Fr } from '@aztec/foundation/curves/bn254';
3
3
  import type { ContractStore } from '@aztec/pxe/server';
4
4
  import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
5
5
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import { type ContractClassPublic, type ContractDataSource, type ContractInstanceWithAddress } from '@aztec/stdlib/contract';
6
+ import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
7
7
  export declare class TXEPublicContractDataSource implements ContractDataSource {
8
- #private;
9
8
  private blockNumber;
10
9
  private contractStore;
11
10
  constructor(blockNumber: BlockNumber, contractStore: ContractStore);
@@ -18,4 +17,4 @@ export declare class TXEPublicContractDataSource implements ContractDataSource {
18
17
  getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
19
18
  registerContractFunctionSignatures(_signatures: []): Promise<void>;
20
19
  }
21
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLGdCQUFnQixFQUFnQixNQUFNLG1CQUFtQixDQUFDO0FBQzFGLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLDZCQUE2QixDQUFDO0FBQ2hFLE9BQU8sRUFDTCxLQUFLLG1CQUFtQixFQUN4QixLQUFLLGtCQUFrQixFQUN2QixLQUFLLDJCQUEyQixFQUlqQyxNQUFNLHdCQUF3QixDQUFDO0FBRWhDLHFCQUFhLDJCQUE0QixZQUFXLGtCQUFrQjs7SUFHbEUsT0FBTyxDQUFDLFdBQVc7SUFDbkIsT0FBTyxDQUFDLGFBQWE7SUFGdkIsWUFDVS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G3D;IAEK,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC,CAGzF;IAED,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC,CAEnC;IAEK,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAGtF;IAEK,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEzG;IAED,kCAAkC,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE;CACF"}
@@ -1,48 +1,31 @@
1
- import { Fr } from '@aztec/foundation/curves/bn254';
2
- import { FunctionType } from '@aztec/stdlib/abi';
3
- import { computePrivateFunctionsRoot, computePublicBytecodeCommitment, getContractClassPrivateFunctionFromArtifact } from '@aztec/stdlib/contract';
4
1
  export class TXEPublicContractDataSource {
5
2
  blockNumber;
6
3
  contractStore;
7
- #privateFunctionsRoot;
8
4
  constructor(blockNumber, contractStore){
9
5
  this.blockNumber = blockNumber;
10
6
  this.contractStore = contractStore;
11
- this.#privateFunctionsRoot = new Map();
12
7
  }
13
8
  getBlockNumber() {
14
9
  return Promise.resolve(this.blockNumber);
15
10
  }
16
11
  async getContractClass(id) {
17
- const contractClass = await this.contractStore.getContractClass(id);
12
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
18
13
  if (!contractClass) {
19
14
  return;
20
15
  }
21
- const artifact = await this.contractStore.getContractArtifact(id);
22
- if (!artifact) {
23
- return;
24
- }
25
- let privateFunctionsRoot;
26
- if (!this.#privateFunctionsRoot.has(id.toString())) {
27
- const privateFunctions = await Promise.all(artifact.functions.filter((fn)=>fn.functionType === FunctionType.PRIVATE).map((fn)=>getContractClassPrivateFunctionFromArtifact(fn)));
28
- privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
29
- this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
30
- } else {
31
- privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString()));
32
- }
33
16
  return {
34
- id,
17
+ id: contractClass.id,
35
18
  artifactHash: contractClass.artifactHash,
36
19
  packedBytecode: contractClass.packedBytecode,
37
- privateFunctionsRoot,
20
+ privateFunctionsRoot: contractClass.privateFunctionsRoot,
38
21
  version: contractClass.version,
39
22
  privateFunctions: [],
40
23
  utilityFunctions: []
41
24
  };
42
25
  }
43
26
  async getBytecodeCommitment(id) {
44
- const contractClass = await this.contractStore.getContractClass(id);
45
- return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
27
+ const contractClass = await this.contractStore.getContractClassWithPreimage(id);
28
+ return contractClass?.publicBytecodeCommitment;
46
29
  }
47
30
  async getContract(address) {
48
31
  const instance = await this.contractStore.getContractInstance(address);
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5Q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AC,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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "0.0.1-commit.6230a0c",
3
+ "version": "0.0.1-commit.643667a5cb",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "bin": "./dest/bin/index.js",
@@ -61,20 +61,20 @@
61
61
  ]
62
62
  },
63
63
  "dependencies": {
64
- "@aztec/accounts": "0.0.1-commit.6230a0c",
65
- "@aztec/archiver": "0.0.1-commit.6230a0c",
66
- "@aztec/aztec-node": "0.0.1-commit.6230a0c",
67
- "@aztec/aztec.js": "0.0.1-commit.6230a0c",
68
- "@aztec/bb-prover": "0.0.1-commit.6230a0c",
69
- "@aztec/constants": "0.0.1-commit.6230a0c",
70
- "@aztec/foundation": "0.0.1-commit.6230a0c",
71
- "@aztec/key-store": "0.0.1-commit.6230a0c",
72
- "@aztec/kv-store": "0.0.1-commit.6230a0c",
73
- "@aztec/protocol-contracts": "0.0.1-commit.6230a0c",
74
- "@aztec/pxe": "0.0.1-commit.6230a0c",
75
- "@aztec/simulator": "0.0.1-commit.6230a0c",
76
- "@aztec/stdlib": "0.0.1-commit.6230a0c",
77
- "@aztec/world-state": "0.0.1-commit.6230a0c",
64
+ "@aztec/accounts": "0.0.1-commit.643667a5cb",
65
+ "@aztec/archiver": "0.0.1-commit.643667a5cb",
66
+ "@aztec/aztec-node": "0.0.1-commit.643667a5cb",
67
+ "@aztec/aztec.js": "0.0.1-commit.643667a5cb",
68
+ "@aztec/bb-prover": "0.0.1-commit.643667a5cb",
69
+ "@aztec/constants": "0.0.1-commit.643667a5cb",
70
+ "@aztec/foundation": "0.0.1-commit.643667a5cb",
71
+ "@aztec/key-store": "0.0.1-commit.643667a5cb",
72
+ "@aztec/kv-store": "0.0.1-commit.643667a5cb",
73
+ "@aztec/protocol-contracts": "0.0.1-commit.643667a5cb",
74
+ "@aztec/pxe": "0.0.1-commit.643667a5cb",
75
+ "@aztec/simulator": "0.0.1-commit.643667a5cb",
76
+ "@aztec/stdlib": "0.0.1-commit.643667a5cb",
77
+ "@aztec/world-state": "0.0.1-commit.643667a5cb",
78
78
  "zod": "^3.23.8"
79
79
  },
80
80
  "devDependencies": {
package/src/index.ts CHANGED
@@ -9,9 +9,12 @@ import { Fr } from '@aztec/aztec.js/fields';
9
9
  import { PublicKeys, deriveKeys } from '@aztec/aztec.js/keys';
10
10
  import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
11
11
  import type { Logger } from '@aztec/foundation/log';
12
- import { type ProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
12
+ import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
13
+ import { protocolContractNames } from '@aztec/protocol-contracts';
13
14
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
15
+ import { ContractStore } from '@aztec/pxe/server';
14
16
  import { computeArtifactHash } from '@aztec/stdlib/contract';
17
+ import type { ContractArtifactWithHash } from '@aztec/stdlib/contract';
15
18
  import type { ApiSchemaFor } from '@aztec/stdlib/schemas';
16
19
  import { zodFor } from '@aztec/stdlib/schemas';
17
20
 
@@ -33,18 +36,24 @@ import {
33
36
  fromSingle,
34
37
  toSingle,
35
38
  } from './util/encoding.js';
36
- import type { ContractArtifactWithHash } from './util/txe_contract_store.js';
37
39
 
38
40
  const sessions = new Map<number, TXESession>();
39
41
 
40
42
  /*
41
43
  * TXE typically has to load the same contract artifacts over and over again for multiple tests,
42
- * so we cache them here to avoid both loading them from disk repeatedly and computing their artifact hashes
44
+ * so we cache them here to avoid loading from disk repeatedly.
45
+ *
46
+ * The in-flight map coalesces concurrent requests for the same cache key so that
47
+ * computeArtifactHash (very expensive) is only run once even under parallelism.
43
48
  */
44
49
  const TXEArtifactsCache = new Map<
45
50
  string,
46
51
  { artifact: ContractArtifactWithHash; instance: ContractInstanceWithAddress }
47
52
  >();
53
+ const TXEArtifactsCacheInFlight = new Map<
54
+ string,
55
+ Promise<{ artifact: ContractArtifactWithHash; instance: ContractInstanceWithAddress }>
56
+ >();
48
57
 
49
58
  type TXEForeignCallInput = {
50
59
  session_id: number;
@@ -68,7 +77,7 @@ const TXEForeignCallInputSchema = zodFor<TXEForeignCallInput>()(
68
77
  );
69
78
 
70
79
  class TXEDispatcher {
71
- private protocolContracts!: ProtocolContract[];
80
+ private contractStore!: ContractStore;
72
81
 
73
82
  constructor(private logger: Logger) {}
74
83
 
@@ -135,29 +144,36 @@ class TXEDispatcher {
135
144
  this.logger.debug(`Using cached artifact for ${cacheKey}`);
136
145
  ({ artifact, instance } = TXEArtifactsCache.get(cacheKey)!);
137
146
  } else {
138
- this.logger.debug(`Loading compiled artifact ${artifactPath}`);
139
- const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8')) as NoirCompiledContract;
140
- const artifactWithoutHash = loadContractArtifact(artifactJSON);
141
- artifact = {
142
- ...artifactWithoutHash,
143
- // Artifact hash is *very* expensive to compute, so we do it here once
144
- // and the TXE contract data provider can cache it
145
- artifactHash: await computeArtifactHash(artifactWithoutHash),
146
- };
147
- this.logger.debug(
148
- `Deploy ${
149
- artifact.name
150
- } with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`,
151
- );
152
- instance = await getContractInstanceFromInstantiationParams(artifact, {
153
- constructorArgs: decodedArgs,
154
- skipArgsDecoding: true,
155
- salt: Fr.ONE,
156
- publicKeys,
157
- constructorArtifact: initializer ? initializer : undefined,
158
- deployer: AztecAddress.ZERO,
159
- });
160
- TXEArtifactsCache.set(cacheKey, { artifact, instance });
147
+ if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
148
+ this.logger.debug(`Loading compiled artifact ${artifactPath}`);
149
+ const compute = async () => {
150
+ const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8')) as NoirCompiledContract;
151
+ const artifactWithoutHash = loadContractArtifact(artifactJSON);
152
+ const computedArtifact: ContractArtifactWithHash = {
153
+ ...artifactWithoutHash,
154
+ // Artifact hash is *very* expensive to compute, so we do it here once
155
+ // and the TXE contract data provider can cache it
156
+ artifactHash: await computeArtifactHash(artifactWithoutHash),
157
+ };
158
+ this.logger.debug(
159
+ `Deploy ${computedArtifact.name} with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`,
160
+ );
161
+ const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
162
+ constructorArgs: decodedArgs,
163
+ skipArgsDecoding: true,
164
+ salt: Fr.ONE,
165
+ publicKeys,
166
+ constructorArtifact: initializer ? initializer : undefined,
167
+ deployer: AztecAddress.ZERO,
168
+ });
169
+ const result = { artifact: computedArtifact, instance: computedInstance };
170
+ TXEArtifactsCache.set(cacheKey, result);
171
+ TXEArtifactsCacheInFlight.delete(cacheKey);
172
+ return result;
173
+ };
174
+ TXEArtifactsCacheInFlight.set(cacheKey, compute());
175
+ }
176
+ ({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey)!);
161
177
  }
162
178
 
163
179
  inputs.splice(0, 1, artifact, instance, toSingle(secret));
@@ -175,23 +191,35 @@ class TXEDispatcher {
175
191
  this.logger.debug(`Using cached artifact for ${cacheKey}`);
176
192
  ({ artifact, instance } = TXEArtifactsCache.get(cacheKey)!);
177
193
  } else {
178
- const keys = await deriveKeys(secret);
179
- const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y];
180
- artifact = {
181
- ...SchnorrAccountContractArtifact,
182
- // Artifact hash is *very* expensive to compute, so we do it here once
183
- // and the TXE contract data provider can cache it
184
- artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact),
185
- };
186
- instance = await getContractInstanceFromInstantiationParams(artifact, {
187
- constructorArgs: args,
188
- skipArgsDecoding: true,
189
- salt: Fr.ONE,
190
- publicKeys: keys.publicKeys,
191
- constructorArtifact: 'constructor',
192
- deployer: AztecAddress.ZERO,
193
- });
194
- TXEArtifactsCache.set(cacheKey, { artifact, instance });
194
+ if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
195
+ const compute = async () => {
196
+ const keys = await deriveKeys(secret);
197
+ const args = [
198
+ keys.publicKeys.masterIncomingViewingPublicKey.x,
199
+ keys.publicKeys.masterIncomingViewingPublicKey.y,
200
+ ];
201
+ const computedArtifact: ContractArtifactWithHash = {
202
+ ...SchnorrAccountContractArtifact,
203
+ // Artifact hash is *very* expensive to compute, so we do it here once
204
+ // and the TXE contract data provider can cache it
205
+ artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact),
206
+ };
207
+ const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
208
+ constructorArgs: args,
209
+ skipArgsDecoding: true,
210
+ salt: Fr.ONE,
211
+ publicKeys: keys.publicKeys,
212
+ constructorArtifact: 'constructor',
213
+ deployer: AztecAddress.ZERO,
214
+ });
215
+ const result = { artifact: computedArtifact, instance: computedInstance };
216
+ TXEArtifactsCache.set(cacheKey, result);
217
+ TXEArtifactsCacheInFlight.delete(cacheKey);
218
+ return result;
219
+ };
220
+ TXEArtifactsCacheInFlight.set(cacheKey, compute());
221
+ }
222
+ ({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey)!);
195
223
  }
196
224
 
197
225
  inputs.splice(0, 0, artifact, instance);
@@ -204,12 +232,18 @@ class TXEDispatcher {
204
232
 
205
233
  if (!sessions.has(sessionId)) {
206
234
  this.logger.debug(`Creating new session ${sessionId}`);
207
- if (!this.protocolContracts) {
208
- this.protocolContracts = await Promise.all(
209
- protocolContractNames.map(name => new BundledProtocolContractsProvider().getProtocolContractArtifact(name)),
210
- );
235
+ if (!this.contractStore) {
236
+ const kvStore = await openTmpStore('txe-contracts');
237
+ this.contractStore = new ContractStore(kvStore);
238
+ const provider = new BundledProtocolContractsProvider();
239
+ for (const name of protocolContractNames) {
240
+ const { instance, artifact } = await provider.getProtocolContractArtifact(name);
241
+ await this.contractStore.addContractArtifact(artifact);
242
+ await this.contractStore.addContractInstance(instance);
243
+ }
244
+ this.logger.debug('Registered protocol contracts in shared contract store');
211
245
  }
212
- sessions.set(sessionId, await TXESession.init(this.protocolContracts));
246
+ sessions.set(sessionId, await TXESession.init(this.contractStore));
213
247
  }
214
248
 
215
249
  switch (functionName) {
@@ -72,7 +72,7 @@ export interface ITxeExecutionOracle {
72
72
  argsHash: Fr,
73
73
  isStaticCall: boolean,
74
74
  ): Promise<Fr[]>;
75
- txeSimulateUtilityFunction(
75
+ txeExecuteUtilityFunction(
76
76
  targetContractAddress: AztecAddress,
77
77
  functionSelector: FunctionSelector,
78
78
  args: Fr[],