@aztec/txe 1.2.0 → 2.0.0-nightly.20250813

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.
@@ -9,7 +9,7 @@ export class TXEPublicContractDataSource {
9
9
  this.#privateFunctionsRoot = new Map();
10
10
  }
11
11
  getBlockNumber() {
12
- return this.txeOracle.getBlockNumber();
12
+ return this.txeOracle.utilityGetBlockNumber();
13
13
  }
14
14
  async getContractClass(id) {
15
15
  const contractClass = await this.txeOracle.getContractDataProvider().getContractClass(id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "1.2.0",
3
+ "version": "2.0.0-nightly.20250813",
4
4
  "type": "module",
5
5
  "exports": "./dest/index.js",
6
6
  "bin": "./dest/bin/index.js",
@@ -16,7 +16,7 @@
16
16
  "build:dev": "tsc -b --watch",
17
17
  "clean": "rm -rf ./dest .tsbuildinfo",
18
18
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
19
- "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",
20
20
  "start": "node --no-warnings ./dest/bin/index.js"
21
21
  },
22
22
  "inherits": [
@@ -61,20 +61,20 @@
61
61
  ]
62
62
  },
63
63
  "dependencies": {
64
- "@aztec/accounts": "1.2.0",
65
- "@aztec/archiver": "1.2.0",
66
- "@aztec/aztec-node": "1.2.0",
67
- "@aztec/aztec.js": "1.2.0",
68
- "@aztec/bb-prover": "1.2.0",
69
- "@aztec/constants": "1.2.0",
70
- "@aztec/foundation": "1.2.0",
71
- "@aztec/key-store": "1.2.0",
72
- "@aztec/kv-store": "1.2.0",
73
- "@aztec/protocol-contracts": "1.2.0",
74
- "@aztec/pxe": "1.2.0",
75
- "@aztec/simulator": "1.2.0",
76
- "@aztec/stdlib": "1.2.0",
77
- "@aztec/world-state": "1.2.0",
64
+ "@aztec/accounts": "2.0.0-nightly.20250813",
65
+ "@aztec/archiver": "2.0.0-nightly.20250813",
66
+ "@aztec/aztec-node": "2.0.0-nightly.20250813",
67
+ "@aztec/aztec.js": "2.0.0-nightly.20250813",
68
+ "@aztec/bb-prover": "2.0.0-nightly.20250813",
69
+ "@aztec/constants": "2.0.0-nightly.20250813",
70
+ "@aztec/foundation": "2.0.0-nightly.20250813",
71
+ "@aztec/key-store": "2.0.0-nightly.20250813",
72
+ "@aztec/kv-store": "2.0.0-nightly.20250813",
73
+ "@aztec/protocol-contracts": "2.0.0-nightly.20250813",
74
+ "@aztec/pxe": "2.0.0-nightly.20250813",
75
+ "@aztec/simulator": "2.0.0-nightly.20250813",
76
+ "@aztec/stdlib": "2.0.0-nightly.20250813",
77
+ "@aztec/world-state": "2.0.0-nightly.20250813",
78
78
  "zod": "^3.23.8"
79
79
  },
80
80
  "devDependencies": {
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  type NoirCompiledContract,
7
7
  PublicKeys,
8
8
  deriveKeys,
9
- getContractInstanceFromDeployParams,
9
+ getContractInstanceFromInstantiationParams,
10
10
  loadContractArtifact,
11
11
  } from '@aztec/aztec.js';
12
12
  import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
@@ -19,7 +19,7 @@ import type { ApiSchemaFor, ZodFor } from '@aztec/stdlib/schemas';
19
19
  import { createHash } from 'crypto';
20
20
  import { createReadStream } from 'fs';
21
21
  import { readFile, readdir } from 'fs/promises';
22
- import { join } from 'path';
22
+ import { join, parse } from 'path';
23
23
  import { z } from 'zod';
24
24
 
25
25
  import { TXEService } from './txe_service/txe_service.js';
@@ -32,7 +32,6 @@ import {
32
32
  type ForeignCallSingle,
33
33
  fromArray,
34
34
  fromSingle,
35
- toForeignCallResult,
36
35
  toSingle,
37
36
  } from './util/encoding.js';
