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

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 (54) 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 +23 -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 +61 -47
  12. package/dest/rpc_translator.d.ts +87 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +273 -151
  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/mock_epoch_cache.d.ts +17 -3
  25. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  26. package/dest/state_machine/mock_epoch_cache.js +32 -2
  27. package/dest/state_machine/synchronizer.d.ts +5 -5
  28. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  29. package/dest/state_machine/synchronizer.js +3 -3
  30. package/dest/txe_session.d.ts +10 -6
  31. package/dest/txe_session.d.ts.map +1 -1
  32. package/dest/txe_session.js +36 -24
  33. package/dest/util/encoding.d.ts +69 -1
  34. package/dest/util/encoding.d.ts.map +1 -1
  35. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  36. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  37. package/dest/util/txe_public_contract_data_source.js +6 -25
  38. package/package.json +15 -15
  39. package/src/index.ts +89 -52
  40. package/src/oracle/interfaces.ts +32 -31
  41. package/src/oracle/txe_oracle_public_context.ts +12 -12
  42. package/src/oracle/txe_oracle_top_level_context.ts +73 -45
  43. package/src/rpc_translator.ts +305 -173
  44. package/src/state_machine/archiver.ts +5 -5
  45. package/src/state_machine/dummy_p2p_client.ts +19 -7
  46. package/src/state_machine/index.ts +7 -1
  47. package/src/state_machine/mock_epoch_cache.ts +42 -3
  48. package/src/state_machine/synchronizer.ts +4 -4
  49. package/src/txe_session.ts +43 -21
  50. package/src/util/txe_public_contract_data_source.ts +10 -38
  51. package/dest/util/txe_contract_store.d.ts +0 -12
  52. package/dest/util/txe_contract_store.d.ts.map +0 -1
  53. package/dest/util/txe_contract_store.js +0 -22
  54. package/src/util/txe_contract_store.ts +0 -36
