@aztec/simulator 0.47.0 → 0.48.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 (113) hide show
  1. package/dest/acvm/acvm.d.ts +1 -1
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.d.ts +5 -5
  4. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  5. package/dest/acvm/oracle/oracle.js +13 -16
  6. package/dest/acvm/oracle/typed_oracle.d.ts +12 -9
  7. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  8. package/dest/acvm/oracle/typed_oracle.js +6 -6
  9. package/dest/acvm/serialize.d.ts +0 -11
  10. package/dest/acvm/serialize.d.ts.map +1 -1
  11. package/dest/acvm/serialize.js +1 -26
  12. package/dest/avm/avm_gas.d.ts.map +1 -1
  13. package/dest/avm/avm_gas.js +2 -1
  14. package/dest/avm/fixtures/index.d.ts.map +1 -1
  15. package/dest/avm/fixtures/index.js +2 -2
  16. package/dest/avm/opcodes/commitment.d.ts +16 -0
  17. package/dest/avm/opcodes/commitment.d.ts.map +1 -0
  18. package/dest/avm/opcodes/commitment.js +50 -0
  19. package/dest/avm/serialization/bytecode_serialization.d.ts.map +1 -1
  20. package/dest/avm/serialization/bytecode_serialization.js +3 -1
  21. package/dest/avm/serialization/instruction_serialization.d.ts +4 -3
  22. package/dest/avm/serialization/instruction_serialization.d.ts.map +1 -1
  23. package/dest/avm/serialization/instruction_serialization.js +6 -5
  24. package/dest/client/client_execution_context.d.ts +20 -17
  25. package/dest/client/client_execution_context.d.ts.map +1 -1
  26. package/dest/client/client_execution_context.js +42 -45
  27. package/dest/client/db_oracle.d.ts +4 -3
  28. package/dest/client/db_oracle.d.ts.map +1 -1
  29. package/dest/client/execution_note_cache.d.ts +17 -13
  30. package/dest/client/execution_note_cache.d.ts.map +1 -1
  31. package/dest/client/execution_note_cache.js +65 -26
  32. package/dest/client/execution_result.d.ts +15 -8
  33. package/dest/client/execution_result.d.ts.map +1 -1
  34. package/dest/client/execution_result.js +40 -16
  35. package/dest/client/private_execution.js +3 -3
  36. package/dest/client/simulator.d.ts +7 -6
  37. package/dest/client/simulator.d.ts.map +1 -1
  38. package/dest/client/simulator.js +14 -12
  39. package/dest/client/test_utils.d.ts +9 -0
  40. package/dest/client/test_utils.d.ts.map +1 -0
  41. package/dest/client/test_utils.js +21 -0
  42. package/dest/client/view_data_oracle.d.ts +2 -1
  43. package/dest/client/view_data_oracle.d.ts.map +1 -1
  44. package/dest/client/view_data_oracle.js +4 -3
  45. package/dest/index.d.ts +0 -1
  46. package/dest/index.d.ts.map +1 -1
  47. package/dest/index.js +1 -2
  48. package/dest/mocks/fixtures.d.ts +5 -5
  49. package/dest/mocks/fixtures.d.ts.map +1 -1
  50. package/dest/mocks/fixtures.js +6 -9
  51. package/dest/public/abstract_phase_manager.d.ts +4 -5
  52. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  53. package/dest/public/abstract_phase_manager.js +17 -84
  54. package/dest/public/execution.d.ts +8 -10
  55. package/dest/public/execution.d.ts.map +1 -1
  56. package/dest/public/execution.js +10 -1
  57. package/dest/public/executor.d.ts +6 -2
  58. package/dest/public/executor.d.ts.map +1 -1
  59. package/dest/public/executor.js +12 -4
  60. package/dest/public/executor_metrics.d.ts +10 -0
  61. package/dest/public/executor_metrics.d.ts.map +1 -0
  62. package/dest/public/executor_metrics.js +32 -0
  63. package/dest/public/fee_payment.d.ts +2 -2
  64. package/dest/public/fee_payment.d.ts.map +1 -1
  65. package/dest/public/fee_payment.js +9 -10
  66. package/dest/public/hints_builder.d.ts.map +1 -1
  67. package/dest/public/hints_builder.js +1 -1
  68. package/dest/public/index.d.ts +1 -1
  69. package/dest/public/index.d.ts.map +1 -1
  70. package/dest/public/index.js +1 -1
  71. package/dest/public/public_processor.d.ts +3 -3
  72. package/dest/public/public_processor.d.ts.map +1 -1
  73. package/dest/public/public_processor.js +33 -14
  74. package/dest/public/public_processor_metrics.d.ts +19 -0
  75. package/dest/public/public_processor_metrics.d.ts.map +1 -0
  76. package/dest/public/public_processor_metrics.js +57 -0
  77. package/dest/public/side_effect_trace.d.ts +1 -0
  78. package/dest/public/side_effect_trace.d.ts.map +1 -1
  79. package/dest/public/side_effect_trace.js +9 -9
  80. package/package.json +9 -9
  81. package/src/acvm/acvm.ts +1 -1
  82. package/src/acvm/oracle/oracle.ts +13 -30
  83. package/src/acvm/oracle/typed_oracle.ts +12 -31
  84. package/src/acvm/serialize.ts +0 -29
  85. package/src/avm/avm_gas.ts +1 -0
  86. package/src/avm/fixtures/index.ts +1 -0
  87. package/src/avm/opcodes/commitment.ts +66 -0
  88. package/src/avm/serialization/bytecode_serialization.ts +2 -0
  89. package/src/avm/serialization/instruction_serialization.ts +2 -1
  90. package/src/client/client_execution_context.ts +51 -49
  91. package/src/client/db_oracle.ts +9 -3
  92. package/src/client/execution_note_cache.ts +76 -25
  93. package/src/client/execution_result.ts +54 -19
  94. package/src/client/private_execution.ts +2 -2
  95. package/src/client/simulator.ts +18 -14
  96. package/src/client/test_utils.ts +30 -0
  97. package/src/client/view_data_oracle.ts +2 -1
  98. package/src/index.ts +0 -1
  99. package/src/mocks/fixtures.ts +13 -11
  100. package/src/public/abstract_phase_manager.ts +23 -104
  101. package/src/public/execution.ts +30 -14
  102. package/src/public/executor.ts +18 -4
  103. package/src/public/executor_metrics.ts +48 -0
  104. package/src/public/fee_payment.ts +8 -10
  105. package/src/public/hints_builder.ts +2 -2
  106. package/src/public/index.ts +1 -1
  107. package/src/public/public_processor.ts +46 -15
  108. package/src/public/public_processor_metrics.ts +90 -0
  109. package/src/public/side_effect_trace.ts +13 -7
  110. package/dest/utils.d.ts +0 -12
  111. package/dest/utils.d.ts.map +0 -1
  112. package/dest/utils.js +0 -11
  113. package/src/utils.ts +0 -18
