@aztec/simulator 0.47.1 → 0.49.2

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 (103) hide show
  1. package/dest/acvm/acvm.d.ts +2 -2
  2. package/dest/acvm/acvm.d.ts.map +1 -1
  3. package/dest/acvm/acvm.js +12 -7
  4. package/dest/acvm/oracle/oracle.d.ts +3 -3
  5. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/oracle.js +8 -9
  7. package/dest/acvm/oracle/typed_oracle.d.ts +5 -5
  8. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  9. package/dest/acvm/oracle/typed_oracle.js +6 -6
  10. package/dest/avm/avm_gas.d.ts +1 -0
  11. package/dest/avm/avm_gas.d.ts.map +1 -1
  12. package/dest/avm/avm_gas.js +142 -79
  13. package/dest/avm/fixtures/index.d.ts.map +1 -1
  14. package/dest/avm/fixtures/index.js +2 -2
  15. package/dest/avm/opcodes/accrued_substate.js +2 -2
  16. package/dest/avm/opcodes/commitment.js +4 -4
  17. package/dest/avm/opcodes/conversion.js +2 -2
  18. package/dest/avm/opcodes/external_calls.js +4 -4
  19. package/dest/avm/opcodes/instruction.d.ts +2 -1
  20. package/dest/avm/opcodes/instruction.d.ts.map +1 -1
  21. package/dest/avm/opcodes/instruction.js +8 -5
  22. package/dest/avm/opcodes/memory.js +2 -2
  23. package/dest/avm/opcodes/storage.js +3 -3
  24. package/dest/avm/serialization/instruction_serialization.js +2 -2
  25. package/dest/client/client_execution_context.d.ts +8 -8
  26. package/dest/client/client_execution_context.d.ts.map +1 -1
  27. package/dest/client/client_execution_context.js +22 -23
  28. package/dest/client/db_oracle.d.ts +4 -3
  29. package/dest/client/db_oracle.d.ts.map +1 -1
  30. package/dest/client/execution_note_cache.d.ts +17 -13
  31. package/dest/client/execution_note_cache.d.ts.map +1 -1
  32. package/dest/client/execution_note_cache.js +65 -26
  33. package/dest/client/execution_result.d.ts +3 -2
  34. package/dest/client/execution_result.d.ts.map +1 -1
  35. package/dest/client/execution_result.js +20 -9
  36. package/dest/client/private_execution.js +3 -3
  37. package/dest/client/simulator.d.ts +7 -6
  38. package/dest/client/simulator.d.ts.map +1 -1
  39. package/dest/client/simulator.js +14 -12
  40. package/dest/client/test_utils.d.ts +9 -0
  41. package/dest/client/test_utils.d.ts.map +1 -0
  42. package/dest/client/test_utils.js +21 -0
  43. package/dest/client/view_data_oracle.d.ts +2 -1
  44. package/dest/client/view_data_oracle.d.ts.map +1 -1
  45. package/dest/client/view_data_oracle.js +4 -3
  46. package/dest/index.d.ts +0 -1
  47. package/dest/index.d.ts.map +1 -1
  48. package/dest/index.js +1 -2
  49. package/dest/providers/acvm_native.js +2 -2
  50. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  51. package/dest/public/abstract_phase_manager.js +3 -3
  52. package/dest/public/executor.d.ts +4 -1
  53. package/dest/public/executor.d.ts.map +1 -1
  54. package/dest/public/executor.js +10 -2
  55. package/dest/public/executor_metrics.d.ts +10 -0
  56. package/dest/public/executor_metrics.d.ts.map +1 -0
  57. package/dest/public/executor_metrics.js +32 -0
  58. package/dest/public/fee_payment.d.ts +2 -2
  59. package/dest/public/fee_payment.d.ts.map +1 -1
  60. package/dest/public/fee_payment.js +9 -10
  61. package/dest/public/hints_builder.d.ts.map +1 -1
  62. package/dest/public/hints_builder.js +1 -1
  63. package/dest/public/public_processor.d.ts +6 -5
  64. package/dest/public/public_processor.d.ts.map +1 -1
  65. package/dest/public/public_processor.js +38 -18
  66. package/dest/public/public_processor_metrics.d.ts +19 -0
  67. package/dest/public/public_processor_metrics.d.ts.map +1 -0
  68. package/dest/public/public_processor_metrics.js +59 -0
  69. package/package.json +9 -9
  70. package/src/acvm/acvm.ts +14 -5
  71. package/src/acvm/oracle/oracle.ts +8 -23
  72. package/src/acvm/oracle/typed_oracle.ts +8 -21
  73. package/src/avm/avm_gas.ts +145 -79
  74. package/src/avm/fixtures/index.ts +1 -0
  75. package/src/avm/opcodes/accrued_substate.ts +1 -1
  76. package/src/avm/opcodes/commitment.ts +3 -3
  77. package/src/avm/opcodes/conversion.ts +1 -1
  78. package/src/avm/opcodes/external_calls.ts +3 -3
  79. package/src/avm/opcodes/instruction.ts +7 -4
  80. package/src/avm/opcodes/memory.ts +1 -1
  81. package/src/avm/opcodes/storage.ts +2 -2
  82. package/src/avm/serialization/instruction_serialization.ts +1 -1
  83. package/src/client/client_execution_context.ts +23 -20
  84. package/src/client/db_oracle.ts +9 -3
  85. package/src/client/execution_note_cache.ts +76 -25
  86. package/src/client/execution_result.ts +29 -9
  87. package/src/client/private_execution.ts +2 -2
  88. package/src/client/simulator.ts +18 -14
  89. package/src/client/test_utils.ts +30 -0
  90. package/src/client/view_data_oracle.ts +2 -1
  91. package/src/index.ts +0 -1
  92. package/src/providers/acvm_native.ts +1 -1
  93. package/src/public/abstract_phase_manager.ts +1 -2
  94. package/src/public/executor.ts +14 -1
  95. package/src/public/executor_metrics.ts +48 -0
  96. package/src/public/fee_payment.ts +8 -10
  97. package/src/public/hints_builder.ts +2 -2
  98. package/src/public/public_processor.ts +52 -20
  99. package/src/public/public_processor_metrics.ts +92 -0
  100. package/dest/utils.d.ts +0 -12
  101. package/dest/utils.d.ts.map +0 -1
  102. package/dest/utils.js +0 -11
  103. package/src/utils.ts +0 -18