38
37
  import type { ContractArtifactWithHash } from './util/txe_contract_data_provider.js';
@@ -54,7 +53,7 @@ type MethodNames<T> = {
54
53
 
55
54
  type TXEForeignCallInput = {
56
55
  session_id: number;
57
- function: MethodNames<TXEService> | 'reset';
56
+ function: MethodNames<TXEService>;
58
57
  root_path: string;
59
58
  package_name: string;
60
59
  inputs: ForeignCallArgs;
@@ -63,7 +62,7 @@ type TXEForeignCallInput = {
63
62
  const TXEForeignCallInputSchema = z.object({
64
63
  // eslint-disable-next-line camelcase
65
64
  session_id: z.number().int().nonnegative(),
66
- function: z.string() as ZodFor<MethodNames<TXEService> | 'reset'>,
65
+ function: z.string() as ZodFor<MethodNames<TXEService>>,
67
66
  // eslint-disable-next-line camelcase
68
67
  root_path: z.string(),
69
68
  // eslint-disable-next-line camelcase
@@ -92,42 +91,43 @@ class TXEDispatcher {
92
91
  }
93
92
 
94
93
  async #processDeployInputs({ inputs, root_path: rootPath, package_name: packageName }: TXEForeignCallInput) {
95
- const [pathStr, contractName, initializer] = inputs.slice(0, 3).map(input =>
94
+ const [contractPath, initializer] = inputs.slice(0, 2).map(input =>
96
95
  fromArray(input as ForeignCallArray)
97
96
  .map(char => String.fromCharCode(char.toNumber()))
98
97
  .join(''),
99
98
  );
100
99
 
101
- const decodedArgs = fromArray(inputs[4] as ForeignCallArray);
102
- const secret = fromSingle(inputs[5] as ForeignCallSingle);
100
+ const decodedArgs = fromArray(inputs[3] as ForeignCallArray);
101
+ const secret = fromSingle(inputs[4] as ForeignCallSingle);
103
102
  const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys;
104
103
  const publicKeysHash = await publicKeys.hash();
105
104
 
106
105
  let artifactPath = '';
107
- // We're deploying the contract under test
108
- // env.deploy_self("contractName")
109
- if (!pathStr) {
110
- artifactPath = join(rootPath, './target', `${packageName}-${contractName}.json`);
111
- } else {
112
- // We're deploying a contract that belongs in a workspace
113
- // env.deploy("../path/to/workspace/root@packageName", "contractName")
114
- if (pathStr.includes('@')) {
115
- const [workspace, pkg] = pathStr.split('@');
116
- const targetPath = join(rootPath, workspace, './target');
106
+ const { dir: contractDirectory, base: contractFilename } = parse(contractPath);
107
+ if (contractDirectory) {
108
+ if (contractDirectory.includes('@')) {
109
+ // We're deploying a contract that belongs in a workspace
110
+ // env.deploy("../path/to/workspace/root@packageName/contractName")
111
+ const [workspace, pkg] = contractDirectory.split('@');
112
+ const targetPath = join(rootPath, workspace, '/target');
117
113
  this.logger.debug(`Looking for compiled artifact in workspace ${targetPath}`);
118
- artifactPath = join(targetPath, `${pkg}-${contractName}.json`);
114
+ artifactPath = join(targetPath, `${pkg}-${contractFilename}.json`);
119
115
  } else {
120
- // We're deploying a standalone contract
121
- // env.deploy("../path/to/contract/root", "contractName")
122
- const targetPath = join(rootPath, pathStr, './target');
116
+ // We're deploying a standalone external contract
117
+ // env.deploy("../path/to/contract/root/contractName")
118
+ const targetPath = join(rootPath, contractDirectory, '/target');
123
119
  this.logger.debug(`Looking for compiled artifact in ${targetPath}`);
124
- [artifactPath] = (await readdir(targetPath)).filter(file => file.endsWith(`-${contractName}.json`));
120
+ [artifactPath] = (await readdir(targetPath)).filter(file => file.endsWith(`-${contractFilename}.json`));
125
121
  }
122
+ } else {
123
+ // We're deploying a local contract
124
+ // env.deploy("contractName")
125
+ artifactPath = join(rootPath, './target', `${packageName}-${contractFilename}.json`);
126
126
  }
127
127
 
128
128
  const fileHash = await this.fastHashFile(artifactPath);
129
129
 
130
- const cacheKey = `${pathStr}-${contractName}-${initializer}-${decodedArgs
130
+ const cacheKey = `${contractDirectory ?? ''}-${contractFilename}-${initializer}-${decodedArgs
131
131
  .map(arg => arg.toString())
132
132
  .join('-')}-${publicKeysHash}-${fileHash}`;
133
133
 
@@ -152,7 +152,7 @@ class TXEDispatcher {
152
152
  artifact.name
153
153
  } with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`,
154
154
  );
155
- instance = await getContractInstanceFromDeployParams(artifact, {
155
+ instance = await getContractInstanceFromInstantiationParams(artifact, {
156
156
  constructorArgs: decodedArgs,
157
157
  skipArgsDecoding: true,
158
158
  salt: Fr.ONE,
@@ -163,7 +163,7 @@ class TXEDispatcher {
163
163
  TXEArtifactsCache.set(cacheKey, { artifact, instance });
164
164
  }
165
165
 
166
- inputs.splice(0, 2, artifact, instance, toSingle(secret));
166
+ inputs.splice(0, 1, artifact, instance, toSingle(secret));
167
167
  }
168
168
 
169
169
  async #processAddAccountInputs({ inputs }: TXEForeignCallInput) {
@@ -186,7 +186,7 @@ class TXEDispatcher {
186
186
  // and the TXE contract data provider can cache it
187
187
  artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact),
188
188
  };
189
- instance = await getContractInstanceFromDeployParams(artifact, {
189
+ instance = await getContractInstanceFromInstantiationParams(artifact, {
190
190
  constructorArgs: args,
191
191
  skipArgsDecoding: true,
192
192
  salt: Fr.ONE,
@@ -205,7 +205,7 @@ class TXEDispatcher {
205
205
  const { session_id: sessionId, function: functionName, inputs } = callData;
206
206
  this.logger.debug(`Calling ${functionName} on session ${sessionId}`);
207
207
 
208
- if (!TXESessions.has(sessionId) && functionName != 'reset') {
208
+ if (!TXESessions.has(sessionId)) {
209
209
  this.logger.debug(`Creating new session ${sessionId}`);
210
210
  if (!this.protocolContracts) {
211
211
  this.protocolContracts = await Promise.all(
@@ -216,22 +216,29 @@ class TXEDispatcher {
216
216
  }
217
217
 
218
218
  switch (functionName) {
219
- case 'reset': {
220
- TXESessions.delete(sessionId) &&
221
- this.logger.debug(`Called reset on session ${sessionId}, yeeting it out of existence`);
222
- return toForeignCallResult([]);
223
- }
224
- case 'deploy': {
219
+ case 'txeDeploy': {
225
220
  await this.#processDeployInputs(callData);
226
221
  break;
227
222
  }
228
- case 'addAccount': {
223
+ case 'txeAddAccount': {
229
224
  await this.#processAddAccountInputs(callData);
230
225
  break;
231
226
  }
232
227
  }
233
228
 
234
229
  const txeService = TXESessions.get(sessionId);
230
+
231
+ // Check if the function exists on the txeService before calling it
232
+ if (typeof (txeService as any)[functionName] !== 'function') {
233
+ const availableMethods = Object.getOwnPropertyNames(Object.getPrototypeOf(txeService))
234
+ .filter(name => typeof (txeService as any)[name] === 'function' && name !== 'constructor')
235
+ .sort();
236
+
237
+ throw new Error(
238
+ `TXE function '${functionName}' is not available. ` + `Available methods: ${availableMethods.join(', ')}`,
239
+ );
240
+ }
241
+
235
242
  const response = await (txeService as any)[functionName](...inputs);
236
243
  return response;
237
244
  }