@aztec/txe 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec

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 (36) 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 +4 -3
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_top_level_context.d.ts +7 -8
  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 -32
  9. package/dest/rpc_translator.d.ts +4 -4
  10. package/dest/rpc_translator.d.ts.map +1 -1
  11. package/dest/rpc_translator.js +18 -6
  12. package/dest/state_machine/dummy_p2p_client.d.ts +8 -5
  13. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  14. package/dest/state_machine/dummy_p2p_client.js +13 -4
  15. package/dest/state_machine/index.d.ts +1 -1
  16. package/dest/state_machine/index.d.ts.map +1 -1
  17. package/dest/state_machine/index.js +1 -1
  18. package/dest/txe_session.d.ts +9 -6
  19. package/dest/txe_session.d.ts.map +1 -1
  20. package/dest/txe_session.js +74 -18
  21. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  22. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  23. package/dest/util/txe_public_contract_data_source.js +5 -22
  24. package/package.json +15 -15
  25. package/src/index.ts +83 -49
  26. package/src/oracle/interfaces.ts +6 -1
  27. package/src/oracle/txe_oracle_top_level_context.ts +86 -70
  28. package/src/rpc_translator.ts +20 -5
  29. package/src/state_machine/dummy_p2p_client.ts +19 -7
  30. package/src/state_machine/index.ts +1 -0
  31. package/src/txe_session.ts +77 -68
  32. package/src/util/txe_public_contract_data_source.ts +10 -36
  33. package/dest/util/txe_contract_store.d.ts +0 -12
  34. package/dest/util/txe_contract_store.d.ts.map +0 -1
  35. package/dest/util/txe_contract_store.js +0 -22
  36. package/src/util/txe_contract_store.ts +0 -36
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLGdCQUFnQixFQUFnQixNQUFNLG1CQUFtQixDQUFDO0FBQzFGLE9BQU8sS0F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O,CAAC,WAAW;IACnB,OAAO,CAAC,aAAa;IAFvB,YACU,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAClC;IAEJ,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAErC;IAEK,gBAAgB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC,CAcvE;IAEK,qBAAqB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,GAAG,SAAS,CAAC,CAG3D;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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/txe",
3
- "version": "0.0.1-commit.d6f2b3f94",
3
+ "version": "0.0.1-commit.dbf9cec",
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.d6f2b3f94",
65
- "@aztec/archiver": "0.0.1-commit.d6f2b3f94",
66
- "@aztec/aztec-node": "0.0.1-commit.d6f2b3f94",
67
- "@aztec/aztec.js": "0.0.1-commit.d6f2b3f94",
68
- "@aztec/bb-prover": "0.0.1-commit.d6f2b3f94",
69
- "@aztec/constants": "0.0.1-commit.d6f2b3f94",
70
- "@aztec/foundation": "0.0.1-commit.d6f2b3f94",
71
- "@aztec/key-store": "0.0.1-commit.d6f2b3f94",
72
- "@aztec/kv-store": "0.0.1-commit.d6f2b3f94",
73
- "@aztec/protocol-contracts": "0.0.1-commit.d6f2b3f94",
74
- "@aztec/pxe": "0.0.1-commit.d6f2b3f94",
75
- "@aztec/simulator": "0.0.1-commit.d6f2b3f94",
76
- "@aztec/stdlib": "0.0.1-commit.d6f2b3f94",
77
- "@aztec/world-state": "0.0.1-commit.d6f2b3f94",
64
+ "@aztec/accounts": "0.0.1-commit.dbf9cec",
65
+ "@aztec/archiver": "0.0.1-commit.dbf9cec",
66
+ "@aztec/aztec-node": "0.0.1-commit.dbf9cec",
67
+ "@aztec/aztec.js": "0.0.1-commit.dbf9cec",
68
+ "@aztec/bb-prover": "0.0.1-commit.dbf9cec",
69
+ "@aztec/constants": "0.0.1-commit.dbf9cec",
70
+ "@aztec/foundation": "0.0.1-commit.dbf9cec",
71
+ "@aztec/key-store": "0.0.1-commit.dbf9cec",
72
+ "@aztec/kv-store": "0.0.1-commit.dbf9cec",
73
+ "@aztec/protocol-contracts": "0.0.1-commit.dbf9cec",
74
+ "@aztec/pxe": "0.0.1-commit.dbf9cec",
75
+ "@aztec/simulator": "0.0.1-commit.dbf9cec",
76
+ "@aztec/stdlib": "0.0.1-commit.dbf9cec",
77
+ "@aztec/world-state": "0.0.1-commit.dbf9cec",
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) {
@@ -71,11 +71,13 @@ export interface ITxeExecutionOracle {
71
71
  args: Fr[],
72
72
  argsHash: Fr,
73
73
  isStaticCall: boolean,
74
+ jobId: string,
74
75
  ): Promise<Fr[]>;
75
- txeSimulateUtilityFunction(
76
+ txeExecuteUtilityFunction(
76
77
  targetContractAddress: AztecAddress,
77
78
  functionSelector: FunctionSelector,
78
79
  args: Fr[],
80
+ jobId: string,
79
81
  ): Promise<Fr[]>;
80
82
  txePublicCallNewFlow(
81
83
  from: AztecAddress,
@@ -83,4 +85,7 @@ export interface ITxeExecutionOracle {
83
85
  calldata: Fr[],
84
86
  isStaticCall: boolean,
85
87
  ): Promise<Fr[]>;
88
+ // TODO(F-335): Drop this from here as it's not a real oracle handler - it's only called from
89
+ // RPCTranslator::txeGetPrivateEvents and never from Noir.
90
+ syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string): Promise<void>;
86
91
  }
@@ -12,9 +12,11 @@ import { Fr } from '@aztec/foundation/curves/bn254';
12
12
  import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
13
13
  import { TestDateProvider } from '@aztec/foundation/timer';
14
14
  import type { KeyStore } from '@aztec/key-store';
15
+ import type { AccessScopes } from '@aztec/pxe/client/lazy';
15
16
  import {
16
17
  AddressStore,
17
18
  CapsuleStore,
19
+ type ContractStore,
18
20
  NoteStore,
19
21
  ORACLE_VERSION,
20
22
  PrivateEventStore,
@@ -83,7 +85,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
83
85
  import { DEFAULT_ADDRESS } from '../constants.js';
84
86
  import type { TXEStateMachine } from '../state_machine/index.js';
85
87
  import type { TXEAccountStore } from '../util/txe_account_store.js';
86
- import type { TXEContractStore } from '../util/txe_contract_store.js';
87
88
  import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
88
89
  import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
89
90
  import type { ITxeExecutionOracle } from './interfaces.js';
@@ -96,7 +97,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
96
97
 
97
98
  constructor(
98
99
  private stateMachine: TXEStateMachine,
99
- private contractStore: TXEContractStore,
100
+ private contractStore: ContractStore,
100
101
  private noteStore: NoteStore,
101
102
  private keyStore: KeyStore,
102
103
  private addressStore: AddressStore,
@@ -106,7 +107,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
106
107
  private senderAddressBookStore: SenderAddressBookStore,
107
108
  private capsuleStore: CapsuleStore,
108
109
  private privateEventStore: PrivateEventStore,
109
- private jobId: string,
110
110
  private nextBlockTimestamp: bigint,
111
111
  private version: Fr,
112
112
  private chainId: Fr,
@@ -131,9 +131,9 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
131
131
  }
132
132
 
133
133
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
134
- utilityDebugLog(level: number, message: string, fields: Fr[]): Promise<void> {
134
+ utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
135
135
  if (!LogLevels[level]) {
136
- throw new Error(`Invalid debug log level: ${level}`);
136
+ throw new Error(`Invalid log level: ${level}`);
137
137
  }
138
138
  const levelName = LogLevels[level];
139
139
 
@@ -171,6 +171,25 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
171
171
  return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
172
172
  }
173
173
 
174
+ async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
175
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
176
+ this.logger.debug(`Skipping sync in txeGetPrivateEvents because the events correspond to the default address.`);
177
+ return;
178
+ }
179
+
180
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
181
+ await this.stateMachine.contractSyncService.ensureContractSynced(
182
+ contractAddress,
183
+ null,
184
+ async (call, execScopes) => {
185
+ await this.executeUtilityCall(call, execScopes, jobId);
186
+ },
187
+ blockHeader,
188
+ jobId,
189
+ [scope],
190
+ );
191
+ }
192
+
174
193
  async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