@@ -36,15 +36,15 @@ export class TXEOracleTopLevelContext {
36
36
  senderAddressBookStore;
37
37
  capsuleStore;
38
38
  privateEventStore;
39
- jobId;
40
39
  nextBlockTimestamp;
41
40
  version;
42
41
  chainId;
43
42
  authwits;
43
+ contractSyncService;
44
44
  isMisc;
45
45
  isTxe;
46
46
  logger;
47
- constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobId, nextBlockTimestamp, version, chainId, authwits){
47
+ constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
48
48
  this.stateMachine = stateMachine;
49
49
  this.contractStore = contractStore;
50
50
  this.noteStore = noteStore;
@@ -56,28 +56,28 @@ export class TXEOracleTopLevelContext {
56
56
  this.senderAddressBookStore = senderAddressBookStore;
57
57
  this.capsuleStore = capsuleStore;
58
58
  this.privateEventStore = privateEventStore;
59
- this.jobId = jobId;
60
59
  this.nextBlockTimestamp = nextBlockTimestamp;
61
60
  this.version = version;
62
61
  this.chainId = chainId;
63
62
  this.authwits = authwits;
63
+ this.contractSyncService = contractSyncService;
64
64
  this.isMisc = true;
65
65
  this.isTxe = true;
66
66
  this.logger = createLogger('txe:top_level_context');
67
67
  this.logger.debug('Entering Top Level Context');
68
68
  }
69
- utilityAssertCompatibleOracleVersion(version) {
69
+ assertCompatibleOracleVersion(version) {
70
70
  if (version !== ORACLE_VERSION) {
71
71
  throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
72
72
  }
73
73
  }
74
74
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
75
75
  // setup.
76
- utilityGetRandomField() {
76
+ getRandomField() {
77
77
  return Fr.random();
78
78
  }
79
79
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
80
- utilityLog(level, message, fields) {
80
+ log(level, message, fields) {
81
81
  if (!LogLevels[level]) {
82
82
  throw new Error(`Invalid log level: ${level}`);
83
83
  }
@@ -87,19 +87,19 @@ export class TXEOracleTopLevelContext {
87
87
  });
88
88
  return Promise.resolve();
89
89
  }
90
- txeGetDefaultAddress() {
90
+ getDefaultAddress() {
91
91
  return DEFAULT_ADDRESS;
92
92
  }
93
- async txeGetNextBlockNumber() {
93
+ async getNextBlockNumber() {
94
94
  return BlockNumber(await this.getLastBlockNumber() + 1);
95
95
  }
96
- txeGetNextBlockTimestamp() {
96
+ getNextBlockTimestamp() {
97
97
  return Promise.resolve(this.nextBlockTimestamp);
98
98
  }
99
- async txeGetLastBlockTimestamp() {
99
+ async getLastBlockTimestamp() {
100
100
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
101
101
  }
102
- async txeGetLastTxEffects() {
102
+ async getLastTxEffects() {
103
103
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
104
104
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
105
105
  if (block.body.txEffects.length != 1) {
@@ -113,7 +113,19 @@ export class TXEOracleTopLevelContext {
113
113
  nullifiers: txEffects.nullifiers
114
114
  };
115
115
  }
116
- async txeGetPrivateEvents(selector, contractAddress, scope) {
116
+ async syncContractNonOracleMethod(contractAddress, scope, jobId) {
117
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
118
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
119
+ return;
120
+ }
121
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
122
+ await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
123
+ await this.executeUtilityCall(call, execScopes, jobId);
124
+ }, blockHeader, jobId, [
125
+ scope
126
+ ]);
127
+ }
128
+ async getPrivateEvents(selector, contractAddress, scope) {
117
129
  return (await this.privateEventStore.getPrivateEvents(selector, {
118
130
  contractAddress,
119
131
  scopes: [
@@ -123,17 +135,17 @@ export class TXEOracleTopLevelContext {
123
135
  toBlock: await this.getLastBlockNumber() + 1
124
136
  })).map((e)=>e.packedEvent);
125
137
  }
126
- async txeAdvanceBlocksBy(blocks) {
138
+ async advanceBlocksBy(blocks) {
127
139
  this.logger.debug(`time traveling ${blocks} blocks`);
128
140
  for(let i = 0; i < blocks; i++){
129
141
  await this.mineBlock();
130
142
  }
131
143
  }
132
- txeAdvanceTimestampBy(duration) {
144
+ advanceTimestampBy(duration) {
133
145
  this.logger.debug(`time traveling ${duration} seconds`);
134
146
  this.nextBlockTimestamp += duration;
135
147
  }
136
- async txeDeploy(artifact, instance, secret) {
148
+ async deploy(artifact, instance, secret) {
137
149
  // Emit deployment nullifier
138
150
  await this.mineBlock({
139
151
  nullifiers: [
@@ -141,25 +153,25 @@ export class TXEOracleTopLevelContext {
141
153
  ]
142
154
  });
143
155
  if (!secret.equals(Fr.ZERO)) {
144
- await this.txeAddAccount(artifact, instance, secret);
156
+ await this.addAccount(artifact, instance, secret);
145
157
  } else {
146
158
  await this.contractStore.addContractInstance(instance);
147
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
159
+ await this.contractStore.addContractArtifact(artifact);
148
160
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
149
161
  }
150
162
  }
151
- async txeAddAccount(artifact, instance, secret) {
163
+ async addAccount(artifact, instance, secret) {
152
164
  const partialAddress = await computePartialAddress(instance);
153
165
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
154
166
  await this.contractStore.addContractInstance(instance);
155
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
167
+ await this.contractStore.addContractArtifact(artifact);
156
168
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
157
169
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
158
170
  await this.addressStore.addCompleteAddress(completeAddress);
159
171
  this.logger.debug(`Created account ${completeAddress.address}`);
160
172
  return completeAddress;
161
173
  }
162
- async txeCreateAccount(secret) {
174
+ async createAccount(secret) {
163
175
  // This is a foot gun !
164
176
  const completeAddress = await this.keyStore.addAccount(secret, secret);
165
177
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -167,7 +179,7 @@ export class TXEOracleTopLevelContext {
167
179
  this.logger.debug(`Created account ${completeAddress.address}`);
168
180
  return completeAddress;
169
181
  }
170
- async txeAddAuthWitness(address, messageHash) {
182
+ async addAuthWitness(address, messageHash) {
171
183
  const account = await this.accountStore.getAccount(address);
172
184
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
173
185
  const schnorr = new Schnorr();
@@ -178,7 +190,7 @@ export class TXEOracleTopLevelContext {
178
190
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
179
191
  }
180
192
  async mineBlock(options = {}) {
181
- const blockNumber = await this.txeGetNextBlockNumber();
193
+ const blockNumber = await this.getNextBlockNumber();
182
194
  const txEffect = TxEffect.empty();
183
195
  txEffect.nullifiers = [
184
196
  getSingleTxBlockRequestHash(blockNumber),
@@ -200,26 +212,25 @@ export class TXEOracleTopLevelContext {
200
212
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
201
213
  await this.stateMachine.handleL2Block(block);
202
214
  }
203
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
215
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
204
216
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
205
217
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
206
218
  if (!artifact) {
207
219
  const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)')) ? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.' : 'Function Artifact does not exist';
208
220
  throw new Error(message);
209
221
  }
210
- // When `from` is the zero address (used when creating a new contract account for example),
211
- // we disable scope filtering by setting effectiveScopes to undefined. This allows these operations
212
- // to proceed without requiring keys registered for the zero address.
213
- const effectiveScopes = from.isZero() ? undefined : [
222
+ // When `from` is the zero address (e.g. when deploying a new account contract), we return an
223
+ // empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
224
+ const effectiveScopes = from.isZero() ? [] : [
214
225
  from
215
226
  ];
216
227
  // Sync notes before executing private function to discover notes from previous transactions
217
- const utilityExecutor = async (call)=>{
218
- await this.executeUtilityCall(call, effectiveScopes);
228
+ const utilityExecutor = async (call, execScopes)=>{
229
+ await this.executeUtilityCall(call, execScopes, jobId);
219
230
  };
220
231
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
221
- await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, this.jobId);
222
- const blockNumber = await this.txeGetNextBlockNumber();
232
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
233
+ const blockNumber = await this.getNextBlockNumber();
223
234
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
224
235
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
225
236
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
@@ -258,14 +269,15 @@ export class TXEOracleTopLevelContext {
258
269
  capsuleStore: this.capsuleStore,
259
270
  privateEventStore: this.privateEventStore,
260
271
  contractSyncService: this.stateMachine.contractSyncService,
261
- jobId: this.jobId,
272
+ jobId,
262
273
  totalPublicCalldataCount: 0,
263
274
  sideEffectCounter: minRevertibleSideEffectCounter,
264
275
  scopes: effectiveScopes,
265
276
  // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
266
277
  // contract would perform, including setting senderForTags.
267
278
  senderForTags: from,
268
- simulator
279
+ simulator,
280
+ messageContextService: this.stateMachine.messageContextService
269
281
  });
270
282
  // 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.
271
283
  let result;
@@ -278,7 +290,7 @@ export class TXEOracleTopLevelContext {
278
290
  r.publicInputs.publicTeardownCallRequest
279
291
  ]));
280
292
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
281
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
293
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
282
294
  return new HashedValues(calldata, r.calldataHash);
283
295
  }));
284
296
  noteCache.finish();
@@ -290,7 +302,7 @@ export class TXEOracleTopLevelContext {
290
302
  // According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
291
303
  // the nonce generator for the note hashes.
292
304
  // We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
293
- const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), minRevertibleSideEffectCounter);
305
+ const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
294
306
  const globals = makeGlobalVariables();
295
307
  globals.blockNumber = blockNumber;
296
308
  globals.timestamp = this.nextBlockTimestamp;
@@ -358,9 +370,9 @@ export class TXEOracleTopLevelContext {
358
370
  await forkedWorldTrees.close();
359
371
  return executionResult.returnValues ?? [];
360
372
  }
361
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
373
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
362
374
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
363
- const blockNumber = await this.txeGetNextBlockNumber();
375
+ const blockNumber = await this.getNextBlockNumber();
364
376
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
365
377
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
366
378
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
@@ -399,7 +411,7 @@ export class TXEOracleTopLevelContext {
399
411
  revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
400
412
  const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
401
413
  const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
402
- const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, inputsForPublic, undefined);
414
+ const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
403
415
  const tx = await Tx.create({
404
416
  data: txData,
405
417
  chonkProof: ChonkProof.empty(),
@@ -452,16 +464,16 @@ export class TXEOracleTopLevelContext {
452
464
  await forkedWorldTrees.close();
453
465
  return returnValues ?? [];
454
466
  }
455
- async txeSimulateUtilityFunction(targetContractAddress, functionSelector, args) {
467
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
456
468
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
457
469
  if (!artifact) {
458
470
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
459
471
  }
460
472
  // Sync notes before executing utility function to discover notes from previous transactions
461
473
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
462
- await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call)=>{
463
- await this.executeUtilityCall(call);
464
- }, blockHeader, this.jobId);
474
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
475
+ await this.executeUtilityCall(call, execScopes, jobId);
476
+ }, blockHeader, jobId, 'ALL_SCOPES');
465
477
  const call = FunctionCall.from({
466
478
  name: artifact.name,
467
479
  to: targetContractAddress,
@@ -472,9 +484,9 @@ export class TXEOracleTopLevelContext {
472
484
  args,
473
485
  returnTypes: []
474
486
  });
475
- return this.executeUtilityCall(call);
487
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
476
488
  }
477
- async executeUtilityCall(call, scopes) {
489
+ async executeUtilityCall(call, scopes, jobId) {
478
490
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
479
491
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
480
492
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -499,7 +511,9 @@ export class TXEOracleTopLevelContext {
499
511
  senderAddressBookStore: this.senderAddressBookStore,
500
512
  capsuleStore: this.capsuleStore,
501
513
  privateEventStore: this.privateEventStore,
502
- jobId: this.jobId,
514
+ messageContextService: this.stateMachine.messageContextService,
515
+ contractSyncService: this.contractSyncService,
516
+ jobId,
503
517
  scopes
504
518
  });
505
519
  const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
@@ -511,10 +525,10 @@ export class TXEOracleTopLevelContext {
511
525
  cause: err
512
526
  });
513
527
  });
514
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
528
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
515
529
  return witnessMapToFields(acirExecutionResult.returnWitness);
516
530
  } catch (err) {
517
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
531
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
518
532
  }
519
533
  }
520
534
  close() {