@aztec/txe 0.0.1-commit.993d240 → 0.0.1-commit.9a89641

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 (144) hide show
  1. package/dest/AuthRegistry-QVGDDH5X.js +3 -0
  2. package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
  3. package/dest/ContractClassRegistry-PVNCKGG7.js +3 -0
  4. package/dest/ContractClassRegistry-PVNCKGG7.js.map +7 -0
  5. package/dest/ContractInstanceRegistry-WLOZKTR6.js +3 -0
  6. package/dest/ContractInstanceRegistry-WLOZKTR6.js.map +7 -0
  7. package/dest/FeeJuice-MAQJU53K.js +3 -0
  8. package/dest/FeeJuice-MAQJU53K.js.map +7 -0
  9. package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
  10. package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
  11. package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
  12. package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
  13. package/dest/SchnorrAccount-ADD65DYA.js +3 -0
  14. package/dest/SchnorrAccount-ADD65DYA.js.map +7 -0
  15. package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js +3 -0
  16. package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js.map +7 -0
  17. package/dest/bin/check_txe_oracle_version.js +9 -19
  18. package/dest/bin/index.js +1 -1
  19. package/dest/bin/oracle_test_server.d.ts +3 -0
  20. package/dest/bin/oracle_test_server.d.ts.map +1 -0
  21. package/dest/bin/oracle_test_server.js +41 -0
  22. package/dest/chunk-32UHX7YY.js +3 -0
  23. package/dest/{chunk-DF6RMOC6.js → chunk-RVEPNDEP.js} +2 -2
  24. package/dest/{chunk-DF6RMOC6.js.map → chunk-RVEPNDEP.js.map} +3 -3
  25. package/dest/chunk-XWIMXLKD.js +258 -0
  26. package/dest/chunk-XWIMXLKD.js.map +7 -0
  27. package/dest/constants.d.ts +3 -1
  28. package/dest/constants.d.ts.map +1 -1
  29. package/dest/constants.js +5 -2
  30. package/dest/dispatcher_pool.d.ts +2 -2
  31. package/dest/dispatcher_pool.d.ts.map +1 -1
  32. package/dest/dispatcher_pool.js +5 -3
  33. package/dest/index.d.ts +6 -143
  34. package/dest/index.d.ts.map +1 -1
  35. package/dest/index.js +12 -169
  36. package/dest/metafile.json +10267 -9581
  37. package/dest/oracle/interfaces.d.ts +38 -11
  38. package/dest/oracle/interfaces.d.ts.map +1 -1
  39. package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
  40. package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
  41. package/dest/oracle/tagging_secret_strategy.js +12 -0
  42. package/dest/oracle/test-resolver/default_fixtures.d.ts +16 -0
  43. package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
  44. package/dest/oracle/test-resolver/default_fixtures.js +200 -0
  45. package/dest/oracle/test-resolver/index.d.ts +9 -0
  46. package/dest/oracle/test-resolver/index.d.ts.map +1 -0
  47. package/dest/oracle/test-resolver/index.js +32 -0
  48. package/dest/oracle/test-resolver/resolver.d.ts +48 -0
  49. package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
  50. package/dest/oracle/test-resolver/resolver.js +181 -0
  51. package/dest/oracle/txe_oracle_public_context.d.ts +25 -6
  52. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  53. package/dest/oracle/txe_oracle_public_context.js +34 -1
  54. package/dest/oracle/txe_oracle_registry.d.ts +172 -0
  55. package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
  56. package/dest/oracle/txe_oracle_registry.js +767 -0
  57. package/dest/oracle/txe_oracle_top_level_context.d.ts +39 -14
  58. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  59. package/dest/oracle/txe_oracle_top_level_context.js +489 -289
  60. package/dest/{txe_oracle_version.d.ts → oracle/txe_oracle_version.d.ts} +5 -5
  61. package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
  62. package/dest/{txe_oracle_version.js → oracle/txe_oracle_version.js} +4 -4
  63. package/dest/rpc_translator.d.ts +116 -284
  64. package/dest/rpc_translator.d.ts.map +1 -1
  65. package/dest/rpc_translator.js +809 -860
  66. package/dest/server.bundle.js +1 -1
  67. package/dest/state_machine/archiver.d.ts +3 -2
  68. package/dest/state_machine/archiver.d.ts.map +1 -1
  69. package/dest/state_machine/archiver.js +9 -3
  70. package/dest/state_machine/dummy_p2p_client.d.ts +5 -2
  71. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  72. package/dest/state_machine/dummy_p2p_client.js +9 -0
  73. package/dest/state_machine/global_variable_builder.d.ts +3 -4
  74. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  75. package/dest/state_machine/global_variable_builder.js +0 -3
  76. package/dest/state_machine/index.d.ts +8 -6
  77. package/dest/state_machine/index.d.ts.map +1 -1
  78. package/dest/state_machine/index.js +41 -19
  79. package/dest/state_machine/mock_epoch_cache.d.ts +2 -3
  80. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  81. package/dest/state_machine/mock_epoch_cache.js +3 -6
  82. package/dest/state_machine/synchronizer.d.ts +10 -2
  83. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  84. package/dest/state_machine/synchronizer.js +18 -5
  85. package/dest/txe_session.d.ts +43 -28
  86. package/dest/txe_session.d.ts.map +1 -1
  87. package/dest/txe_session.js +183 -47
  88. package/dest/utils/block_creation.d.ts +2 -2
  89. package/dest/utils/block_creation.d.ts.map +1 -1
  90. package/dest/utils/block_creation.js +2 -2
  91. package/dest/utils/encoding.d.ts +8 -5
  92. package/dest/utils/encoding.d.ts.map +1 -1
  93. package/dest/utils/tx_effect_creation.d.ts +1 -1
  94. package/dest/utils/tx_effect_creation.d.ts.map +1 -1
  95. package/dest/utils/tx_effect_creation.js +0 -1
  96. package/dest/utils/txe_artifact_resolver.d.ts +37 -0
  97. package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
  98. package/dest/utils/txe_artifact_resolver.js +161 -0
  99. package/dest/utils/txe_public_contract_data_source.d.ts +1 -1
  100. package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -1
  101. package/dest/utils/txe_public_contract_data_source.js +7 -4
  102. package/dest/worker.bundle.js +1 -1
  103. package/package.json +18 -17
  104. package/src/bin/check_txe_oracle_version.ts +11 -17
  105. package/src/bin/oracle_test_server.ts +51 -0
  106. package/src/constants.ts +6 -2
  107. package/src/dispatcher_pool.ts +4 -3
  108. package/src/index.ts +21 -198
  109. package/src/oracle/interfaces.ts +35 -9
  110. package/src/oracle/tagging_secret_strategy.ts +25 -0
  111. package/src/oracle/test-resolver/default_fixtures.ts +271 -0
  112. package/src/oracle/test-resolver/index.ts +44 -0
  113. package/src/oracle/test-resolver/resolver.ts +245 -0
  114. package/src/oracle/txe_oracle_public_context.ts +36 -4
  115. package/src/oracle/txe_oracle_registry.ts +556 -0
  116. package/src/oracle/txe_oracle_top_level_context.ts +249 -66
  117. package/src/{txe_oracle_version.ts → oracle/txe_oracle_version.ts} +4 -4
  118. package/src/rpc_translator.ts +850 -1065
  119. package/src/state_machine/archiver.ts +9 -3
  120. package/src/state_machine/dummy_p2p_client.ts +13 -0
  121. package/src/state_machine/global_variable_builder.ts +2 -16
  122. package/src/state_machine/index.ts +50 -34
  123. package/src/state_machine/mock_epoch_cache.ts +4 -8
  124. package/src/state_machine/synchronizer.ts +26 -5
  125. package/src/txe_session.ts +325 -56
  126. package/src/utils/block_creation.ts +2 -1
  127. package/src/utils/tx_effect_creation.ts +0 -2
  128. package/src/utils/txe_artifact_resolver.ts +217 -0
  129. package/src/utils/txe_public_contract_data_source.ts +6 -4
  130. package/dest/ContractClassRegistry-KKNT527R.js +0 -3
  131. package/dest/ContractClassRegistry-KKNT527R.js.map +0 -7
  132. package/dest/ContractInstanceRegistry-GSKBNL3Q.js +0 -3
  133. package/dest/ContractInstanceRegistry-GSKBNL3Q.js.map +0 -7
  134. package/dest/FeeJuice-GUJ5O6GB.js +0 -3
  135. package/dest/FeeJuice-GUJ5O6GB.js.map +0 -7
  136. package/dest/MultiCallEntrypoint-ZQPCKVKL.js +0 -3
  137. package/dest/MultiCallEntrypoint-ZQPCKVKL.js.map +0 -7
  138. package/dest/SchnorrAccount-QIXE5DXA.js +0 -3
  139. package/dest/SchnorrAccount-QIXE5DXA.js.map +0 -7
  140. package/dest/chunk-BJVAAXNA.js +0 -3
  141. package/dest/chunk-PPJTNNUG.js +0 -265
  142. package/dest/chunk-PPJTNNUG.js.map +0 -7
  143. package/dest/txe_oracle_version.d.ts.map +0 -1
  144. /package/dest/{chunk-BJVAAXNA.js.map → chunk-32UHX7YY.js.map} +0 -0
