@aztec/simulator 0.65.2 → 0.66.0

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 (61) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +0 -3
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +1 -17
  4. package/dest/acvm/oracle/typed_oracle.d.ts +0 -5
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +1 -10
  7. package/dest/avm/avm_memory_types.js +4 -4
  8. package/dest/avm/avm_simulator.d.ts.map +1 -1
  9. package/dest/avm/avm_simulator.js +5 -4
  10. package/dest/avm/avm_tree.d.ts +31 -14
  11. package/dest/avm/avm_tree.d.ts.map +1 -1
  12. package/dest/avm/avm_tree.js +34 -40
  13. package/dest/avm/journal/journal.d.ts.map +1 -1
  14. package/dest/avm/journal/journal.js +16 -10
  15. package/dest/avm/opcodes/environment_getters.d.ts +10 -11
  16. package/dest/avm/opcodes/environment_getters.d.ts.map +1 -1
  17. package/dest/avm/opcodes/environment_getters.js +12 -15
  18. package/dest/client/client_execution_context.d.ts +3 -30
  19. package/dest/client/client_execution_context.d.ts.map +1 -1
  20. package/dest/client/client_execution_context.js +5 -47
  21. package/dest/client/private_execution.d.ts.map +1 -1
  22. package/dest/client/private_execution.js +2 -4
  23. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  24. package/dest/public/enqueued_call_side_effect_trace.js +15 -15
  25. package/dest/public/fixtures/index.d.ts +1 -6
  26. package/dest/public/fixtures/index.d.ts.map +1 -1
  27. package/dest/public/fixtures/index.js +6 -9
  28. package/dest/public/public_db_sources.d.ts.map +1 -1
  29. package/dest/public/public_db_sources.js +27 -13
  30. package/dest/public/public_processor.d.ts.map +1 -1
  31. package/dest/public/public_processor.js +8 -5
  32. package/dest/public/public_processor_metrics.d.ts +1 -1
  33. package/dest/public/public_processor_metrics.d.ts.map +1 -1
  34. package/dest/public/public_tx_context.d.ts +2 -6
  35. package/dest/public/public_tx_context.d.ts.map +1 -1
  36. package/dest/public/public_tx_context.js +23 -29
  37. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  38. package/dest/public/public_tx_simulator.js +1 -3
  39. package/dest/public/side_effect_trace.js +8 -8
  40. package/dest/public/transitional_adapters.d.ts +2 -6
  41. package/dest/public/transitional_adapters.d.ts.map +1 -1
  42. package/dest/public/transitional_adapters.js +4 -67
  43. package/package.json +9 -9
  44. package/src/acvm/oracle/oracle.ts +0 -30
  45. package/src/acvm/oracle/typed_oracle.ts +0 -17
  46. package/src/avm/avm_memory_types.ts +4 -4
  47. package/src/avm/avm_simulator.ts +4 -3
  48. package/src/avm/avm_tree.ts +67 -53
  49. package/src/avm/journal/journal.ts +21 -9
  50. package/src/avm/opcodes/environment_getters.ts +1 -4
  51. package/src/client/client_execution_context.ts +5 -59
  52. package/src/client/private_execution.ts +0 -4
  53. package/src/public/enqueued_call_side_effect_trace.ts +14 -16
  54. package/src/public/fixtures/index.ts +5 -7
  55. package/src/public/public_db_sources.ts +29 -16
  56. package/src/public/public_processor.ts +6 -8
  57. package/src/public/public_processor_metrics.ts +1 -1
  58. package/src/public/public_tx_context.ts +37 -44
  59. package/src/public/public_tx_simulator.ts +0 -11
  60. package/src/public/side_effect_trace.ts +7 -7
  61. package/src/public/transitional_adapters.ts +6 -193
