@aztec/simulator 0.66.0 → 0.67.1

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 (125) hide show
  1. package/dest/acvm/acvm.js +3 -3
  2. package/dest/acvm/oracle/oracle.d.ts +1 -1
  3. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  4. package/dest/acvm/oracle/oracle.js +3 -3
  5. package/dest/acvm/oracle/typed_oracle.d.ts +2 -2
  6. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  7. package/dest/acvm/oracle/typed_oracle.js +3 -3
  8. package/dest/acvm/serialize.js +2 -2
  9. package/dest/avm/avm_context.d.ts +2 -2
  10. package/dest/avm/avm_context.d.ts.map +1 -1
  11. package/dest/avm/avm_context.js +3 -4
  12. package/dest/avm/avm_execution_environment.d.ts +4 -6
  13. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  14. package/dest/avm/avm_execution_environment.js +8 -13
  15. package/dest/avm/avm_memory_types.d.ts +2 -2
  16. package/dest/avm/avm_memory_types.d.ts.map +1 -1
  17. package/dest/avm/avm_memory_types.js +3 -3
  18. package/dest/avm/avm_simulator.d.ts +3 -3
  19. package/dest/avm/avm_simulator.d.ts.map +1 -1
  20. package/dest/avm/avm_simulator.js +22 -13
  21. package/dest/avm/errors.d.ts +3 -3
  22. package/dest/avm/errors.d.ts.map +1 -1
  23. package/dest/avm/errors.js +8 -15
  24. package/dest/avm/fixtures/index.d.ts.map +1 -1
  25. package/dest/avm/fixtures/index.js +4 -4
  26. package/dest/avm/journal/journal.d.ts +15 -4
  27. package/dest/avm/journal/journal.d.ts.map +1 -1
  28. package/dest/avm/journal/journal.js +108 -29
  29. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  30. package/dest/avm/opcodes/external_calls.js +4 -11
  31. package/dest/avm/opcodes/misc.d.ts.map +1 -1
  32. package/dest/avm/opcodes/misc.js +3 -3
  33. package/dest/client/client_execution_context.d.ts +3 -3
  34. package/dest/client/client_execution_context.d.ts.map +1 -1
  35. package/dest/client/client_execution_context.js +14 -8
  36. package/dest/client/db_oracle.d.ts +2 -2
  37. package/dest/client/db_oracle.d.ts.map +1 -1
  38. package/dest/client/execution_note_cache.d.ts +9 -1
  39. package/dest/client/execution_note_cache.d.ts.map +1 -1
  40. package/dest/client/execution_note_cache.js +10 -3
  41. package/dest/client/private_execution.d.ts.map +1 -1
  42. package/dest/client/private_execution.js +4 -4
  43. package/dest/client/simulator.d.ts.map +1 -1
  44. package/dest/client/simulator.js +4 -4
  45. package/dest/client/unconstrained_execution.d.ts.map +1 -1
  46. package/dest/client/unconstrained_execution.js +3 -3
  47. package/dest/client/view_data_oracle.d.ts +2 -2
  48. package/dest/client/view_data_oracle.d.ts.map +1 -1
  49. package/dest/client/view_data_oracle.js +5 -6
  50. package/dest/common/debug_fn_name.d.ts +2 -2
  51. package/dest/common/debug_fn_name.d.ts.map +1 -1
  52. package/dest/common/debug_fn_name.js +8 -14
  53. package/dest/providers/acvm_native.js +4 -4
  54. package/dest/providers/factory.d.ts +2 -2
  55. package/dest/providers/factory.d.ts.map +1 -1
  56. package/dest/providers/factory.js +4 -4
  57. package/dest/public/enqueued_call_side_effect_trace.d.ts +11 -23
  58. package/dest/public/enqueued_call_side_effect_trace.d.ts.map +1 -1
  59. package/dest/public/enqueued_call_side_effect_trace.js +37 -58
  60. package/dest/public/executor_metrics.d.ts.map +1 -1
  61. package/dest/public/executor_metrics.js +2 -5
  62. package/dest/public/fixtures/index.d.ts +24 -1
  63. package/dest/public/fixtures/index.d.ts.map +1 -1
  64. package/dest/public/fixtures/index.js +15 -9
  65. package/dest/public/index.d.ts +0 -1
  66. package/dest/public/index.d.ts.map +1 -1
  67. package/dest/public/index.js +1 -2
  68. package/dest/public/public_db_sources.d.ts.map +1 -1
  69. package/dest/public/public_db_sources.js +4 -4
  70. package/dest/public/public_processor.d.ts +7 -8
  71. package/dest/public/public_processor.d.ts.map +1 -1
  72. package/dest/public/public_processor.js +30 -22
  73. package/dest/public/public_tx_context.d.ts +13 -10
  74. package/dest/public/public_tx_context.d.ts.map +1 -1
  75. package/dest/public/public_tx_context.js +46 -31
  76. package/dest/public/public_tx_simulator.d.ts +2 -2
  77. package/dest/public/public_tx_simulator.d.ts.map +1 -1
  78. package/dest/public/public_tx_simulator.js +43 -23
  79. package/dest/public/side_effect_trace_interface.d.ts +4 -17
  80. package/dest/public/side_effect_trace_interface.d.ts.map +1 -1
  81. package/dest/public/transitional_adapters.d.ts +2 -2
  82. package/dest/public/transitional_adapters.d.ts.map +1 -1
  83. package/dest/public/transitional_adapters.js +28 -24
  84. package/package.json +16 -9
  85. package/src/acvm/acvm.ts +2 -2
  86. package/src/acvm/oracle/oracle.ts +2 -2
  87. package/src/acvm/oracle/typed_oracle.ts +3 -3
  88. package/src/acvm/serialize.ts +1 -1
  89. package/src/avm/avm_context.ts +2 -3
  90. package/src/avm/avm_execution_environment.ts +6 -31
  91. package/src/avm/avm_memory_types.ts +2 -2
  92. package/src/avm/avm_simulator.ts +24 -20
  93. package/src/avm/errors.ts +12 -14
  94. package/src/avm/fixtures/index.ts +2 -3
  95. package/src/avm/journal/journal.ts +189 -63
  96. package/src/avm/opcodes/external_calls.ts +3 -19
  97. package/src/avm/opcodes/misc.ts +2 -2
  98. package/src/client/client_execution_context.ts +17 -9
  99. package/src/client/db_oracle.ts +2 -2
  100. package/src/client/execution_note_cache.ts +13 -3
  101. package/src/client/private_execution.ts +3 -3
  102. package/src/client/simulator.ts +4 -4
  103. package/src/client/unconstrained_execution.ts +2 -2
  104. package/src/client/view_data_oracle.ts +5 -6
  105. package/src/common/debug_fn_name.ts +7 -13
  106. package/src/providers/acvm_native.ts +3 -3
  107. package/src/providers/factory.ts +3 -3
  108. package/src/public/enqueued_call_side_effect_trace.ts +54 -74
  109. package/src/public/executor_metrics.ts +0 -4
  110. package/src/public/fixtures/index.ts +23 -10
  111. package/src/public/index.ts +0 -1
  112. package/src/public/public_db_sources.ts +3 -3
  113. package/src/public/public_processor.ts +46 -47
  114. package/src/public/public_tx_context.ts +52 -32
  115. package/src/public/public_tx_simulator.ts +58 -38
  116. package/src/public/side_effect_trace_interface.ts +8 -15
  117. package/src/public/transitional_adapters.ts +39 -24
  118. package/dest/public/dual_side_effect_trace.d.ts +0 -77
  119. package/dest/public/dual_side_effect_trace.d.ts.map +0 -1
  120. package/dest/public/dual_side_effect_trace.js +0 -119
  121. package/dest/public/side_effect_trace.d.ts +0 -96
  122. package/dest/public/side_effect_trace.d.ts.map +0 -1
  123. package/dest/public/side_effect_trace.js +0 -309
  124. package/src/public/dual_side_effect_trace.ts +0 -242
  125. package/src/public/side_effect_trace.ts +0 -536
