@aztec/txe 0.0.1-commit.96dac018d → 0.0.1-commit.9badcec54

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 (56) hide show
  1. package/dest/index.d.ts +1 -1
  2. package/dest/index.d.ts.map +1 -1
  3. package/dest/index.js +8 -6
  4. package/dest/oracle/interfaces.d.ts +28 -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 +27 -21
  10. package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
  11. package/dest/oracle/txe_oracle_top_level_context.js +56 -39
  12. package/dest/rpc_translator.d.ts +120 -82
  13. package/dest/rpc_translator.d.ts.map +1 -1
  14. package/dest/rpc_translator.js +372 -162
  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 +3 -2
  19. package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
  20. package/dest/state_machine/dummy_p2p_client.js +5 -2
  21. package/dest/state_machine/global_variable_builder.d.ts +9 -4
  22. package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
  23. package/dest/state_machine/global_variable_builder.js +9 -3
  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 +8 -4
  27. package/dest/state_machine/mock_epoch_cache.d.ts +18 -3
  28. package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
  29. package/dest/state_machine/mock_epoch_cache.js +35 -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 +4 -3
  34. package/dest/txe_session.d.ts.map +1 -1
  35. package/dest/txe_session.js +27 -15
  36. package/dest/util/encoding.d.ts +71 -1
  37. package/dest/util/encoding.d.ts.map +1 -1
  38. package/dest/util/encoding.js +4 -0
  39. package/dest/util/txe_public_contract_data_source.d.ts +1 -1
  40. package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
  41. package/dest/util/txe_public_contract_data_source.js +1 -3
  42. package/package.json +15 -15
  43. package/src/index.ts +8 -5
  44. package/src/oracle/interfaces.ts +27 -31
  45. package/src/oracle/txe_oracle_public_context.ts +12 -12
  46. package/src/oracle/txe_oracle_top_level_context.ts +66 -43
  47. package/src/rpc_translator.ts +431 -183
  48. package/src/state_machine/archiver.ts +6 -5
  49. package/src/state_machine/dummy_p2p_client.ts +6 -2
  50. package/src/state_machine/global_variable_builder.ts +18 -3
  51. package/src/state_machine/index.ts +8 -2
  52. package/src/state_machine/mock_epoch_cache.ts +46 -3
  53. package/src/state_machine/synchronizer.ts +4 -4
  54. package/src/txe_session.ts +29 -13
  55. package/src/util/encoding.ts +5 -0
  56. package/src/util/txe_public_contract_data_source.ts +0 -2
@@ -1,10 +1,10 @@
1
- import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT, DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
1
+ import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
2
2
  import { BlockNumber } from '@aztec/foundation/branded-types';
3
3
  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_MAJOR, 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';
@@ -13,7 +13,7 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
13
13
  import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
14
14
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
15
15
  import { computePartialAddress } from '@aztec/stdlib/contract';
16
- import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
16
+ import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
17
17
  import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
18
18
  import { PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PublicCallRequest } from '@aztec/stdlib/kernel';
19
19
  import { ChonkProof } from '@aztec/stdlib/proofs';
