@aztec/simulator 0.82.3 → 0.83.1-alpha-testnet.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 (93) hide show
  1. package/dest/private/acvm/oracle/oracle.d.ts +2 -1
  2. package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/private/acvm/oracle/oracle.js +8 -3
  4. package/dest/private/acvm/oracle/typed_oracle.d.ts +4 -3
  5. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/private/acvm/oracle/typed_oracle.js +4 -1
  7. package/dest/private/execution_data_provider.d.ts +20 -16
  8. package/dest/private/execution_data_provider.d.ts.map +1 -1
  9. package/dest/private/private_execution_oracle.d.ts +1 -1
  10. package/dest/private/private_execution_oracle.d.ts.map +1 -1
  11. package/dest/private/private_execution_oracle.js +2 -6
  12. package/dest/private/unconstrained_execution_oracle.d.ts +4 -2
  13. package/dest/private/unconstrained_execution_oracle.d.ts.map +1 -1
  14. package/dest/private/unconstrained_execution_oracle.js +5 -6
  15. package/dest/public/avm/avm_context.d.ts +3 -3
  16. package/dest/public/avm/avm_context.d.ts.map +1 -1
  17. package/dest/public/avm/avm_simulator.d.ts +2 -2
  18. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  19. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +2 -2
  20. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  21. package/dest/public/avm/fixtures/avm_simulation_tester.js +2 -2
  22. package/dest/public/avm/fixtures/index.d.ts +5 -5
  23. package/dest/public/avm/fixtures/index.d.ts.map +1 -1
  24. package/dest/public/avm/fixtures/index.js +2 -2
  25. package/dest/public/avm/index.d.ts +0 -1
  26. package/dest/public/avm/index.d.ts.map +1 -1
  27. package/dest/public/avm/index.js +0 -1
  28. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  29. package/dest/public/avm/opcodes/accrued_substate.js +1 -1
  30. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  31. package/dest/public/avm/serialization/instruction_serialization.js +3 -5
  32. package/dest/public/avm/test_utils.d.ts +1 -1
  33. package/dest/public/avm/test_utils.d.ts.map +1 -1
  34. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  35. package/dest/public/hinting_db_sources.js +37 -5
  36. package/dest/public/public_db_sources.js +1 -1
  37. package/dest/public/public_processor/public_processor.d.ts +3 -3
  38. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  39. package/dest/public/public_processor/public_processor.js +4 -25
  40. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts +2 -2
  41. package/dest/public/public_tx_simulator/measured_public_tx_simulator.d.ts.map +1 -1
  42. package/dest/public/public_tx_simulator/public_tx_context.d.ts +3 -3
  43. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  44. package/dest/public/public_tx_simulator/public_tx_context.js +2 -2
  45. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +2 -2
  46. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  47. package/dest/public/public_tx_simulator/public_tx_simulator.js +1 -1
  48. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts +2 -2
  49. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.d.ts.map +1 -1
  50. package/dest/public/state_manager/index.d.ts +2 -0
  51. package/dest/public/state_manager/index.d.ts.map +1 -0
  52. package/dest/public/state_manager/index.js +1 -0
  53. package/dest/public/{avm/journal → state_manager}/nullifiers.d.ts +1 -1
  54. package/dest/public/state_manager/nullifiers.d.ts.map +1 -0
  55. package/dest/public/{avm/journal → state_manager}/public_storage.d.ts +1 -1
  56. package/dest/public/state_manager/public_storage.d.ts.map +1 -0
  57. package/dest/public/{avm/journal/journal.d.ts → state_manager/state_manager.d.ts} +10 -10
  58. package/dest/public/state_manager/state_manager.d.ts.map +1 -0
  59. package/dest/public/{avm/journal/journal.js → state_manager/state_manager.js} +5 -5
  60. package/package.json +14 -14
  61. package/src/private/acvm/oracle/oracle.ts +24 -3
  62. package/src/private/acvm/oracle/typed_oracle.ts +14 -3
  63. package/src/private/execution_data_provider.ts +34 -18
  64. package/src/private/private_execution_oracle.ts +2 -13
  65. package/src/private/unconstrained_execution_oracle.ts +22 -15
  66. package/src/public/avm/avm_context.ts +2 -2
  67. package/src/public/avm/avm_simulator.ts +2 -2
  68. package/src/public/avm/fixtures/avm_simulation_tester.ts +3 -3
  69. package/src/public/avm/fixtures/index.ts +6 -6
  70. package/src/public/avm/index.ts +0 -1
  71. package/src/public/avm/opcodes/accrued_substate.ts +1 -1
  72. package/src/public/avm/serialization/instruction_serialization.ts +3 -5
  73. package/src/public/avm/test_utils.ts +1 -1
  74. package/src/public/hinting_db_sources.ts +59 -15
  75. package/src/public/public_db_sources.ts +1 -1
  76. package/src/public/public_processor/public_processor.ts +4 -24
  77. package/src/public/public_tx_simulator/measured_public_tx_simulator.ts +2 -2
  78. package/src/public/public_tx_simulator/public_tx_context.ts +4 -4
  79. package/src/public/public_tx_simulator/public_tx_simulator.ts +4 -3
  80. package/src/public/public_tx_simulator/telemetry_public_tx_simulator.ts +2 -2
  81. package/src/public/state_manager/index.ts +1 -0
  82. package/src/public/{avm/journal → state_manager}/nullifiers.ts +1 -1
  83. package/src/public/{avm/journal → state_manager}/public_storage.ts +1 -1
  84. package/src/public/{avm/journal/journal.ts → state_manager/state_manager.ts} +20 -13
  85. package/dest/public/avm/journal/index.d.ts +0 -2
  86. package/dest/public/avm/journal/index.d.ts.map +0 -1
  87. package/dest/public/avm/journal/index.js +0 -1
  88. package/dest/public/avm/journal/journal.d.ts.map +0 -1
  89. package/dest/public/avm/journal/nullifiers.d.ts.map +0 -1
  90. package/dest/public/avm/journal/public_storage.d.ts.map +0 -1
  91. package/src/public/avm/journal/index.ts +0 -1
  92. /package/dest/public/{avm/journal → state_manager}/nullifiers.js +0 -0
  93. /package/dest/public/{avm/journal → state_manager}/public_storage.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.82.3",