@@ -1,3 +1,5 @@
1
+ import * as c from '@aztec/circuits.js/constants';
2
+
1
3
  import { TypeTag } from './avm_memory_types.js';
2
4
  import { InstructionExecutionError } from './errors.js';
3
5
  import { Addressing, AddressingMode } from './opcodes/addressing_mode.js';
@@ -46,90 +48,150 @@ export const EmptyGas: Gas = {
46
48
  daGas: 0,
47
49
  };
48
50
 
51
+ function makeCost(l2Gas: number, daGas: number): Gas {
52
+ return { l2Gas, daGas };
53
+ }
54
+
49
55
  /** Dimensions of gas usage: L1, L2, and DA. */
50
56
  export const GasDimensions = ['l2Gas', 'daGas'] as const;
51
57
 
52
- /** Default gas cost for an opcode. */
53
- const DefaultBaseGasCost: Gas = { l2Gas: 10, daGas: 0 };
54
-
55
58
  /** Base gas costs for each instruction. Additional gas cost may be added on top due to memory or storage accesses, etc. */
56
59
  const BaseGasCosts: Record<Opcode, Gas> = {
57
- [Opcode.ADD]: DefaultBaseGasCost,
58
- [Opcode.SUB]: DefaultBaseGasCost,
59
- [Opcode.MUL]: DefaultBaseGasCost,
60
- [Opcode.DIV]: DefaultBaseGasCost,
61
- [Opcode.FDIV]: DefaultBaseGasCost,
62
- [Opcode.EQ]: DefaultBaseGasCost,
63
- [Opcode.LT]: DefaultBaseGasCost,
64
- [Opcode.LTE]: DefaultBaseGasCost,
65
- [Opcode.AND]: DefaultBaseGasCost,
66
- [Opcode.OR]: DefaultBaseGasCost,
67
- [Opcode.XOR]: DefaultBaseGasCost,
68
- [Opcode.NOT]: DefaultBaseGasCost,
69
- [Opcode.SHL]: DefaultBaseGasCost,
70
- [Opcode.SHR]: DefaultBaseGasCost,
71
- [Opcode.CAST]: DefaultBaseGasCost,
72
- // Execution environment
73
- [Opcode.ADDRESS]: DefaultBaseGasCost,
74
- [Opcode.STORAGEADDRESS]: DefaultBaseGasCost,
75
- [Opcode.SENDER]: DefaultBaseGasCost,
76
- [Opcode.FEEPERL2GAS]: DefaultBaseGasCost,
77
- [Opcode.FEEPERDAGAS]: DefaultBaseGasCost,
78
- [Opcode.TRANSACTIONFEE]: DefaultBaseGasCost,
79
- [Opcode.FUNCTIONSELECTOR]: DefaultBaseGasCost,
80
- [Opcode.CHAINID]: DefaultBaseGasCost,
81
- [Opcode.VERSION]: DefaultBaseGasCost,
82
- [Opcode.BLOCKNUMBER]: DefaultBaseGasCost,
83
- [Opcode.TIMESTAMP]: DefaultBaseGasCost,
84
- [Opcode.COINBASE]: DefaultBaseGasCost,
85
- [Opcode.BLOCKL2GASLIMIT]: DefaultBaseGasCost,
86
- [Opcode.BLOCKDAGASLIMIT]: DefaultBaseGasCost,
87
- [Opcode.CALLDATACOPY]: DefaultBaseGasCost,
88
- // Gas
89
- [Opcode.L2GASLEFT]: DefaultBaseGasCost,
90
- [Opcode.DAGASLEFT]: DefaultBaseGasCost,
91
- // Control flow
92
- [Opcode.JUMP]: DefaultBaseGasCost,
93
- [Opcode.JUMPI]: DefaultBaseGasCost,
94
- [Opcode.INTERNALCALL]: DefaultBaseGasCost,
95
- [Opcode.INTERNALRETURN]: DefaultBaseGasCost,
96
- // Memory
97
- [Opcode.SET]: DefaultBaseGasCost,
98
- [Opcode.MOV]: DefaultBaseGasCost,
99
- [Opcode.CMOV]: DefaultBaseGasCost,
100
- // World state
101
- [Opcode.SLOAD]: DefaultBaseGasCost,
102
- [Opcode.SSTORE]: DefaultBaseGasCost,
103
- [Opcode.NOTEHASHEXISTS]: DefaultBaseGasCost,
104
- [Opcode.EMITNOTEHASH]: DefaultBaseGasCost,
105
- [Opcode.NULLIFIEREXISTS]: DefaultBaseGasCost,
106
- [Opcode.EMITNULLIFIER]: DefaultBaseGasCost,
107
- [Opcode.L1TOL2MSGEXISTS]: DefaultBaseGasCost,
108
- [Opcode.HEADERMEMBER]: DefaultBaseGasCost,
109
- [Opcode.EMITUNENCRYPTEDLOG]: DefaultBaseGasCost,
110
- [Opcode.SENDL2TOL1MSG]: DefaultBaseGasCost,
111
- [Opcode.GETCONTRACTINSTANCE]: DefaultBaseGasCost,
112
- // External calls
113
- [Opcode.CALL]: DefaultBaseGasCost,
114
- [Opcode.STATICCALL]: DefaultBaseGasCost,
115
- [Opcode.DELEGATECALL]: DefaultBaseGasCost,
116
- [Opcode.RETURN]: DefaultBaseGasCost,
117
- [Opcode.REVERT]: DefaultBaseGasCost,
118
- // Misc
119
- [Opcode.DEBUGLOG]: DefaultBaseGasCost,
120
- // Gadgets
121
- [Opcode.KECCAK]: DefaultBaseGasCost,
122
- [Opcode.POSEIDON2]: DefaultBaseGasCost,
123
- [Opcode.SHA256]: DefaultBaseGasCost,
124
- [Opcode.PEDERSEN]: DefaultBaseGasCost,
125
- [Opcode.ECADD]: DefaultBaseGasCost,
126
- [Opcode.MSM]: DefaultBaseGasCost,
127
- [Opcode.PEDERSENCOMMITMENT]: DefaultBaseGasCost,
128
- // Conversions
129
- [Opcode.TORADIXLE]: DefaultBaseGasCost,
130
- // Other
131
- [Opcode.SHA256COMPRESSION]: DefaultBaseGasCost,
132
- [Opcode.KECCAKF1600]: DefaultBaseGasCost,
60
+ [Opcode.ADD]: makeCost(c.AVM_ADD_BASE_L2_GAS, 0),
61
+ [Opcode.SUB]: makeCost(c.AVM_SUB_BASE_L2_GAS, 0),
62
+ [Opcode.MUL]: makeCost(c.AVM_MUL_BASE_L2_GAS, 0),
63
+ [Opcode.DIV]: makeCost(c.AVM_DIV_BASE_L2_GAS, 0),
64
+ [Opcode.FDIV]: makeCost(c.AVM_FDIV_BASE_L2_GAS, 0),
65
+ [Opcode.EQ]: makeCost(c.AVM_EQ_BASE_L2_GAS, 0),
66
+ [Opcode.LT]: makeCost(c.AVM_LT_BASE_L2_GAS, 0),
67
+ [Opcode.LTE]: makeCost(c.AVM_LTE_BASE_L2_GAS, 0),
68
+ [Opcode.AND]: makeCost(c.AVM_AND_BASE_L2_GAS, 0),
69
+ [Opcode.OR]: makeCost(c.AVM_OR_BASE_L2_GAS, 0),
70
+ [Opcode.XOR]: makeCost(c.AVM_XOR_BASE_L2_GAS, 0),
71
+ [Opcode.NOT]: makeCost(c.AVM_NOT_BASE_L2_GAS, 0),
72
+ [Opcode.SHL]: makeCost(c.AVM_SHL_BASE_L2_GAS, 0),
73
+ [Opcode.SHR]: makeCost(c.AVM_SHR_BASE_L2_GAS, 0),
74
+ [Opcode.CAST]: makeCost(c.AVM_CAST_BASE_L2_GAS, 0),
75
+ [Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_BASE_L2_GAS, 0),
76
+ [Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_BASE_L2_GAS, 0),
77
+ [Opcode.SENDER]: makeCost(c.AVM_SENDER_BASE_L2_GAS, 0),
78
+ [Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_BASE_L2_GAS, 0),
79
+ [Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_BASE_L2_GAS, 0),
80
+ [Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_BASE_L2_GAS, 0),
81
+ [Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_BASE_L2_GAS, 0),
82
+ [Opcode.CHAINID]: makeCost(c.AVM_CHAINID_BASE_L2_GAS, 0),
83
+ [Opcode.VERSION]: makeCost(c.AVM_VERSION_BASE_L2_GAS, 0),
84
+ [Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_BASE_L2_GAS, 0),
85
+ [Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_BASE_L2_GAS, 0),
86
+ [Opcode.COINBASE]: makeCost(c.AVM_COINBASE_BASE_L2_GAS, 0),
87
+ [Opcode.BLOCKL2GASLIMIT]: makeCost(c.AVM_BLOCKL2GASLIMIT_BASE_L2_GAS, 0),
88
+ [Opcode.BLOCKDAGASLIMIT]: makeCost(c.AVM_BLOCKDAGASLIMIT_BASE_L2_GAS, 0),
89
+ [Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_BASE_L2_GAS, 0),
90
+ [Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_BASE_L2_GAS, 0),
91
+ [Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_BASE_L2_GAS, 0),
92
+ [Opcode.JUMP]: makeCost(c.AVM_JUMP_BASE_L2_GAS, 0),
93
+ [Opcode.JUMPI]: makeCost(c.AVM_JUMPI_BASE_L2_GAS, 0),
94
+ [Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_BASE_L2_GAS, 0),
95
+ [Opcode.INTERNALRETURN]: makeCost(c.AVM_INTERNALRETURN_BASE_L2_GAS, 0),
96
+ [Opcode.SET]: makeCost(c.AVM_SET_BASE_L2_GAS, 0),
97
+ [Opcode.MOV]: makeCost(c.AVM_MOV_BASE_L2_GAS, 0),
98
+ [Opcode.CMOV]: makeCost(c.AVM_CMOV_BASE_L2_GAS, 0),
99
+ [Opcode.SLOAD]: makeCost(c.AVM_SLOAD_BASE_L2_GAS, 0),
100
+ [Opcode.SSTORE]: makeCost(c.AVM_SSTORE_BASE_L2_GAS, 0),
101
+ [Opcode.NOTEHASHEXISTS]: makeCost(c.AVM_NOTEHASHEXISTS_BASE_L2_GAS, 0),
102
+ [Opcode.EMITNOTEHASH]: makeCost(c.AVM_EMITNOTEHASH_BASE_L2_GAS, 0),
103
+ [Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_BASE_L2_GAS, 0),
104
+ [Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_BASE_L2_GAS, 0),
105
+ [Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_BASE_L2_GAS, 0),
106
+ [Opcode.HEADERMEMBER]: makeCost(c.AVM_HEADERMEMBER_BASE_L2_GAS, 0),
107
+ [Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_BASE_L2_GAS, 0),
108
+ [Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_BASE_L2_GAS, 0),
109
+ [Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_BASE_L2_GAS, 0),
110
+ [Opcode.CALL]: makeCost(c.AVM_CALL_BASE_L2_GAS, 0),
111
+ [Opcode.STATICCALL]: makeCost(c.AVM_STATICCALL_BASE_L2_GAS, 0),
112
+ [Opcode.DELEGATECALL]: makeCost(c.AVM_DELEGATECALL_BASE_L2_GAS, 0),
113
+ [Opcode.RETURN]: makeCost(c.AVM_RETURN_BASE_L2_GAS, 0),
114
+ [Opcode.REVERT]: makeCost(c.AVM_REVERT_BASE_L2_GAS, 0),
115
+ [Opcode.DEBUGLOG]: makeCost(c.AVM_DEBUGLOG_BASE_L2_GAS, 0),
116
+ [Opcode.KECCAK]: makeCost(c.AVM_KECCAK_BASE_L2_GAS, 0),
117
+ [Opcode.POSEIDON2]: makeCost(c.AVM_POSEIDON2_BASE_L2_GAS, 0),
118
+ [Opcode.SHA256]: makeCost(c.AVM_SHA256_BASE_L2_GAS, 0),
119
+ [Opcode.PEDERSEN]: makeCost(c.AVM_PEDERSEN_BASE_L2_GAS, 0),
120
+ [Opcode.ECADD]: makeCost(c.AVM_ECADD_BASE_L2_GAS, 0),
121
+ [Opcode.MSM]: makeCost(c.AVM_MSM_BASE_L2_GAS, 0),
122
+ [Opcode.PEDERSENCOMMITMENT]: makeCost(c.AVM_PEDERSENCOMMITMENT_BASE_L2_GAS, 0),
123
+ [Opcode.TORADIXLE]: makeCost(c.AVM_TORADIXLE_BASE_L2_GAS, 0),
124
+ [Opcode.SHA256COMPRESSION]: makeCost(c.AVM_SHA256COMPRESSION_BASE_L2_GAS, 0),
125
+ [Opcode.KECCAKF1600]: makeCost(c.AVM_KECCAKF1600_BASE_L2_GAS, 0),
126
+ };
127
+
128
+ const DynamicGasCosts: Record<Opcode, Gas> = {
129
+ [Opcode.ADD]: makeCost(c.AVM_ADD_DYN_L2_GAS, 0),
130
+ [Opcode.SUB]: makeCost(c.AVM_SUB_DYN_L2_GAS, 0),
131
+ [Opcode.MUL]: makeCost(c.AVM_MUL_DYN_L2_GAS, 0),
132
+ [Opcode.DIV]: makeCost(c.AVM_DIV_DYN_L2_GAS, 0),
133
+ [Opcode.FDIV]: makeCost(c.AVM_FDIV_DYN_L2_GAS, 0),
134
+ [Opcode.EQ]: makeCost(c.AVM_EQ_DYN_L2_GAS, 0),
135
+ [Opcode.LT]: makeCost(c.AVM_LT_DYN_L2_GAS, 0),
136
+ [Opcode.LTE]: makeCost(c.AVM_LTE_DYN_L2_GAS, 0),
137
+ [Opcode.AND]: makeCost(c.AVM_AND_DYN_L2_GAS, 0),
138
+ [Opcode.OR]: makeCost(c.AVM_OR_DYN_L2_GAS, 0),
139
+ [Opcode.XOR]: makeCost(c.AVM_XOR_DYN_L2_GAS, 0),
140
+ [Opcode.NOT]: makeCost(c.AVM_NOT_DYN_L2_GAS, 0),
141
+ [Opcode.SHL]: makeCost(c.AVM_SHL_DYN_L2_GAS, 0),
142
+ [Opcode.SHR]: makeCost(c.AVM_SHR_DYN_L2_GAS, 0),
143
+ [Opcode.CAST]: makeCost(c.AVM_CAST_DYN_L2_GAS, 0),
144
+ [Opcode.ADDRESS]: makeCost(c.AVM_ADDRESS_DYN_L2_GAS, 0),
145
+ [Opcode.STORAGEADDRESS]: makeCost(c.AVM_STORAGEADDRESS_DYN_L2_GAS, 0),
146
+ [Opcode.SENDER]: makeCost(c.AVM_SENDER_DYN_L2_GAS, 0),
147
+ [Opcode.FEEPERL2GAS]: makeCost(c.AVM_FEEPERL2GAS_DYN_L2_GAS, 0),
148
+ [Opcode.FEEPERDAGAS]: makeCost(c.AVM_FEEPERDAGAS_DYN_L2_GAS, 0),
149
+ [Opcode.TRANSACTIONFEE]: makeCost(c.AVM_TRANSACTIONFEE_DYN_L2_GAS, 0),
150
+ [Opcode.FUNCTIONSELECTOR]: makeCost(c.AVM_FUNCTIONSELECTOR_DYN_L2_GAS, 0),
151
+ [Opcode.CHAINID]: makeCost(c.AVM_CHAINID_DYN_L2_GAS, 0),
152
+ [Opcode.VERSION]: makeCost(c.AVM_VERSION_DYN_L2_GAS, 0),
153
+ [Opcode.BLOCKNUMBER]: makeCost(c.AVM_BLOCKNUMBER_DYN_L2_GAS, 0),
154
+ [Opcode.TIMESTAMP]: makeCost(c.AVM_TIMESTAMP_DYN_L2_GAS, 0),
155
+ [Opcode.COINBASE]: makeCost(c.AVM_COINBASE_DYN_L2_GAS, 0),
156
+ [Opcode.BLOCKL2GASLIMIT]: makeCost(c.AVM_BLOCKL2GASLIMIT_DYN_L2_GAS, 0),
157
+ [Opcode.BLOCKDAGASLIMIT]: makeCost(c.AVM_BLOCKDAGASLIMIT_DYN_L2_GAS, 0),
158
+ [Opcode.CALLDATACOPY]: makeCost(c.AVM_CALLDATACOPY_DYN_L2_GAS, 0),
159
+ [Opcode.L2GASLEFT]: makeCost(c.AVM_L2GASLEFT_DYN_L2_GAS, 0),
160
+ [Opcode.DAGASLEFT]: makeCost(c.AVM_DAGASLEFT_DYN_L2_GAS, 0),
161
+ [Opcode.JUMP]: makeCost(c.AVM_JUMP_DYN_L2_GAS, 0),
162
+ [Opcode.JUMPI]: makeCost(c.AVM_JUMPI_DYN_L2_GAS, 0),
163
+ [Opcode.INTERNALCALL]: makeCost(c.AVM_INTERNALCALL_DYN_L2_GAS, 0),
164
+ [Opcode.INTERNALRETURN]: makeCost(c.AVM_INTERNALRETURN_DYN_L2_GAS, 0),
165
+ [Opcode.SET]: makeCost(c.AVM_SET_DYN_L2_GAS, 0),
166
+ [Opcode.MOV]: makeCost(c.AVM_MOV_DYN_L2_GAS, 0),
167
+ [Opcode.CMOV]: makeCost(c.AVM_CMOV_DYN_L2_GAS, 0),
168
+ [Opcode.SLOAD]: makeCost(c.AVM_SLOAD_DYN_L2_GAS, 0),
169
+ [Opcode.SSTORE]: makeCost(c.AVM_SSTORE_DYN_L2_GAS, 0),
170
+ [Opcode.NOTEHASHEXISTS]: makeCost(c.AVM_NOTEHASHEXISTS_DYN_L2_GAS, 0),
171
+ [Opcode.EMITNOTEHASH]: makeCost(c.AVM_EMITNOTEHASH_DYN_L2_GAS, 0),
172
+ [Opcode.NULLIFIEREXISTS]: makeCost(c.AVM_NULLIFIEREXISTS_DYN_L2_GAS, 0),
173
+ [Opcode.EMITNULLIFIER]: makeCost(c.AVM_EMITNULLIFIER_DYN_L2_GAS, 0),
174
+ [Opcode.L1TOL2MSGEXISTS]: makeCost(c.AVM_L1TOL2MSGEXISTS_DYN_L2_GAS, 0),
175
+ [Opcode.HEADERMEMBER]: makeCost(c.AVM_HEADERMEMBER_DYN_L2_GAS, 0),
176
+ [Opcode.EMITUNENCRYPTEDLOG]: makeCost(c.AVM_EMITUNENCRYPTEDLOG_DYN_L2_GAS, 0),
177
+ [Opcode.SENDL2TOL1MSG]: makeCost(c.AVM_SENDL2TOL1MSG_DYN_L2_GAS, 0),
178
+ [Opcode.GETCONTRACTINSTANCE]: makeCost(c.AVM_GETCONTRACTINSTANCE_DYN_L2_GAS, 0),
179
+ [Opcode.CALL]: makeCost(c.AVM_CALL_DYN_L2_GAS, 0),
180
+ [Opcode.STATICCALL]: makeCost(c.AVM_STATICCALL_DYN_L2_GAS, 0),
181
+ [Opcode.DELEGATECALL]: makeCost(c.AVM_DELEGATECALL_DYN_L2_GAS, 0),
182
+ [Opcode.RETURN]: makeCost(c.AVM_RETURN_DYN_L2_GAS, 0),
183
+ [Opcode.REVERT]: makeCost(c.AVM_REVERT_DYN_L2_GAS, 0),
184
+ [Opcode.DEBUGLOG]: makeCost(c.AVM_DEBUGLOG_DYN_L2_GAS, 0),
185
+ [Opcode.KECCAK]: makeCost(c.AVM_KECCAK_DYN_L2_GAS, 0),
186
+ [Opcode.POSEIDON2]: makeCost(c.AVM_POSEIDON2_DYN_L2_GAS, 0),
187
+ [Opcode.SHA256]: makeCost(c.AVM_SHA256_DYN_L2_GAS, 0),
188
+ [Opcode.PEDERSEN]: makeCost(c.AVM_PEDERSEN_DYN_L2_GAS, 0),
189
+ [Opcode.ECADD]: makeCost(c.AVM_ECADD_DYN_L2_GAS, 0),
190
+ [Opcode.MSM]: makeCost(c.AVM_MSM_DYN_L2_GAS, 0),
191
+ [Opcode.PEDERSENCOMMITMENT]: makeCost(c.AVM_PEDERSENCOMMITMENT_DYN_L2_GAS, 0),
192
+ [Opcode.TORADIXLE]: makeCost(c.AVM_TORADIXLE_DYN_L2_GAS, 0),
193
+ [Opcode.SHA256COMPRESSION]: makeCost(c.AVM_SHA256COMPRESSION_DYN_L2_GAS, 0),
194
+ [Opcode.KECCAKF1600]: makeCost(c.AVM_KECCAKF1600_DYN_L2_GAS, 0),
133
195
  };
