@aztec/txe 0.0.1-commit.3d8f95d → 0.0.1-commit.3e3d0c9cd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +88 -54
  4. package/dest/oracle/interfaces.d.ts +29 -28
  5. package/dest/oracle/interfaces.d.ts.map +1 -1
  6. package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
  7. package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
  8. package/dest/oracle/txe_oracle_public_context.js +12 -12
  9. package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -23
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +58 -47
  12. package/dest/rpc_translator.d.ts +84 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +250 -150
  15. package/dest/state_machine/archiver.d.ts +3 -3
  16. package/dest/state_machine/archiver.d.ts.map +1 -1
  17. package/dest/state_machine/archiver.js +5 -7
  18. package/dest/state_machine/dummy_p2p_client.d.ts +8 -5
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +13 -4
  21. package/dest/state_machine/index.d.ts +4 -2
  22. package/dest/state_machine/index.d.ts.map +1 -1
  23. package/dest/state_machine/index.js +7 -3
  24. package/dest/state_machine/synchronizer.d.ts +5 -5
  25. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  26. package/dest/state_machine/synchronizer.js +3 -3
  27. package/dest/txe_session.d.ts +9 -6
  28. package/dest/txe_session.d.ts.map +1 -1
  29. package/dest/txe_session.js +27 -21
  30. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  31. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  32. package/dest/util/txe_public_contract_data_source.js +5 -22
  33. package/package.json +15 -15
  34. package/src/index.ts +89 -52
  35. package/src/oracle/interfaces.ts +32 -31
  36. package/src/oracle/txe_oracle_public_context.ts +12 -12
  37. package/src/oracle/txe_oracle_top_level_context.ts +70 -45
  38. package/src/rpc_translator.ts +278 -169
  39. package/src/state_machine/archiver.ts +5 -5
  40. package/src/state_machine/dummy_p2p_client.ts +19 -7
  41. package/src/state_machine/index.ts +6 -1
  42. package/src/state_machine/synchronizer.ts +4 -4
  43. package/src/txe_session.ts +32 -20
  44. package/src/util/txe_public_contract_data_source.ts +10 -36
  45. package/dest/util/txe_contract_store.d.ts +0 -12
  46. package/dest/util/txe_contract_store.d.ts.map +0 -1
  47. package/dest/util/txe_contract_store.js +0 -22
  48. package/src/util/txe_contract_store.ts +0 -36
@@ -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,
@@ -116,7 +116,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
116
116
  this.logger.debug('Entering Top Level Context');
117
117
  }
118
118
 
