@aztec/txe 0.0.1-commit.ff7989d6c → 0.0.1-commit.ffe5b04ea

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.
@@ -107,7 +107,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
107
107
  private senderAddressBookStore: SenderAddressBookStore,
108
108
  private capsuleStore: CapsuleStore,
109
109
  private privateEventStore: PrivateEventStore,
110
- private jobId: string,
111
110
  private nextBlockTimestamp: bigint,
112
111
  private version: Fr,
113
112
  private chainId: Fr,
@@ -117,7 +116,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
117
116
  this.logger.debug('Entering Top Level Context');
118
117
  }
119
118
 
120
- utilityAssertCompatibleOracleVersion(version: number): void {
119
+ assertCompatibleOracleVersion(version: number): void {
121
120
  if (version !== ORACLE_VERSION) {
122
121
  throw new Error(
123
122
  `Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
@@ -127,12 +126,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
127
126
 
128
127
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
129
128
  // setup.
130
- utilityGetRandomField(): Fr {
129
+ getRandomField(): Fr {
131
130
  return Fr.random();
132
131
  }
133
132
 
134
133
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
135
- utilityLog(level: number, message: string, fields: Fr[]): Promise<void> {
134
+ log(level: number, message: string, fields: Fr[]): Promise<void> {
136
135
  if (!LogLevels[level]) {
137
136
  throw new Error(`Invalid log level: ${level}`);
138
137
  }
@@ -142,23 +141,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
142
141
  return Promise.resolve();
143
142
  }
144
143
 
145
- txeGetDefaultAddress(): AztecAddress {
144
+ getDefaultAddress(): AztecAddress {
146
145
  return DEFAULT_ADDRESS;
147
146
  }
148
147
 
149
- async txeGetNextBlockNumber(): Promise<BlockNumber> {
148
+ async getNextBlockNumber(): Promise<BlockNumber> {
150
149
  return BlockNumber((await this.getLastBlockNumber()) + 1);
151
150
  }
152
151
 
153
- txeGetNextBlockTimestamp(): Promise<bigint> {
152
+ getNextBlockTimestamp(): Promise<bigint> {
154
153
  return Promise.resolve(this.nextBlockTimestamp);
155
154
  }
156
155
 
157
- async txeGetLastBlockTimestamp() {
156
+ async getLastBlockTimestamp() {
158
157
  return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
159
158
  }
160
159
 
161
- async txeGetLastTxEffects() {
160
+ async getLastTxEffects() {
162
161
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
163
162
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
164
163
 
@@ -172,7 +171,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
172
171
  return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
173
172
  }
174
173
 
175
- 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) {
176
194
  return (
177
195
  await this.privateEventStore.getPrivateEvents(selector, {
178
196
  contractAddress,
@@ -183,7 +201,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
183
201
  ).map(e => e.packedEvent);
184
202
  }
185
203
 
186
- async txeAdvanceBlocksBy(blocks: number) {
204
+ async advanceBlocksBy(blocks: number) {
187
205
  this.logger.debug(`time traveling ${blocks} blocks`);
188
206
 
189
207
  for (let i = 0; i < blocks; i++) {
@@ -191,12 +209,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
191
209
  }
192
210
  }
193
211
 
194
- txeAdvanceTimestampBy(duration: UInt64) {
212
+ advanceTimestampBy(duration: UInt64) {
195
213
  this.logger.debug(`time traveling ${duration} seconds`);
196
214
  this.nextBlockTimestamp += duration;
197
215
  }
198
216
 
199
- async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
217
+ async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
200
218
  // Emit deployment nullifier
201
219
  await this.mineBlock({
202
220
  nullifiers: [
@@ -208,7 +226,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
208
226
  });
209
227
 
210
228
  if (!secret.equals(Fr.ZERO)) {
211
- await this.txeAddAccount(artifact, instance, secret);
229
+ await this.addAccount(artifact, instance, secret);
212
230
  } else {
213
231
  await this.contractStore.addContractInstance(instance);
214
232
  await this.contractStore.addContractArtifact(artifact);
@@ -216,7 +234,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
216
234
  }
217
235
  }
218
236
 
219
- async txeAddAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
237
+ async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
220
238
  const partialAddress = await computePartialAddress(instance);
221
239
 
222
240
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
@@ -231,7 +249,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
231
249
  return completeAddress;
232
250
  }
233
251
 
234
- async txeCreateAccount(secret: Fr) {
252
+ async createAccount(secret: Fr) {
235
253
  // This is a foot gun !
236
254
  const completeAddress = await this.keyStore.addAccount(secret, secret);
237
255
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -241,7 +259,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
241
259
  return completeAddress;
242
260
  }
243
261
 
244
- async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
262
+ async addAuthWitness(address: AztecAddress, messageHash: Fr) {
245
263
  const account = await this.accountStore.getAccount(address);
246
264
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
247
265
 
@@ -254,7 +272,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
254
272
  }
255
273
 
256
274
  async mineBlock(options: { nullifiers?: Fr[] } = {}) {
257
- const blockNumber = await this.txeGetNextBlockNumber();
275
+ const blockNumber = await this.getNextBlockNumber();
258
276
 
259
277
  const txEffect = TxEffect.empty();
260
278
  txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
@@ -278,13 +296,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
278
296
  await this.stateMachine.handleL2Block(block);
279
297
  }
280
298
 
281
- async txePrivateCallNewFlow(
299
+ async privateCallNewFlow(
282
300
  from: AztecAddress,
283
301
  targetContractAddress: AztecAddress = AztecAddress.zero(),
284
302
  functionSelector: FunctionSelector = FunctionSelector.empty(),
285
303
  args: Fr[],
286
304
  argsHash: Fr = Fr.zero(),
287
305
  isStaticCall: boolean = false,
306
+ jobId: string,
288
307
  ) {
289
308
  this.logger.verbose(
290
309
  `Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
@@ -304,7 +323,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
304
323
 
305
324
  // Sync notes before executing private function to discover notes from previous transactions
306
325
  const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
307
- await this.executeUtilityCall(call, execScopes);
326
+ await this.executeUtilityCall(call, execScopes, jobId);
308
327
  };
309
328
 
310
329
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
@@ -313,11 +332,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
313
332
  functionSelector,
314
333
  utilityExecutor,
315
334
  blockHeader,
316
- this.jobId,
335
+ jobId,
317
336
  effectiveScopes,
318
337
  );
319
338
 
320
- const blockNumber = await this.txeGetNextBlockNumber();
339
+ const blockNumber = await this.getNextBlockNumber();
321
340
 
322
341
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
323
342
 
@@ -360,7 +379,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
360
379
  capsuleStore: this.capsuleStore,
361
380
  privateEventStore: this.privateEventStore,
362
381
  contractSyncService: this.stateMachine.contractSyncService,
363
- jobId: this.jobId,
382
+ jobId,
364
383
  totalPublicCalldataCount: 0,
365
384
  sideEffectCounter: minRevertibleSideEffectCounter,
366
385
  scopes: effectiveScopes,
@@ -390,7 +409,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
390
409
  );
391
410
  const publicFunctionsCalldata = await Promise.all(
392
411
  publicCallRequests.map(async r => {
393
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
412
+ const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
394
413
  return new HashedValues(calldata, r.calldataHash);
395
414
  }),
396
415
  );
@@ -504,7 +523,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
504
523
  return executionResult.returnValues ?? [];
505
524
  }
