@aztec/txe 0.0.0-test.1 → 0.0.1-commit.b655e406

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 (86) hide show
  1. package/dest/bin/index.js +3 -2
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +78 -49
  4. package/dest/oracle/interfaces.d.ts +54 -0
  5. package/dest/oracle/interfaces.d.ts.map +1 -0
  6. package/dest/oracle/interfaces.js +3 -0
  7. package/dest/oracle/txe_oracle_public_context.d.ts +34 -0
  8. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -0
  9. package/dest/oracle/txe_oracle_public_context.js +124 -0
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts +56 -0
  11. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
  12. package/dest/oracle/txe_oracle_top_level_context.js +423 -0
  13. package/dest/rpc_translator.d.ts +237 -0
  14. package/dest/rpc_translator.d.ts.map +1 -0
  15. package/dest/rpc_translator.js +617 -0
  16. package/dest/state_machine/archiver.d.ts +61 -0
  17. package/dest/state_machine/archiver.d.ts.map +1 -0
  18. package/dest/state_machine/archiver.js +118 -0
  19. package/dest/state_machine/dummy_p2p_client.d.ts +52 -0
  20. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -0
  21. package/dest/state_machine/dummy_p2p_client.js +133 -0
  22. package/dest/state_machine/global_variable_builder.d.ts +9 -0
  23. package/dest/state_machine/global_variable_builder.d.ts.map +1 -0
  24. package/dest/state_machine/global_variable_builder.js +10 -0
  25. package/dest/state_machine/index.d.ts +16 -0
  26. package/dest/state_machine/index.d.ts.map +1 -0
  27. package/dest/state_machine/index.js +51 -0
  28. package/dest/state_machine/mock_epoch_cache.d.ts +25 -0
  29. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -0
  30. package/dest/state_machine/mock_epoch_cache.js +50 -0
  31. package/dest/state_machine/synchronizer.d.ts +32 -0
  32. package/dest/state_machine/synchronizer.d.ts.map +1 -0
  33. package/dest/state_machine/synchronizer.js +58 -0
  34. package/dest/txe_session.d.ts +67 -0
  35. package/dest/txe_session.d.ts.map +1 -0
  36. package/dest/txe_session.js +253 -0
  37. package/dest/util/encoding.d.ts +26 -8
  38. package/dest/util/encoding.d.ts.map +1 -1
  39. package/dest/util/encoding.js +65 -10
  40. package/dest/util/txe_contract_data_provider.d.ts +12 -0
  41. package/dest/util/txe_contract_data_provider.d.ts.map +1 -0
  42. package/dest/util/txe_contract_data_provider.js +22 -0
  43. package/dest/util/txe_public_contract_data_source.d.ts +8 -8
  44. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  45. package/dest/util/txe_public_contract_data_source.js +36 -57
  46. package/dest/utils/block_creation.d.ts +13 -0
  47. package/dest/utils/block_creation.d.ts.map +1 -0
  48. package/dest/utils/block_creation.js +24 -0
  49. package/dest/utils/tx_effect_creation.d.ts +5 -0
  50. package/dest/utils/tx_effect_creation.d.ts.map +1 -0
  51. package/dest/utils/tx_effect_creation.js +16 -0
  52. package/package.json +27 -22
  53. package/src/bin/index.ts +3 -2
  54. package/src/index.ts +92 -64
  55. package/src/oracle/interfaces.ts +83 -0
  56. package/src/oracle/txe_oracle_public_context.ts +165 -0
  57. package/src/oracle/txe_oracle_top_level_context.ts +658 -0
  58. package/src/rpc_translator.ts +1013 -0
  59. package/src/state_machine/archiver.ts +151 -0
  60. package/src/state_machine/dummy_p2p_client.ts +197 -0
  61. package/src/state_machine/global_variable_builder.ts +20 -0
  62. package/src/state_machine/index.ts +77 -0
  63. package/src/state_machine/mock_epoch_cache.ts +67 -0
  64. package/src/state_machine/synchronizer.ts +87 -0
  65. package/src/txe_session.ts +432 -0
  66. package/src/util/encoding.ts +84 -10
  67. package/src/util/txe_contract_data_provider.ts +36 -0
  68. package/src/util/txe_public_contract_data_source.ts +40 -56
  69. package/src/utils/block_creation.ts +62 -0
  70. package/src/utils/tx_effect_creation.ts +37 -0
  71. package/dest/node/txe_node.d.ts +0 -358
  72. package/dest/node/txe_node.d.ts.map +0 -1
  73. package/dest/node/txe_node.js +0 -504
  74. package/dest/oracle/txe_oracle.d.ts +0 -152
  75. package/dest/oracle/txe_oracle.d.ts.map +0 -1
  76. package/dest/oracle/txe_oracle.js +0 -833
  77. package/dest/txe_service/txe_service.d.ts +0 -212
  78. package/dest/txe_service/txe_service.d.ts.map +0 -1
  79. package/dest/txe_service/txe_service.js +0 -572
  80. package/dest/util/txe_world_state_db.d.ts +0 -14
  81. package/dest/util/txe_world_state_db.d.ts.map +0 -1
  82. package/dest/util/txe_world_state_db.js +0 -27
  83. package/src/node/txe_node.ts +0 -725
  84. package/src/oracle/txe_oracle.ts +0 -1241
  85. package/src/txe_service/txe_service.ts +0 -749
  86. package/src/util/txe_world_state_db.ts +0 -38