3
+ "version": "0.83.1-alpha-testnet.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -60,16 +60,16 @@
60
60
  ]
61
61
  },
62
62
  "dependencies": {
63
- "@aztec/constants": "0.82.3",
64
- "@aztec/foundation": "0.82.3",
65
- "@aztec/noir-acvm_js": "0.82.3",
66
- "@aztec/noir-noirc_abi": "0.82.3",
67
- "@aztec/noir-protocol-circuits-types": "0.82.3",
68
- "@aztec/noir-types": "0.82.3",
69
- "@aztec/protocol-contracts": "0.82.3",
70
- "@aztec/stdlib": "0.82.3",
71
- "@aztec/telemetry-client": "0.82.3",
72
- "@aztec/world-state": "0.82.3",
63
+ "@aztec/constants": "0.83.1-alpha-testnet.0",
64
+ "@aztec/foundation": "0.83.1-alpha-testnet.0",
65
+ "@aztec/noir-acvm_js": "0.83.1-alpha-testnet.0",
66
+ "@aztec/noir-noirc_abi": "0.83.1-alpha-testnet.0",
67
+ "@aztec/noir-protocol-circuits-types": "0.83.1-alpha-testnet.0",
68
+ "@aztec/noir-types": "0.83.1-alpha-testnet.0",
69
+ "@aztec/protocol-contracts": "0.83.1-alpha-testnet.0",
70
+ "@aztec/stdlib": "0.83.1-alpha-testnet.0",
71
+ "@aztec/telemetry-client": "0.83.1-alpha-testnet.0",
72
+ "@aztec/world-state": "0.83.1-alpha-testnet.0",
73
73
  "levelup": "^5.1.1",
74
74
  "lodash.clonedeep": "^4.5.0",
75
75
  "lodash.merge": "^4.6.2",
@@ -77,9 +77,9 @@
77
77
  "tslib": "^2.4.0"
78
78
  },