134
196
 
135
197
  /** Returns the fixed base gas cost for a given opcode. */
@@ -137,6 +199,10 @@ export function getBaseGasCost(opcode: Opcode): Gas {
137
199
  return BaseGasCosts[opcode];
138
200
  }
139
201
 
202
+ export function getDynamicGasCost(opcode: Opcode): Gas {
203
+ return DynamicGasCosts[opcode];
204
+ }
205
+
140
206
  /** Returns the gas cost associated with the memory operations performed. */
141
207
  export function getMemoryGasCost(args: { reads?: number; writes?: number; indirect?: number }) {
142
208
  const { reads, writes, indirect } = args;
@@ -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(),
@@ -241,7 +241,7 @@ export class EmitUnencryptedLog extends Instruction {
241
241
  const contractAddress = context.environment.address;
242
242
 
243
243
  const memoryOperations = { reads: 1 + logSize, indirect: this.indirect };
244
- context.machineState.consumeGas(this.gasCost(memoryOperations));
244
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: logSize }));
245
245
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
246
246
  context.persistableState.writeUnencryptedLog(contractAddress, log);
247
247
 
@@ -43,15 +43,15 @@ export class PedersenCommitment extends Instruction {
43
43
  const inputs = memory.getSlice(inputOffset, inputSize);
44
44
  memory.checkTagsRange(TypeTag.FIELD, inputOffset, inputSize);
45
45
 
46
- // Generator index not used for now since we dont utilise it in the pedersenCommit function
46
+ const generatorIndex = memory.get(genIndexOffset).toNumber();
47
47
  memory.checkTag(TypeTag.UINT32, genIndexOffset);
48
48
 
49
- const memoryOperations = { reads: inputSize + 1, writes: 3, indirect: this.indirect };
49
+ const memoryOperations = { reads: inputSize + 2, writes: 3, indirect: this.indirect };
50
50
  context.machineState.consumeGas(this.gasCost(memoryOperations));
51
51
 
52
52
  const inputBuffer: Buffer[] = inputs.map(input => input.toBuffer());
53
53
  // TODO: Add the generate index to the pedersenCommit function
54
- const commitment = pedersenCommit(inputBuffer).map(f => new Field(f));
54
+ const commitment = pedersenCommit(inputBuffer, generatorIndex).map(f => new Field(f));
55
55
  // The function doesnt include a flag if the output point is infinity, come back to this
56
56
  // for now we just check if theyre zero - until we know how bb encodes them
57
57
  const isInfinity = commitment[0].equals(new Field(0)) && commitment[1].equals(new Field(0));
@@ -35,7 +35,7 @@ export class ToRadixLE extends Instruction {
35
35
  const memory = context.machineState.memory.track(this.type);
36
36
  const [srcOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.srcOffset, this.dstOffset], memory);
37
37
  const memoryOperations = { reads: 1, writes: this.numLimbs, indirect: this.indirect };
38
- context.machineState.consumeGas(this.gasCost(memoryOperations));
38
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.numLimbs }));
39
39
 
