@aztec/txe 0.0.1-commit.4ad48494d → 0.0.1-commit.4d3c002

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 (58) 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 +60 -44
  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 +285 -152
  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 +7 -8
  18. package/dest/state_machine/dummy_p2p_client.d.ts +8 -6
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +12 -6
  21. package/dest/state_machine/global_variable_builder.d.ts +3 -3
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +1 -1
  24. package/dest/state_machine/index.d.ts +4 -2
  25. package/dest/state_machine/index.d.ts.map +1 -1
  26. package/dest/state_machine/index.js +7 -3
  27. package/dest/state_machine/mock_epoch_cache.d.ts +17 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +32 -2
  30. package/dest/state_machine/synchronizer.d.ts +5 -5
  31. package/dest/state_machine/synchronizer.d.ts.map +1 -1
  32. package/dest/state_machine/synchronizer.js +3 -3
  33. package/dest/txe_session.d.ts +10 -6
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +36 -25
  36. package/dest/util/encoding.d.ts +69 -1
  37. package/dest/util/encoding.d.ts.map +1 -1
  38. package/dest/util/txe_public_contract_data_source.d.ts +2 -3
  39. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  40. package/dest/util/txe_public_contract_data_source.js +6 -25
  41. package/package.json +15 -15
  42. package/src/index.ts +89 -52
  43. package/src/oracle/interfaces.ts +32 -31
  44. package/src/oracle/txe_oracle_public_context.ts +12 -12
  45. package/src/oracle/txe_oracle_top_level_context.ts +74 -44
  46. package/src/rpc_translator.ts +332 -174
  47. package/src/state_machine/archiver.ts +6 -5
  48. package/src/state_machine/dummy_p2p_client.ts +17 -9
  49. package/src/state_machine/global_variable_builder.ts +7 -1
  50. package/src/state_machine/index.ts +7 -1
  51. package/src/state_machine/mock_epoch_cache.ts +42 -3
  52. package/src/state_machine/synchronizer.ts +4 -4
  53. package/src/txe_session.ts +45 -24
  54. package/src/util/txe_public_contract_data_source.ts +10 -38
  55. package/dest/util/txe_contract_store.d.ts +0 -12
  56. package/dest/util/txe_contract_store.d.ts.map +0 -1
  57. package/dest/util/txe_contract_store.js +0 -22
  58. package/src/util/txe_contract_store.ts +0 -36
@@ -4,7 +4,7 @@ import { Schnorr } from '@aztec/foundation/crypto/schnorr';
4
4
  import { Fr } from '@aztec/foundation/curves/bn254';
5
5
  import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
6
6
  import { TestDateProvider } from '@aztec/foundation/timer';
7
- import { ORACLE_VERSION, enrichPublicSimulationError } from '@aztec/pxe/server';
7
+ import { CapsuleService, ORACLE_VERSION, enrichPublicSimulationError } from '@aztec/pxe/server';
8
8
  import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle, executePrivateFunction, generateSimulatedProvingResult } from '@aztec/pxe/simulator';
9
9
  import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
10
10
  import { CppPublicTxSimulator, GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor } from '@aztec/simulator/server';
@@ -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,29 @@ 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
- throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
71
+ const hint = version > ORACLE_VERSION ? 'The contract was compiled with a newer version of Aztec.nr than this aztec cli version supports. Upgrade your aztec cli version to a compatible version.' : 'The contract was compiled with an older version of Aztec.nr than this aztec cli version supports. Recompile the contract with a compatible version of Aztec.nr.';
72
+ throw new Error(`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle version ${ORACLE_VERSION}, got ${version})`);
72
73
  }
73
74
  }
74
75
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
75
76
  // setup.
76
- utilityGetRandomField() {
77
+ getRandomField() {
77
78
  return Fr.random();
78
79
  }
79
80
  // 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) {
81
+ log(level, message, fields) {
81
82
  if (!LogLevels[level]) {
82
83
  throw new Error(`Invalid log level: ${level}`);
83
84
  }
@@ -87,19 +88,19 @@ export class TXEOracleTopLevelContext {
87
88
  });
88
89
  return Promise.resolve();
89
90
  }