@@ -40,10 +40,11 @@ export class TXEOracleTopLevelContext {
40
40
  version;
41
41
  chainId;
42
42
  authwits;
43
+ contractSyncService;
43
44
  isMisc;
44
45
  isTxe;
45
46
  logger;
46
- constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits){
47
+ constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
47
48
  this.stateMachine = stateMachine;
48
49
  this.contractStore = contractStore;
49
50
  this.noteStore = noteStore;
@@ -59,23 +60,34 @@ export class TXEOracleTopLevelContext {
59
60
  this.version = version;
60
61
  this.chainId = chainId;
61
62
  this.authwits = authwits;
63
+ this.contractSyncService = contractSyncService;
62
64
  this.isMisc = true;
63
65
  this.isTxe = true;
64
66
  this.logger = createLogger('txe:top_level_context');
65
67
  this.logger.debug('Entering Top Level Context');
66
68
  }
67
- utilityAssertCompatibleOracleVersion(version) {
68
- if (version !== ORACLE_VERSION) {
69
- throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
69
+ contractOracleVersion;
70
+ assertCompatibleOracleVersion(major, minor) {
71
+ if (major !== ORACLE_VERSION_MAJOR) {
72
+ const hint = major > ORACLE_VERSION_MAJOR ? '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.';
73
+ throw new Error(`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`);
70
74
  }
75
+ this.contractOracleVersion = {
76
+ major,
77
+ minor
78
+ };
79
+ }
80
+ // Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
81
+ nonOracleFunctionGetContractOracleVersion() {
82
+ return this.contractOracleVersion;
71
83
  }
72
84
  // This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
73
85
  // setup.
74
- utilityGetRandomField() {
86
+ getRandomField() {
75
87
  return Fr.random();
76
88
  }
77
89
  // We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
78
- utilityLog(level, message, fields) {
90
+ log(level, message, fields) {
79
91
  if (!LogLevels[level]) {
80
92
  throw new Error(`Invalid log level: ${level}`);
81
93
  }
@@ -85,19 +97,19 @@ export class TXEOracleTopLevelContext {
85
97
  });
86
98
  return Promise.resolve();
87
99
  }
88
- txeGetDefaultAddress() {
100
+ getDefaultAddress() {
89
101
  return DEFAULT_ADDRESS;
90
102
  }
91
- async txeGetNextBlockNumber() {
103
+ async getNextBlockNumber() {
92
104
  return BlockNumber(await this.getLastBlockNumber() + 1);
93
105
  }
94
- txeGetNextBlockTimestamp() {
106
+ getNextBlockTimestamp() {
95
107
  return Promise.resolve(this.nextBlockTimestamp);
96
108
  }
97
- async txeGetLastBlockTimestamp() {
109
+ async getLastBlockTimestamp() {
98
110
  return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
99
111
  }
100
- async txeGetLastTxEffects() {
112
+ async getLastTxEffects() {
101
113
  const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
102
114
  const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
103
115
  if (block.body.txEffects.length != 1) {
@@ -113,7 +125,7 @@ export class TXEOracleTopLevelContext {
113
125
  }
114
126
  async syncContractNonOracleMethod(contractAddress, scope, jobId) {
115
127
  if (contractAddress.equals(DEFAULT_ADDRESS)) {
116
- this.logger.debug(`Skipping sync in txeGetPrivateEvents because the events correspond to the default address.`);
128
+ this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
117
129
  return;
118
130
  }
119
131
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
@@ -123,7 +135,7 @@ export class TXEOracleTopLevelContext {
123
135
  scope
124
136
  ]);
125
137
  }
126
- async txeGetPrivateEvents(selector, contractAddress, scope) {
138
+ async getPrivateEvents(selector, contractAddress, scope) {
127
139
  return (await this.privateEventStore.getPrivateEvents(selector, {
128
140
  contractAddress,
129
141
  scopes: [
@@ -133,17 +145,17 @@ export class TXEOracleTopLevelContext {
133
145
  toBlock: await this.getLastBlockNumber() + 1
134
146
  })).map((e)=>e.packedEvent);
135
147
  }
136
- async txeAdvanceBlocksBy(blocks) {
148
+ async advanceBlocksBy(blocks) {
137
149
  this.logger.debug(`time traveling ${blocks} blocks`);
138
150
  for(let i = 0; i < blocks; i++){
139
151
  await this.mineBlock();
140
152
  }
141
153
  }
142
- txeAdvanceTimestampBy(duration) {
154
+ advanceTimestampBy(duration) {
143
155
  this.logger.debug(`time traveling ${duration} seconds`);
144
156
  this.nextBlockTimestamp += duration;
145
157
  }
146
- async txeDeploy(artifact, instance, secret) {
158
+ async deploy(artifact, instance, secret) {
147
159
  // Emit deployment nullifier
148
160
  await this.mineBlock({
149
161
  nullifiers: [
@@ -151,14 +163,14 @@ export class TXEOracleTopLevelContext {
151
163
  ]
152
164
  });
153
165
  if (!secret.equals(Fr.ZERO)) {
154
- await this.txeAddAccount(artifact, instance, secret);
166
+ await this.addAccount(artifact, instance, secret);
155
167
  } else {
156
168
  await this.contractStore.addContractInstance(instance);
157
169
  await this.contractStore.addContractArtifact(artifact);
158
170
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
159
171
  }
160
172
  }
161
- async txeAddAccount(artifact, instance, secret) {
173
+ async addAccount(artifact, instance, secret) {
162
174
  const partialAddress = await computePartialAddress(instance);
163
175
  this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
164
176
  await this.contractStore.addContractInstance(instance);
@@ -169,7 +181,7 @@ export class TXEOracleTopLevelContext {
169
181
  this.logger.debug(`Created account ${completeAddress.address}`);
170
182
  return completeAddress;
171
183
  }
172
- async txeCreateAccount(secret) {
184
+ async createAccount(secret) {
173
185
  // This is a foot gun !
174
186
  const completeAddress = await this.keyStore.addAccount(secret, secret);
175
187
  await this.accountStore.setAccount(completeAddress.address, completeAddress);
@@ -177,7 +189,7 @@ export class TXEOracleTopLevelContext {
177
189
  this.logger.debug(`Created account ${completeAddress.address}`);
178
190
  return completeAddress;
179
191
  }
180
- async txeAddAuthWitness(address, messageHash) {
192
+ async addAuthWitness(address, messageHash) {
181
193
  const account = await this.accountStore.getAccount(address);
182
194
  const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
183
195
  const schnorr = new Schnorr();
@@ -188,7 +200,7 @@ export class TXEOracleTopLevelContext {
188
200
  this.authwits.set(authWitness.requestHash.toString(), authWitness);
189
201
  }
190
202
  async mineBlock(options = {}) {
191
- const blockNumber = await this.txeGetNextBlockNumber();
203
+ const blockNumber = await this.getNextBlockNumber();
192
204
  const txEffect = TxEffect.empty();
193
205
  txEffect.nullifiers = [
194
206
  getSingleTxBlockRequestHash(blockNumber),
@@ -210,7 +222,7 @@ export class TXEOracleTopLevelContext {
210
222
  this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
211
223
  await this.stateMachine.handleL2Block(block);
212
224
  }
213
- async txePrivateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
225
+ async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
214
226
  this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
215
227
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
216
228
  if (!artifact) {
@@ -228,10 +240,10 @@ export class TXEOracleTopLevelContext {
228
240
  };
229
241
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
230
242
  await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
231
- const blockNumber = await this.txeGetNextBlockNumber();
243
+ const blockNumber = await this.getNextBlockNumber();
232
244
  const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
233
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
234
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
245
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
246
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
235
247
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
236
248
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
237
249
  const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
@@ -264,7 +276,7 @@ export class TXEOracleTopLevelContext {
264
276
  senderTaggingStore: this.senderTaggingStore,
265
277
  recipientTaggingStore: this.recipientTaggingStore,
266
278
  senderAddressBookStore: this.senderAddressBookStore,
267
- capsuleStore: this.capsuleStore,
279
+ capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
268
280
  privateEventStore: this.privateEventStore,
269
281
  contractSyncService: this.stateMachine.contractSyncService,
270
282
  jobId,
@@ -274,7 +286,9 @@ export class TXEOracleTopLevelContext {
274
286
  // In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
275
287
  // contract would perform, including setting senderForTags.
276
288
  senderForTags: from,
277
- simulator
289
+ simulator,
290
+ messageContextService: this.stateMachine.messageContextService,
291
+ l2TipsStore: this.stateMachine.node
278
292
  });
279
293
  // 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.
280
294
  let result;
@@ -287,7 +301,7 @@ export class TXEOracleTopLevelContext {
287
301
  r.publicInputs.publicTeardownCallRequest
288
302
  ]));
289
303
  const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
290
- const calldata = await privateExecutionOracle.privateLoadFromExecutionCache(r.calldataHash);
304
+ const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
291
305
  return new HashedValues(calldata, r.calldataHash);
292
306
  }));
293
307
  noteCache.finish();
@@ -367,11 +381,11 @@ export class TXEOracleTopLevelContext {
367
381
  await forkedWorldTrees.close();
368
382
  return executionResult.returnValues ?? [];
369
383
  }
370
- async txePublicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
384
+ async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
371
385
  this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
372
- const blockNumber = await this.txeGetNextBlockNumber();
373
- const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
374
- const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
386
+ const blockNumber = await this.getNextBlockNumber();
387
+ const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
388
+ const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
375
389
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
376
390
  const txContext = new TxContext(this.chainId, this.version, gasSettings);
377
391
  const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
@@ -461,7 +475,7 @@ export class TXEOracleTopLevelContext {
461
475
  await forkedWorldTrees.close();
462
476
  return returnValues ?? [];
463
477
  }
464
- async txeExecuteUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
478
+ async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
465
479
  const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
466
480
  if (!artifact) {
467
481
  throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
@@ -470,7 +484,7 @@ export class TXEOracleTopLevelContext {
470
484
  const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
471
485
  await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
472
486
  await this.executeUtilityCall(call, execScopes, jobId);
473
- }, blockHeader, jobId, 'ALL_SCOPES');
487
+ }, blockHeader, jobId, await this.keyStore.getAccounts());
474
488
  const call = FunctionCall.from({
475
489
  name: artifact.name,
476
490
  to: targetContractAddress,
@@ -481,7 +495,7 @@ export class TXEOracleTopLevelContext {
481
495
  args,
482
496
  returnTypes: []
483
497
  });
484
- return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
498
+ return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
485
499
  }
486
500
  async executeUtilityCall(call, scopes, jobId) {
487
501
  const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
@@ -506,8 +520,11 @@ export class TXEOracleTopLevelContext {
506
520
  aztecNode: this.stateMachine.node,
507
521
  recipientTaggingStore: this.recipientTaggingStore,
508
522
  senderAddressBookStore: this.senderAddressBookStore,
509
- capsuleStore: this.capsuleStore,
523
+ capsuleService: new CapsuleService(this.capsuleStore, scopes),
510
524
  privateEventStore: this.privateEventStore,
525
+ messageContextService: this.stateMachine.messageContextService,
526
+ contractSyncService: this.contractSyncService,
527
+ l2TipsStore: this.stateMachine.node,
511
528
  jobId,
512
529
  scopes
513
530
  });