79
79
  "devDependencies": {
80
- "@aztec/kv-store": "0.82.3",
81
- "@aztec/merkle-tree": "0.82.3",
82
- "@aztec/noir-contracts.js": "0.82.3",
80
+ "@aztec/kv-store": "0.83.1-alpha-testnet.0",
81
+ "@aztec/merkle-tree": "0.83.1-alpha-testnet.0",
82
+ "@aztec/noir-contracts.js": "0.83.1-alpha-testnet.0",
83
83
  "@jest/globals": "^29.5.0",
84
84
  "@types/jest": "^29.5.0",
85
85
  "@types/levelup": "^5.1.3",
@@ -1,8 +1,9 @@
1
1
  import { Fr, Point } from '@aztec/foundation/fields';
2
- import { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
2
+ import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
3
3
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
4
4
  import { ContractClassLog, LogWithTxData } from '@aztec/stdlib/logs';
5
5
  import { MerkleTreeId } from '@aztec/stdlib/trees';
6
+ import { TxHash } from '@aztec/stdlib/tx';
6
7
 
7
8
  import type { ACVMField } from '../acvm_types.js';
8
9
  import { fromBoundedVec, fromUintArray, fromUintBoundedVec } from '../deserialize.js';
@@ -371,8 +372,8 @@ export class Oracle {
371
372
  return [];
372
373
  }
373
374
 
374
- async syncNotes(): Promise<ACVMField[]> {
375
- await this.typedOracle.syncNotes();
375
+ async syncNotes([pendingTaggedLogArrayBaseSlot]: ACVMField[]): Promise<ACVMField[]> {
376
+ await this.typedOracle.syncNotes(Fr.fromString(pendingTaggedLogArrayBaseSlot));
376
377
  return [];
377
378
  }
378
379
 
@@ -490,4 +491,24 @@ export class Oracle {
490
491
  );
491
492
  return secret.toFields().map(toACVMField);
492
493
  }
494
+
495
+ async storePrivateEventLog(
496
+ [contractAddress]: ACVMField[],
497
+ [recipient]: ACVMField[],
498
+ [eventSelector]: ACVMField[],
499
+ logContentBVecStorage: ACVMField[],
500
+ [logContentLength]: ACVMField[],
501
+ [txHash]: ACVMField[],
502
+ [logIndexInTx]: ACVMField[],
503
+ ) {
504
+ await this.typedOracle.storePrivateEventLog(
505
+ AztecAddress.fromField(Fr.fromString(contractAddress)),
506
+ AztecAddress.fromField(Fr.fromString(recipient)),
507
+ EventSelector.fromField(Fr.fromString(eventSelector)),
508
+ fromBoundedVec(logContentBVecStorage, logContentLength),
509
+ new TxHash(Fr.fromString(txHash)),
510
+ Fr.fromString(logIndexInTx).toNumber(),
511
+ );
512
+ return [];
513
+ }
493
514
  }
@@ -1,13 +1,13 @@
1
1
  import type { L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/constants';
2
2
  import { Fr, Point } from '@aztec/foundation/fields';
3
- import type { FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
3
+ import type { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
4
4
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
5
  import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
6
6
  import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
7
7
  import type { ContractClassLog, IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
8
8
  import type { Note, NoteStatus } from '@aztec/stdlib/note';
9
9
  import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
10
- import type { BlockHeader } from '@aztec/stdlib/tx';
10
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
11
11
 
12
12
  import type { MessageLoadOracleInputs } from '../../../common/message_load_oracle_inputs.js';
13
13
 
@@ -214,7 +214,7 @@ export abstract class TypedOracle {
214
214
  return Promise.reject(new OracleMethodNotAvailableError('incrementAppTaggingSecretIndexAsSender'));
215
215
  }
216
216
 
217
- syncNotes(): Promise<void> {
217
+ syncNotes(_pendingTaggedLogArrayBaseSlot: Fr): Promise<void> {
218
218
  return Promise.reject(new OracleMethodNotAvailableError('syncNotes'));
219
219
  }
220
220
 
@@ -258,4 +258,15 @@ export abstract class TypedOracle {
258
258
  getSharedSecret(_address: AztecAddress, _ephPk: Point): Promise<Point> {
259
259
  return Promise.reject(new OracleMethodNotAvailableError('getSharedSecret'));
260
260
  }
261
+
262
+ storePrivateEventLog(
263
+ _contractAddress: AztecAddress,
264
+ _recipient: AztecAddress,
265
+ _eventSelector: EventSelector,
266
+ _logContent: Fr[],
267
+ _txHash: TxHash,
268
+ _logIndexInTx: number,
269
+ ): Promise<void> {
270
+ return Promise.reject(new OracleMethodNotAvailableError('storePrivateEventLog'));
271
+ }
261
272
  }
@@ -1,13 +1,18 @@
1
1
  import type { Fr, Point } from '@aztec/foundation/fields';
2
- import type { FunctionArtifact, FunctionArtifactWithContractName, FunctionSelector } from '@aztec/stdlib/abi';
2
+ import type {
3
+ EventSelector,
4
+ FunctionArtifact,
5
+ FunctionArtifactWithContractName,
6
+ FunctionSelector,
7
+ } from '@aztec/stdlib/abi';
3
8
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
9
  import type { L2Block } from '@aztec/stdlib/block';
5
10
  import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
6
11
  import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
7
- import { IndexedTaggingSecret, LogWithTxData, TxScopedL2Log } from '@aztec/stdlib/logs';
12
+ import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
8
13
  import type { NoteStatus } from '@aztec/stdlib/note';
9
14
  import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
10
- import type { BlockHeader } from '@aztec/stdlib/tx';
15
+ import type { BlockHeader, TxHash } from '@aztec/stdlib/tx';
11
16
 
12
17
  import type { CommitmentsDBInterface } from '../common/db_interfaces.js';
13
18
  import type { NoteData } from './acvm/index.js';
@@ -221,25 +226,18 @@ export interface ExecutionDataProvider extends CommitmentsDBInterface {
221
226
  ): Promise<void>;
222
227
 
223
228
  /**
224
- * Synchronizes the logs tagged with the recipient's address and all the senders in the address book.
225
- * Returns the unsynched logs and updates the indexes of the secrets used to tag them until there are no more logs to sync.
226
- * @param contractAddress - The address of the contract that the logs are tagged for
227
- * @param recipient - The address of the recipient
228
- * @returns A list of encrypted logs tagged with the recipient's address
229
+ * Synchronizes the logs tagged with scoped addresses and all the senders in the address book. Stores the found logs
230
+ * in CapsuleArray ready for a later retrieval in Aztec.nr.
231
+ * @param contractAddress - The address of the contract that the logs are tagged for.
232
+ * @param pendingTaggedLogArrayBaseSlot - The base slot of the pending tagged log capsule array in which found logs will be stored.
233
+ * @param scopes - The scoped addresses to sync logs for. If not provided, all accounts in the address book will be
234
+ * synced.
229
235
  */
230
236
  syncTaggedLogs(
231
237
  contractAddress: AztecAddress,
232
- maxBlockNumber: number,
238
+ pendingTaggedLogArrayBaseSlot: Fr,
233
239
  scopes?: AztecAddress[],
234
- ): Promise<Map<string, TxScopedL2Log[]>>;
235
-
236
- /**
237
- * Processes the tagged logs returned by syncTaggedLogs by decrypting them and storing them in the database.
238
- * @param contractAddress - The address of the contract that emitted the logs.
239
- * @param logs - The logs to process.
240
- * @param recipient - The recipient of the logs.
241
- */
242
- processTaggedLogs(contractAddress: AztecAddress, logs: TxScopedL2Log[], recipient: AztecAddress): Promise<void>;
240
+ ): Promise<void>;
243
241
 
244
242
  /**
245
243
  * Delivers the preimage and metadata of a committed note so that it can be later requested via the `getNotes`
@@ -325,4 +323,22 @@ export interface ExecutionDataProvider extends CommitmentsDBInterface {
325
323
  * @returns The secret for the given address.
326
324
  */
327
325
  getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point>;
326
+
327
+ /**
328
+ * Stores an event log in the database.
329
+ * @param contractAddress - The address of the contract that emitted the log.
330
+ * @param recipient - The address of the recipient.
331
+ * @param eventSelector - The event selector of the event.
332
+ * @param logContent - The content of the private event log.
333
+ * @param txHash - The hash of the transaction that emitted the log.
334
+ * @param logIndexInTx - The index of the log within the transaction.
335
+ */
336
+ storePrivateEventLog(
337
+ contractAddress: AztecAddress,
338
+ recipient: AztecAddress,
339
+ eventSelector: EventSelector,
340
+ logContent: Fr[],
341
+ txHash: TxHash,
342
+ logIndexInTx: number,
343
+ ): Promise<void>;
328
344
  }
@@ -500,19 +500,8 @@ export class PrivateExecutionOracle extends UnconstrainedExecutionOracle {
500
500
  await this.executionDataProvider.incrementAppTaggingSecretIndexAsSender(this.contractAddress, sender, recipient);
501
501
  }
502
502
 
503
- public override async syncNotes() {
504
- const taggedLogsByRecipient = await this.executionDataProvider.syncTaggedLogs(
505
- this.contractAddress,
506
- this.historicalHeader.globalVariables.blockNumber.toNumber(),
507
- this.scopes,
508
- );
509
- for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
510
- await this.executionDataProvider.processTaggedLogs(
511
- this.contractAddress,
512
- taggedLogs,
513
- AztecAddress.fromString(recipient),
514
- );
515
- }
503
+ public override async syncNotes(pendingTaggedLogArrayBaseSlot: Fr) {
504
+ await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
516
505
 
517
506
  await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
518
507
  }
@@ -1,6 +1,7 @@
1
1
  import { Aes128 } from '@aztec/foundation/crypto';
2
2
  import { Fr, Point } from '@aztec/foundation/fields';
3
3
  import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
4
+ import type { EventSelector } from '@aztec/stdlib/abi';
4
5
  import type { AuthWitness } from '@aztec/stdlib/auth-witness';
5
6
  import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
7
  import type { CompleteAddress, ContractInstance } from '@aztec/stdlib/contract';
@@ -9,7 +10,7 @@ import type { KeyValidationRequest } from '@aztec/stdlib/kernel';
9
10
  import { IndexedTaggingSecret, LogWithTxData } from '@aztec/stdlib/logs';
10
11
  import type { NoteStatus } from '@aztec/stdlib/note';
11
12
  import { type MerkleTreeId, type NullifierMembershipWitness, PublicDataWitness } from '@aztec/stdlib/trees';
12
- import type { BlockHeader, Capsule } from '@aztec/stdlib/tx';
13
+ import type { BlockHeader, Capsule, TxHash } from '@aztec/stdlib/tx';
13
14
 
14
15
  import { type NoteData, TypedOracle } from './acvm/index.js';
15
16
  import type { ExecutionDataProvider } from './execution_data_provider.js';
@@ -277,20 +278,8 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
277
278
  return await this.executionDataProvider.getIndexedTaggingSecretAsSender(this.contractAddress, sender, recipient);
278
279
  }
279
280
 
280
- public override async syncNotes() {
281
- const taggedLogsByRecipient = await this.executionDataProvider.syncTaggedLogs(
282
- this.contractAddress,
283
- await this.executionDataProvider.getBlockNumber(),
284
- this.scopes,
285
- );
286
-
287
- for (const [recipient, taggedLogs] of taggedLogsByRecipient.entries()) {
288
- await this.executionDataProvider.processTaggedLogs(
289
- this.contractAddress,
290
- taggedLogs,
291
- AztecAddress.fromString(recipient),
292
- );
293
- }
281
+ public override async syncNotes(pendingTaggedLogArrayBaseSlot: Fr) {
282
+ await this.executionDataProvider.syncTaggedLogs(this.contractAddress, pendingTaggedLogArrayBaseSlot, this.scopes);
294
283
 
295
284
  await this.executionDataProvider.removeNullifiedNotes(this.contractAddress);
296
285
  }
@@ -376,4 +365,22 @@ export class UnconstrainedExecutionOracle extends TypedOracle {
376
365
  public override getSharedSecret(address: AztecAddress, ephPk: Point): Promise<Point> {
377
366
  return this.executionDataProvider.getSharedSecret(address, ephPk);
378
367
  }
368
+
369
+ public override storePrivateEventLog(
370
+ contractAddress: AztecAddress,
371
+ recipient: AztecAddress,
372
+ eventSelector: EventSelector,
373
+ logContent: Fr[],
374
+ txHash: TxHash,
375
+ logIndexInTx: number,
376
+ ): Promise<void> {
377
+ return this.executionDataProvider.storePrivateEventLog(
378
+ contractAddress,
379
+ recipient,
380
+ eventSelector,
381
+ logContent,
382
+ txHash,
383
+ logIndexInTx,
384
+ );
385
+ }
379
386
  }
@@ -1,11 +1,11 @@
1
1
  import type { Fr } from '@aztec/foundation/fields';
2
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
3
3
 
4
+ import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
4
5
  import type { AvmExecutionEnvironment } from './avm_execution_environment.js';
5
6
  import { type Gas, gasToGasLeft } from './avm_gas.js';
6
7
  import { AvmMachineState } from './avm_machine_state.js';
7
8
  import type { AvmSimulator } from './avm_simulator.js';
8
- import type { AvmPersistableStateManager } from './journal/journal.js';
9
9
 
10
10
  /**
11
11
  * An execution context includes the information necessary to initiate AVM
@@ -20,7 +20,7 @@ export class AvmContext {
20
20
  * @returns new AvmContext instance
21
21
  */
22
22
  constructor(
23
- public persistableState: AvmPersistableStateManager,
23
+ public persistableState: PublicPersistableStateManager,
24
24
  public environment: AvmExecutionEnvironment,
25
25
  public machineState: AvmMachineState,
26
26
  ) {}
@@ -7,6 +7,7 @@ import type { GlobalVariables } from '@aztec/stdlib/tx';
7
7
  import { strict as assert } from 'assert';
8
8
 
9
9
  import { SideEffectLimitReachedError } from '../side_effect_errors.js';
10
+ import type { PublicPersistableStateManager } from '../state_manager/state_manager.js';
10
11
  import { AvmContext } from './avm_context.js';
11
12
  import { AvmContractCallResult } from './avm_contract_call_result.js';
12
13
  import { AvmExecutionEnvironment } from './avm_execution_environment.js';
@@ -19,7 +20,6 @@ import {
19
20
  revertReasonFromExceptionalHalt,
20
21
  revertReasonFromExplicitRevert,
21
22
  } from './errors.js';
22
- import type { AvmPersistableStateManager } from './journal/journal.js';
23
23
  import type { Instruction } from './opcodes/instruction.js';
24
24
  import {
25
25
  INSTRUCTION_SET,
@@ -75,7 +75,7 @@ export class AvmSimulator {
75
75
  }
76
76
 
77
77
  public static async create(
78
- stateManager: AvmPersistableStateManager,
78
+ stateManager: PublicPersistableStateManager,
79
79
  address: AztecAddress,
80
80
  sender: AztecAddress,
81
81
  transactionFee: Fr,
@@ -16,8 +16,8 @@ import {
16
16
  initExecutionEnvironment,
17
17
  resolveContractAssertionMessage,
18
18
  } from '../../avm/fixtures/index.js';
19
- import { AvmPersistableStateManager } from '../../avm/journal/journal.js';
20
19
  import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
20
+ import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
21
21
  import { AvmSimulator } from '../avm_simulator.js';
22
22
  import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
23
23
  import { SimpleContractDataSource } from './simple_contract_data_source.js';
@@ -34,7 +34,7 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
34
34
  constructor(
35
35
  contractDataSource: SimpleContractDataSource,
36
36
  merkleTrees: MerkleTreeWriteOperations,
37
- private stateManager: AvmPersistableStateManager,
37
+ private stateManager: PublicPersistableStateManager,
38
38
  ) {
39
39
  super(contractDataSource, merkleTrees);
40
40
  }
@@ -47,7 +47,7 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
47
47
  const trace = new SideEffectTrace();
48
48
  const firstNullifier = new Fr(420000);
49
49
 
50
- const stateManager = AvmPersistableStateManager.create(
50
+ const stateManager = PublicPersistableStateManager.create(
51
51
  treesDB,
52
52
  contractsDB,
53
53
  trace,
@@ -30,15 +30,15 @@ import merge from 'lodash.merge';
30
30
  import { resolveAssertionMessageFromRevertData, traverseCauseChain } from '../../../common/index.js';
31
31
  import type { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
32
32
  import type { PublicSideEffectTraceInterface } from '../../side_effect_trace_interface.js';
33
+ import { NullifierManager } from '../../state_manager/nullifiers.js';
34
+ import { PublicStorage } from '../../state_manager/public_storage.js';
35
+ import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
33
36
  import { AvmContext } from '../avm_context.js';
34
37
  import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
35
38
  import { AvmMachineState } from '../avm_machine_state.js';
36
39
  import { Field, Uint8, Uint32, Uint64 } from '../avm_memory_types.js';
37
40
  import { AvmSimulator } from '../avm_simulator.js';
38
41
  import type { AvmRevertReason } from '../errors.js';
39
- import { AvmPersistableStateManager } from '../journal/journal.js';
40
- import { NullifierManager } from '../journal/nullifiers.js';
41
- import { PublicStorage } from '../journal/public_storage.js';
42
42
 
43
43
  export const PUBLIC_DISPATCH_FN_NAME = 'public_dispatch';
44
44
  export const DEFAULT_BLOCK_NUMBER = 42;
@@ -47,7 +47,7 @@ export const DEFAULT_BLOCK_NUMBER = 42;
47
47
  * Create a new AVM context with default values.
48
48
  */
49
49
  export function initContext(overrides?: {
50
- persistableState?: AvmPersistableStateManager;
50
+ persistableState?: PublicPersistableStateManager;
51
51
  env?: AvmExecutionEnvironment;
52
52
  machineState?: AvmMachineState;
53
53
  }): AvmContext {
@@ -70,9 +70,9 @@ export function initPersistableStateManager(overrides?: {
70
70
  doMerkleOperations?: boolean;
71
71
  firstNullifier?: Fr;
72
72
  blockNumber?: number;
73
- }): AvmPersistableStateManager {
73
+ }): PublicPersistableStateManager {
74
74
  const treesDB = overrides?.treesDB || mock<PublicTreesDB>();
75
- return new AvmPersistableStateManager(
75
+ return new PublicPersistableStateManager(
76
76
  treesDB,
77
77
  overrides?.contractsDB || mock<PublicContractsDB>(),
78
78
  overrides?.trace || mock<PublicSideEffectTraceInterface>(),
@@ -1,3 +1,2 @@
1
1
  export * from './avm_simulator.js';
2
- export * from './journal/index.js';
3
2
  export * from './fixtures/simple_contract_data_source.js';
@@ -1,7 +1,7 @@
1
+ import { NullifierCollisionError } from '../../state_manager/nullifiers.js';
1
2
  import type { AvmContext } from '../avm_context.js';
2
3
  import { TypeTag, Uint1 } from '../avm_memory_types.js';
3
4
  import { InstructionExecutionError, StaticCallAlterationError } from '../errors.js';
4
- import { NullifierCollisionError } from '../journal/nullifiers.js';
5
5
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
6
  import { Addressing } from './addressing_mode.js';
7
7
  import { Instruction } from './instruction.js';
@@ -93,10 +93,8 @@ export const MAX_OPCODE_VALUE = Math.max(
93
93
  .filter(k => !isNaN(k)),
94
94
  );
95
95
 
96
- // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
97
- // See vm/avm_trace/deserialization.cpp)
98
- // Note that cpp code introduced an additional enum value TAG to express the instruction tag. In TS,
99
- // this one is parsed as UINT8.
96
+ // Possible types for an instruction's operand in its wire format.
97
+ // The counterpart cpp file is: vm2/simulation/lib/serialization.hpp.
100
98
  export enum OperandType {
101
99
  UINT8,
102
100
  UINT16,
@@ -186,7 +184,7 @@ export function deserialize(cursor: BufferCursor | Buffer, operands: OperandType
186
184
  if (operands[i] === OperandType.TAG) {
187
185
  // We parsed a single byte (readUInt8()) and therefore value is of number type (not bigint)
188
186
  // We need to cast to number because checkIsValidTag expects a number.
189
- TaggedMemory.checkIsValidTag(Number(argValues[i]) ?? 0);
187
+ TaggedMemory.checkIsValidTag(Number(argValues[i] ?? 0));
190
188
  }
191
189
  }
192
190
 
@@ -4,7 +4,7 @@ import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/st
4
4
  import type { jest } from '@jest/globals';
5
5
  import { mock } from 'jest-mock-extended';
6
6
 
7
- import type { PublicContractsDB, PublicTreesDB } from '../../public/public_db_sources.js';
7
+ import type { PublicContractsDB, PublicTreesDB } from '../public_db_sources.js';
8
8
  import type { PublicSideEffectTraceInterface } from '../side_effect_trace_interface.js';
9
9
 
10
10
  export function mockTraceFork(trace: PublicSideEffectTraceInterface, nestedTrace?: PublicSideEffectTraceInterface) {
@@ -12,6 +12,8 @@ import {
12
12
  AvmGetLeafValueHint,
13
13
  AvmGetPreviousValueIndexHint,
14
14
  AvmGetSiblingPathHint,
15
+ AvmSequentialInsertHintNullifierTree,
16
+ AvmSequentialInsertHintPublicDataTree,
15
17
  } from '@aztec/stdlib/avm';
16
18
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
17
19
  import type { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
@@ -21,7 +23,9 @@ import {
21
23
  MerkleTreeId,
22
24
  type MerkleTreeLeafType,
23
25
  NullifierLeaf,
26
+ NullifierLeafPreimage,
24
27
  PublicDataTreeLeaf,
28
+ PublicDataTreeLeafPreimage,
25
29
  type SequentialInsertionResult,
26
30
  getTreeName,
27
31
  } from '@aztec/stdlib/trees';
@@ -144,24 +148,12 @@ export class HintingPublicTreesDB extends PublicTreesDB {
144
148
  switch (treeId) {
145
149
  case MerkleTreeId.PUBLIC_DATA_TREE:
146
150
  this.hints.getLeafPreimageHintsPublicDataTree.push(
147
- new AvmGetLeafPreimageHintPublicDataTree(
148
- key,
149
- index,
150
- preimage.asLeaf() as PublicDataTreeLeaf,
151
- preimage.getNextIndex(),
152
- new Fr(preimage.getNextKey()),
153
- ),
151
+ new AvmGetLeafPreimageHintPublicDataTree(key, index, preimage as PublicDataTreeLeafPreimage),
154
152
  );
155
153
  break;
156
154
  case MerkleTreeId.NULLIFIER_TREE:
157
155
  this.hints.getLeafPreimageHintsNullifierTree.push(
158
- new AvmGetLeafPreimageHintNullifierTree(
159
- key,
160
- index,
161
- preimage.asLeaf() as NullifierLeaf,
162
- preimage.getNextIndex(),
163
- new Fr(preimage.getNextKey()),
164
- ),
156
+ new AvmGetLeafPreimageHintNullifierTree(key, index, preimage as NullifierLeafPreimage),
165
157
  );
166
158
  break;
167
159
  default:
@@ -192,11 +184,17 @@ export class HintingPublicTreesDB extends PublicTreesDB {
192
184
  }
193
185
 
194
186
  // State modification.
187
+ // FIXME(fcarreiro): This is a horrible interface (in the merkle ops). It's receiving the leaves as buffers,
188
+ // from a leaf class that is NOT the one that will be used to write. Make this type safe.
195
189
  public override async sequentialInsert<TreeHeight extends number, ID extends IndexedTreeId>(
196
190
  treeId: ID,
197
191
  leaves: Buffer[],
198
192
  ): Promise<SequentialInsertionResult<TreeHeight>> {
199
- HintingPublicTreesDB.log.debug('sequentialInsert not hinted yet!');
193
+ // Use appendLeaf for NoteHashTree and L1ToL2MessageTree.
194
+ assert(treeId == MerkleTreeId.PUBLIC_DATA_TREE || treeId == MerkleTreeId.NULLIFIER_TREE);
195
+ // We only support 1 leaf at a time for now. Can easily be extended.
196
+ assert(leaves.length === 1, 'sequentialInsert supports only one leaf at a time!');
197
+
200
198
  const beforeState = await this.getHintKey(treeId);
201
199
 
202
200
  const result = await super.sequentialInsert<TreeHeight, ID>(treeId, leaves);
@@ -208,6 +206,52 @@ export class HintingPublicTreesDB extends PublicTreesDB {
208
206
  }, ${afterState.nextAvailableLeafIndex}.`,
209
207
  );
210
208
 
209
+ switch (treeId) {
210
+ case MerkleTreeId.PUBLIC_DATA_TREE:
211
+ this.hints.sequentialInsertHintsPublicDataTree.push(
212
+ new AvmSequentialInsertHintPublicDataTree(
213
+ beforeState,
214
+ afterState,
215
+ treeId,
216
+ PublicDataTreeLeaf.fromBuffer(leaves[0]),
217
+ {
218
+ leaf: result.lowLeavesWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
219
+ index: result.lowLeavesWitnessData[0].index,
220
+ path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
221
+ },
222
+ {
223
+ leaf: result.insertionWitnessData[0].leafPreimage as PublicDataTreeLeafPreimage,
224
+ index: result.insertionWitnessData[0].index,
225
+ path: result.insertionWitnessData[0].siblingPath.toFields(),
226
+ },
227
+ ),
228
+ );
229
+ break;
230
+ case MerkleTreeId.NULLIFIER_TREE:
231
+ this.hints.sequentialInsertHintsNullifierTree.push(
232
+ new AvmSequentialInsertHintNullifierTree(
233
+ beforeState,
234
+ afterState,
235
+ treeId,
236
+ NullifierLeaf.fromBuffer(leaves[0]),
237
+ {
238
+ leaf: result.lowLeavesWitnessData[0].leafPreimage as NullifierLeafPreimage,
239
+ index: result.lowLeavesWitnessData[0].index,
240
+ path: result.lowLeavesWitnessData[0].siblingPath.toFields(),
241
+ },
242
+ {
243
+ leaf: result.insertionWitnessData[0].leafPreimage as NullifierLeafPreimage,
244
+ index: result.insertionWitnessData[0].index,
245
+ path: result.insertionWitnessData[0].siblingPath.toFields(),
246
+ },
247
+ ),
248
+ );
249
+ break;
250
+ default:
251
+ throw new Error('sequentialInsert only supported for PublicDataTree and NullifierTree!');
252
+ break;
253
+ }
254
+
211
255
  return result;
212
256
  }
213
257
 
@@ -418,7 +418,7 @@ export class PublicTreesDB extends ForwardMerkleTree implements PublicStateDBInt
418
418
  lowLeafResult.index,
419
419
  )) as PublicDataTreeLeafPreimage;
420
420
 
421
- return lowLeafResult.alreadyPresent ? preimage.value : Fr.ZERO;
421
+ return lowLeafResult.alreadyPresent ? preimage.leaf.value : Fr.ZERO;
422
422
  }
423
423
 
424
424
  /**
@@ -131,7 +131,8 @@ export class PublicProcessor implements Traceable {
131
131
  /**
132
132
  * Run each tx through the public circuit and the public kernel circuit if needed.
133
133
  * @param txs - Txs to process.
134
- * @param processedTxHandler - Handler for processed txs in the context of block building or proving.
134
+ * @param limits - Limits for processing the txs.
135
+ * @param validator - Pre-process validator and nullifier cache to use for processing the txs.
135
136
  * @returns The list of processed txs with their circuit simulation outputs.
136
137
  */
137
138
  public async process(
@@ -142,14 +143,13 @@ export class PublicProcessor implements Traceable {
142
143
  maxBlockGas?: Gas;
143
144
  deadline?: Date;
144
145
  } = {},
145
- validators: {
146
+ validator: {
146
147
  preprocessValidator?: TxValidator<Tx>;
147
- postprocessValidator?: TxValidator<ProcessedTx>;
148
148
  nullifierCache?: { addNullifiers: (nullifiers: Buffer[]) => void };
149
149
  } = {},
150
150
  ): Promise<[ProcessedTx[], FailedTx[], NestedProcessReturnValues[]]> {
151
151
  const { maxTransactions, maxBlockSize, deadline, maxBlockGas } = limits;
152
- const { preprocessValidator, postprocessValidator, nullifierCache } = validators;
152
+ const { preprocessValidator, nullifierCache } = validator;
153
153
  const result: ProcessedTx[] = [];
154
154
  const failed: FailedTx[] = [];
155
155
  const timer = new Timer();
@@ -242,26 +242,6 @@ export class PublicProcessor implements Traceable {
242
242
  continue;
243
243
  }
244
244
 
245
- // Re-validate the transaction
246
- if (postprocessValidator) {
247
- // Only accept processed transactions that are not double-spends,
248
- // public functions emitting nullifiers would pass earlier check but fail here.
249
- // Note that we're checking all nullifiers generated in the private execution twice,
250
- // we could store the ones already checked and skip them here as an optimization.
251
- // TODO(palla/txs): Can we get into this case? AVM validates this. We should be able to remove it.
252
- const result = await postprocessValidator.validateTx(processedTx);
253
- if (result.result !== 'valid') {
254
- const reason = result.reason.join(', ');
255
- this.log.error(`Rejecting tx ${processedTx.hash} after processing: ${reason}.`);
256
- failed.push({ tx, error: new Error(`Tx failed post-process validation: ${reason}`) });
257
- // Need to revert the checkpoint here and don't go any further
258
- await checkpoint.revert();
259
- continue;
260
- } else {
261
- this.log.trace(`Tx ${txHash.toString()} is valid post processing.`);
262
- }
263
- }
264
-
265
245
  if (!tx.hasPublicCalls()) {
266
246
  // If there are no public calls, perform all tree insertions for side effects from private
267
247
  // When there are public calls, the PublicTxSimulator & AVM handle tree insertions.