@@ -1 +1 @@
1
- {"version":3,"file":"txe_public_contract_data_source.d.ts","sourceRoot":"","sources":["../../src/util/txe_public_contract_data_source.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAE9C,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAEnD,qBAAa,2BAA4B,YAAW,kBAAkB;IACxD,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,GAAG;IAE5B,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IAQ/G,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3B,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IA0BlE,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAKtD,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAK1F,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAI9B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAKjF,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAgB7G,kCAAkC,CAAC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAK1F,gBAAgB,CAAC,cAAc,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAIrE"}
1
+ {"version":3,"file":"txe_public_contract_data_source.d.ts","sourceRoot":"","sources":["../../src/util/txe_public_contract_data_source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,KAAK,gBAAgB,EAAE,gBAAgB,EAAgB,MAAM,mBAAmB,CAAC;AAC1F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAIjC,MAAM,wBAAwB,CAAC;AAEhC,qBAAa,2BAA4B,YAAW,kBAAkB;;IAGlE,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,oBAAoB;gBADpB,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,oBAAoB;IAGpD,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC;IAI3B,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAkClE,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC;IAKtD,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,2BAA2B,GAAG,SAAS,CAAC;IAK1F,mBAAmB,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;IAI9B,mBAAmB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAKjF,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAI1G,kCAAkC,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGnE"}
@@ -1,56 +1,52 @@
1
- import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
2
1
  import { Fr } from '@aztec/foundation/fields';
3
- import { PrivateFunctionsTree } from '@aztec/pxe/server';
4
- import { FunctionSelector } from '@aztec/stdlib/abi';
5
- import { computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
2
+ import { FunctionType } from '@aztec/stdlib/abi';
3
+ import { computePrivateFunctionsRoot, computePublicBytecodeCommitment, getContractClassPrivateFunctionFromArtifact } from '@aztec/stdlib/contract';
6
4
  export class TXEPublicContractDataSource {
7
- txeOracle;
8
- constructor(txeOracle){
9
- this.txeOracle = txeOracle;
10
- }
11
- async getPublicFunction(address, selector) {
12
- const bytecode = await this.txeOracle.getContractDataProvider().getBytecode(address, selector);
13
- if (!bytecode) {
14
- return undefined;
15
- }
16
- return {
17
- bytecode,
18
- selector
19
- };
5
+ blockNumber;
6
+ contractDataProvider;
7
+ #privateFunctionsRoot;
8
+ constructor(blockNumber, contractDataProvider){
9
+ this.blockNumber = blockNumber;
10
+ this.contractDataProvider = contractDataProvider;
11
+ this.#privateFunctionsRoot = new Map();
20
12
  }
21
13
  getBlockNumber() {
22
- return this.txeOracle.getBlockNumber();
14
+ return Promise.resolve(this.blockNumber);
23
15
  }
24
16
  async getContractClass(id) {
25
- const contractClass = await this.txeOracle.getContractDataProvider().getContractClass(id);
26
- const artifact = await this.txeOracle.getContractDataProvider().getContractArtifact(id);
27
- const tree = await PrivateFunctionsTree.create(artifact);
28
- const privateFunctionsRoot = await tree.getFunctionTreeRoot();
29
- const publicFunctions = [];
30
- if (contractClass.packedBytecode.length > 0) {
31
- publicFunctions.push({
32
- selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
33
- bytecode: contractClass.packedBytecode
34
- });
17
+ const contractClass = await this.contractDataProvider.getContractClass(id);
18
+ if (!contractClass) {
19
+ return;
20
+ }
21
+ const artifact = await this.contractDataProvider.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()));
35
32
  }
36
33
  return {
37
34
  id,
38
35
  artifactHash: contractClass.artifactHash,
39
36
  packedBytecode: contractClass.packedBytecode,
40
- publicFunctions: publicFunctions,
41
- privateFunctionsRoot: new Fr(privateFunctionsRoot.root),
37
+ privateFunctionsRoot,
42
38
  version: contractClass.version,
43
39
  privateFunctions: [],
44
- unconstrainedFunctions: []
40
+ utilityFunctions: []
45
41
  };
46
42
  }
47
43
  async getBytecodeCommitment(id) {
48
- const contractClass = await this.txeOracle.getContractDataProvider().getContractClass(id);
49
- return computePublicBytecodeCommitment(contractClass.packedBytecode);
44
+ const contractClass = await this.contractDataProvider.getContractClass(id);
45
+ return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
50
46
  }
51
47
  async getContract(address) {
52
- const instance = await this.txeOracle.getContractDataProvider().getContractInstance(address);
53
- return {
48
+ const instance = await this.contractDataProvider.getContractInstance(address);
49
+ return instance && {
54
50
  ...instance,
55
51
  address
56
52
  };
@@ -59,30 +55,13 @@ export class TXEPublicContractDataSource {
59
55
  throw new Error('Method not implemented.');
60
56
  }
61
57
  async getContractArtifact(address) {
62
- const instance = await this.txeOracle.getContractDataProvider().getContractInstance(address);
63
- return this.txeOracle.getContractDataProvider().getContractArtifact(instance.currentContractClassId);
64
- }
65
- async getContractFunctionName(address, selector) {
66
- const artifact = await this.getContractArtifact(address);
67
- if (!artifact) {
68
- return undefined;
69
- }
70
- const functionSelectorsAndNames = await Promise.all(artifact.functions.map(async (f)=>({
71
- name: f.name,
72
- selector: await FunctionSelector.fromNameAndParameters({
73
- name: f.name,
74
- parameters: f.parameters
75
- })
76
- })));
77
- const func = functionSelectorsAndNames.find((f)=>f.selector.equals(selector));
78
- return Promise.resolve(func?.name);
58
+ const instance = await this.contractDataProvider.getContractInstance(address);
59
+ return instance && this.contractDataProvider.getContractArtifact(instance.currentContractClassId);
79
60
  }
80
- registerContractFunctionSignatures(_address, _signatures) {
81
- return Promise.resolve();
61
+ async getDebugFunctionName(address, selector) {
62
+ return await this.contractDataProvider.getDebugFunctionName(address, selector);
82
63
  }
83
- // TODO(#10007): Remove this method.
84
- addContractClass(_contractClass) {
85
- // We don't really need to do anything for the txe here
64
+ registerContractFunctionSignatures(_signatures) {
86
65
  return Promise.resolve();
87
66
  }
88
67
  }
@@ -0,0 +1,13 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { L2BlockHeader } from '@aztec/stdlib/block';
3
+ import { type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
4
+ import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
5
+ /**
6
+ * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
7
+ * @param blockNumber The number for the block in which there is a single transaction.
8
+ * @returns The transaction request hash.
9
+ */
10
+ export declare function getSingleTxBlockRequestHash(blockNumber: number): Fr;
11
+ export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations): Promise<void>;
12
+ export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables): Promise<L2BlockHeader>;
13
+ //# sourceMappingURL=block_creation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block_creation.d.ts","sourceRoot":"","sources":["../../src/utils/block_creation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAwC,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,EAAE,CAEnE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,aAAa,CAAC,CAaxB"}
@@ -0,0 +1,24 @@
1
+ import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, NULLIFIER_SUBTREE_HEIGHT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
3
+ import { Fr } from '@aztec/foundation/fields';
4
+ import { L2BlockHeader } from '@aztec/stdlib/block';
5
+ import { makeContentCommitment } from '@aztec/stdlib/testing';
6
+ import { AppendOnlyTreeSnapshot, MerkleTreeId } from '@aztec/stdlib/trees';
7
+ /**
8
+ * Returns a transaction request hash that is valid for transactions that are the only ones in a block.
9
+ * @param blockNumber The number for the block in which there is a single transaction.
10
+ * @returns The transaction request hash.
11
+ */ export function getSingleTxBlockRequestHash(blockNumber) {
12
+ return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
13
+ }
14
+ export async function insertTxEffectIntoWorldTrees(txEffect, worldTrees) {
15
+ await worldTrees.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
16
+ await worldTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
17
+ await worldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, padArrayEnd(txEffect.l2ToL1Msgs, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP));
18
+ // We do not need to add public data writes because we apply them as we go.
19
+ }
20
+ export async function makeTXEBlockHeader(worldTrees, globalVariables) {
21
+ const stateReference = await worldTrees.getStateReference();
22
+ 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);
24
+ }
@@ -0,0 +1,5 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
3
+ import { TxEffect } from '@aztec/stdlib/tx';
4
+ export declare function makeTxEffect(noteCache: ExecutionNoteCache, txRequestHash: Fr, txBlockNumber: number): Promise<TxEffect>;
5
+ //# sourceMappingURL=tx_effect_creation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tx_effect_creation.d.ts","sourceRoot":"","sources":["../../src/utils/tx_effect_creation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAU,MAAM,kBAAkB,CAAC;AAEpD,wBAAsB,YAAY,CAChC,SAAS,EAAE,kBAAkB,EAC7B,aAAa,EAAE,EAAE,EACjB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,QAAQ,CAAC,CA2BnB"}
@@ -0,0 +1,16 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
3
+ import { TxEffect, TxHash } from '@aztec/stdlib/tx';
4
+ export async function makeTxEffect(noteCache, txRequestHash, txBlockNumber) {
5
+ const txEffect = TxEffect.empty();
6
+ const { usedTxRequestHashForNonces } = noteCache.finish();
7
+ const nonceGenerator = usedTxRequestHashForNonces ? txRequestHash : noteCache.getAllNullifiers()[0];
8
+ txEffect.noteHashes = await Promise.all(noteCache.getAllNotes().map(async (pendingNote, i)=>computeUniqueNoteHash(await computeNoteHashNonce(nonceGenerator, i), await siloNoteHash(pendingNote.note.contractAddress, pendingNote.noteHashForConsumption))));
9
+ // Nullifiers are already siloed
10
+ txEffect.nullifiers = noteCache.getAllNullifiers();
11
+ if (usedTxRequestHashForNonces) {
12
+ txEffect.nullifiers.unshift(txRequestHash);
13
+ }
14
+ txEffect.txHash = new TxHash(new Fr(txBlockNumber));
15
+ return txEffect;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "0.0.0-test.1",
3
+ "version": "0.0.1-commit.b655e406",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "bin": "./dest/bin/index.js",
@@ -15,10 +15,8 @@
15
15
  "build": "yarn clean && tsc -b",
16
16
  "build:dev": "tsc -b --watch",
17
17
  "clean": "rm -rf ./dest .tsbuildinfo",
18
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
19
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
20
18
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
21
- "dev": "LOG_LEVEL=debug node ./dest/bin/index.js",
19
+ "dev": "LOG_LEVEL=\"debug; trace: simulator:state_manager; info: json-rpc:proxy\" node ./dest/bin/index.js",
22
20
  "start": "node --no-warnings ./dest/bin/index.js"
23
21
  },
24
22
  "inherits": [
@@ -56,30 +54,37 @@
56
54
  "testTimeout": 120000,
57
55
  "setupFiles": [
58
56
  "../../foundation/src/jest/setup.mjs"
57
+ ],
58
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
59
+ "setupFilesAfterEnv": [
60
+ "../../foundation/src/jest/setupAfterEnv.mjs"
59
61
  ]
60
62
  },
61
63
  "dependencies": {
62
- "@aztec/accounts": "0.0.0-test.1",
63
- "@aztec/aztec.js": "0.0.0-test.1",
64
- "@aztec/constants": "0.0.0-test.1",
65
- "@aztec/foundation": "0.0.0-test.1",
66
- "@aztec/key-store": "0.0.0-test.1",
67
- "@aztec/kv-store": "0.0.0-test.1",
68
- "@aztec/protocol-contracts": "0.0.0-test.1",
69
- "@aztec/pxe": "0.0.0-test.1",
70
- "@aztec/simulator": "0.0.0-test.1",
71
- "@aztec/stdlib": "0.0.0-test.1",
72
- "@aztec/world-state": "0.0.0-test.1",
64
+ "@aztec/accounts": "0.0.1-commit.b655e406",
65
+ "@aztec/archiver": "0.0.1-commit.b655e406",
66
+ "@aztec/aztec-node": "0.0.1-commit.b655e406",
67
+ "@aztec/aztec.js": "0.0.1-commit.b655e406",
68
+ "@aztec/bb-prover": "0.0.1-commit.b655e406",
69
+ "@aztec/constants": "0.0.1-commit.b655e406",
70
+ "@aztec/foundation": "0.0.1-commit.b655e406",
71
+ "@aztec/key-store": "0.0.1-commit.b655e406",
72
+ "@aztec/kv-store": "0.0.1-commit.b655e406",
73
+ "@aztec/protocol-contracts": "0.0.1-commit.b655e406",
74
+ "@aztec/pxe": "0.0.1-commit.b655e406",
75
+ "@aztec/simulator": "0.0.1-commit.b655e406",
76
+ "@aztec/stdlib": "0.0.1-commit.b655e406",
77
+ "@aztec/world-state": "0.0.1-commit.b655e406",
73
78
  "zod": "^3.23.8"
74
79
  },
75
80
  "devDependencies": {
76
- "@jest/globals": "^29.5.0",
77
- "@types/jest": "^29.5.0",
78
- "@types/node": "^18.7.23",
79
- "jest": "^29.5.0",
80
- "jest-mock-extended": "^3.0.3",
81
+ "@jest/globals": "^30.0.0",
82
+ "@types/jest": "^30.0.0",
83
+ "@types/node": "^22.15.17",
84
+ "jest": "^30.0.0",
85
+ "jest-mock-extended": "^4.0.0",
81
86
  "ts-node": "^10.9.1",
82
- "typescript": "^5.0.4"
87
+ "typescript": "^5.3.3"
83
88
  },
84
89
  "files": [
85
90
  "dest",
@@ -88,6 +93,6 @@
88
93
  ],
89
94
  "types": "./dest/index.d.ts",
90
95
  "engines": {
91
- "node": ">=18"
96
+ "node": ">=20.10"
92
97
  }
93
98
  }
package/src/bin/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env -S node --no-warnings
2
- import { createLogger } from '@aztec/aztec.js';
2
+ import { createLogger } from '@aztec/aztec.js/log';
3
3
  import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
4
4
 
5
5
  import { createTXERpcServer } from '../index.js';
@@ -20,11 +20,12 @@ async function main() {
20
20
  process.exit(0);
21
21
  });
22
22
 
23
- const logger = createLogger('txe:service');
23
+ const logger = createLogger('txe:rpc');
24
24
  logger.info(`Setting up TXE...`);
25
25
 
26
26
  const txeServer = createTXERpcServer(logger);
27
27
  const { port } = await startHttpRpcServer(txeServer, {
28
+ host: '127.0.0.1',
28
29
  port: TXE_PORT,
29
30
  timeoutMs: 1e3 * 60 * 5,
30
31
  });
package/src/index.ts CHANGED
@@ -1,25 +1,26 @@
1
1
  import { SchnorrAccountContractArtifact } from '@aztec/accounts/schnorr';
2
+ import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js/abi';
3
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
2
4
  import {
3
- AztecAddress,
4
- type ContractArtifact,
5
5
  type ContractInstanceWithAddress,
6
- Fr,
7
- PublicKeys,
8
- deriveKeys,
9
- getContractInstanceFromDeployParams,
10
- loadContractArtifact,
11
- } from '@aztec/aztec.js';
6
+ getContractInstanceFromInstantiationParams,
7
+ } from '@aztec/aztec.js/contracts';
8
+ import { Fr } from '@aztec/aztec.js/fields';
9
+ import { PublicKeys, deriveKeys } from '@aztec/aztec.js/keys';
12
10
  import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