@@ -8,15 +8,15 @@ import {
8
8
  type PublicDataWitness,
9
9
  } from '@aztec/circuit-types';
10
10
  import {
11
+ type BlockHeader,
11
12
  type ContractInstance,
12
- type Header,
13
13
  type IndexedTaggingSecret,
14
14
  type KeyValidationRequest,
15
15
  } from '@aztec/circuits.js';
16
16
  import { siloNullifier } from '@aztec/circuits.js/hash';
17
17
  import { AztecAddress } from '@aztec/foundation/aztec-address';
18
18
  import { Fr } from '@aztec/foundation/fields';
19
- import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
19
+ import { applyStringFormatting, createLogger } from '@aztec/foundation/log';
20
20
 
21
21
  import { type NoteData, TypedOracle } from '../acvm/index.js';
22
22
  import { type DBOracle } from './db_oracle.js';
@@ -33,7 +33,7 @@ export class ViewDataOracle extends TypedOracle {
33
33
  protected readonly authWitnesses: AuthWitness[],
34
34
  protected readonly db: DBOracle,
35
35
  protected readonly aztecNode: AztecNode,
36
- protected log = createDebugLogger('aztec:simulator:client_view_context'),
36
+ protected log = createLogger('simulator:client_view_context'),
37
37
  protected readonly scopes?: AztecAddress[],
38
38
  ) {
39
39
  super();
@@ -139,7 +139,7 @@ export class ViewDataOracle extends TypedOracle {
139
139
  * @param blockNumber - The number of a block of which to get the block header.
140
140
  * @returns Block extracted from a block with block number `blockNumber`.
141
141
  */
142
- public override async getHeader(blockNumber: number): Promise<Header | undefined> {
142
+ public override async getBlockHeader(blockNumber: number): Promise<BlockHeader | undefined> {
143
143
  const block = await this.db.getBlock(blockNumber);
144
144
  if (!block) {
145
145
  return undefined;
@@ -290,8 +290,7 @@ export class ViewDataOracle extends TypedOracle {
290
290
  }
291
291
 
292
292
  public override debugLog(message: string, fields: Fr[]): void {
293
- const formattedStr = applyStringFormatting(message, fields);
294
- this.log.verbose(`debug_log ${formattedStr}`);
293
+ this.log.verbose(`${applyStringFormatting(message, fields)}`, { module: `${this.log.module}:debug_log` });
295
294
  }
296
295
 
297
296
  /**
@@ -1,22 +1,16 @@
1
- import { type AztecAddress, Fr, FunctionSelector, PUBLIC_DISPATCH_SELECTOR } from '@aztec/circuits.js';
1
+ import { type AztecAddress, type Fr, FunctionSelector } from '@aztec/circuits.js';
2
2
 
3
3
  import { type WorldStateDB } from '../public/public_db_sources.js';
4
4
 
5
5
  export async function getPublicFunctionDebugName(
6
6
  db: WorldStateDB,
7
7
  contractAddress: AztecAddress,
8
- fn: FunctionSelector,
9
8
  calldata: Fr[],
10
9
  ): Promise<string> {
11
- if (fn.equals(FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)))) {
12
- // If the function is a dispatch, we need to look up the target function which
13
- // is expected to be the first argument.
14
- const targetFunction =
15
- calldata[0] !== undefined
16
- ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
17
- : `<calldata[0] undefined>`;
18
- return `${targetFunction} (via dispatch)`;
19
- } else {
20
- return (await db.getDebugFunctionName(contractAddress, fn)) ?? `${contractAddress}:${fn}`;
21
- }
10
+ // Public function is dispatched and therefore the target function is passed in the first argument.
11
+ const targetFunction =
12
+ calldata[0] !== undefined
13
+ ? await db.getDebugFunctionName(contractAddress, FunctionSelector.fromField(calldata[0]))
14
+ : `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
+ return `${targetFunction}`;
22
16
  }
@@ -1,15 +1,15 @@
1
1
  import { runInDirectory } from '@aztec/foundation/fs';
2
- import { createDebugLogger } from '@aztec/foundation/log';
2
+ import { createLogger } from '@aztec/foundation/log';
3
3
  import { Timer } from '@aztec/foundation/timer';
4
4
  import { type NoirCompiledCircuit } from '@aztec/types/noir';
5
5
 
6
6
  import { type WitnessMap } from '@noir-lang/types';
7
7
  import * as proc from 'child_process';
8
- import fs from 'fs/promises';
8
+ import { promises as fs } from 'fs';
9
9
 
10
10
  import { type SimulationProvider } from './simulation_provider.js';
11
11
 
12
- const logger = createDebugLogger('aztec:acvm-native');
12
+ const logger = createLogger('simulator:acvm-native');
13
13
 
14
14
  export enum ACVM_RESULT {
15
15
  SUCCESS,
@@ -1,6 +1,6 @@
1
- import { type DebugLogger, createDebugLogger } from '@aztec/foundation/log';
1
+ import { type Logger, createLogger } from '@aztec/foundation/log';
2
2
 
3
- import * as fs from 'fs/promises';
3
+ import { promises as fs } from 'fs';
4
4
 
5
5
  import { NativeACVMSimulator } from './acvm_native.js';
6
6
  import { WASMSimulator } from './acvm_wasm.js';
@@ -21,7 +21,7 @@ export function getSimulationProviderConfigFromEnv() {
21
21
 
22
22
  export async function createSimulationProvider(
23
23
  config: SimulationProviderConfig,
24
- logger: DebugLogger = createDebugLogger('aztec:simulator'),
24
+ logger: Logger = createLogger('simulator'),
25
25
  ): Promise<SimulationProvider> {
26
26
  if (config.acvmBinaryPath && config.acvmWorkingDirectory) {
27
27
  try {
@@ -7,7 +7,6 @@ import {
7
7
  AvmContractInstanceHint,
8
8
  AvmEnqueuedCallHint,
9
9
  AvmExecutionHints,
10
- AvmExternalCallHint,
11
10
  AvmNullifierReadTreeHint,
12
11
  AvmNullifierWriteTreeHint,
13
12
  AvmPublicDataReadTreeHint,
@@ -26,12 +25,14 @@ import {
26
25
  MAX_NOTE_HASHES_PER_TX,
27
26
  MAX_NULLIFIERS_PER_TX,
28
27
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
28
+ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
29
29
  MAX_UNENCRYPTED_LOGS_PER_TX,
30
30
  NOTE_HASH_TREE_HEIGHT,
31
31
  NULLIFIER_TREE_HEIGHT,
32
32
  NoteHash,
33
33
  Nullifier,
34
34
  NullifierLeafPreimage,
35
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
35
36
  PUBLIC_DATA_TREE_HEIGHT,
36
37
  PrivateToAvmAccumulatedData,
37
38
  PrivateToAvmAccumulatedDataArrayLengths,
@@ -49,11 +50,11 @@ import { computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
49
50
  import { padArrayEnd } from '@aztec/foundation/collection';
50
51
  import { Fr } from '@aztec/foundation/fields';
51
52
  import { jsonStringify } from '@aztec/foundation/json-rpc';
52
- import { createDebugLogger } from '@aztec/foundation/log';
53
+ import { createLogger } from '@aztec/foundation/log';
53
54
 
54
- import { assert } from 'console';
55
+ import { strict as assert } from 'assert';
55
56
 
56
- import { type AvmContractCallResult, type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
57
+ import { type AvmFinalizedCallResult } from '../avm/avm_contract_call_result.js';
57
58
  import { type AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
58
59
  import { type EnqueuedPublicCallExecutionResultWithSideEffects, type PublicFunctionCallResult } from './execution.js';
59
60
  import { SideEffectLimitReachedError } from './side_effect_errors.js';
@@ -84,6 +85,7 @@ export type SideEffects = {
84
85
  export class SideEffectArrayLengths {
85
86
  constructor(
86
87
  public readonly publicDataWrites: number,
88
+ public readonly protocolPublicDataWrites: number,
87
89
  public readonly noteHashes: number,
88
90
  public readonly nullifiers: number,
89
91
  public readonly l2ToL1Msgs: number,
@@ -91,7 +93,7 @@ export class SideEffectArrayLengths {
91
93
  ) {}
92
94
 
93
95
  static empty() {
94
- return new this(0, 0, 0, 0, 0);
96
+ return new this(0, 0, 0, 0, 0, 0);
95
97
  }
96
98
  }
97
99
 
@@ -99,7 +101,7 @@ export class SideEffectArrayLengths {
99
101
  * Trace side effects for an entire enqueued call.
100
102
  */
101
103
  export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceInterface {
102
- public log = createDebugLogger('aztec:public_enqueued_call_side_effect_trace');
104
+ public log = createLogger('simulator:public_enqueued_call_side_effect_trace');
103
105
 
104
106
  /** The side effect counter increments with every call to the trace. */
105
107
  private sideEffectCounter: number;
@@ -107,6 +109,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
107
109
  private enqueuedCalls: PublicCallRequest[] = [];
108
110
 
109
111
  private publicDataWrites: PublicDataUpdateRequest[] = [];
112
+ private protocolPublicDataWritesLength: number = 0;
113
+ private userPublicDataWritesLength: number = 0;
110
114
  private noteHashes: ScopedNoteHash[] = [];
111
115
  private nullifiers: Nullifier[] = [];
112
116
  private l2ToL1Messages: ScopedL2ToL1Message[] = [];
@@ -135,7 +139,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
135
139
  return new PublicEnqueuedCallSideEffectTrace(
136
140
  this.sideEffectCounter,
137
141
  new SideEffectArrayLengths(
138
- this.previousSideEffectArrayLengths.publicDataWrites + this.publicDataWrites.length,
142
+ this.previousSideEffectArrayLengths.publicDataWrites + this.userPublicDataWritesLength,
143
+ this.previousSideEffectArrayLengths.protocolPublicDataWrites + this.protocolPublicDataWritesLength,
139
144
  this.previousSideEffectArrayLengths.noteHashes + this.noteHashes.length,
140
145
  this.previousSideEffectArrayLengths.nullifiers + this.nullifiers.length,
141
146
  this.previousSideEffectArrayLengths.l2ToL1Msgs + this.l2ToL1Messages.length,
@@ -169,13 +174,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
169
174
  private mergeHints(forkedTrace: this) {
170
175
  this.avmCircuitHints.enqueuedCalls.items.push(...forkedTrace.avmCircuitHints.enqueuedCalls.items);
171
176
 
172
- this.avmCircuitHints.storageValues.items.push(...forkedTrace.avmCircuitHints.storageValues.items);
173
- this.avmCircuitHints.noteHashExists.items.push(...forkedTrace.avmCircuitHints.noteHashExists.items);
174
- this.avmCircuitHints.nullifierExists.items.push(...forkedTrace.avmCircuitHints.nullifierExists.items);
175
- this.avmCircuitHints.l1ToL2MessageExists.items.push(...forkedTrace.avmCircuitHints.l1ToL2MessageExists.items);
176
-
177
- this.avmCircuitHints.externalCalls.items.push(...forkedTrace.avmCircuitHints.externalCalls.items);
178
-
179
177
  this.avmCircuitHints.contractInstances.items.push(...forkedTrace.avmCircuitHints.contractInstances.items);
180
178
  this.avmCircuitHints.contractBytecodeHints.items.push(...forkedTrace.avmCircuitHints.contractBytecodeHints.items);
181
179
 
@@ -197,20 +195,17 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
197
195
  }
198
196
 
199
197
  public tracePublicStorageRead(
200
- _contractAddress: AztecAddress,
198
+ contractAddress: AztecAddress,
201
199
  slot: Fr,
202
200
  value: Fr,
203
201
  leafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
204
202
  leafIndex: Fr = Fr.zero(),
205
203
  path: Fr[] = emptyPublicDataPath(),
206
204
  ) {
207
- if (!leafIndex.equals(Fr.zero())) {
208
- // if we have real merkle hint content, make sure the value matches the the provided preimage
209
- assert(leafPreimage.value.equals(value), 'Value mismatch when tracing in public data write');
210
- }
211
-
212
205
  this.avmCircuitHints.publicDataReads.items.push(new AvmPublicDataReadTreeHint(leafPreimage, leafIndex, path));
213
- this.log.debug(`SLOAD cnt: ${this.sideEffectCounter} val: ${value} slot: ${slot}`);
206
+ this.log.debug(
207
+ `Tracing storage read (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter})`,
208
+ );
214
209
  this.incrementSideEffectCounter();
215
210
  }
216
211
 
@@ -218,24 +213,35 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
218
213
  contractAddress: AztecAddress,
219
214
  slot: Fr,
220
215
  value: Fr,
216
+ protocolWrite: boolean,
221
217
  lowLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
222
218
  lowLeafIndex: Fr = Fr.zero(),
223
219
  lowLeafPath: Fr[] = emptyPublicDataPath(),
224
220
  newLeafPreimage: PublicDataTreeLeafPreimage = PublicDataTreeLeafPreimage.empty(),
225
221
  insertionPath: Fr[] = emptyPublicDataPath(),
226
222
  ) {
227
- if (!lowLeafIndex.equals(Fr.zero())) {
228
- // if we have real merkle hint content, make sure the value matches the the provided preimage
229
- assert(newLeafPreimage.value.equals(value), 'Value mismatch when tracing in public data read');
230
- }
231
- if (
232
- this.publicDataWrites.length + this.previousSideEffectArrayLengths.publicDataWrites >=
233
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
234
- ) {
235
- throw new SideEffectLimitReachedError(
236
- 'public data (contract storage) write',
237
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
238
- );
223
+ if (protocolWrite) {
224
+ if (
225
+ this.protocolPublicDataWritesLength + this.previousSideEffectArrayLengths.protocolPublicDataWrites >=
226
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
227
+ ) {
228
+ throw new SideEffectLimitReachedError(
229
+ 'protocol public data (contract storage) write',
230
+ PROTOCOL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
231
+ );
232
+ }
233
+ this.protocolPublicDataWritesLength++;
234
+ } else {
235
+ if (
236
+ this.userPublicDataWritesLength + this.previousSideEffectArrayLengths.publicDataWrites >=
237
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX
238
+ ) {
239
+ throw new SideEffectLimitReachedError(
240
+ 'public data (contract storage) write',
241
+ MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
242
+ );
243
+ }
244
+ this.userPublicDataWritesLength++;
239
245
  }
240
246
 
241
247
  const leafSlot = computePublicDataTreeLeafSlot(contractAddress, slot);
@@ -248,7 +254,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
248
254
  );
249
255
 
250
256
  this.log.debug(
251
- `Traced public data write (address=${contractAddress}, slot=${slot}, leafSlot=${leafSlot}): value=${value} (counter=${this.sideEffectCounter})`,
257
+ `Traced public data write (address=${contractAddress}, slot=${slot}): value=${value} (counter=${this.sideEffectCounter}, isProtocol:${protocolWrite})`,
252
258
  );
253
259
  this.incrementSideEffectCounter();
254
260
  }
@@ -365,7 +371,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
365
371
  contractAddress: AztecAddress,
366
372
  exists: boolean,
367
373
  instance: SerializableContractInstance = SerializableContractInstance.default(),
374
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
375
+ lowLeafIndex: Fr = Fr.zero(),
376
+ lowLeafPath: Fr[] = emptyNullifierPath(),
368
377
  ) {
378
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
369
379
  this.avmCircuitHints.contractInstances.items.push(
370
380
  new AvmContractInstanceHint(
371
381
  contractAddress,
@@ -375,6 +385,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
375
385
  instance.contractClassId,
376
386
  instance.initializationHash,
377
387
  instance.publicKeys,
388
+ membershipHint,
378
389
  ),
379
390
  );
380
391
  this.log.debug(`CONTRACT_INSTANCE cnt: ${this.sideEffectCounter}`);
@@ -394,7 +405,11 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
394
405
  privateFunctionsRoot: Fr.zero(),
395
406
  publicBytecodeCommitment: Fr.zero(),
396
407
  },
408
+ lowLeafPreimage: NullifierLeafPreimage = NullifierLeafPreimage.empty(),
409
+ lowLeafIndex: Fr = Fr.zero(),
410
+ lowLeafPath: Fr[] = emptyNullifierPath(),
397
411
  ) {
412
+ const membershipHint = new AvmNullifierReadTreeHint(lowLeafPreimage, lowLeafIndex, lowLeafPath);
398
413
  const instance = new AvmContractInstanceHint(
399
414
  contractAddress,
400
415
  exists,
@@ -403,6 +418,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
403
418
  contractInstance.contractClassId,
404
419
  contractInstance.initializationHash,
405
420
  contractInstance.publicKeys,
421
+ membershipHint,
406
422
  );
407
423
  // We need to deduplicate the contract instances based on addresses
408
424
  this.avmCircuitHints.contractBytecodeHints.items.push(
@@ -413,45 +429,6 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
413
429
  );
414
430
  }
415
431
 
416
- /**
417
- * Trace a nested call.
418
- * Accept some results from a finished nested call's trace into this one.
419
- */
420
- public traceNestedCall(
421
- /** The trace of the nested call. */
422
- _nestedCallTrace: this,
423
- /** The execution environment of the nested call. */
424
- nestedEnvironment: AvmExecutionEnvironment,
425
- /** How much gas was available for this public execution. */
426
- startGasLeft: Gas,
427
- /** Bytecode used for this execution. */
428
- _bytecode: Buffer,
429
- /** The call's results */
430
- avmCallResults: AvmContractCallResult,
431
- /** Function name for logging */
432
- _functionName: string = 'unknown',
433
- ) {
434
- // TODO(4805): check if some threshold is reached for max nested calls (to unique contracts?)
435
- //
436
- // Store end side effect counter before it gets updated by absorbing nested call trace
437
- const endSideEffectCounter = new Fr(this.sideEffectCounter);
438
-
439
- const gasUsed = new Gas(
440
- startGasLeft.daGas - avmCallResults.gasLeft.daGas,
441
- startGasLeft.l2Gas - avmCallResults.gasLeft.l2Gas,
442
- );
443
-
444
- this.avmCircuitHints.externalCalls.items.push(
445
- new AvmExternalCallHint(
446
- /*success=*/ new Fr(avmCallResults.reverted ? 0 : 1),
447
- avmCallResults.output,
448
- gasUsed,
449
- endSideEffectCounter,
450
- nestedEnvironment.address,
451
- ),
452
- );
453
- }
454
-
455
432
  /**
456
433
  * Trace an enqueued call.
457
434
  * Accept some results from a finished call's trace into this one.
@@ -515,6 +492,8 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
515
492
  startGasUsed: Gas,
516
493
  /** How much gas was available for this public execution. */
517
494
  gasLimits: GasSettings,
495
+ /** Address of the fee payer. */
496
+ feePayer: AztecAddress,
518
497
  /** Call requests for setup phase. */
519
498
  publicSetupCallRequests: PublicCallRequest[],
520
499
  /** Call requests for app logic phase. */
@@ -538,6 +517,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
538
517
  startTreeSnapshots,
539
518
  startGasUsed,
540
519
  gasLimits,
520
+ feePayer,
541
521
  padArrayEnd(publicSetupCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
542
522
  padArrayEnd(publicAppLogicCallRequests, PublicCallRequest.empty(), MAX_ENQUEUED_CALLS_PER_TX),
543
523
  publicTeardownCallRequest,
@@ -593,7 +573,7 @@ export class PublicEnqueuedCallSideEffectTrace implements PublicSideEffectTraceI
593
573
  padArrayEnd(
594
574
  this.publicDataWrites.map(w => new PublicDataWrite(w.leafSlot, w.newValue)),
595
575
  PublicDataWrite.empty(),
596
- MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
576
+ MAX_TOTAL_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
597
577
  ),
598
578
  );
599
579
  }
@@ -6,7 +6,6 @@ import {
6
6
  type Tracer,
7
7
  type UpDownCounter,
8
8
  ValueType,
9
- linearBuckets,
10
9
  } from '@aztec/telemetry-client';
11
10
 
12
11
  export class ExecutorMetrics {
@@ -33,9 +32,6 @@ export class ExecutorMetrics {
33
32
  description: 'Mana used per second',
34
33
  unit: 'mana/s',
35
34
  valueType: ValueType.INT,
36
- advice: {
37
- explicitBucketBoundaries: linearBuckets(0, 10_000_000, 10),
38
- },
39
35
  });
40
36
  }
41
37
 
@@ -1,17 +1,18 @@
1
- import { PublicExecutionRequest, Tx } from '@aztec/circuit-types';
1
+ import { MerkleTreeId, PublicExecutionRequest, Tx } from '@aztec/circuit-types';
2
2
  import {
3
3
  type AvmCircuitInputs,
4
+ BlockHeader,
4
5
  CallContext,
5
6
  type ContractClassPublic,
6
7
  type ContractInstanceWithAddress,
7
8
  DEFAULT_GAS_LIMIT,
9
+ DEPLOYER_CONTRACT_ADDRESS,
8
10
  FunctionSelector,
9
11
  Gas,
10
12
  GasFees,
11
13
  GasSettings,
12
14
  GlobalVariables,
13
- Header,
14
- MAX_L2_GAS_PER_ENQUEUED_CALL,
15
+ MAX_L2_GAS_PER_TX_PUBLIC_PORTION,
15
16
  PartialPrivateTailPublicInputsForPublic,
16
17
  PrivateKernelTailCircuitPublicInputs,
17
18
  type PublicFunction,
@@ -22,11 +23,12 @@ import {
22
23
  TxContext,
23
24
  computePublicBytecodeCommitment,
24
25
  } from '@aztec/circuits.js';
26
+ import { siloNullifier } from '@aztec/circuits.js/hash';
25
27
  import { makeContractClassPublic, makeContractInstanceFromClassId } from '@aztec/circuits.js/testing';
26
28
  import { type ContractArtifact, type FunctionArtifact } from '@aztec/foundation/abi';
27
29
  import { AztecAddress } from '@aztec/foundation/aztec-address';
28
30
  import { Fr, Point } from '@aztec/foundation/fields';
29
- import { openTmpStore } from '@aztec/kv-store/utils';
31
+ import { openTmpStore } from '@aztec/kv-store/lmdb';
30
32
  import { AvmTestContractArtifact } from '@aztec/noir-contracts.js';
31
33
  import { PublicTxSimulator, WorldStateDB } from '@aztec/simulator';
32
34
  import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';
@@ -54,13 +56,23 @@ export async function simulateAvmTestContractGenerateCircuitInputs(
54
56
  const worldStateDB = new WorldStateDB(merkleTrees, contractDataSource);
55
57
 
56
58
  const contractInstance = contractDataSource.contractInstance;
59
+ const contractAddressNullifier = siloNullifier(
60
+ AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
61
+ contractInstance.address.toField(),
62
+ );
63
+ await merkleTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, [contractAddressNullifier.toBuffer()], 0);
64
+ // other contract address used by the bulk test's GETCONTRACTINSTANCE test
65
+ const otherContractAddressNullifier = siloNullifier(
66
+ AztecAddress.fromNumber(DEPLOYER_CONTRACT_ADDRESS),
67
+ contractDataSource.otherContractInstance.address.toField(),
68
+ );
69
+ await merkleTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, [otherContractAddressNullifier.toBuffer()], 0);
57
70
 
58
71
  const simulator = new PublicTxSimulator(
59
72
  merkleTrees,
60
73
  worldStateDB,
61
74
  new NoopTelemetryClient(),
62
75
  globalVariables,
63
- /*realAvmProving=*/ true,
64
76
  /*doMerkleOperations=*/ true,
65
77
  );
66
78
 
@@ -101,7 +113,7 @@ export function createTxForPublicCall(
101
113
  ): Tx {
102
114
  const callRequest = executionRequest.toCallRequest();
103
115
  // use max limits
104
- const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_ENQUEUED_CALL);
116
+ const gasLimits = new Gas(DEFAULT_GAS_LIMIT, MAX_L2_GAS_PER_TX_PUBLIC_PORTION);
105
117
 
106
118
  const forPublic = PartialPrivateTailPublicInputsForPublic.empty();
107
119
  // TODO(#9269): Remove this fake nullifier method as we move away from 1st nullifier as hash.
@@ -115,7 +127,7 @@ export function createTxForPublicCall(
115
127
  const teardownGasLimits = isTeardown ? gasLimits : Gas.empty();
116
128
  const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty());
117
129
  const txContext = new TxContext(Fr.zero(), Fr.zero(), gasSettings);
118
- const constantData = new TxConstantData(Header.empty(), txContext, Fr.zero(), Fr.zero());
130
+ const constantData = new TxConstantData(BlockHeader.empty(), txContext, Fr.zero(), Fr.zero());
119
131
 
120
132
  const txData = new PrivateKernelTailCircuitPublicInputs(
121
133
  constantData,
@@ -132,7 +144,7 @@ export function createTxForPublicCall(
132
144
  return tx;
133
145
  }
134
146
 
135
- class MockedAvmTestContractDataSource {
147
+ export class MockedAvmTestContractDataSource {
136
148
  private fnName = 'public_dispatch';
137
149
  private bytecode: Buffer;
138
150
  public fnSelector: FunctionSelector;
@@ -140,7 +152,7 @@ class MockedAvmTestContractDataSource {
140
152
  private contractClass: ContractClassPublic;
141
153
  public contractInstance: ContractInstanceWithAddress;
142
154
  private bytecodeCommitment: Fr;
143
- private otherContractInstance: ContractInstanceWithAddress;
155
+ public otherContractInstance: ContractInstanceWithAddress;
144
156
 
145
157
  constructor() {
146
158
  this.bytecode = getAvmTestContractBytecode(this.fnName);
@@ -150,6 +162,7 @@ class MockedAvmTestContractDataSource {
150
162
  this.contractInstance = makeContractInstanceFromClassId(this.contractClass.id);
151
163
  this.bytecodeCommitment = computePublicBytecodeCommitment(this.bytecode);
152
164
  // The values here should match those in `avm_simulator.test.ts`
165
+ // Used for GETCONTRACTINSTANCE test
153
166
  this.otherContractInstance = new SerializableContractInstance({
154
167
  version: 1,
155
168
  salt: new Fr(0x123),
@@ -162,7 +175,7 @@ class MockedAvmTestContractDataSource {
162
175
  new Point(new Fr(0x252627), new Fr(0x282930), false),
163
176
  new Point(new Fr(0x313233), new Fr(0x343536), false),
164
177
  ),
165
- }).withAddress(this.contractInstance.address);
178
+ }).withAddress(AztecAddress.fromNumber(0x4444));
166
179
  }
167
180
 
168
181
  getPublicFunction(_address: AztecAddress, _selector: FunctionSelector): Promise<PublicFunction> {
@@ -4,6 +4,5 @@ export { type EnqueuedPublicCallExecutionResult, type PublicFunctionCallResult }
4
4
  export * from './fee_payment.js';
5
5
  export * from './public_db_sources.js';
6
6
  export { PublicProcessor, PublicProcessorFactory } from './public_processor.js';
7
- export { PublicSideEffectTrace } from './side_effect_trace.js';
8
7
  export { PublicEnqueuedCallSideEffectTrace } from './enqueued_call_side_effect_trace.js';
9
8
  export { getExecutionRequestsByPhase } from './utils.js';
@@ -20,7 +20,7 @@ import {
20
20
  computePublicBytecodeCommitment,
21
21
  } from '@aztec/circuits.js';
22
22
  import { computeL1ToL2MessageNullifier, computePublicDataTreeLeafSlot } from '@aztec/circuits.js/hash';
23
- import { createDebugLogger } from '@aztec/foundation/log';
23
+ import { createLogger } from '@aztec/foundation/log';
24
24
  import { Timer } from '@aztec/foundation/timer';
25
25
  import { ContractClassRegisteredEvent, ContractInstanceDeployedEvent } from '@aztec/protocol-contracts';
26
26
  import {
@@ -39,7 +39,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
39
39
  private classCache = new Map<string, ContractClassPublic>();
40
40
  private bytecodeCommitmentCache = new Map<string, Fr>();
41
41
 
42
- private log = createDebugLogger('aztec:sequencer:contracts-data-source');
42
+ private log = createLogger('simulator:contracts-data-source');
43
43
 
44
44
  constructor(private dataSource: ContractDataSource) {}
45
45
  /**
@@ -152,7 +152,7 @@ export class ContractsDataSourcePublicDB implements PublicContractsDB {
152
152
  * A public state DB that reads and writes to the world state.
153
153
  */
154
154
  export class WorldStateDB extends ContractsDataSourcePublicDB implements PublicStateDB, CommitmentsDB {
155
- private logger = createDebugLogger('aztec:sequencer:world-state-db');
155
+ private logger = createLogger('simulator:world-state-db');
156
156
 
157
157
  private publicCommittedWriteCache: Map<bigint, Fr> = new Map();
158
158
  private publicCheckpointedWriteCache: Map<bigint, Fr> = new Map();