@@ -23,6 +23,7 @@ export function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr {
23
23
  export async function insertTxEffectIntoWorldTrees(
24
24
  txEffect: TxEffect,
25
25
  worldTrees: MerkleTreeWriteOperations,
26
+ l1ToL2Messages: Fr[] = [],
26
27
  ): Promise<void> {
27
28
  await worldTrees.appendLeaves(
28
29
  MerkleTreeId.NOTE_HASH_TREE,
@@ -37,7 +38,7 @@ export async function insertTxEffectIntoWorldTrees(
37
38
 
38
39
  await worldTrees.appendLeaves(
39
40
  MerkleTreeId.L1_TO_L2_MESSAGE_TREE,
40
- padArrayEnd<Fr, number>(txEffect.l2ToL1Msgs, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
41
+ padArrayEnd<Fr, number>(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP),
41
42
  );
42
43
 
43
44
  // We do not need to add public data writes because we apply them as we go.
@@ -7,8 +7,6 @@ import { TxEffect, TxHash } from '@aztec/stdlib/tx';
7
7
  export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
8
8
  const txEffect = TxEffect.empty();
9
9
 
10
- noteCache.finish();
11
-
12
10
  const nonceGenerator = noteCache.getNonceGenerator();
13
11
  txEffect.noteHashes = await Promise.all(
14
12
  noteCache
@@ -0,0 +1,217 @@
1
+ import { type NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js/abi';
2
+ import { AztecAddress } from '@aztec/aztec.js/addresses';
3
+ import {
4
+ type ContractInstanceWithAddress,
5
+ getContractInstanceFromInstantiationParams,
6
+ } from '@aztec/aztec.js/contracts';
7
+ import { Fr } from '@aztec/aztec.js/fields';
8
+ import { PublicKeys, deriveKeys } from '@aztec/aztec.js/keys';
9
+ import { createLogger } from '@aztec/foundation/log';
10
+ import type { ContractStore } from '@aztec/pxe/client/lazy';
11
+ import type { ContractArtifactWithHash } from '@aztec/stdlib/contract';
12
+ import { computeArtifactHash } from '@aztec/stdlib/contract';
13
+
14
+ import { createHash } from 'crypto';
15
+ import { createReadStream } from 'fs';
16
+ import { readFile, readdir } from 'fs/promises';
17
+ import { join, parse } from 'path';
18
+
19
+ export interface ResolvedArtifact {
20
+ artifact: ContractArtifactWithHash;
21
+ instance: ContractInstanceWithAddress;
22
+ }
23
+
24
+ /**
25
+ * Cache + in-flight map pair. Lookup hits the cache, then awaits an in-flight `compute()` if one
26
+ * exists, otherwise starts one and stores it. Guarantees `compute()` runs at most once per `key`
27
+ * across concurrent callers, which matters because `computeArtifactHash` is expensive.
28
+ */
29
+ class AsyncCache<K, V> {
30
+ #cache = new Map<K, V>();
31
+ #inFlight = new Map<K, Promise<V>>();
32
+
33
+ getOrCompute(key: K, compute: () => Promise<V>): Promise<V> {
34
+ const cached = this.#cache.get(key);
35
+ if (cached !== undefined) {
36
+ return Promise.resolve(cached);
37
+ }
38
+ let pending = this.#inFlight.get(key);
39
+ if (!pending) {
40
+ pending = (async () => {
41
+ try {
42
+ const value = await compute();
43
+ this.#cache.set(key, value);
44
+ return value;
45
+ } finally {
46
+ this.#inFlight.delete(key);
47
+ }
48
+ })();
49
+ this.#inFlight.set(key, pending);
50
+ }
51
+ return pending;
52
+ }
53
+ }
54
+
55
+ /**
56
+ * Resolves and caches contract artifacts and their associated instances.
57
+ *
58
+ * Artifact hash computation is expensive, so this service deduplicates both completed and in-flight computations.
59
+ * Two cache levels are kept: full deploys (artifact + computed instance) keyed by the full deploy context, and loaded +
60
+ * hashed artifacts keyed by the compiled-bytecode hash so deploys of the same contract with different args / salt /
61
+ * deployer reuse the same `ContractArtifactWithHash`.
62
+ */
63
+ export class TXEArtifactResolver {
64
+ #deployments = new AsyncCache<string, ResolvedArtifact>();
65
+ #artifacts = new AsyncCache<string, ContractArtifactWithHash>();
66
+ #logger = createLogger('txe:artifact_resolver');
67
+
68
+ constructor(
69
+ private readonly contractStore: ContractStore,
70
+ private readonly schnorrClassId: Fr,
71
+ ) {}
72
+
73
+ /** Resolves the Schnorr account contract artifact and instance for the given secret, caching the result. */
74
+ resolveAccountArtifact(secret: Fr): Promise<ResolvedArtifact> {
75
+ return this.#deployments.getOrCompute(`SchnorrAccountContract-${secret}`, () =>
76
+ this.#computeAccountArtifact(secret),
77
+ );
78
+ }
79
+
80
+ /** Resolves a contract artifact from disk by path, computes its instance, and caches the result. */
81
+ async resolveDeployArtifact({
82
+ rootPath,
83
+ packageName,
84
+ contractPath,
85
+ initializer,
86
+ args,
87
+ secret,
88
+ salt,
89
+ deployer,
90
+ }: {
91
+ rootPath: string;
92
+ packageName: string;
93
+ contractPath: string;
94
+ initializer: string;
95
+ args: Fr[];
96
+ secret: Fr;
97
+ salt: Fr;
98
+ deployer: AztecAddress;
99
+ }): Promise<ResolvedArtifact> {
100
+ const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys;
101
+ const publicKeysHash = await publicKeys.hash();
102
+
103
+ const artifactPath = await this.#resolveArtifactPath(rootPath, packageName, contractPath);
104
+ const fileHash = await this.#fastHashFile(artifactPath);
105
+
106
+ const { dir: contractDirectory, base: contractFilename } = parse(contractPath);
107
+ const cacheKey = `${contractDirectory ?? ''}-${contractFilename}-${initializer}-${args
108
+ .map(arg => arg.toString())
109
+ .join('-')}-${publicKeysHash}-${salt}-${deployer}-${fileHash}`;
110
+
111
+ return this.#deployments.getOrCompute(cacheKey, () =>
112
+ this.#computeDeployArtifact(
113
+ artifactPath,
114
+ fileHash,
115
+ initializer,
116
+ args,
117
+ salt,
118
+ publicKeys,
119
+ publicKeysHash,
120
+ deployer,
121
+ ),
122
+ );
123
+ }
124
+
125
+ async #resolveArtifactPath(rootPath: string, packageName: string, contractPath: string): Promise<string> {
126
+ const { dir: contractDirectory, base: contractFilename } = parse(contractPath);
127
+ if (contractDirectory) {
128
+ if (contractDirectory.includes('@')) {
129
+ // env.deploy("../path/to/workspace/root@packageName/contractName")
130
+ const [workspace, pkg] = contractDirectory.split('@');
131
+ const targetPath = join(rootPath, workspace, '/target');
132
+ this.#logger.debug(`Looking for compiled artifact in workspace ${targetPath}`);
133
+ return join(targetPath, `${pkg}-${contractFilename}.json`);
134
+ } else {
135
+ // env.deploy("../path/to/contract/root/contractName")
136
+ const targetPath = join(rootPath, contractDirectory, '/target');
137
+ this.#logger.debug(`Looking for compiled artifact in ${targetPath}`);
138
+ const [artifactPath] = (await readdir(targetPath)).filter(file => file.endsWith(`-${contractFilename}.json`));
139
+ return artifactPath;
140
+ }
141
+ } else {
142
+ // env.deploy("contractName")
143
+ return join(rootPath, './target', `${packageName}-${contractFilename}.json`);
144
+ }
145
+ }
146
+
147
+ async #computeAccountArtifact(secret: Fr): Promise<ResolvedArtifact> {
148
+ const [artifactFromStore, classWithPreimage] = await Promise.all([
149
+ this.contractStore.getContractArtifact(this.schnorrClassId),
150
+ this.contractStore.getContractClassWithPreimage(this.schnorrClassId),
151
+ ]);
152
+ if (!artifactFromStore || !classWithPreimage) {
153
+ throw new Error(
154
+ `SchnorrAccount not found in shared contract store at class id ${this.schnorrClassId.toString()}`,
155
+ );
156
+ }
157
+ const artifact: ContractArtifactWithHash = { ...artifactFromStore, artifactHash: classWithPreimage.artifactHash };
158
+ const keys = await deriveKeys(secret);
159
+ const args = [keys.publicKeys.ivpkM.x, keys.publicKeys.ivpkM.y];
160
+ const instance = await getContractInstanceFromInstantiationParams(artifact, {
161
+ constructorArgs: args,
162
+ skipArgsDecoding: true,
163
+ salt: Fr.ONE,
164
+ publicKeys: keys.publicKeys,
165
+ constructorArtifact: 'constructor',
166
+ deployer: AztecAddress.ZERO,
167
+ });
168
+ return { artifact, instance };
169
+ }
170
+
171
+ async #computeDeployArtifact(
172
+ artifactPath: string,
173
+ fileHash: string,
174
+ initializer: string,
175
+ args: Fr[],
176
+ salt: Fr,
177
+ publicKeys: PublicKeys,
178
+ publicKeysHash: Fr,
179
+ deployer: AztecAddress,
180
+ ): Promise<ResolvedArtifact> {
181
+ // Inner cache: artifact load + hash depends only on the compiled bytecode (`fileHash`), so subsequent deploys of
182
+ // the same contract — regardless of constructor args / deployer / salt — reuse the same `ContractArtifactWithHash`.
183
+ const artifact = await this.#artifacts.getOrCompute(fileHash, async () => {
184
+ this.#logger.debug(`Loading compiled artifact ${artifactPath}`);
185
+ const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8')) as NoirCompiledContract;
186
+ const artifactWithoutHash = loadContractArtifact(artifactJSON);
187
+ return { ...artifactWithoutHash, artifactHash: await computeArtifactHash(artifactWithoutHash) };
188
+ });
189
+ this.#logger.debug(
190
+ `Deploy ${artifact.name} with initializer ${initializer}(${args}) and public keys hash ${publicKeysHash}`,
191
+ );
192
+ const instance = await getContractInstanceFromInstantiationParams(artifact, {
193
+ constructorArgs: args,
194
+ skipArgsDecoding: true,
195
+ salt,
196
+ publicKeys,
197
+ constructorArtifact: initializer || undefined,
198
+ deployer,
199
+ });
200
+ return { artifact, instance };
201
+ }
202
+
203
+ #fastHashFile(path: string): Promise<string> {
204
+ return new Promise(resolve => {
205
+ const fd = createReadStream(path);
206
+ const hash = createHash('sha1');
207
+ hash.setEncoding('hex');
208
+
209
+ fd.on('end', function () {
210
+ hash.end();
211
+ resolve(hash.read() as string);
212
+ });
213
+
214
+ fd.pipe(hash);
215
+ });
216
+ }
217
+ }
@@ -36,7 +36,8 @@ export class TXEPublicContractDataSource implements ContractDataSource {
36
36
 
37
37
  async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
38
38
  const instance = await this.contractStore.getContractInstance(address);
39
- return instance && { ...instance, address };
39
+ // TXE has no contract updates, so the current class always equals the original.
40
+ return instance && { ...instance, address, currentContractClassId: instance.originalContractClassId };
40
41
  }
41
42
 
42
43
  getContractClassIds(): Promise<Fr[]> {
@@ -44,12 +45,13 @@ export class TXEPublicContractDataSource implements ContractDataSource {
44
45
  }
45
46
 
46
47
  async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
47
- const instance = await this.contractStore.getContractInstance(address);
48
- return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
48
+ const instance = await this.getContract(address);
49
+ return instance && this.contractStore.getContractArtifact(instance.originalContractClassId);
49
50
  }
50
51
 
51
52
  async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
52
- return await this.contractStore.getDebugFunctionName(address, selector);
53
+ const instance = await this.getContract(address);
54
+ return instance && this.contractStore.getDebugFunctionName(instance.originalContractClassId, selector);
53
55
  }
54
56
 
55
57
  registerContractFunctionSignatures(_signatures: []): Promise<void> {