40
40
  // The radix gadget only takes in a Field
41
41
  memory.checkTag(TypeTag.FIELD, srcOffset);
@@ -67,7 +67,7 @@ abstract class ExternalCall extends Instruction {
67
67
 
68
68
  // First we consume the gas for this operation.
69
69
  const memoryOperations = { reads: calldataSize + 5, writes: 1 + this.retSize, indirect: this.indirect };
70
- context.machineState.consumeGas(this.gasCost(memoryOperations));
70
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: calldataSize + this.retSize }));
71
71
  // Then we consume the gas allocated for the nested call. The excess will be refunded later.
72
72
  // Gas allocation is capped by the amount of gas left in the current context.
73
73
  // We have to do some dancing here because the gas allocation is a field,
@@ -170,7 +170,7 @@ export class Return extends Instruction {
170
170
  public async execute(context: AvmContext): Promise<void> {
171
171
  const memoryOperations = { reads: this.copySize, indirect: this.indirect };
172
172
  const memory = context.machineState.memory.track(this.type);
173
- context.machineState.consumeGas(this.gasCost(memoryOperations));
173
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.copySize }));
174
174
 
175
175
  const [returnOffset] = Addressing.fromWire(this.indirect).resolve([this.returnOffset], memory);
176
176
 
@@ -199,7 +199,7 @@ export class Revert extends Instruction {
199
199
  public async execute(context: AvmContext): Promise<void> {
200
200
  const memoryOperations = { reads: this.retSize, indirect: this.indirect };
201
201
  const memory = context.machineState.memory.track(this.type);
202
- context.machineState.consumeGas(this.gasCost(memoryOperations));
202
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.retSize }));
203
203
 