506
525
 
507
- async txePublicCallNewFlow(
526
+ async publicCallNewFlow(
508
527
  from: AztecAddress,
509
528
  targetContractAddress: AztecAddress,
510
529
  calldata: Fr[],
@@ -514,7 +533,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
514
533
  `Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
515
534
  );
516
535
 
517
- const blockNumber = await this.txeGetNextBlockNumber();
536
+ const blockNumber = await this.getNextBlockNumber();
518
537
 
519
538
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
520
539
 
@@ -659,7 +678,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
659
678
  return returnValues ?? [];
660
679
  }
661
680
 
662
- async txeExecuteUtilityFunction(targetContractAddress: AztecAddress, functionSelector: FunctionSelector, args: Fr[]) {
681
+ async executeUtilityFunction(
682
+ targetContractAddress: AztecAddress,
683
+ functionSelector: FunctionSelector,
684
+ args: Fr[],
685
+ jobId: string,
686
+ ) {
663
687
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
664
688
  if (!artifact) {
665
689
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
@@ -671,10 +695,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
671
695
  targetContractAddress,
672
696
  functionSelector,
673
697
  async (call, execScopes) => {
674
- await this.executeUtilityCall(call, execScopes);
698
+ await this.executeUtilityCall(call, execScopes, jobId);
675
699
  },
676
700
  blockHeader,
677
- this.jobId,
701
+ jobId,
678
702
  'ALL_SCOPES',
679
703
  );
680
704
 
@@ -689,10 +713,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
689
713
  returnTypes: [],
690
714
  });
691
715
 
692
- return this.executeUtilityCall(call, 'ALL_SCOPES');
716
+ return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
693
717
  }
694
718
 
695
- private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes): Promise<Fr[]> {
719
+ private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
696
720
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
697
721
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
698
722
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -719,7 +743,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
719
743
  senderAddressBookStore: this.senderAddressBookStore,
720
744
  capsuleStore: this.capsuleStore,
721
745
  privateEventStore: this.privateEventStore,
722
- jobId: this.jobId,
746
+ jobId,
723
747
  scopes,
724
748
  });
725
749
  const acirExecutionResult = await new WASMSimulator()