13
11
  import type { Logger } from '@aztec/foundation/log';
14
12
  import { type ProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
15
13
  import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
14
+ import { computeArtifactHash } from '@aztec/stdlib/contract';
16
15
  import type { ApiSchemaFor, ZodFor } from '@aztec/stdlib/schemas';
17
16
 
17
+ import { createHash } from 'crypto';
18
+ import { createReadStream } from 'fs';
18
19
  import { readFile, readdir } from 'fs/promises';
19
- import { join } from 'path';
20
+ import { join, parse } from 'path';
20
21
  import { z } from 'zod';
21
22
 
22
- import { TXEService } from './txe_service/txe_service.js';
23
+ import { type TXEOracleFunctionName, TXESession } from './txe_session.js';
23
24
  import {
24
25
  type ForeignCallArgs,
25
26
  ForeignCallArgsSchema,
@@ -29,21 +30,24 @@ import {
29
30
  type ForeignCallSingle,
30
31
  fromArray,
31
32
  fromSingle,
32
- toForeignCallResult,
33
33
  toSingle,
34
34
  } from './util/encoding.js';
35
+ import type { ContractArtifactWithHash } from './util/txe_contract_data_provider.js';
35
36
 
36
- const TXESessions = new Map<number, TXEService>();
37
+ const sessions = new Map<number, TXESession>();
37
38
 
38
- const TXEArtifactsCache = new Map<string, { artifact: ContractArtifact; instance: ContractInstanceWithAddress }>();
39
-
40
- type MethodNames<T> = {
41
- [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
42
- }[keyof T];
39
+ /*
40
+ * TXE typically has to load the same contract artifacts over and over again for multiple tests,
41
+ * so we cache them here to avoid both loading them from disk repeatedly and computing their artifact hashes
42
+ */
43
+ const TXEArtifactsCache = new Map<
44
+ string,
45
+ { artifact: ContractArtifactWithHash; instance: ContractInstanceWithAddress }
46
+ >();
43
47
 
44
48
  type TXEForeignCallInput = {
45
49
  session_id: number;
46
- function: MethodNames<TXEService> | 'reset';
50
+ function: TXEOracleFunctionName;
47
51
  root_path: string;
48
52
  package_name: string;
49
53
  inputs: ForeignCallArgs;
@@ -52,7 +56,7 @@ type TXEForeignCallInput = {
52
56
  const TXEForeignCallInputSchema = z.object({
53
57
  // eslint-disable-next-line camelcase
54
58
  session_id: z.number().int().nonnegative(),
55
- function: z.string() as ZodFor<MethodNames<TXEService> | 'reset'>,
59
+ function: z.string() as ZodFor<TXEOracleFunctionName>,
56
60
  // eslint-disable-next-line camelcase
57
61
  root_path: z.string(),
58
62
  // eslint-disable-next-line camelcase
@@ -65,58 +69,84 @@ class TXEDispatcher {
65
69
 
66
70
  constructor(private logger: Logger) {}
67
71
 
72
+ private fastHashFile(path: string) {
73
+ return new Promise(resolve => {
74
+ const fd = createReadStream(path);
75
+ const hash = createHash('sha1');
76
+ hash.setEncoding('hex');
77
+
78
+ fd.on('end', function () {
79
+ hash.end();
80
+ resolve(hash.read());
81
+ });
82
+
83
+ fd.pipe(hash);
84
+ });
85
+ }
86
+
68
87
  async #processDeployInputs({ inputs, root_path: rootPath, package_name: packageName }: TXEForeignCallInput) {
69
- const [pathStr, contractName, initializer] = inputs.slice(0, 3).map(input =>
88
+ const [contractPath, initializer] = inputs.slice(0, 2).map(input =>
70
89
  fromArray(input as ForeignCallArray)
71
90
  .map(char => String.fromCharCode(char.toNumber()))
72
91
  .join(''),
73
92
  );
74
93
 
75
- const decodedArgs = fromArray(inputs[4] as ForeignCallArray);
76
- const secret = fromSingle(inputs[5] as ForeignCallSingle);
94
+ const decodedArgs = fromArray(inputs[3] as ForeignCallArray);
95
+ const secret = fromSingle(inputs[4] as ForeignCallSingle);
77
96
  const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys;
78
97
  const publicKeysHash = await publicKeys.hash();
79
98
 
80
- const cacheKey = `${pathStr}-${contractName}-${initializer}-${decodedArgs
99
+ let artifactPath = '';
100
+ const { dir: contractDirectory, base: contractFilename } = parse(contractPath);
101
+ if (contractDirectory) {
102
+ if (contractDirectory.includes('@')) {
103
+ // We're deploying a contract that belongs in a workspace
104
+ // env.deploy("../path/to/workspace/root@packageName/contractName")
105
+ const [workspace, pkg] = contractDirectory.split('@');
106
+ const targetPath = join(rootPath, workspace, '/target');
107
+ this.logger.debug(`Looking for compiled artifact in workspace ${targetPath}`);
108
+ artifactPath = join(targetPath, `${pkg}-${contractFilename}.json`);
109
+ } else {
110
+ // We're deploying a standalone external contract
111
+ // env.deploy("../path/to/contract/root/contractName")
112
+ const targetPath = join(rootPath, contractDirectory, '/target');
113
+ this.logger.debug(`Looking for compiled artifact in ${targetPath}`);
114
+ [artifactPath] = (await readdir(targetPath)).filter(file => file.endsWith(`-${contractFilename}.json`));
115
+ }
116
+ } else {
117
+ // We're deploying a local contract
118
+ // env.deploy("contractName")
119
+ artifactPath = join(rootPath, './target', `${packageName}-${contractFilename}.json`);
120
+ }
121
+
122
+ const fileHash = await this.fastHashFile(artifactPath);
123
+
124
+ const cacheKey = `${contractDirectory ?? ''}-${contractFilename}-${initializer}-${decodedArgs
81
125
  .map(arg => arg.toString())
82
- .join('-')}-${publicKeysHash.toString()}`;
126
+ .join('-')}-${publicKeysHash}-${fileHash}`;
83
127
 
84
- let artifact;
85
128
  let instance;
129
+ let artifact: ContractArtifactWithHash;
86
130
 
87
131
  if (TXEArtifactsCache.has(cacheKey)) {
88
132
  this.logger.debug(`Using cached artifact for ${cacheKey}`);
89
133
  ({ artifact, instance } = TXEArtifactsCache.get(cacheKey)!);
90
134
  } else {
91
- let artifactPath = '';
92
- // We're deploying the contract under test
93
- // env.deploy_self("contractName")
94
- if (!pathStr) {
95
- artifactPath = join(rootPath, './target', `${packageName}-${contractName}.json`);
96
- } else {
97
- // We're deploying a contract that belongs in a workspace
98
- // env.deploy("../path/to/workspace/root@packageName", "contractName")
99
- if (pathStr.includes('@')) {
100
- const [workspace, pkg] = pathStr.split('@');
101
- const targetPath = join(rootPath, workspace, './target');
102
- this.logger.debug(`Looking for compiled artifact in workspace ${targetPath}`);
103
- artifactPath = join(targetPath, `${pkg}-${contractName}.json`);
104
- } else {
105
- // We're deploying a standalone contract
106
- // env.deploy("../path/to/contract/root", "contractName")
107
- const targetPath = join(rootPath, pathStr, './target');
108
- this.logger.debug(`Looking for compiled artifact in ${targetPath}`);
109
- [artifactPath] = (await readdir(targetPath)).filter(file => file.endsWith(`-${contractName}.json`));
110
- }
111
- }
112
135
  this.logger.debug(`Loading compiled artifact ${artifactPath}`);
113
- artifact = loadContractArtifact(JSON.parse(await readFile(artifactPath, 'utf-8')));
136
+ const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8')) as NoirCompiledContract;
137
+ const artifactWithoutHash = loadContractArtifact(artifactJSON);
138
+ artifact = {
139
+ ...artifactWithoutHash,
140
+ // Artifact hash is *very* expensive to compute, so we do it here once
141
+ // and the TXE contract data provider can cache it
142
+ artifactHash: await computeArtifactHash(artifactWithoutHash),
143
+ };
114
144
  this.logger.debug(
115
145
  `Deploy ${
116
146
  artifact.name
117
147
  } with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`,
118
148
  );
119
- instance = await getContractInstanceFromDeployParams(artifact, {
149
+ instance = await getContractInstanceFromInstantiationParams(artifact, {
120
150
  constructorArgs: decodedArgs,
121
151
  skipArgsDecoding: true,
122
152
  salt: Fr.ONE,
@@ -127,7 +157,7 @@ class TXEDispatcher {
127
157
  TXEArtifactsCache.set(cacheKey, { artifact, instance });
128
158
  }
129
159
 
130
- inputs.splice(0, 2, artifact, instance, toSingle(secret));
160
+ inputs.splice(0, 1, artifact, instance, toSingle(secret));
131
161
  }
132
162
 
133
163
  async #processAddAccountInputs({ inputs }: TXEForeignCallInput) {
@@ -135,7 +165,7 @@ class TXEDispatcher {
135
165
 
136
166
  const cacheKey = `SchnorrAccountContract-${secret}`;
137
167
 
138
- let artifact;
168
+ let artifact: ContractArtifactWithHash;
139
169
  let instance;
140
170
 
141
171
  if (TXEArtifactsCache.has(cacheKey)) {
@@ -144,8 +174,13 @@ class TXEDispatcher {
144
174
  } else {
145
175
  const keys = await deriveKeys(secret);
146
176
  const args = [keys.publicKeys.masterIncomingViewingPublicKey.x, keys.publicKeys.masterIncomingViewingPublicKey.y];
147
- artifact = SchnorrAccountContractArtifact;
148
- instance = await getContractInstanceFromDeployParams(artifact, {
177
+ artifact = {
178
+ ...SchnorrAccountContractArtifact,
179
+ // Artifact hash is *very* expensive to compute, so we do it here once
180
+ // and the TXE contract data provider can cache it
181
+ artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact),
182
+ };
183
+ instance = await getContractInstanceFromInstantiationParams(artifact, {
149
184
  constructorArgs: args,
150
185
  skipArgsDecoding: true,
151
186
  salt: Fr.ONE,
@@ -164,35 +199,28 @@ class TXEDispatcher {
164
199
  const { session_id: sessionId, function: functionName, inputs } = callData;
165
200
  this.logger.debug(`Calling ${functionName} on session ${sessionId}`);
166
201
 
167
- if (!TXESessions.has(sessionId) && functionName != 'reset') {
202
+ if (!sessions.has(sessionId)) {
168
203
  this.logger.debug(`Creating new session ${sessionId}`);
169
204
  if (!this.protocolContracts) {
170
205
  this.protocolContracts = await Promise.all(
171
206
  protocolContractNames.map(name => new BundledProtocolContractsProvider().getProtocolContractArtifact(name)),
172
207
  );
173
208
  }
174
- TXESessions.set(sessionId, await TXEService.init(this.logger, this.protocolContracts));
209
+ sessions.set(sessionId, await TXESession.init(this.protocolContracts));
175
210
  }
176
211
 
177
212
  switch (functionName) {
178
- case 'reset': {
179
- TXESessions.delete(sessionId) &&
180
- this.logger.debug(`Called reset on session ${sessionId}, yeeting it out of existence`);
181
- return toForeignCallResult([]);
182
- }
183
- case 'deploy': {
213
+ case 'txeDeploy': {
184
214
  await this.#processDeployInputs(callData);
185
215
  break;
186
216
  }
187
- case 'addAccount': {
217
+ case 'txeAddAccount': {
188
218
  await this.#processAddAccountInputs(callData);
189
219
  break;
190
220
  }
191
221
  }
192
222
 
193
- const txeService = TXESessions.get(sessionId);
194
- const response = await (txeService as any)[functionName](...inputs);
195
- return response;
223
+ return await sessions.get(sessionId)!.processFunction(functionName, inputs);
196
224
  }
197
225
  }
198
226