204
204
  const [returnOffset] = Addressing.fromWire(this.indirect).resolve([this.returnOffset], memory);
205
205
 
@@ -1,7 +1,7 @@
1
1
  import { strict as assert } from 'assert';
2
2
 
3
3
  import type { AvmContext } from '../avm_context.js';
4
- import { getBaseGasCost, sumGas } from '../avm_gas.js';
4
+ import { getBaseGasCost, getDynamicGasCost, mulGas, sumGas } from '../avm_gas.js';
5
5
  import { type MemoryOperations } from '../avm_memory_types.js';
6
6
  import { type BufferCursor } from '../serialization/buffer_cursor.js';
7
7
  import { Opcode, type OperandType, deserialize, serialize } from '../serialization/instruction_serialization.js';
@@ -67,12 +67,15 @@ export abstract class Instruction {
67
67
  * @param memoryOps Memory operations performed by the instruction.
68
68
  * @returns Gas cost.
69
69
  */
70
- protected gasCost(_memoryOps: Partial<MemoryOperations & { indirect: number }> = {}) {
70
+ protected gasCost(ops: Partial<MemoryOperations & { indirect: number; dynMultiplier: number }> = {}) {
71
71
  const baseGasCost = getBaseGasCost(this.opcode);
72
+ // TODO: We are using a simplified gas model to reduce complexity in the circuit.
73
+ // Memory accounting will probably be removed.
72
74
  // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6861): reconsider.
73
75
  // const memoryGasCost = getMemoryGasCost(memoryOps);
74
- const memoryGasCost = { l2Gas: 0, daGas: 0 };
75
- return sumGas(baseGasCost, memoryGasCost);
76
+ // const memoryGasCost = { l2Gas: 0, daGas: 0 };
77
+ const dynGasCost = mulGas(getDynamicGasCost(this.opcode), ops.dynMultiplier ?? 0);
78
+ return sumGas(baseGasCost, dynGasCost);
76
79
  }
77
80
 
78
81
  /**
@@ -208,7 +208,7 @@ export class CalldataCopy extends Instruction {
208
208
  public async execute(context: AvmContext): Promise<void> {
209
209
  const memoryOperations = { writes: this.copySize, indirect: this.indirect };
210
210
  const memory = context.machineState.memory.track(this.type);
211
- context.machineState.consumeGas(this.gasCost(memoryOperations));
211
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.copySize }));
212
212
 
213
213
  // We don't need to check tags here because: (1) the calldata is NOT in memory, and (2) we are the ones writing to destination.
214
214
  const [cdOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.cdOffset, this.dstOffset], memory);
@@ -42,7 +42,7 @@ export class SStore extends BaseStorageInstruction {
42
42
 
43
43
  const memoryOperations = { reads: this.size + 1, indirect: this.indirect };
44
44
  const memory = context.machineState.memory.track(this.type);
45
- context.machineState.consumeGas(this.gasCost(memoryOperations));
45
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.size }));
46
46
 
47
47
  const [srcOffset, slotOffset] = Addressing.fromWire(this.indirect).resolve([this.aOffset, this.bOffset], memory);
48
48
  memory.checkTag(TypeTag.FIELD, slotOffset);
@@ -72,7 +72,7 @@ export class SLoad extends BaseStorageInstruction {
72
72
  public async execute(context: AvmContext): Promise<void> {
73
73
  const memoryOperations = { writes: this.size, reads: 1, indirect: this.indirect };
74
74
  const memory = context.machineState.memory.track(this.type);
75
- context.machineState.consumeGas(this.gasCost(memoryOperations));
75
+ context.machineState.consumeGas(this.gasCost({ ...memoryOperations, dynMultiplier: this.size }));
76
76
 
77
77
  const [slotOffset, dstOffset] = Addressing.fromWire(this.indirect).resolve([this.aOffset, this.bOffset], memory);
78
78
  memory.checkTag(TypeTag.FIELD, slotOffset);
@@ -87,7 +87,7 @@ export enum Opcode {
87
87
  }
88
88
 
89
89
  // Possible types for an instruction's operand in its wire format. (Keep in sync with CPP code.
90
- // See vm/avm_trace/avm_deserialization.cpp)
90
+ // See vm/avm_trace/deserialization.cpp)
91
91
  // Note that cpp code introduced an additional enum value TAG to express the instruction tag. In TS,
92
92
  // this one is parsed as UINT8.
93
93
  export enum OperandType {
@@ -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
 
@@ -71,7 +71,7 @@ export class ClientExecutionContext extends ViewDataOracle {
71
71
  * They should act as references for the read requests output by an app circuit via public inputs.
72
72
  */
73
73
  private noteHashLeafIndexMap: Map<bigint, bigint> = new Map();
74
- private nullifiedNoteHashCounters: Map<number, number> = new Map();
74
+ private noteHashNullifierCounterMap: Map<number, number> = new Map();
75
75
  private noteEncryptedLogs: CountedNoteLog[] = [];
76
76
  private encryptedLogs: CountedLog<EncryptedL2Log>[] = [];
77
77
  private unencryptedLogs: CountedLog<UnencryptedL2Log>[] = [];
@@ -94,8 +94,9 @@ export class ClientExecutionContext extends ViewDataOracle {
94
94
  private node: AztecNode,
95
95
  protected sideEffectCounter: number = 0,
96
96
  log = createDebugLogger('aztec:simulator:client_execution_context'),
97
+ scopes?: AztecAddress[],
97
98
  ) {
98
- super(contractAddress, authWitnesses, db, node, log);
99
+ super(contractAddress, authWitnesses, db, node, log, scopes);
99
100
  }
100
101
 
101
102
  // We still need this function until we can get user-defined ordering of structs for fn arguments
@@ -135,14 +136,13 @@ export class ClientExecutionContext extends ViewDataOracle {
135
136
 
136
137
  /**
137
138
  * Get the data for the newly created notes.
138
- * @param innerNoteHashes - Inner note hashes for the notes.
139
139
  */
140
140
  public getNewNotes(): NoteAndSlot[] {
141
141
  return this.newNotes;
142
142
  }
143
143
 
144
- public getNullifiedNoteHashCounters() {
145
- return this.nullifiedNoteHashCounters;
144
+ public getNoteHashNullifierCounterMap() {
145
+ return this.noteHashNullifierCounterMap;
146
146
  }
147
147
 
148
148
  /**
@@ -251,7 +251,7 @@ export class ClientExecutionContext extends ViewDataOracle {
251
251
  const pendingNotes = this.noteCache.getNotes(this.callContext.storageContractAddress, storageSlot);
252
252
 
253
253
  const pendingNullifiers = this.noteCache.getNullifiers(this.callContext.storageContractAddress);
254
- 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);
255
255
  const dbNotesFiltered = dbNotes.filter(n => !pendingNullifiers.has((n.siloedNullifier as Fr).value));
256
256
 
257
257
  const notes = pickNotes<NoteData>([...dbNotesFiltered, ...pendingNotes], {
@@ -276,12 +276,9 @@ export class ClientExecutionContext extends ViewDataOracle {
276
276
 
277
277
  notes.forEach(n => {
278
278
  if (n.index !== undefined) {
279
- // TODO(https://github.com/AztecProtocol/aztec-packages/issues/1386)
280
- // Should always call computeUniqueNoteHash when publicly created notes include nonces.
281
- const uniqueNoteHash = n.nonce.isZero() ? n.innerNoteHash : computeUniqueNoteHash(n.nonce, n.innerNoteHash);
279
+ const uniqueNoteHash = computeUniqueNoteHash(n.nonce, n.noteHash);
282
280
  const siloedNoteHash = siloNoteHash(n.contractAddress, uniqueNoteHash);
283
- const noteHashForReadRequest = siloedNoteHash;
284
- this.noteHashLeafIndexMap.set(noteHashForReadRequest.toBigInt(), n.index);
281
+ this.noteHashLeafIndexMap.set(siloedNoteHash.toBigInt(), n.index);
285
282
  }
286
283
  });
287
284
 
@@ -295,14 +292,14 @@ export class ClientExecutionContext extends ViewDataOracle {
295
292
  * @param storageSlot - The storage slot.
296
293
  * @param noteTypeId - The type ID of the note.
297
294
  * @param noteItems - The items to be included in a Note.
298
- * @param innerNoteHash - The inner note hash of the new note.
295
+ * @param noteHash - A hash of the new note.
299
296
  * @returns
300
297
  */
301
298
  public override notifyCreatedNote(
302
299
  storageSlot: Fr,
303
300
  noteTypeId: NoteSelector,
304
301
  noteItems: Fr[],
305
- innerNoteHash: Fr,
302
+ noteHash: Fr,
306
303
  counter: number,
307
304
  ) {
308
305
  const note = new Note(noteItems);
@@ -313,7 +310,7 @@ export class ClientExecutionContext extends ViewDataOracle {
313
310
  nonce: Fr.ZERO, // Nonce cannot be known during private execution.
314
311
  note,
315
312
  siloedNullifier: undefined, // Siloed nullifier cannot be known for newly created note.
316
- innerNoteHash,
313
+ noteHash,
317
314
  },
318
315
  counter,
319
316
  );
@@ -328,16 +325,16 @@ export class ClientExecutionContext extends ViewDataOracle {
328
325
  * Adding a siloed nullifier into the current set of all pending nullifiers created
329
326
  * within the current transaction/execution.
330
327
  * @param innerNullifier - The pending nullifier to add in the list (not yet siloed by contract address).
331
- * @param innerNoteHash - The inner note hash of the new note.
328
+ * @param noteHash - A hash of the new note.
332
329
  */
333
- public override notifyNullifiedNote(innerNullifier: Fr, innerNoteHash: Fr, counter: number) {
330
+ public override notifyNullifiedNote(innerNullifier: Fr, noteHash: Fr, counter: number) {
334
331
  const nullifiedNoteHashCounter = this.noteCache.nullifyNote(
335
332
  this.callContext.storageContractAddress,
336
333
  innerNullifier,
337
- innerNoteHash,
334
+ noteHash,
338
335
  );
339
336
  if (nullifiedNoteHashCounter !== undefined) {
340
- this.nullifiedNoteHashCounters.set(nullifiedNoteHashCounter, counter);
337
+ this.noteHashNullifierCounterMap.set(nullifiedNoteHashCounter, counter);
341
338
  }
342
339
  return Promise.resolve();
343
340
  }
@@ -360,7 +357,7 @@ export class ClientExecutionContext extends ViewDataOracle {
360
357
  // An app providing randomness = 0 signals to not mask the address.
361
358
  const maskedContractAddress = randomness.isZero()
362
359
  ? contractAddress.toField()
363
- : pedersenHash([contractAddress, randomness], 0);
360
+ : poseidon2HashWithSeparator([contractAddress, randomness], 0);
364
361
  const encryptedLog = new CountedLog(new EncryptedL2Log(encryptedEvent, maskedContractAddress), counter);
365
362
  this.encryptedLogs.push(encryptedLog);
366
363
  }
@@ -519,6 +516,8 @@ export class ClientExecutionContext extends ViewDataOracle {
519
516
  this.db,
520
517
  this.node,
521
518
  sideEffectCounter,
519
+ this.log,
520
+ this.scopes,
522
521
  );
523
522
 
524
523
  const childExecutionResult = await executePrivateFunction(
@@ -645,6 +644,10 @@ export class ClientExecutionContext extends ViewDataOracle {
645
644
  );
646
645
  }
647
646
 
647
+ public override notifySetMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter: number): void {
648
+ this.noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
649
+ }
650
+
648
651
  /**
649
652
  * Derives the call context for a nested execution.
650
653
  * @param targetContractAddress - The address of the contract being called.
@@ -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.