119
- utilityAssertCompatibleOracleVersion(version: number): void {
119
+ assertCompatibleOracleVersion(version: number): void {
120
120
  if (version !== ORACLE_VERSION) {
121
121
  throw new Error(
122
122
  `Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
@@ -126,12 +126,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
126
126
 
127
127
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
128
128
  // setup.
129
- utilityGetRandomField(): Fr {
129
+ getRandomField(): Fr {
130
130
  return Fr.random();
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
- utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
134
+ log(level: number, message: string, fields: Fr[]): Promise<void> {
135
135
  if (!LogLevels[level]) {
136
136
  throw new Error(`Invalid log level: ${level}`);
137
137
  }
@@ -141,23 +141,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
141
141
  return Promise.resolve();
142
142
  }
143
143
 
144
- txeGetDefaultAddress(): AztecAddress {
144
+ getDefaultAddress(): AztecAddress {
145
145
  return DEFAULT_ADDRESS;
146
146
  }
147
147
 
148
- async txeGetNextBlockNumber(): Promise<BlockNumber> {
148
+ async getNextBlockNumber(): Promise<BlockNumber> {
149
149
  return BlockNumber((await this.getLastBlockNumber()) + 1);
150
150
  }
151
151
 
152
- txeGetNextBlockTimestamp(): Promise<bigint> {
152
+ getNextBlockTimestamp(): Promise<bigint> {
153
153
  return Promise.resolve(this.nextBlockTimestamp);
154
154
  }
155
155
 
156
- async txeGetLastBlockTimestamp() {
156
+ async getLastBlockTimestamp() {
157
157
  return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
158
158
  }
159
159
 
160
- async txeGetLastTxEffects() {
160
+ async getLastTxEffects() {
161
161
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
162
162
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
163
163
 
@@ -171,7 +171,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
171
171
  return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
172
172
  }
173
173
 
174
- async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
174
+ async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
175
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
176
+ this.logger.debug(`Skipping sync in getPrivateEvents 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
+
193
+ async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
175
194
  return (
176
195
  await this.privateEventStore.getPrivateEvents(selector, {
177
196
  contractAddress,
@@ -182,7 +201,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
182
201
  ).map(e => e.packedEvent);
183
202
  }
184
203
 
185
- async txeAdvanceBlocksBy(blocks: number) {
204
+ async advanceBlocksBy(blocks: number) {
186
205
  this.logger.debug(`time traveling ${blocks} blocks`);
187
206
 
188
207
  for (let i = 0; i < blocks; i++) {
@@ -190,12 +209,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
190
209
  }
191
210
  }
192
211
 
193
- txeAdvanceTimestampBy(duration: UInt64) {
212
+ advanceTimestampBy(duration: UInt64) {
194
213
  this.logger.debug(`time traveling ${duration} seconds`);
195
214
  this.nextBlockTimestamp += duration;
196
215
  }
197
216
 
198
- async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
217
+ async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
199
218
  // Emit deployment nullifier
200
219
  await this.mineBlock({
201
220
  nullifiers: [
@@ -207,20 +226,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
207
226
  });
208
227
 
209
228
  if (!secret.equals(Fr.ZERO)) {
210
- await this.txeAddAccount(artifact, instance, secret);
229
+ await this.addAccount(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
  }
217
236
 
218
- async txeAddAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
237
+ async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
219
238
  const partialAddress = await computePartialAddress(instance);
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);
@@ -230,7 +249,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
230
249
  return completeAddress;
231
250
  }
232
251
 
233
- async txeCreateAccount(secret: Fr) {
252
+ async createAccount(secret: Fr) {
234
253
  // This is a foot gun !
235
254
  const completeAddress = await this.keyStore.addAccount(secret, secret);
236
255
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -240,7 +259,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
240
259
  return completeAddress;
241
260
  }
242
261
 
243
- async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
262
+ async addAuthWitness(address: AztecAddress, messageHash: Fr) {
244
263
  const account = await this.accountStore.getAccount(address);
245
264
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
246
265
 
@@ -253,7 +272,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
253
272
  }
254
273
 
255
274
  async mineBlock(options: { nullifiers?: Fr[] } = {}) {
256
- const blockNumber = await this.txeGetNextBlockNumber();
275
+ const blockNumber = await this.getNextBlockNumber();
257
276
 
258
277
  const txEffect = TxEffect.empty();
259
278
  txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
@@ -277,13 +296,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
277
296
  await this.stateMachine.handleL2Block(block);
278
297
  }
279
298
 
280
- async txePrivateCallNewFlow(
299
+ async privateCallNewFlow(
281
300
  from: AztecAddress,
282
301
  targetContractAddress: AztecAddress = AztecAddress.zero(),
283
302
  functionSelector: FunctionSelector = FunctionSelector.empty(),
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,10 +332,11 @@ 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
- const blockNumber = await this.txeGetNextBlockNumber();
339
+ const blockNumber = await this.getNextBlockNumber();
320
340
 
321
341
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
322
342
 
@@ -359,7 +379,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
359
379
  capsuleStore: this.capsuleStore,
360
380
  privateEventStore: this.privateEventStore,
361
381
  contractSyncService: this.stateMachine.contractSyncService,
362
- jobId: this.jobId,
382
+ jobId,
363
383
  totalPublicCalldataCount: 0,
364
384
  sideEffectCounter: minRevertibleSideEffectCounter,
365
385
  scopes: effectiveScopes,
@@ -367,6 +387,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
367
387
  // contract would perform, including setting senderForTags.
368
388
  senderForTags: from,
369
389
  simulator,
390
+ messageContextService: this.stateMachine.messageContextService,
370
391
  });
371
392
 
372
393
  // 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.
@@ -389,7 +410,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
389
410
  );
390
411
  const publicFunctionsCalldata = await Promise.all(
391
412
  publicCallRequests.map(async r => {
392
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
413
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
393
414
  return new HashedValues(calldata, r.calldataHash);
394
415
  }),
395
416
  );
@@ -407,6 +428,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
407
428
  const { publicInputs } = await generateSimulatedProvingResult(
408
429
  result,
409
430
  (addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
431
+ this.stateMachine.node,
410
432
  minRevertibleSideEffectCounter,
411
433
  );
412
434
 
@@ -502,7 +524,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
502
524
  return executionResult.returnValues ?? [];
503
525
  }
504
526
 
505
- async txePublicCallNewFlow(
527
+ async publicCallNewFlow(
506
528
  from: AztecAddress,
507
529
  targetContractAddress: AztecAddress,
508
530
  calldata: Fr[],
@@ -512,7 +534,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
512
534
  `Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
513
535
  );
514
536
 
515
- const blockNumber = await this.txeGetNextBlockNumber();
537
+ const blockNumber = await this.getNextBlockNumber();
516
538
 
517
539
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
518
540
 
@@ -589,7 +611,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
589
611
  constantData,
590
612
  /*gasUsed=*/ new Gas(0, 0),
591
613
  /*feePayer=*/ AztecAddress.zero(),
592
- /*includeByTimestamp=*/ 0n,
614
+ /*expirationTimestamp=*/ 0n,
593
615
  inputsForPublic,
594
616
  undefined,
595
617
  );
@@ -657,10 +679,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
657
679
  return returnValues ?? [];
658
680
  }
659
681
 
660
- async txeSimulateUtilityFunction(
682
+ async executeUtilityFunction(
661
683
  targetContractAddress: AztecAddress,
662
684
  functionSelector: FunctionSelector,
663
685
  args: Fr[],
686
+ jobId: string,
664
687
  ) {
665
688
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
666
689
  if (!artifact) {
@@ -672,11 +695,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
672
695
  await this.stateMachine.contractSyncService.ensureContractSynced(
673
696
  targetContractAddress,
674
697
  functionSelector,
675
- async call => {
676
- await this.executeUtilityCall(call);
698
+ async (call, execScopes) => {
699
+ await this.executeUtilityCall(call, execScopes, jobId);
677
700
  },
678
701
  blockHeader,
679
- this.jobId,
702
+ jobId,
703
+ 'ALL_SCOPES',
680
704
  );
681
705
 
682
706
  const call = FunctionCall.from({
@@ -690,10 +714,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
690
714
  returnTypes: [],
691
715
  });
692
716
 
693
- return this.executeUtilityCall(call);
717
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
694
718
  }
695
719
 
696
- private async executeUtilityCall(call: FunctionCall, scopes?: AztecAddress[]): Promise<Fr[]> {
720
+ private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
697
721
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
698
722
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
699
723
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -720,7 +744,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
720
744
  senderAddressBookStore: this.senderAddressBookStore,
721
745
  capsuleStore: this.capsuleStore,
722
746
  privateEventStore: this.privateEventStore,
723
- jobId: this.jobId,
747
+ messageContextService: this.stateMachine.messageContextService,
748
+ jobId,
724
749
  scopes,
725
750
  });
726
751
  const acirExecutionResult = await new WASMSimulator()
@@ -738,10 +763,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
738
763
  );
739
764
  });
740
765
 
741
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
766
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
742
767
  return witnessMapToFields(acirExecutionResult.returnWitness);
743
768
  } catch (err) {
744
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
769
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
745
770
  }
746
771
  }
747
772