175
194
  return (
176
195
  await this.privateEventStore.getPrivateEvents(selector, {
@@ -210,7 +229,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
210
229
  await this.txeAddAccount(artifact, instance, secret);
211
230
  } else {
212
231
  await this.contractStore.addContractInstance(instance);
213
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
232
+ await this.contractStore.addContractArtifact(artifact);
214
233
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
215
234
  }
216
235
  }
@@ -220,7 +239,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
220
239
 
221
240
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
222
241
  await this.contractStore.addContractInstance(instance);
223
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
242
+ await this.contractStore.addContractArtifact(artifact);
224
243
 
225
244
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
226
245
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -284,6 +303,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
284
303
  args: Fr[],
285
304
  argsHash: Fr = Fr.zero(),
286
305
  isStaticCall: boolean = false,
306
+ jobId: string,
287
307
  ) {
288
308
  this.logger.verbose(
289
309
  `Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
@@ -297,14 +317,13 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
297
317
  throw new Error(message);
298
318
  }
299
319
 
300
- // When `from` is the zero address (used when creating a new contract account for example),
301
- // we disable scope filtering by setting effectiveScopes to undefined. This allows these operations
302
- // to proceed without requiring keys registered for the zero address.
303
- const effectiveScopes = from.isZero() ? undefined : [from];
320
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
321
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
322
+ const effectiveScopes = from.isZero() ? [] : [from];
304
323
 
305
324
  // Sync notes before executing private function to discover notes from previous transactions
306
- const utilityExecutor = async (call: FunctionCall) => {
307
- await this.executeUtilityCall(call, effectiveScopes);
325
+ const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
326
+ await this.executeUtilityCall(call, execScopes, jobId);
308
327
  };
309
328
 
310
329
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
@@ -313,7 +332,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
313
332
  functionSelector,
314
333
  utilityExecutor,
315
334
  blockHeader,
316
- this.jobId,
335
+ jobId,
336
+ effectiveScopes,
317
337
  );
318
338
 
319
339
  const blockNumber = await this.txeGetNextBlockNumber();
@@ -337,43 +357,37 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
337
357
 
338
358
  const simulator = new WASMSimulator();
339
359
 
340
- const privateExecutionOracle = new PrivateExecutionOracle(
360
+ const privateExecutionOracle = new PrivateExecutionOracle({
341
361
  argsHash,
342
362
  txContext,
343
363
  callContext,
344
- /** Header of a block whose state is used during private execution (not the block the transaction is included in). */
345
- blockHeader,
364
+ anchorBlockHeader: blockHeader,
346
365
  utilityExecutor,
347
- /** List of transient auth witnesses to be used during this simulation */
348
- Array.from(this.authwits.values()),
349
- /** List of transient auth witnesses to be used during this simulation */
350
- [],
351
- HashedValuesCache.create([new HashedValues(args, argsHash)]),
366
+ authWitnesses: Array.from(this.authwits.values()),
367
+ capsules: [],
368
+ executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
352
369
  noteCache,
353
370
  taggingIndexCache,
354
- this.contractStore,
355
- this.noteStore,
356
- this.keyStore,
357
- this.addressStore,
358
- this.stateMachine.node,
359
- this.senderTaggingStore,
360
- this.recipientTaggingStore,
361
- this.senderAddressBookStore,
362
- this.capsuleStore,
363
- this.privateEventStore,
364
- this.stateMachine.contractSyncService,
365
- this.jobId,
366
- 0, // totalPublicArgsCount
367
- minRevertibleSideEffectCounter, // (start) sideEffectCounter
368
- undefined, // log
369
- effectiveScopes, // scopes
370
- /**
371
- * In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
372
- * contract would perform, including setting senderForTags.
373
- */
374
- from,
371
+ contractStore: this.contractStore,
372
+ noteStore: this.noteStore,
373
+ keyStore: this.keyStore,
374
+ addressStore: this.addressStore,
375
+ aztecNode: this.stateMachine.node,
376
+ senderTaggingStore: this.senderTaggingStore,
377
+ recipientTaggingStore: this.recipientTaggingStore,
378
+ senderAddressBookStore: this.senderAddressBookStore,
379
+ capsuleStore: this.capsuleStore,
380
+ privateEventStore: this.privateEventStore,
381
+ contractSyncService: this.stateMachine.contractSyncService,
382
+ jobId,
383
+ totalPublicCalldataCount: 0,
384
+ sideEffectCounter: minRevertibleSideEffectCounter,
385
+ scopes: effectiveScopes,
386
+ // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
387
+ // contract would perform, including setting senderForTags.
388
+ senderForTags: from,
375
389
  simulator,
376
- );
390
+ });
377
391
 
378
392
  // Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
379
393
  let result: PrivateExecutionResult;
@@ -413,6 +427,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
413
427
  const { publicInputs } = await generateSimulatedProvingResult(
414
428
  result,
415
429
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
430
+ this.stateMachine.node,
416
431
  minRevertibleSideEffectCounter,
417
432
  );
418
433
 
@@ -595,7 +610,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
595
610
  constantData,
596
611
  /*gasUsed=*/ new Gas(0, 0),
597
612
  /*feePayer=*/ AztecAddress.zero(),
598
- /*includeByTimestamp=*/ 0n,
613
+ /*expirationTimestamp=*/ 0n,
599
614
  inputsForPublic,
600
615
  undefined,
601
616
  );
@@ -663,10 +678,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
663
678
  return returnValues ?? [];
664
679
  }
665
680
 
666
- async txeSimulateUtilityFunction(
681
+ async txeExecuteUtilityFunction(
667
682
  targetContractAddress: AztecAddress,
668
683
  functionSelector: FunctionSelector,
669
684
  args: Fr[],
685
+ jobId: string,
670
686
  ) {
671
687
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
672
688
  if (!artifact) {
@@ -678,11 +694,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
678
694
  await this.stateMachine.contractSyncService.ensureContractSynced(
679
695
  targetContractAddress,
680
696
  functionSelector,
681
- async call => {
682
- await this.executeUtilityCall(call);
697
+ async (call, execScopes) => {
698
+ await this.executeUtilityCall(call, execScopes, jobId);
683
699
  },
684
700
  blockHeader,
685
- this.jobId,
701
+ jobId,
702
+ 'ALL_SCOPES',
686
703
  );
687
704
 
688
705
  const call = FunctionCall.from({
@@ -696,10 +713,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
696
713
  returnTypes: [],
697
714
  });
698
715
 
699
- return this.executeUtilityCall(call);
716
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
700
717
  }
701
718
 
702
- private async executeUtilityCall(call: FunctionCall, scopes?: AztecAddress[]): Promise<Fr[]> {
719
+ private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
703
720
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
704
721
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
705
722
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -712,24 +729,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
712
729
 
713
730
  try {
714
731
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
715
- const oracle = new UtilityExecutionOracle(
716
- call.to,
717
- [],
718
- [],
732
+ const oracle = new UtilityExecutionOracle({
733
+ contractAddress: call.to,
734
+ authWitnesses: [],
735
+ capsules: [],
719
736
  anchorBlockHeader,
720
- this.contractStore,
721
- this.noteStore,
722
- this.keyStore,
723
- this.addressStore,
724
- this.stateMachine.node,
725
- this.recipientTaggingStore,
726
- this.senderAddressBookStore,
727
- this.capsuleStore,
728
- this.privateEventStore,
729
- this.jobId,
730
- undefined, // log
731
- scopes, // scopes - used to filter notes by account
732
- );
737
+ contractStore: this.contractStore,
738
+ noteStore: this.noteStore,
739
+ keyStore: this.keyStore,
740
+ addressStore: this.addressStore,
741
+ aztecNode: this.stateMachine.node,
742
+ recipientTaggingStore: this.recipientTaggingStore,
743
+ senderAddressBookStore: this.senderAddressBookStore,
744
+ capsuleStore: this.capsuleStore,
745
+ privateEventStore: this.privateEventStore,
746
+ jobId,
747
+ scopes,
748
+ });
733
749
  const acirExecutionResult = await new WASMSimulator()
734
750
  .executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
735
751
  .catch((err: Error) => {
@@ -745,10 +761,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
745
761
  );
746
762
  });
747
763
 
748
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
764
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
749
765
  return witnessMapToFields(acirExecutionResult.returnWitness);
750
766
  } catch (err) {
751
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
767
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
752
768
  }
753
769
  }
754
770