90
- txeGetDefaultAddress() {
91
+ getDefaultAddress() {
91
92
  return DEFAULT_ADDRESS;
92
93
  }
93
- async txeGetNextBlockNumber() {
94
+ async getNextBlockNumber() {
94
95
  return BlockNumber(await this.getLastBlockNumber() + 1);
95
96
  }
96
- txeGetNextBlockTimestamp() {
97
+ getNextBlockTimestamp() {
97
98
  return Promise.resolve(this.nextBlockTimestamp);
98
99
  }
99
- async txeGetLastBlockTimestamp() {
100
+ async getLastBlockTimestamp() {
100
101
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
101
102
  }
102
- async txeGetLastTxEffects() {
103
+ async getLastTxEffects() {
103
104
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
104
105
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
105
106
  if (block.body.txEffects.length != 1) {
@@ -113,7 +114,19 @@ export class TXEOracleTopLevelContext {
113
114
  nullifiers: txEffects.nullifiers
114
115
  };
115
116
  }
116
- async txeGetPrivateEvents(selector, contractAddress, scope) {
117
+ async syncContractNonOracleMethod(contractAddress, scope, jobId) {
118
+ if (contractAddress.equals(DEFAULT_ADDRESS)) {
119
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
120
+ return;
121
+ }
122
+ const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
123
+ await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
124
+ await this.executeUtilityCall(call, execScopes, jobId);
125
+ }, blockHeader, jobId, [
126
+ scope
127
+ ]);
128
+ }
129
+ async getPrivateEvents(selector, contractAddress, scope) {
117
130
  return (await this.privateEventStore.getPrivateEvents(selector, {
118
131
  contractAddress,
119
132
  scopes: [
@@ -123,17 +136,17 @@ export class TXEOracleTopLevelContext {
123
136
  toBlock: await this.getLastBlockNumber() + 1
124
137
  })).map((e)=>e.packedEvent);
125
138
  }
126
- async txeAdvanceBlocksBy(blocks) {
139
+ async advanceBlocksBy(blocks) {
127
140
  this.logger.debug(`time traveling ${blocks} blocks`);
128
141
  for(let i = 0; i < blocks; i++){
129
142
  await this.mineBlock();
130
143
  }
131
144
  }
132
- txeAdvanceTimestampBy(duration) {
145
+ advanceTimestampBy(duration) {
133
146
  this.logger.debug(`time traveling ${duration} seconds`);
134
147
  this.nextBlockTimestamp += duration;
135
148
  }
136
- async txeDeploy(artifact, instance, secret) {
149
+ async deploy(artifact, instance, secret) {
137
150
  // Emit deployment nullifier
138
151
  await this.mineBlock({
139
152
  nullifiers: [
@@ -141,25 +154,25 @@ export class TXEOracleTopLevelContext {
141
154
  ]
142
155
  });
143
156
  if (!secret.equals(Fr.ZERO)) {
144
- await this.txeAddAccount(artifact, instance, secret);
157
+ await this.addAccount(artifact, instance, secret);
145
158
  } else {
146
159
  await this.contractStore.addContractInstance(instance);
147
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
160
+ await this.contractStore.addContractArtifact(artifact);
148
161
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
149
162
  }
150
163
  }
151
- async txeAddAccount(artifact, instance, secret) {
164
+ async addAccount(artifact, instance, secret) {
152
165
  const partialAddress = await computePartialAddress(instance);
153
166
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
154
167
  await this.contractStore.addContractInstance(instance);
155
- await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
168
+ await this.contractStore.addContractArtifact(artifact);
156
169
  const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
157
170
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
158
171
  await this.addressStore.addCompleteAddress(completeAddress);
159
172
  this.logger.debug(`Created account ${completeAddress.address}`);
160
173
  return completeAddress;
161
174
  }
162
- async txeCreateAccount(secret) {
175
+ async createAccount(secret) {
163
176
  // This is a foot gun !
164
177
  const completeAddress = await this.keyStore.addAccount(secret, secret);
165
178
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -167,7 +180,7 @@ export class TXEOracleTopLevelContext {
167
180
  this.logger.debug(`Created account ${completeAddress.address}`);
168
181
  return completeAddress;
169
182
  }
170
- async txeAddAuthWitness(address, messageHash) {
183
+ async addAuthWitness(address, messageHash) {
171
184
  const account = await this.accountStore.getAccount(address);
172
185
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
173
186
  const schnorr = new Schnorr();
@@ -178,7 +191,7 @@ export class TXEOracleTopLevelContext {
178
191
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
179
192
  }
180
193
  async mineBlock(options = {}) {
181
- const blockNumber = await this.txeGetNextBlockNumber();
194
+ const blockNumber = await this.getNextBlockNumber();
182
195
  const txEffect = TxEffect.empty();
183
196
  txEffect.nullifiers = [
184
197
  getSingleTxBlockRequestHash(blockNumber),
@@ -200,7 +213,7 @@ export class TXEOracleTopLevelContext {
200
213
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
201
214
  await this.stateMachine.handleL2Block(block);
202
215
  }
203
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false) {
216
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
204
217
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
205
218
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
206
219
  if (!artifact) {
@@ -214,11 +227,11 @@ export class TXEOracleTopLevelContext {
214
227
  ];
215
228
  // Sync notes before executing private function to discover notes from previous transactions
216
229
  const utilityExecutor = async (call, execScopes)=>{
217
- await this.executeUtilityCall(call, execScopes);
230
+ await this.executeUtilityCall(call, execScopes, jobId);
218
231
  };
219
232
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
220
- await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, this.jobId, effectiveScopes);
221
- const blockNumber = await this.txeGetNextBlockNumber();
233
+ await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
234
+ const blockNumber = await this.getNextBlockNumber();
222
235
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
223
236
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
224
237
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
@@ -254,17 +267,18 @@ export class TXEOracleTopLevelContext {
254
267
  senderTaggingStore: this.senderTaggingStore,
255
268
  recipientTaggingStore: this.recipientTaggingStore,
256
269
  senderAddressBookStore: this.senderAddressBookStore,
257
- capsuleStore: this.capsuleStore,
270
+ capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
258
271
  privateEventStore: this.privateEventStore,
259
272
  contractSyncService: this.stateMachine.contractSyncService,
260
- jobId: this.jobId,
273
+ jobId,
261
274
  totalPublicCalldataCount: 0,
262
275
  sideEffectCounter: minRevertibleSideEffectCounter,
263
276
  scopes: effectiveScopes,
264
277
  // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
265
278
  // contract would perform, including setting senderForTags.
266
279
  senderForTags: from,
267
- simulator
280
+ simulator,
281
+ messageContextService: this.stateMachine.messageContextService
268
282
  });
269
283
  // 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.
270
284
  let result;
@@ -277,7 +291,7 @@ export class TXEOracleTopLevelContext {
277
291
  r.publicInputs.publicTeardownCallRequest
278
292
  ]));
279
293
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
280
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
294
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
281
295
  return new HashedValues(calldata, r.calldataHash);
282
296
  }));
283
297
  noteCache.finish();
@@ -357,9 +371,9 @@ export class TXEOracleTopLevelContext {
357
371
  await forkedWorldTrees.close();
358
372
  return executionResult.returnValues ?? [];
359
373
  }
360
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
374
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
361
375
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
362
- const blockNumber = await this.txeGetNextBlockNumber();
376
+ const blockNumber = await this.getNextBlockNumber();
363
377
  const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
364
378
  const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
365
379
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
@@ -398,7 +412,7 @@ export class TXEOracleTopLevelContext {
398
412
  revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
399
413
  const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
400
414
  const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
401
- const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*includeByTimestamp=*/ 0n, inputsForPublic, undefined);
415
+ const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
402
416
  const tx = await Tx.create({
403
417
  data: txData,
404
418
  chonkProof: ChonkProof.empty(),
@@ -451,7 +465,7 @@ export class TXEOracleTopLevelContext {
451
465
  await forkedWorldTrees.close();
452
466
  return returnValues ?? [];
453
467
  }
454
- async txeSimulateUtilityFunction(targetContractAddress, functionSelector, args) {
468
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
455
469
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
456
470
  if (!artifact) {
457
471
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
@@ -459,8 +473,8 @@ export class TXEOracleTopLevelContext {
459
473
  // Sync notes before executing utility function to discover notes from previous transactions
460
474
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
461
475
  await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
462
- await this.executeUtilityCall(call, execScopes);
463
- }, blockHeader, this.jobId, undefined);
476
+ await this.executeUtilityCall(call, execScopes, jobId);
477
+ }, blockHeader, jobId, await this.keyStore.getAccounts());
464
478
  const call = FunctionCall.from({
465
479
  name: artifact.name,
466
480
  to: targetContractAddress,
@@ -471,9 +485,9 @@ export class TXEOracleTopLevelContext {
471
485
  args,
472
486
  returnTypes: []
473
487
  });
474
- return this.executeUtilityCall(call, undefined);
488
+ return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
475
489
  }
476
- async executeUtilityCall(call, scopes) {
490
+ async executeUtilityCall(call, scopes, jobId) {
477
491
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
478
492
  if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
479
493
  throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
@@ -496,9 +510,11 @@ export class TXEOracleTopLevelContext {
496
510
  aztecNode: this.stateMachine.node,
497
511
  recipientTaggingStore: this.recipientTaggingStore,
498
512
  senderAddressBookStore: this.senderAddressBookStore,
499
- capsuleStore: this.capsuleStore,
513
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
500
514
  privateEventStore: this.privateEventStore,
501
- jobId: this.jobId,
515
+ messageContextService: this.stateMachine.messageContextService,
516
+ contractSyncService: this.contractSyncService,
517
+ jobId,
502
518
  scopes
503
519
  });
504
520
  const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
@@ -510,10 +526,10 @@ export class TXEOracleTopLevelContext {
510
526
  cause: err
511
527
  });
512
528
  });
513
- this.logger.verbose(`Utility simulation for ${call.to}.${call.selector} completed`);
529
+ this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
514
530
  return witnessMapToFields(acirExecutionResult.returnWitness);
515
531
  } catch (err) {
516
- throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility simulation'));
532
+ throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
517
533
  }
518
534
  }
519
535
  close() {