@@ -9,9 +9,7 @@ import { type PublicDBAccessStats } from '@aztec/circuit-types/stats';
9
9
  import {
10
10
  type AztecAddress,
11
11
  type ContractClassPublic,
12
- ContractClassRegisteredEvent,
13
12
  type ContractDataSource,
14
- ContractInstanceDeployedEvent,
15
13
  type ContractInstanceWithAddress,
16
14
  Fr,
17
15
  type FunctionSelector,
@@ -24,7 +22,7 @@ import {
24
22
  import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
25
23
  import { createDebugLogger } from '@aztec/foundation/log';
26
24
  import { Timer } from '@aztec/foundation/timer';
27
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
25
+ import { ContractClassRegisteredEvent, ContractInstanceDeployedEvent } from '@aztec/protocol-contracts';
28
26
  import {
29
27
  type CommitmentsDB,
30
28
  MessageLoadOracleInputs,
@@ -51,13 +49,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
51
49
  public addNewContracts(tx: Tx): Promise<void> {
52
50
  // Extract contract class and instance data from logs and add to cache for this block
53
51
  const logs = tx.contractClassLogs.unrollLogs();
54
- ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e => {
55
- this.log.debug(`Adding class ${e.contractClassId.toString()} to public execution contract cache`);
56
- this.classCache.set(e.contractClassId.toString(), e.toContractClassPublic());
57
- });
58
- // We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
59
- const encLogs = tx.encryptedLogs.unrollLogs();
60
- ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => {
52
+ logs
53
+ .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
54
+ .forEach(log => {
55
+ const event = ContractClassRegisteredEvent.fromLog(log.data);
56
+ this.log.debug(`Adding class ${event.contractClassId.toString()} to public execution contract cache`);
57
+ this.classCache.set(event.contractClassId.toString(), event.toContractClassPublic());
58
+ });
59
+
60
+ // We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
61
+ const contractInstanceEvents = tx.data
62
+ .getNonEmptyPrivateLogs()
63
+ .filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
64
+ .map(ContractInstanceDeployedEvent.fromLog);
65
+ contractInstanceEvents.forEach(e => {
61
66
  this.log.debug(
62
67
  `Adding instance ${e.address.toString()} with class ${e.contractClassId.toString()} to public execution contract cache`,
63
68
  );
@@ -76,12 +81,20 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
76
81
  // Let's say we have two txs adding the same contract on the same block. If the 2nd one reverts,
77
82
  // wouldn't that accidentally remove the contract added on the first one?
78
83
  const logs = tx.contractClassLogs.unrollLogs();
79
- ContractClassRegisteredEvent.fromLogs(logs, ProtocolContractAddress.ContractClassRegisterer).forEach(e =>
80
- this.classCache.delete(e.contractClassId.toString()),
81
- );
82
- // We store the contract instance deployed event log in enc logs, contract_instance_deployer_contract/src/main.nr
83
- const encLogs = tx.encryptedLogs.unrollLogs();
84
- ContractInstanceDeployedEvent.fromLogs(encLogs).forEach(e => this.instanceCache.delete(e.address.toString()));
84
+ logs
85
+ .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
86
+ .forEach(log => {
87
+ const event = ContractClassRegisteredEvent.fromLog(log.data);
88
+ this.classCache.delete(event.contractClassId.toString());
89
+ });
90
+
91
+ // We store the contract instance deployed event log in private logs, contract_instance_deployer_contract/src/main.nr
92
+ const contractInstanceEvents = tx.data
93
+ .getNonEmptyPrivateLogs()
94
+ .filter(log => ContractInstanceDeployedEvent.isContractInstanceDeployedEvent(log))
95
+ .map(ContractInstanceDeployedEvent.fromLog);
96
+ contractInstanceEvents.forEach(e => this.instanceCache.delete(e.address.toString()));
97
+
85
98
  return Promise.resolve();
86
99
  }
87
100
 
@@ -13,7 +13,6 @@ import {
13
13
  } from '@aztec/circuit-types';
14
14
  import {
15
15
  type AztecAddress,
16
- ContractClassRegisteredEvent,
17
16
  type ContractDataSource,
18
17
  Fr,
19
18
  type GlobalVariables,
@@ -26,7 +25,7 @@ import {
26
25
  import { padArrayEnd } from '@aztec/foundation/collection';
27
26
  import { createDebugLogger } from '@aztec/foundation/log';
28
27
  import { Timer } from '@aztec/foundation/timer';
29
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
28
+ import { ContractClassRegisteredEvent, ProtocolContractAddress } from '@aztec/protocol-contracts';
30
29
  import { Attributes, type TelemetryClient, type Tracer, trackSpan } from '@aztec/telemetry-client';
31
30
 
32
31
  import { computeFeePayerBalanceLeafSlot, computeFeePayerBalanceStorageSlot } from './fee_payment.js';
@@ -167,10 +166,9 @@ export class PublicProcessor {
167
166
  }
168
167
  }
169
168
 
170
- await this.db.batchInsert(
169
+ await this.db.sequentialInsert(
171
170
  MerkleTreeId.PUBLIC_DATA_TREE,
172
171
  processedTx.txEffect.publicDataWrites.map(x => x.toBuffer()),
173
- 0,
174
172
  );
175
173
  result.push(processedTx);
176
174
  returns = returns.concat(returnValues ?? []);
@@ -275,10 +273,10 @@ export class PublicProcessor {
275
273
  });
276
274
 
277
275
  this.metrics.recordClassRegistration(
278
- ...ContractClassRegisteredEvent.fromLogs(
279
- tx.contractClassLogs.unrollLogs(),
280
- ProtocolContractAddress.ContractClassRegisterer,
281
- ),
276
+ ...tx.contractClassLogs
277
+ .unrollLogs()
278
+ .filter(log => ContractClassRegisteredEvent.isContractClassRegisteredEvent(log.data))
279
+ .map(log => ContractClassRegisteredEvent.fromLog(log.data)),
282
280
  );
283
281
 
284
282
  const phaseCount = processedPhases.length;
@@ -1,5 +1,5 @@
1
1
  import { type TxExecutionPhase } from '@aztec/circuit-types';
2
- import { type ContractClassRegisteredEvent } from '@aztec/circuits.js';
2
+ import { type ContractClassRegisteredEvent } from '@aztec/protocol-contracts';
3
3
  import {
4
4
  Attributes,
5
5
  type Histogram,
@@ -2,6 +2,7 @@ import {
2
2
  type AvmProvingRequest,
3
3
  MerkleTreeId,
4
4
  type MerkleTreeReadOperations,
5
+ ProvingRequestType,
5
6
  type PublicExecutionRequest,
6
7
  type SimulationError,
7
8
  type Tx,
@@ -9,16 +10,19 @@ import {
9
10
  TxHash,
10
11
  } from '@aztec/circuit-types';
11
12
  import {
13
+ AppendOnlyTreeSnapshot,
14
+ AvmCircuitInputs,
12
15
  type AvmCircuitPublicInputs,
13
16
  Fr,
14
17
  Gas,
15
18
  type GasSettings,
16
19
  type GlobalVariables,
17
- type Header,
18
20
  type PrivateToPublicAccumulatedData,
19
21
  type PublicCallRequest,
22
+ PublicCircuitPublicInputs,
20
23
  RevertCode,
21
24
  type StateReference,
25
+ TreeSnapshots,
22
26
  countAccumulatedItems,
23
27
  } from '@aztec/circuits.js';
24
28
  import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
@@ -26,13 +30,12 @@ import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
26
30
  import { strict as assert } from 'assert';
27
31
  import { inspect } from 'util';
28
32
 
29
- import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
30
33
  import { AvmPersistableStateManager } from '../avm/index.js';
31
34
  import { DualSideEffectTrace } from './dual_side_effect_trace.js';
32
35
  import { PublicEnqueuedCallSideEffectTrace, SideEffectArrayLengths } from './enqueued_call_side_effect_trace.js';
33
36
  import { type WorldStateDB } from './public_db_sources.js';
34
37
  import { PublicSideEffectTrace } from './side_effect_trace.js';
35
- import { generateAvmCircuitPublicInputs, generateAvmProvingRequest } from './transitional_adapters.js';
38
+ import { generateAvmCircuitPublicInputs } from './transitional_adapters.js';
36
39
  import { getCallRequestsByPhase, getExecutionRequestsByPhase } from './utils.js';
37
40
 
38
41
  /**
@@ -58,7 +61,6 @@ export class PublicTxContext {
58
61
  constructor(
59
62
  public readonly state: PhaseStateManager,
60
63
  private readonly globalVariables: GlobalVariables,
61
- private readonly historicalHeader: Header, // FIXME(dbanks12): remove
62
64
  private readonly startStateReference: StateReference,
63
65
  private readonly startGasUsed: Gas,
64
66
  private readonly gasSettings: GasSettings,
@@ -89,7 +91,7 @@ export class PublicTxContext {
89
91
  const previousAccumulatedDataArrayLengths = new SideEffectArrayLengths(
90
92
  /*publicDataWrites*/ 0,
91
93
  countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.noteHashes),
92
- countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.nullifiers),
94
+ /*nullifiers=*/ 0,
93
95
  countAccumulatedItems(nonRevertibleAccumulatedDataFromPrivate.l2ToL1Msgs),
94
96
  /*unencryptedLogsHashes*/ 0,
95
97
  );
@@ -105,7 +107,6 @@ export class PublicTxContext {
105
107
  return new PublicTxContext(
106
108
  new PhaseStateManager(txStateManager),
107
109
  globalVariables,
108
- tx.data.constants.historicalHeader,
109
110
  await db.getStateReference(),
110
111
  tx.data.gasUsed,
111
112
  tx.data.constants.txContext.gasSettings,
@@ -301,11 +302,24 @@ export class PublicTxContext {
301
302
  */
302
303
  private generateAvmCircuitPublicInputs(endStateReference: StateReference): AvmCircuitPublicInputs {
303
304
  assert(this.halted, 'Can only get AvmCircuitPublicInputs after tx execution ends');
304
- // TODO(dbanks12): use the state roots from ephemeral trees
305
- endStateReference.partial.nullifierTree.root = this.state
306
- .getActiveStateManager()
307
- .merkleTrees.treeMap.get(MerkleTreeId.NULLIFIER_TREE)!
308
- .getRoot();
305
+ const ephemeralTrees = this.state.getActiveStateManager().merkleTrees.treeMap;
306
+
307
+ const getAppendSnaphot = (id: MerkleTreeId) => {
308
+ const tree = ephemeralTrees.get(id)!;
309
+ return new AppendOnlyTreeSnapshot(tree.getRoot(), Number(tree.leafCount));
310
+ };
311
+
312
+ const noteHashTree = getAppendSnaphot(MerkleTreeId.NOTE_HASH_TREE);
313
+ const nullifierTree = getAppendSnaphot(MerkleTreeId.NULLIFIER_TREE);
314
+ const publicDataTree = getAppendSnaphot(MerkleTreeId.PUBLIC_DATA_TREE);
315
+
316
+ const endTreeSnapshots = new TreeSnapshots(
317
+ endStateReference.l1ToL2MessageTree,
318
+ noteHashTree,
319
+ nullifierTree,
320
+ publicDataTree,
321
+ );
322
+
309
323
  return generateAvmCircuitPublicInputs(
310
324
  this.trace,
311
325
  this.globalVariables,
@@ -317,7 +331,7 @@ export class PublicTxContext {
317
331
  this.teardownCallRequests,
318
332
  this.nonRevertibleAccumulatedDataFromPrivate,
319
333
  this.revertibleAccumulatedDataFromPrivate,
320
- endStateReference,
334
+ endTreeSnapshots,
321
335
  /*endGasUsed=*/ this.gasUsed,
322
336
  this.getTransactionFeeUnsafe(),
323
337
  this.revertCode,
@@ -328,38 +342,17 @@ export class PublicTxContext {
328
342
  * Generate the proving request for the AVM circuit.
329
343
  */
330
344
  generateProvingRequest(endStateReference: StateReference): AvmProvingRequest {
331
- // TODO(dbanks12): Once we actually have tx-level proving, this will generate the entire
332
- // proving request for the first time
333
- this.avmProvingRequest!.inputs.output = this.generateAvmCircuitPublicInputs(endStateReference);
334
- return this.avmProvingRequest!;
335
- }
336
-
337
- // TODO(dbanks12): remove once AVM proves entire public tx
338
- updateProvingRequest(
339
- real: boolean,
340
- phase: TxExecutionPhase,
341
- fnName: string,
342
- stateManager: AvmPersistableStateManager,
343
- executionRequest: PublicExecutionRequest,
344
- result: AvmFinalizedCallResult,
345
- allocatedGas: Gas,
346
- ) {
347
- if (this.avmProvingRequest === undefined) {
348
- // Propagate the very first avmProvingRequest of the tx for now.
349
- // Eventually this will be the proof for the entire public portion of the transaction.
350
- this.avmProvingRequest = generateAvmProvingRequest(
351
- real,
352
- fnName,
353
- stateManager,
354
- this.historicalHeader,
355
- this.globalVariables,
356
- executionRequest,
357
- // TODO(dbanks12): do we need this return type unless we are doing an isolated call?
358
- stateManager.trace.toPublicEnqueuedCallExecutionResult(result),
359
- allocatedGas,
360
- this.getTransactionFee(phase),
361
- );
362
- }
345
+ const hints = this.trace.getAvmCircuitHints();
346
+ return {
347
+ type: ProvingRequestType.PUBLIC_VM,
348
+ inputs: new AvmCircuitInputs(
349
+ 'public_dispatch',
350
+ [],
351
+ PublicCircuitPublicInputs.empty(),
352
+ hints,
353
+ this.generateAvmCircuitPublicInputs(endStateReference),
354
+ ),
355
+ };
363
356
  }
364
357
  }
365
358
 
@@ -290,17 +290,6 @@ export class PublicTxSimulator {
290
290
  `[AVM] Enqueued public call consumed ${gasUsed.l2Gas} L2 gas ending with ${result.gasLeft.l2Gas} L2 gas left.`,
291
291
  );
292
292
 
293
- // TODO(dbanks12): remove once AVM proves entire public tx
294
- context.updateProvingRequest(
295
- this.realAvmProvingRequests,
296
- phase,
297
- fnName,
298
- stateManager,
299
- executionRequest,
300
- result,
301
- allocatedGas,
302
- );
303
-
304
293
  stateManager.traceEnqueuedCall(callRequest, executionRequest.args, result.reverted);
305
294
 
306
295
  if (result.reverted) {
@@ -138,7 +138,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
138
138
  );
139
139
 
140
140
  // New hinting
141
- this.avmCircuitHints.storageReadRequest.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
141
+ this.avmCircuitHints.publicDataReads.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
142
142
 
143
143
  this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
144
144
  this.incrementSideEffectCounter();
@@ -168,7 +168,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
168
168
 
169
169
  // New hinting
170
170
  const readHint = new AvmPublicDataReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
171
- this.avmCircuitHints.storageUpdateRequest.items.push(
171
+ this.avmCircuitHints.publicDataWrites.items.push(
172
172
  new AvmPublicDataWriteTreeHint(readHint, newLeafPreimage, insertionPath),
173
173
  );
174
174
  this.log.debug(`SSTORE cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
@@ -193,7 +193,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
193
193
  new AvmKeyValueHint(/*key=*/ new Fr(leafIndex), /*value=*/ exists ? Fr.ONE : Fr.ZERO),
194
194
  );
195
195
  // New Hinting
196
- this.avmCircuitHints.noteHashReadRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
196
+ this.avmCircuitHints.noteHashReads.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
197
197
  // NOTE: counter does not increment for note hash checks (because it doesn't rely on pending note hashes)
198
198
  }
199
199
 
@@ -210,7 +210,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
210
210
  this.log.debug(`NEW_NOTE_HASH cnt: ${this.sideEffectCounter}`);
211
211
 
212
212
  // New Hinting
213
- this.avmCircuitHints.noteHashWriteRequest.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
213
+ this.avmCircuitHints.noteHashWrites.items.push(new AvmAppendTreeHint(leafIndex, noteHash, path));
214
214
  this.incrementSideEffectCounter();
215
215
  }
216
216
 
@@ -237,7 +237,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
237
237
  );
238
238
 
239
239
  // New Hints
240
- this.avmCircuitHints.nullifierReadRequest.items.push(
240
+ this.avmCircuitHints.nullifierReads.items.push(
241
241
  new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath),
242
242
  );
243
243
  this.log.debug(`NULLIFIER_EXISTS cnt: ${this.sideEffectCounter}`);
@@ -259,7 +259,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
259
259
  this.nullifiers.push(new Nullifier(siloedNullifier, this.sideEffectCounter, /*noteHash=*/ Fr.ZERO));
260
260
  // New hinting
261
261
  const lowLeafReadHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
262
- this.avmCircuitHints.nullifierWriteHints.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
262
+ this.avmCircuitHints.nullifierWrites.items.push(new AvmNullifierWriteTreeHint(lowLeafReadHint, insertionPath));
263
263
  this.log.debug(`NEW_NULLIFIER cnt: ${this.sideEffectCounter}`);
264
264
  this.incrementSideEffectCounter();
265
265
  }
@@ -282,7 +282,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface {
282
282
  );
283
283
 
284
284
  // New Hinting
285
- this.avmCircuitHints.l1ToL2MessageReadRequest.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
285
+ this.avmCircuitHints.l1ToL2MessageReads.items.push(new AvmAppendTreeHint(msgLeafIndex, msgHash, path));
286
286
  // NOTE: counter does not increment for l1tol2 message checks (because it doesn't rely on pending messages)
287
287
  }
288
288
 
@@ -1,57 +1,28 @@
1
- import { type AvmProvingRequest, ProvingRequestType, type PublicExecutionRequest } from '@aztec/circuit-types';
2
1
  import {
3
- AvmCircuitInputs,
4
- AvmCircuitPublicInputs,
5
- AztecAddress,
6
- ContractStorageRead,
7
- ContractStorageUpdateRequest,
8
- Fr,
9
- Gas,
2
+ type AvmCircuitPublicInputs,
3
+ type Fr,
4
+ type Gas,
10
5
  type GasSettings,
11
6
  type GlobalVariables,
12
- type Header,
13
- L2ToL1Message,
14
- LogHash,
15
- MAX_ENQUEUED_CALLS_PER_CALL,
16
- MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
17
- MAX_L2_TO_L1_MSGS_PER_CALL,
18
7
  MAX_L2_TO_L1_MSGS_PER_TX,
19
- MAX_NOTE_HASHES_PER_CALL,
20
8
  MAX_NOTE_HASHES_PER_TX,
21
- MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
22
- MAX_NULLIFIERS_PER_CALL,
23
- MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
24
- MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
25
- MAX_PUBLIC_DATA_READS_PER_CALL,
26
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
27
9
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
28
- MAX_UNENCRYPTED_LOGS_PER_CALL,
29
- NoteHash,
30
- Nullifier,
31
10
  PrivateToAvmAccumulatedData,
32
11
  PrivateToAvmAccumulatedDataArrayLengths,
33
12
  type PrivateToPublicAccumulatedData,
34
13
  PublicCallRequest,
35
- PublicCircuitPublicInputs,
36
14
  PublicDataWrite,
37
- PublicInnerCallRequest,
38
- ReadRequest,
39
- RevertCode,
15
+ type RevertCode,
40
16
  type StateReference,
41
- TreeLeafReadRequest,
42
17
  TreeSnapshots,
43
18
  countAccumulatedItems,
44
19
  mergeAccumulatedData,
45
20
  } from '@aztec/circuits.js';
46
- import { computeNoteHashNonce, computeUniqueNoteHash, computeVarArgsHash, siloNoteHash } from '@aztec/circuits.js/hash';
21
+ import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/circuits.js/hash';
47
22
  import { padArrayEnd } from '@aztec/foundation/collection';
48
23
  import { assertLength } from '@aztec/foundation/serialize';
49
24
 
50
- import { AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
51
- import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
52
- import { type AvmPersistableStateManager } from '../avm/journal/journal.js';
53
25
  import { type PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
54
- import { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult } from './execution.js';
55
26
 
56
27
  export function generateAvmCircuitPublicInputs(
57
28
  trace: PublicEnqueuedCallSideEffectTrace,
@@ -64,7 +35,7 @@ export function generateAvmCircuitPublicInputs(
64
35
  teardownCallRequests: PublicCallRequest[],
65
36
  nonRevertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
66
37
  revertibleAccumulatedDataFromPrivate: PrivateToPublicAccumulatedData,
67
- endStateReference: StateReference,
38
+ endTreeSnapshots: TreeSnapshots,
68
39
  endGasUsed: Gas,
69
40
  transactionFee: Fr,
70
41
  revertCode: RevertCode,
@@ -75,12 +46,6 @@ export function generateAvmCircuitPublicInputs(
75
46
  startStateReference.partial.nullifierTree,
76
47
  startStateReference.partial.publicDataTree,
77
48
  );
78
- const endTreeSnapshots = new TreeSnapshots(
79
- endStateReference.l1ToL2MessageTree,
80
- endStateReference.partial.noteHashTree,
81
- endStateReference.partial.nullifierTree,
82
- endStateReference.partial.publicDataTree,
83
- );
84
49
 
85
50
  const avmCircuitPublicInputs = trace.toAvmCircuitPublicInputs(
86
51
  globalVariables,
@@ -182,155 +147,3 @@ export function generateAvmCircuitPublicInputs(
182
147
  //console.log(`AvmCircuitPublicInputs:\n${inspect(avmCircuitPublicInputs)}`);
183
148
  return avmCircuitPublicInputs;
184
149
  }
185
-
186
- export function generateAvmProvingRequest(
187
- real: boolean,
188
- fnName: string,
189
- stateManager: AvmPersistableStateManager,
190
- historicalHeader: Header,
191
- globalVariables: GlobalVariables,
192
- executionRequest: PublicExecutionRequest,
193
- result: EnqueuedPublicCallExecutionResult,
194
- allocatedGas: Gas,
195
- transactionFee: Fr,
196
- ): AvmProvingRequest {
197
- const avmExecutionEnv = new AvmExecutionEnvironment(
198
- executionRequest.callContext.contractAddress,
199
- executionRequest.callContext.msgSender,
200
- executionRequest.callContext.functionSelector,
201
- /*contractCallDepth=*/ Fr.zero(),
202
- transactionFee,
203
- globalVariables,
204
- executionRequest.callContext.isStaticCall,
205
- executionRequest.args,
206
- );
207
-
208
- const avmCallResult = new AvmFinalizedCallResult(result.reverted, result.returnValues, result.endGasLeft);
209
-
210
- // Generate an AVM proving request
211
- let avmProvingRequest: AvmProvingRequest;
212
- if (real) {
213
- const deprecatedFunctionCallResult = stateManager.trace.toPublicFunctionCallResult(
214
- avmExecutionEnv,
215
- /*startGasLeft=*/ allocatedGas,
216
- Buffer.alloc(0),
217
- avmCallResult,
218
- fnName,
219
- );
220
- const publicInputs = getPublicCircuitPublicInputs(historicalHeader, globalVariables, deprecatedFunctionCallResult);
221
- avmProvingRequest = makeAvmProvingRequest(publicInputs, deprecatedFunctionCallResult);
222
- } else {
223
- avmProvingRequest = emptyAvmProvingRequest();
224
- }
225
- return avmProvingRequest;
226
- }
227
-
228
- function emptyAvmProvingRequest(): AvmProvingRequest {
229
- return {
230
- type: ProvingRequestType.PUBLIC_VM,
231
- inputs: AvmCircuitInputs.empty(),
232
- };
233
- }
234
- function makeAvmProvingRequest(inputs: PublicCircuitPublicInputs, result: PublicFunctionCallResult): AvmProvingRequest {
235
- return {
236
- type: ProvingRequestType.PUBLIC_VM,
237
- inputs: new AvmCircuitInputs(
238
- result.functionName,
239
- result.calldata,
240
- inputs,
241
- result.avmCircuitHints,
242
- AvmCircuitPublicInputs.empty(),
243
- ),
244
- };
245
- }
246
-
247
- function getPublicCircuitPublicInputs(
248
- historicalHeader: Header,
249
- globalVariables: GlobalVariables,
250
- result: PublicFunctionCallResult,
251
- ) {
252
- const header = historicalHeader.clone(); // don't modify the original
253
- header.state.partial.publicDataTree.root = Fr.zero(); // AVM doesn't check this yet
254
-
255
- return PublicCircuitPublicInputs.from({
256
- callContext: result.executionRequest.callContext,
257
- proverAddress: AztecAddress.ZERO,
258
- argsHash: computeVarArgsHash(result.executionRequest.args),
259
- noteHashes: padArrayEnd(
260
- result.noteHashes,
261
- NoteHash.empty(),
262
- MAX_NOTE_HASHES_PER_CALL,
263
- `Too many note hashes. Got ${result.noteHashes.length} with max being ${MAX_NOTE_HASHES_PER_CALL}`,
264
- ),
265
- nullifiers: padArrayEnd(
266
- result.nullifiers,
267
- Nullifier.empty(),
268
- MAX_NULLIFIERS_PER_CALL,
269
- `Too many nullifiers. Got ${result.nullifiers.length} with max being ${MAX_NULLIFIERS_PER_CALL}`,
270
- ),
271
- l2ToL1Msgs: padArrayEnd(
272
- result.l2ToL1Messages,
273
- L2ToL1Message.empty(),
274
- MAX_L2_TO_L1_MSGS_PER_CALL,
275
- `Too many L2 to L1 messages. Got ${result.l2ToL1Messages.length} with max being ${MAX_L2_TO_L1_MSGS_PER_CALL}`,
276
- ),
277
- startSideEffectCounter: result.startSideEffectCounter,
278
- endSideEffectCounter: result.endSideEffectCounter,
279
- returnsHash: computeVarArgsHash(result.returnValues),
280
- noteHashReadRequests: padArrayEnd(
281
- result.noteHashReadRequests,
282
- TreeLeafReadRequest.empty(),
283
- MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
284
- `Too many note hash read requests. Got ${result.noteHashReadRequests.length} with max being ${MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}`,
285
- ),
286
- nullifierReadRequests: padArrayEnd(
287
- result.nullifierReadRequests,
288
- ReadRequest.empty(),
289
- MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
290
- `Too many nullifier read requests. Got ${result.nullifierReadRequests.length} with max being ${MAX_NULLIFIER_READ_REQUESTS_PER_CALL}`,
291
- ),
292
- nullifierNonExistentReadRequests: padArrayEnd(
293
- result.nullifierNonExistentReadRequests,
294
- ReadRequest.empty(),
295
- MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
296
- `Too many nullifier non-existent read requests. Got ${result.nullifierNonExistentReadRequests.length} with max being ${MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL}`,
297
- ),
298
- l1ToL2MsgReadRequests: padArrayEnd(
299
- result.l1ToL2MsgReadRequests,
300
- TreeLeafReadRequest.empty(),
301
- MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
302
- `Too many L1 to L2 message read requests. Got ${result.l1ToL2MsgReadRequests.length} with max being ${MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL}`,
303
- ),
304
- contractStorageReads: padArrayEnd(
305
- result.contractStorageReads,
306
- ContractStorageRead.empty(),
307
- MAX_PUBLIC_DATA_READS_PER_CALL,
308
- `Too many public data reads. Got ${result.contractStorageReads.length} with max being ${MAX_PUBLIC_DATA_READS_PER_CALL}`,
309
- ),
310
- contractStorageUpdateRequests: padArrayEnd(
311
- result.contractStorageUpdateRequests,
312
- ContractStorageUpdateRequest.empty(),
313
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
314
- `Too many public data update requests. Got ${result.contractStorageUpdateRequests.length} with max being ${MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL}`,
315
- ),
316
- publicCallRequests: padArrayEnd(
317
- result.publicCallRequests,
318
- PublicInnerCallRequest.empty(),
319
- MAX_ENQUEUED_CALLS_PER_CALL,
320
- `Too many public call requests. Got ${result.publicCallRequests.length} with max being ${MAX_ENQUEUED_CALLS_PER_CALL}`,
321
- ),
322
- unencryptedLogsHashes: padArrayEnd(
323
- result.unencryptedLogsHashes,
324
- LogHash.empty(),
325
- MAX_UNENCRYPTED_LOGS_PER_CALL,
326
- `Too many unencrypted logs. Got ${result.unencryptedLogsHashes.length} with max being ${MAX_UNENCRYPTED_LOGS_PER_CALL}`,
327
- ),
328
- historicalHeader: header,
329
- globalVariables: globalVariables,
330
- startGasLeft: Gas.from(result.startGasLeft),
331
- endGasLeft: Gas.from(result.endGasLeft),
332
- transactionFee: result.transactionFee,
333
- // TODO(@just-mitch): need better mapping from simulator to revert code.
334
- revertCode: result.reverted ? RevertCode.APP_LOGIC_REVERTED : RevertCode.OK,
335
- });
336
- }