@@ -6,7 +6,7 @@ import { Fr, Point } from '@aztec/foundation/fields';
6
6
 
7
7
  import { type ACVMField } from '../acvm_types.js';
8
8
  import { frToBoolean, frToNumber, fromACVMField } from '../deserialize.js';
9
- import { toACVMField, toAcvmEnqueuePublicFunctionResult } from '../serialize.js';
9
+ import { toACVMField } from '../serialize.js';
10
10
  import { type TypedOracle } from './typed_oracle.js';
11
11
 
12
12
  /**
@@ -247,14 +247,14 @@ export class Oracle {
247
247
  [storageSlot]: ACVMField[],
248
248
  [noteTypeId]: ACVMField[],
249
249
  note: ACVMField[],
250
- [innerNoteHash]: ACVMField[],
250
+ [noteHash]: ACVMField[],
251
251
  [counter]: ACVMField[],
252
252
  ): ACVMField {
253
253
  this.typedOracle.notifyCreatedNote(
254
254
  fromACVMField(storageSlot),
255
255
  NoteSelector.fromField(fromACVMField(noteTypeId)),
256
256
  note.map(fromACVMField),
257
- fromACVMField(innerNoteHash),
257
+ fromACVMField(noteHash),
258
258
  +counter,
259
259
  );
260
260
  return toACVMField(0);
@@ -262,10 +262,10 @@ export class Oracle {
262
262
 
263
263
  async notifyNullifiedNote(
264
264
  [innerNullifier]: ACVMField[],
265
- [innerNoteHash]: ACVMField[],
265
+ [noteHash]: ACVMField[],
266
266
  [counter]: ACVMField[],
267
267
  ): Promise<ACVMField> {
268
- await this.typedOracle.notifyNullifiedNote(fromACVMField(innerNullifier), fromACVMField(innerNoteHash), +counter);
268
+ await this.typedOracle.notifyNullifiedNote(fromACVMField(innerNullifier), fromACVMField(noteHash), +counter);
269
269
  return toACVMField(0);
270
270
  }
271
271
 
@@ -429,7 +429,7 @@ export class Oracle {
429
429
  [isStaticCall]: ACVMField[],
430
430
  [isDelegateCall]: ACVMField[],
431
431
  ): Promise<ACVMField[]> {
432
- const callStackItem = await this.typedOracle.callPrivateFunction(
432
+ const { endSideEffectCounter, returnsHash } = await this.typedOracle.callPrivateFunction(
433
433
  AztecAddress.fromField(fromACVMField(contractAddress)),
434
434
  FunctionSelector.fromField(fromACVMField(functionSelector)),
435
435
  fromACVMField(argsHash),
@@ -437,26 +437,7 @@ export class Oracle {
437
437
  frToBoolean(fromACVMField(isStaticCall)),
438
438
  frToBoolean(fromACVMField(isDelegateCall)),
439
439
  );
440
- return callStackItem.toFields().map(toACVMField);
441
- }
442
-
443
- async callPublicFunction(
444
- [contractAddress]: ACVMField[],
445
- [functionSelector]: ACVMField[],
446
- [argsHash]: ACVMField[],
447
- [sideEffectCounter]: ACVMField[],
448
- [isStaticCall]: ACVMField[],
449
- [isDelegateCall]: ACVMField[],
450
- ): Promise<ACVMField[]> {
451
- const returnValues = await this.typedOracle.callPublicFunction(
452
- AztecAddress.fromField(fromACVMField(contractAddress)),
453
- FunctionSelector.fromField(fromACVMField(functionSelector)),
454
- fromACVMField(argsHash),
455
- frToNumber(fromACVMField(sideEffectCounter)),
456
- frToBoolean(fromACVMField(isStaticCall)),
457
- frToBoolean(fromACVMField(isDelegateCall)),
458
- );
459
- return returnValues.map(toACVMField);
440
+ return [endSideEffectCounter, returnsHash].map(toACVMField);
460
441
  }
461
442
 
462
443
  async enqueuePublicFunctionCall(
@@ -467,7 +448,7 @@ export class Oracle {
467
448
  [isStaticCall]: ACVMField[],
468
449
  [isDelegateCall]: ACVMField[],
469
450
  ) {
470
- const enqueuedRequest = await this.typedOracle.enqueuePublicFunctionCall(
451
+ await this.typedOracle.enqueuePublicFunctionCall(
471
452
  AztecAddress.fromString(contractAddress),
472
453
  FunctionSelector.fromField(fromACVMField(functionSelector)),
473
454
  fromACVMField(argsHash),
@@ -475,7 +456,6 @@ export class Oracle {
475
456
  frToBoolean(fromACVMField(isStaticCall)),
476
457
  frToBoolean(fromACVMField(isDelegateCall)),
477
458
  );
478
- return toAcvmEnqueuePublicFunctionResult(enqueuedRequest);
479
459
  }
480
460
 
481
461
  async setPublicTeardownFunctionCall(
@@ -486,7 +466,7 @@ export class Oracle {
486
466
  [isStaticCall]: ACVMField[],
487
467
  [isDelegateCall]: ACVMField[],
488
468
  ) {
489
- const teardownRequest = await this.typedOracle.setPublicTeardownFunctionCall(
469
+ await this.typedOracle.setPublicTeardownFunctionCall(
490
470
  AztecAddress.fromString(contractAddress),
491
471
  FunctionSelector.fromField(fromACVMField(functionSelector)),
492
472
  fromACVMField(argsHash),
@@ -494,7 +474,10 @@ export class Oracle {
494
474
  frToBoolean(fromACVMField(isStaticCall)),
495
475
  frToBoolean(fromACVMField(isDelegateCall)),
496
476
  );
497
- return toAcvmEnqueuePublicFunctionResult(teardownRequest);
477
+ }
478
+
479
+ notifySetMinRevertibleSideEffectCounter([minRevertibleSideEffectCounter]: ACVMField[]) {
480
+ this.typedOracle.notifySetMinRevertibleSideEffectCounter(frToNumber(fromACVMField(minRevertibleSideEffectCounter)));
498
481
  }
499
482
 
500
483
  aes128Encrypt(input: ACVMField[], initializationVector: ACVMField[], key: ACVMField[]): ACVMField[] {
@@ -9,13 +9,7 @@ import {
9
9
  type SiblingPath,
10
10
  type UnencryptedL2Log,
11
11
  } from '@aztec/circuit-types';
12
- import {
13
- type Header,
14
- type KeyValidationRequest,
15
- type L1_TO_L2_MSG_TREE_HEIGHT,
16
- type PrivateCallStackItem,
17
- type PublicCallRequest,
18
- } from '@aztec/circuits.js';
12
+ import { type Header, type KeyValidationRequest, type L1_TO_L2_MSG_TREE_HEIGHT } from '@aztec/circuits.js';
19
13
  import { type FunctionSelector, type NoteSelector } from '@aztec/foundation/abi';
20
14
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
21
15
  import { Fr } from '@aztec/foundation/fields';
@@ -33,8 +27,8 @@ export interface NoteData {
33
27
  storageSlot: Fr;
34
28
  /** The nonce of the note. */
35
29
  nonce: Fr;
36
- /** The inner note hash of the note. */
37
- innerNoteHash: Fr;
30
+ /** A hash of the note. */
31
+ noteHash: Fr;
38
32
  /** The corresponding nullifier of the note. Undefined for pending notes. */
39
33
  siloedNullifier?: Fr;
40
34
  /** The note's leaf index in the note hash tree. Undefined for pending notes. */
@@ -164,17 +158,11 @@ export abstract class TypedOracle {
164
158
  throw new OracleMethodNotAvailableError('getNotes');
165
159
  }
166
160
 
167
- notifyCreatedNote(
168
- _storageSlot: Fr,
169
- _noteTypeId: NoteSelector,
170
- _note: Fr[],
171
- _innerNoteHash: Fr,
172
- _counter: number,
173
- ): void {
161
+ notifyCreatedNote(_storageSlot: Fr, _noteTypeId: NoteSelector, _note: Fr[], _noteHash: Fr, _counter: number): void {
174
162
  throw new OracleMethodNotAvailableError('notifyCreatedNote');
175
163
  }
176
164
 
177
- notifyNullifiedNote(_innerNullifier: Fr, _innerNoteHash: Fr, _counter: number): Promise<void> {
165
+ notifyNullifiedNote(_innerNullifier: Fr, _noteHash: Fr, _counter: number): Promise<void> {
178
166
  throw new OracleMethodNotAvailableError('notifyNullifiedNote');
179
167
  }
180
168
 
@@ -255,21 +243,10 @@ export abstract class TypedOracle {
255
243
  _sideEffectCounter: number,
256
244
  _isStaticCall: boolean,
257
245
  _isDelegateCall: boolean,
258
- ): Promise<PrivateCallStackItem> {
246
+ ): Promise<{ endSideEffectCounter: Fr; returnsHash: Fr }> {
259
247
  throw new OracleMethodNotAvailableError('callPrivateFunction');
260
248
  }
261
249
 
262
- callPublicFunction(
263
- _targetContractAddress: AztecAddress,
264
- _functionSelector: FunctionSelector,
265
- _argsHash: Fr,
266
- _sideEffectCounter: number,
267
- _isStaticCall: boolean,
268
- _isDelegateCall: boolean,
269
- ): Promise<Fr[]> {
270
- throw new OracleMethodNotAvailableError('callPublicFunction');
271
- }
272
-
273
250
  enqueuePublicFunctionCall(
274
251
  _targetContractAddress: AztecAddress,
275
252
  _functionSelector: FunctionSelector,
@@ -277,7 +254,7 @@ export abstract class TypedOracle {
277
254
  _sideEffectCounter: number,
278
255
  _isStaticCall: boolean,
279
256
  _isDelegateCall: boolean,
280
- ): Promise<PublicCallRequest> {
257
+ ): Promise<void> {
281
258
  throw new OracleMethodNotAvailableError('enqueuePublicFunctionCall');
282
259
  }
283
260
 
@@ -288,10 +265,14 @@ export abstract class TypedOracle {
288
265
  _sideEffectCounter: number,
289
266
  _isStaticCall: boolean,
290
267
  _isDelegateCall: boolean,
291
- ): Promise<PublicCallRequest> {
268
+ ): Promise<void> {
292
269
  throw new OracleMethodNotAvailableError('setPublicTeardownFunctionCall');
293
270
  }
294
271
 
272
+ notifySetMinRevertibleSideEffectCounter(_minRevertibleSideEffectCounter: number): void {
273
+ throw new OracleMethodNotAvailableError('notifySetMinRevertibleSideEffectCounter');
274
+ }
275
+
295
276
  aes128Encrypt(_input: Buffer, _initializationVector: Buffer, _key: Buffer): Buffer {
296
277
  throw new OracleMethodNotAvailableError('encrypt');
297
278
  }
@@ -1,4 +1,3 @@
1
- import { ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH, type PublicCallRequest } from '@aztec/circuits.js';
2
1
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
3
2
  import { type EthAddress } from '@aztec/foundation/eth-address';
4
3
  import { Fr } from '@aztec/foundation/fields';
@@ -40,34 +39,6 @@ export function toACVMField(
40
39
  return `0x${adaptBufferSize(buffer).toString('hex')}`;
41
40
  }
42
41
 
43
- // Utilities to write TS classes to ACVM Field arrays
44
- // In the order that the ACVM expects them
45
-
46
- /**
47
- * Converts a public call stack item with the request for executing a public function to
48
- * a set of ACVM fields accepted by the enqueue_public_function_call_oracle Aztec.nr function.
49
- * Note that only the fields related to the request are serialized: those related to the result
50
- * are empty since this is just an execution request, so we don't send them to the circuit.
51
- * @param item - The public call stack item to serialize to be passed onto Noir.
52
- * @returns The fields expected by the enqueue_public_function_call_oracle Aztec.nr function.
53
- * TODO(#4380): Nuke this and replace it with PublicCallRequest.toFields()
54
- */
55
- export function toAcvmEnqueuePublicFunctionResult(item: PublicCallRequest): ACVMField[] {
56
- const fields = [
57
- item.contractAddress.toField(),
58
- item.functionSelector.toField(),
59
- ...item.callContext.toFields(),
60
- item.sideEffectCounter,
61
- item.getArgsHash(),
62
- ];
63
- if (fields.length !== ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH) {
64
- throw new Error(
65
- `Invalid length for EnqueuePublicFunctionResult (got ${fields.length} expected ${ENQUEUE_PUBLIC_FUNCTION_CALL_RETURN_LENGTH})`,
66
- );
67
- }
68
- return fields.map(toACVMField);
69
- }
70
-
71
42
  /**
72
43
  * Inserts a list of ACVM fields to a witness.
73
44
  * @param witnessStartIndex - The index where to start inserting the fields.
@@ -124,6 +124,7 @@ const BaseGasCosts: Record<Opcode, Gas> = {
124
124
  [Opcode.PEDERSEN]: DefaultBaseGasCost,
125
125
  [Opcode.ECADD]: DefaultBaseGasCost,
126
126
  [Opcode.MSM]: DefaultBaseGasCost,
127
+ [Opcode.PEDERSENCOMMITMENT]: DefaultBaseGasCost,
127
128
  // Conversions
128
129
  [Opcode.TORADIXLE]: DefaultBaseGasCost,
129
130
  // Other
@@ -91,6 +91,7 @@ export function initGlobalVariables(overrides?: Partial<GlobalVariables>): Globa
91
91
  overrides?.chainId ?? Fr.zero(),
92
92
  overrides?.version ?? Fr.zero(),
93
93
  overrides?.blockNumber ?? Fr.zero(),
94
+ overrides?.slotNumber ?? Fr.zero(),
94
95
  overrides?.timestamp ?? Fr.zero(),
95
96
  overrides?.coinbase ?? EthAddress.ZERO,
96
97
  overrides?.feeRecipient ?? AztecAddress.zero(),
@@ -0,0 +1,66 @@
1
+ import { pedersenCommit } from '@aztec/foundation/crypto';
2
+
3
+ import { type AvmContext } from '../avm_context.js';
4
+ import { Field, TypeTag, Uint8 } from '../avm_memory_types.js';
5
+ import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
6
+ import { Addressing } from './addressing_mode.js';
7
+ import { Instruction } from './instruction.js';
8
+
9
+ export class PedersenCommitment extends Instruction {
10
+ static type: string = 'PEDERSENCOMMITMENT';
11
+ static readonly opcode: Opcode = Opcode.PEDERSENCOMMITMENT;
12
+
13
+ // Informs (de)serialization. See Instruction.deserialize.
14
+ static readonly wireFormat: OperandType[] = [
15
+ OperandType.UINT8 /* Opcode */,
16
+ OperandType.UINT8 /* Indirect */,
17
+ OperandType.UINT32 /* Input Offset*/,
18
+ OperandType.UINT32 /* Dst Offset */,
19
+ OperandType.UINT32 /* Input Size Offset */,
20
+ OperandType.UINT32 /* Generator Index Offset */,
21
+ ];
22
+
23
+ constructor(
24
+ private indirect: number,
25
+ private inputOffset: number,
26
+ private outputOffset: number,
27
+ private inputSizeOffset: number,
28
+ private genIndexOffset: number,
29
+ ) {
30
+ super();
31
+ }
32
+
33
+ public async execute(context: AvmContext): Promise<void> {
34
+ const memory = context.machineState.memory.track(this.type);
35
+ const [inputOffset, outputOffset, inputSizeOffset, genIndexOffset] = Addressing.fromWire(this.indirect).resolve(
36
+ [this.inputOffset, this.outputOffset, this.inputSizeOffset, this.genIndexOffset],
37
+ memory,
38
+ );
39
+
40
+ const inputSize = memory.get(inputSizeOffset).toNumber();
41
+ memory.checkTag(TypeTag.UINT32, inputSizeOffset);
42
+
43
+ const inputs = memory.getSlice(inputOffset, inputSize);
44
+ memory.checkTagsRange(TypeTag.FIELD, inputOffset, inputSize);
45
+
46
+ const generatorIndex = memory.get(genIndexOffset).toNumber();
47
+ memory.checkTag(TypeTag.UINT32, genIndexOffset);
48
+
49
+ const memoryOperations = { reads: inputSize + 2, writes: 3, indirect: this.indirect };
50
+ context.machineState.consumeGas(this.gasCost(memoryOperations));
51
+
52
+ const inputBuffer: Buffer[] = inputs.map(input => input.toBuffer());
53
+ // TODO: Add the generate index to the pedersenCommit function
54
+ const commitment = pedersenCommit(inputBuffer, generatorIndex).map(f => new Field(f));
55
+ // The function doesnt include a flag if the output point is infinity, come back to this
56
+ // for now we just check if theyre zero - until we know how bb encodes them
57
+ const isInfinity = commitment[0].equals(new Field(0)) && commitment[1].equals(new Field(0));
58
+
59
+ memory.set(outputOffset, commitment[0]); // Field typed
60
+ memory.set(outputOffset + 1, commitment[1]); // Field typed
61
+ memory.set(outputOffset + 2, new Uint8(isInfinity ? 1 : 0)); // U8 typed
62
+
63
+ memory.assert(memoryOperations);
64
+ context.machineState.incrementPc();
65
+ }
66
+ }
@@ -1,3 +1,4 @@
1
+ import { PedersenCommitment } from '../opcodes/commitment.js';
1
2
  import { DAGasLeft, L2GasLeft } from '../opcodes/context_getters.js';
2
3
  import { EcAdd } from '../opcodes/ec_add.js';
3
4
  import { Keccak, KeccakF1600, Pedersen, Poseidon2, Sha256 } from '../opcodes/hashing.js';
@@ -146,6 +147,7 @@ const INSTRUCTION_SET = () =>
146
147
  [Sha256.opcode, Sha256],
147
148
  [Pedersen.opcode, Pedersen],
148
149
  [MultiScalarMul.opcode, MultiScalarMul],
150
+ [PedersenCommitment.opcode, PedersenCommitment],
149
151
  // Conversions
150
152
  [ToRadixLE.opcode, ToRadixLE],
151
153
  // Future Gadgets -- pending changes in noir
@@ -78,6 +78,7 @@ export enum Opcode {
78
78
  PEDERSEN, // temp - may be removed, but alot of contracts rely on it
79
79
  ECADD,
80
80
  MSM,
81
+ PEDERSENCOMMITMENT,
81
82
  // Conversion
82
83
  TORADIXLE,
83
84
  // Future Gadgets -- pending changes in noir
@@ -86,7 +87,7 @@ export enum Opcode {
86
87
  }
87
88
 
88
89
  // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
89
- // See vm/avm_trace/avm_deserialization.cpp)
90
+ // See vm/avm_trace/deserialization.cpp)
90
91
  // Note that cpp code introduced an additional enum value TAG to express the instruction tag. In TS,
91
92
  // this one is parsed as UINT8.
92
93
  export enum OperandType {
@@ -8,6 +8,7 @@ import {
8
8
  L1NotePayload,
9
9
  Note,
10
10
  type NoteStatus,
11
+ PublicExecutionRequest,
11
12
  TaggedLog,
12
13
  type UnencryptedL2Log,
13
14
  } from '@aztec/circuit-types';
@@ -17,7 +18,6 @@ import {
17
18
  type Header,
18
19
  type KeyValidationRequest,
19
20
  PrivateContextInputs,
20
- PublicCallRequest,
21
21
  type TxContext,
22
22
  } from '@aztec/circuits.js';
23
23
  import { Aes128 } from '@aztec/circuits.js/barretenberg';
@@ -30,7 +30,7 @@ import {
30
30
  countArgumentsSize,
31
31
  } from '@aztec/foundation/abi';
32
32
  import { type AztecAddress } from '@aztec/foundation/aztec-address';
33
- import { pedersenHash } from '@aztec/foundation/crypto';
33
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
34
34
  import { Fr, GrumpkinScalar, type Point } from '@aztec/foundation/fields';
35
35
  import { applyStringFormatting, createDebugLogger } from '@aztec/foundation/log';
36
36
 
@@ -38,7 +38,13 @@ import { type NoteData, toACVMWitness } from '../acvm/index.js';
38
38
  import { type PackedValuesCache } from '../common/packed_values_cache.js';
39
39
  import { type DBOracle } from './db_oracle.js';
40
40
  import { type ExecutionNoteCache } from './execution_note_cache.js';
41
- import { CountedLog, CountedNoteLog, type ExecutionResult, type NoteAndSlot } from './execution_result.js';
41
+ import {
42
+ CountedLog,
43
+ CountedNoteLog,
44
+ CountedPublicExecutionRequest,
45
+ type ExecutionResult,
46
+ type NoteAndSlot,
47
+ } from './execution_result.js';
42
48
  import { pickNotes } from './pick_notes.js';
43
49
  import { executePrivateFunction } from './private_execution.js';
44
50
  import { ViewDataOracle } from './view_data_oracle.js';
@@ -65,13 +71,13 @@ export class ClientExecutionContext extends ViewDataOracle {
65
71
  * They should act as references for the read requests output by an app circuit via public inputs.
66
72
  */
67
73
  private noteHashLeafIndexMap: Map<bigint, bigint> = new Map();
68
- private nullifiedNoteHashCounters: Map<number, number> = new Map();
74
+ private noteHashNullifierCounterMap: Map<number, number> = new Map();
69
75
  private noteEncryptedLogs: CountedNoteLog[] = [];
70
76
  private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
71
77
  private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
72
78
  private nestedExecutions: ExecutionResult[] = [];
73
- private enqueuedPublicFunctionCalls: PublicCallRequest[] = [];
74
- private publicTeardownFunctionCall: PublicCallRequest = PublicCallRequest.empty();
79
+ private enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[] = [];
80
+ private publicTeardownFunctionCall: PublicExecutionRequest = PublicExecutionRequest.empty();
75
81
 
76
82
  constructor(
77
83
  contractAddress: AztecAddress,
@@ -88,8 +94,9 @@ export class ClientExecutionContext extends ViewDataOracle {
88
94
  private node: AztecNode,
89
95
  protected sideEffectCounter: number = 0,
90
96
  log = createDebugLogger('aztec:simulator:client_execution_context'),
97
+ scopes?: AztecAddress[],
91
98
  ) {
92
- super(contractAddress, authWitnesses, db, node, log);
99
+ super(contractAddress, authWitnesses, db, node, log, scopes);
93
100
  }
94
101
 
95
102
  // We still need this function until we can get user-defined ordering of structs for fn arguments
@@ -129,14 +136,13 @@ export class ClientExecutionContext extends ViewDataOracle {
129
136
 
130
137
  /**
131
138
  * Get the data for the newly created notes.
132
- * @param innerNoteHashes - Inner note hashes for the notes.
133
139
  */
134
140
  public getNewNotes(): NoteAndSlot[] {
135
141
  return this.newNotes;
136
142
  }
137
143
 
138
- public getNullifiedNoteHashCounters() {
139
- return this.nullifiedNoteHashCounters;
144
+ public getNoteHashNullifierCounterMap() {
145
+ return this.noteHashNullifierCounterMap;
140
146
  }
141
147
 
142
148
  /**
@@ -245,7 +251,7 @@ export class ClientExecutionContext extends ViewDataOracle {
245
251
  const pendingNotes = this.noteCache.getNotes(this.callContext.storageContractAddress, storageSlot);
246
252
 
247
253
  const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.storageContractAddress);
248
- const dbNotes = await this.db.getNotes(this.callContext.storageContractAddress, storageSlot, status);
254
+ const dbNotes = await this.db.getNotes(this.callContext.storageContractAddress, storageSlot, status, this.scopes);
249
255
  const dbNotesFiltered = dbNotes.filter(n => !pendingNullifiers.has((n.siloedNullifier as Fr).value));
250
256
 
251
257
  const notes = pickNotes<NoteData>([...dbNotesFiltered, ...pendingNotes], {
@@ -270,12 +276,9 @@ export class ClientExecutionContext extends ViewDataOracle {
270
276
 
271
277
  notes.forEach(n => {
272
278
  if (n.index !== undefined) {
273
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
274
- // Should always call computeUniqueNoteHash when publicly created notes include nonces.
275
- const uniqueNoteHash = n.nonce.isZero() ? n.innerNoteHash : computeUniqueNoteHash(n.nonce, n.innerNoteHash);
279
+ const uniqueNoteHash = computeUniqueNoteHash(n.nonce, n.noteHash);
276
280
  const siloedNoteHash = siloNoteHash(n.contractAddress, uniqueNoteHash);
277
- const noteHashForReadRequest = siloedNoteHash;
278
- this.noteHashLeafIndexMap.set(noteHashForReadRequest.toBigInt(), n.index);
281
+ this.noteHashLeafIndexMap.set(siloedNoteHash.toBigInt(), n.index);
279
282
  }
280
283
  });
281
284
 
@@ -289,14 +292,14 @@ export class ClientExecutionContext extends ViewDataOracle {
289
292
  * @param storageSlot - The storage slot.
290
293
  * @param noteTypeId - The type ID of the note.
291
294
  * @param noteItems - The items to be included in a Note.
292
- * @param innerNoteHash - The inner note hash of the new note.
295
+ * @param noteHash - A hash of the new note.
293
296
  * @returns
294
297
  */
295
298
  public override notifyCreatedNote(
296
299
  storageSlot: Fr,
297
300
  noteTypeId: NoteSelector,
298
301
  noteItems: Fr[],
299
- innerNoteHash: Fr,
302
+ noteHash: Fr,
300
303
  counter: number,
301
304
  ) {
302
305
  const note = new Note(noteItems);
@@ -307,7 +310,7 @@ export class ClientExecutionContext extends ViewDataOracle {
307
310
  nonce: Fr.ZERO, // Nonce cannot be known during private execution.
308
311
  note,
309
312
  siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note.
310
- innerNoteHash,
313
+ noteHash,
311
314
  },
312
315
  counter,
313
316
  );
@@ -322,16 +325,16 @@ export class ClientExecutionContext extends ViewDataOracle {
322
325
  * Adding a siloed nullifier into the current set of all pending nullifiers created
323
326
  * within the current transaction/execution.
324
327
  * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
325
- * @param innerNoteHash - The inner note hash of the new note.
328
+ * @param noteHash - A hash of the new note.
326
329
  */
327
- public override notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr, counter: number) {
330
+ public override notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number) {
328
331
  const nullifiedNoteHashCounter = this.noteCache.nullifyNote(
329
332
  this.callContext.storageContractAddress,
330
333
  innerNullifier,
331
- innerNoteHash,
334
+ noteHash,
332
335
  );
333
336
  if (nullifiedNoteHashCounter !== undefined) {
334
- this.nullifiedNoteHashCounters.set(nullifiedNoteHashCounter, counter);
337
+ this.noteHashNullifierCounterMap.set(nullifiedNoteHashCounter, counter);
335
338
  }
336
339
  return Promise.resolve();
337
340
  }
@@ -354,7 +357,7 @@ export class ClientExecutionContext extends ViewDataOracle {
354
357
  // An app providing randomness = 0 signals to not mask the address.
355
358
  const maskedContractAddress = randomness.isZero()
356
359
  ? contractAddress.toField()
357
- : pedersenHash([contractAddress, randomness], 0);
360
+ : poseidon2HashWithSeparator([contractAddress, randomness], 0);
358
361
  const encryptedLog = new CountedLog(new EncryptedL2Log(encryptedEvent, maskedContractAddress), counter);
359
362
  this.encryptedLogs.push(encryptedLog);
360
363
  }
@@ -513,6 +516,8 @@ export class ClientExecutionContext extends ViewDataOracle {
513
516
  this.db,
514
517
  this.node,
515
518
  sideEffectCounter,
519
+ this.log,
520
+ this.scopes,
516
521
  );
517
522
 
518
523
  const childExecutionResult = await executePrivateFunction(
@@ -528,7 +533,11 @@ export class ClientExecutionContext extends ViewDataOracle {
528
533
 
529
534
  this.nestedExecutions.push(childExecutionResult);
530
535
 
531
- return childExecutionResult.callStackItem;
536
+ const publicInputs = childExecutionResult.callStackItem.publicInputs;
537
+ return {
538
+ endSideEffectCounter: publicInputs.endSideEffectCounter,
539
+ returnsHash: publicInputs.returnsHash,
540
+ };
532
541
  }
533
542
 
534
543
  /**
@@ -540,7 +549,7 @@ export class ClientExecutionContext extends ViewDataOracle {
540
549
  * @param isStaticCall - Whether the call is a static call.
541
550
  * @returns The public call stack item with the request information.
542
551
  */
543
- protected async createPublicCallRequest(
552
+ protected async createPublicExecutionRequest(
544
553
  callType: 'enqueued' | 'teardown',
545
554
  targetContractAddress: AztecAddress,
546
555
  functionSelector: FunctionSelector,
@@ -548,9 +557,7 @@ export class ClientExecutionContext extends ViewDataOracle {
548
557
  sideEffectCounter: number,
549
558
  isStaticCall: boolean,
550
559
  isDelegateCall: boolean,
551
- ): Promise<PublicCallRequest> {
552
- isStaticCall = isStaticCall || this.callContext.isStaticCall;
553
-
560
+ ) {
554
561
  const targetArtifact = await this.db.getFunctionArtifact(targetContractAddress, functionSelector);
555
562
  const derivedCallContext = this.deriveCallContext(
556
563
  targetContractAddress,
@@ -560,22 +567,21 @@ export class ClientExecutionContext extends ViewDataOracle {
560
567
  );
561
568
  const args = this.packedValuesCache.unpack(argsHash);
562
569
 
563
- // TODO($846): if enqueued public calls are associated with global
564
- // side-effect counter, that will leak info about how many other private
565
- // side-effects occurred in the TX. Ultimately the private kernel should
566
- // just output everything in the proper order without any counters.
567
570
  this.log.verbose(
568
- `Created PublicCallRequest of type [${callType}], side-effect counter [${sideEffectCounter}] to ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
571
+ `Created PublicExecutionRequest of type [${callType}], side-effect counter [${sideEffectCounter}] to ${targetContractAddress}:${functionSelector}(${targetArtifact.name})`,
569
572
  );
570
573
 
571
- return PublicCallRequest.from({
574
+ const request = PublicExecutionRequest.from({
572
575
  args,
573
576
  callContext: derivedCallContext,
574
- parentCallContext: this.callContext,
575
- functionSelector,
576
577
  contractAddress: targetContractAddress,
577
- sideEffectCounter,
578
578
  });
579
+
580
+ if (callType === 'enqueued') {
581
+ this.enqueuedPublicFunctionCalls.push(new CountedPublicExecutionRequest(request, sideEffectCounter));
582
+ } else {
583
+ this.publicTeardownFunctionCall = request;
584
+ }
579
585
  }
580
586
 
581
587
  /**
@@ -596,8 +602,8 @@ export class ClientExecutionContext extends ViewDataOracle {
596
602
  sideEffectCounter: number,
597
603
  isStaticCall: boolean,
598
604
  isDelegateCall: boolean,
599
- ): Promise<PublicCallRequest> {
600
- const enqueuedRequest = await this.createPublicCallRequest(
605
+ ) {
606
+ await this.createPublicExecutionRequest(
601
607
  'enqueued',
602
608
  targetContractAddress,
603
609
  functionSelector,
@@ -606,10 +612,6 @@ export class ClientExecutionContext extends ViewDataOracle {
606
612
  isStaticCall,
607
613
  isDelegateCall,
608
614
  );
609
-
610
- this.enqueuedPublicFunctionCalls.push(enqueuedRequest);
611
-
612
- return enqueuedRequest;
613
615
  }
614
616
 
615
617
  /**
@@ -630,8 +632,8 @@ export class ClientExecutionContext extends ViewDataOracle {
630
632
  sideEffectCounter: number,
631
633
  isStaticCall: boolean,
632
634
  isDelegateCall: boolean,
633
- ): Promise<PublicCallRequest> {
634
- const publicTeardownFunctionCall = await this.createPublicCallRequest(
635
+ ) {
636
+ await this.createPublicExecutionRequest(
635
637
  'teardown',
636
638
  targetContractAddress,
637
639
  functionSelector,
@@ -640,10 +642,10 @@ export class ClientExecutionContext extends ViewDataOracle {
640
642
  isStaticCall,
641
643
  isDelegateCall,
642
644
  );
645
+ }
643
646
 
644
- this.publicTeardownFunctionCall = publicTeardownFunctionCall;
645
-
646
- return publicTeardownFunctionCall;
647
+ public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): void {
648
+ this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
647
649
  }
648
650
 
649
651
  /**
@@ -78,12 +78,18 @@ export interface DBOracle extends CommitmentsDB {
78
78
  * The query result is paginated using 'limit' and 'offset' values.
79
79
  * Returns an object containing an array of note data.
80
80
  *
81
- * @param contractAddress - The AztecAddress instance representing the contract address.
82
- * @param storageSlot - The Fr instance representing the storage slot of the notes.
81
+ * @param contractAddress - The contract address of the notes.
82
+ * @param storageSlot - The storage slot of the notes.
83
83
  * @param status - The status of notes to fetch.
84
+ * @param scopes - The accounts whose notes we can access in this call. Currently optional and will default to all.
84
85
  * @returns A Promise that resolves to an array of note data.
85
86
  */
86
- getNotes(contractAddress: AztecAddress, storageSlot: Fr, status: NoteStatus): Promise<NoteData[]>;
87
+ getNotes(
88
+ contractAddress: AztecAddress,
89
+ storageSlot: Fr,
90
+ status: NoteStatus,
91
+ scopes?: AztecAddress[],
92
+ ): Promise<NoteData[]>;
87
93
 
88
94
  /**
89
95
  * Retrieve the artifact information of a specific function within a contract.