@aztec/simulator 0.0.1-commit.d431d1c → 0.0.1-commit.dbf9cec

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 (182) hide show
  1. package/README.md +4 -4
  2. package/dest/private/acvm/acvm.d.ts +4 -2
  3. package/dest/private/acvm/acvm.d.ts.map +1 -1
  4. package/dest/private/acvm/acvm.js +4 -3
  5. package/dest/private/acvm_native.d.ts +5 -3
  6. package/dest/private/acvm_native.d.ts.map +1 -1
  7. package/dest/private/acvm_native.js +8 -6
  8. package/dest/private/acvm_wasm.d.ts +4 -3
  9. package/dest/private/acvm_wasm.d.ts.map +1 -1
  10. package/dest/private/acvm_wasm.js +4 -4
  11. package/dest/private/circuit_recording/circuit_recorder.d.ts +4 -3
  12. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  13. package/dest/private/circuit_recording/circuit_recorder.js +5 -3
  14. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +3 -2
  15. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
  16. package/dest/private/circuit_recording/file_circuit_recorder.js +2 -2
  17. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +7 -2
  18. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -1
  19. package/dest/private/circuit_recording/memory_circuit_recorder.js +4 -4
  20. package/dest/private/factory.d.ts +3 -3
  21. package/dest/private/factory.d.ts.map +1 -1
  22. package/dest/private/factory.js +7 -4
  23. package/dest/public/avm/avm_context.d.ts +3 -3
  24. package/dest/public/avm/avm_context.d.ts.map +1 -1
  25. package/dest/public/avm/avm_contract_call_result.d.ts +6 -6
  26. package/dest/public/avm/avm_contract_call_result.d.ts.map +1 -1
  27. package/dest/public/avm/avm_contract_call_result.js +3 -3
  28. package/dest/public/avm/avm_execution_environment.d.ts +6 -5
  29. package/dest/public/avm/avm_execution_environment.d.ts.map +1 -1
  30. package/dest/public/avm/avm_gas.js +3 -3
  31. package/dest/public/avm/avm_machine_state.d.ts +6 -5
  32. package/dest/public/avm/avm_machine_state.d.ts.map +1 -1
  33. package/dest/public/avm/avm_machine_state.js +3 -2
  34. package/dest/public/avm/avm_memory_types.d.ts +1 -1
  35. package/dest/public/avm/avm_memory_types.d.ts.map +1 -1
  36. package/dest/public/avm/avm_memory_types.js +3 -0
  37. package/dest/public/avm/avm_simulator.d.ts +3 -2
  38. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  39. package/dest/public/avm/avm_simulator.js +5 -4
  40. package/dest/public/avm/calldata.d.ts +51 -0
  41. package/dest/public/avm/calldata.d.ts.map +1 -0
  42. package/dest/public/avm/calldata.js +63 -0
  43. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  44. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  45. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  46. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  47. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  48. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  49. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  50. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  51. package/dest/public/avm/fixtures/initializers.js +2 -1
  52. package/dest/public/avm/opcodes/accrued_substate.d.ts +4 -5
  53. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  54. package/dest/public/avm/opcodes/accrued_substate.js +15 -16
  55. package/dest/public/avm/opcodes/contract.d.ts +1 -1
  56. package/dest/public/avm/opcodes/contract.d.ts.map +1 -1
  57. package/dest/public/avm/opcodes/contract.js +4 -4
  58. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  59. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  60. package/dest/public/avm/opcodes/external_calls.js +7 -7
  61. package/dest/public/avm/opcodes/memory.js +1 -1
  62. package/dest/public/avm/opcodes/storage.d.ts +13 -12
  63. package/dest/public/avm/opcodes/storage.d.ts.map +1 -1
  64. package/dest/public/avm/opcodes/storage.js +30 -20
  65. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  66. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  67. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  68. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  69. package/dest/public/debug_fn_name.d.ts +4 -4
  70. package/dest/public/debug_fn_name.d.ts.map +1 -1
  71. package/dest/public/debug_fn_name.js +7 -5
  72. package/dest/public/executor_metrics.d.ts +1 -1
  73. package/dest/public/executor_metrics.d.ts.map +1 -1
  74. package/dest/public/executor_metrics.js +7 -2
  75. package/dest/public/fixtures/amm_test.js +2 -2
  76. package/dest/public/fixtures/opcode_spammer.d.ts +3 -4
  77. package/dest/public/fixtures/opcode_spammer.d.ts.map +1 -1
  78. package/dest/public/fixtures/opcode_spammer.js +36 -64
  79. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +1 -1
  80. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  81. package/dest/public/fixtures/public_tx_simulation_tester.js +29 -2
  82. package/dest/public/fixtures/utils.js +4 -4
  83. package/dest/public/fuzzing/avm_simulator_bin.js +7 -4
  84. package/dest/public/hinting_db_sources.d.ts +2 -2
  85. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  86. package/dest/public/hinting_db_sources.js +1 -1
  87. package/dest/public/public_db_sources.d.ts +4 -3
  88. package/dest/public/public_db_sources.d.ts.map +1 -1
  89. package/dest/public/public_db_sources.js +4 -4
  90. package/dest/public/public_processor/guarded_merkle_tree.d.ts +2 -2
  91. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  92. package/dest/public/public_processor/guarded_merkle_tree.js +1 -1
  93. package/dest/public/public_processor/public_processor.d.ts +8 -4
  94. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  95. package/dest/public/public_processor/public_processor.js +24 -11
  96. package/dest/public/public_processor/public_processor_metrics.d.ts +2 -2
  97. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  98. package/dest/public/public_processor/public_processor_metrics.js +20 -4
  99. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  100. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  101. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -2
  102. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  103. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  104. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -11
  105. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  106. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  107. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  108. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  109. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  110. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  111. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  112. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  113. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  114. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  115. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  116. package/dest/public/public_tx_simulator/factories.js +4 -4
  117. package/dest/public/public_tx_simulator/public_tx_context.d.ts +4 -3
  118. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  119. package/dest/public/public_tx_simulator/public_tx_context.js +8 -8
  120. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +4 -3
  121. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  122. package/dest/public/public_tx_simulator/public_tx_simulator.js +11 -8
  123. package/dest/public/side_effect_trace.d.ts +4 -4
  124. package/dest/public/side_effect_trace.d.ts.map +1 -1
  125. package/dest/public/side_effect_trace.js +3 -3
  126. package/dest/public/state_manager/state_manager.d.ts +10 -4
  127. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  128. package/dest/public/state_manager/state_manager.js +12 -5
  129. package/dest/public/test_executor_metrics.d.ts +8 -2
  130. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  131. package/dest/public/test_executor_metrics.js +24 -2
  132. package/package.json +16 -16
  133. package/src/private/acvm/acvm.ts +4 -3
  134. package/src/private/acvm_native.ts +11 -5
  135. package/src/private/acvm_wasm.ts +7 -3
  136. package/src/private/circuit_recording/circuit_recorder.ts +5 -3
  137. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  138. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  139. package/src/private/factory.ts +7 -4
  140. package/src/public/avm/avm_context.ts +2 -2
  141. package/src/public/avm/avm_contract_call_result.ts +8 -6
  142. package/src/public/avm/avm_execution_environment.ts +9 -4
  143. package/src/public/avm/avm_gas.ts +2 -2
  144. package/src/public/avm/avm_machine_state.ts +6 -5
  145. package/src/public/avm/avm_memory_types.ts +4 -0
  146. package/src/public/avm/avm_simulator.ts +8 -5
  147. package/src/public/avm/calldata.ts +100 -0
  148. package/src/public/avm/fixtures/account_proof.json +553 -0
  149. package/src/public/avm/fixtures/account_proof_fetcher.ts +166 -0
  150. package/src/public/avm/fixtures/avm_simulation_tester.ts +8 -2
  151. package/src/public/avm/fixtures/initializers.ts +2 -1
  152. package/src/public/avm/opcodes/accrued_substate.ts +16 -19
  153. package/src/public/avm/opcodes/contract.ts +1 -4
  154. package/src/public/avm/opcodes/external_calls.ts +8 -7
  155. package/src/public/avm/opcodes/memory.ts +1 -1
  156. package/src/public/avm/opcodes/storage.ts +28 -20
  157. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  158. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  159. package/src/public/debug_fn_name.ts +10 -8
  160. package/src/public/executor_metrics.ts +4 -1
  161. package/src/public/fixtures/amm_test.ts +2 -2
  162. package/src/public/fixtures/opcode_spammer.ts +55 -63
  163. package/src/public/fixtures/public_tx_simulation_tester.ts +34 -3
  164. package/src/public/fixtures/utils.ts +4 -4
  165. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  166. package/src/public/fuzzing/avm_simulator_bin.ts +11 -1
  167. package/src/public/hinting_db_sources.ts +1 -1
  168. package/src/public/public_db_sources.ts +15 -5
  169. package/src/public/public_processor/guarded_merkle_tree.ts +1 -1
  170. package/src/public/public_processor/public_processor.ts +42 -20
  171. package/src/public/public_processor/public_processor_metrics.ts +10 -4
  172. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +6 -3
  173. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +10 -8
  174. package/src/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.ts +7 -5
  175. package/src/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.ts +7 -5
  176. package/src/public/public_tx_simulator/dumping_cpp_public_tx_simulator.ts +3 -1
  177. package/src/public/public_tx_simulator/factories.ts +6 -3
  178. package/src/public/public_tx_simulator/public_tx_context.ts +13 -6
  179. package/src/public/public_tx_simulator/public_tx_simulator.ts +17 -8
  180. package/src/public/side_effect_trace.ts +5 -2
  181. package/src/public/state_manager/state_manager.ts +27 -4
  182. package/src/public/test_executor_metrics.ts +27 -3
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Fetches an account proof from the Ethereum mainnet and saves it as account_proof.json.
3
+ * This script is not using any Aztec library code, so it's easily portable.
4
+ */
5
+ import fs from 'fs';
6
+ import { dirname, join } from 'path';
7
+ import { fileURLToPath } from 'url';
8
+ import { createPublicClient, fromRlp, hexToBytes, http } from 'viem';
9
+ import { mainnet } from 'viem/chains';
10
+
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+
13
+ const RPC_URL = process.env.RPC_URL;
14
+ const ADDRESS = (process.env.ADDRESS || '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045') as `0x${string}`;
15
+ const BLOCK_TAG = process.env.BLOCK_NUMBER ? BigInt(process.env.BLOCK_NUMBER) : 'latest';
16
+ const MAX_ACCOUNT_PATH = 15;
17
+
18
+ function padTo(arr: number[], len: number) {
19
+ return [...arr, ...Array(len - arr.length).fill(0)].slice(0, len);
20
+ }
21
+
22
+ function toBytes(hex: `0x${string}`) {
23
+ return Array.from(hexToBytes(hex));
24
+ }
25
+
26
+ function bytesToU64s(bytes: number[]) {
27
+ const paddedBytes = padTo(bytes, 32);
28
+ return Array.from({ length: 4 }, (_, i) => {
29
+ let val = 0n;
30
+ for (let j = 0; j < 8; j++) {
31
+ val += BigInt(paddedBytes[i * 8 + j]) << BigInt(j * 8);
32
+ }
33
+ return val.toString();
34
+ });
35
+ }
36
+
37
+ function toBytesAndLen(val: bigint | number) {
38
+ if (val === 0n || val === 0) {
39
+ return { bytes: [0], length: 0 };
40
+ }
41
+ let hex = val.toString(16);
42
+ if (hex.length % 2) {
43
+ hex = '0' + hex;
44
+ }
45
+ const bytes = toBytes(`0x${hex}`);
46
+ return { bytes, length: bytes.length };
47
+ }
48
+
49
+ function parseNode(rlp: `0x${string}`) {
50
+ // Should be safe when working with branches and extensions without embedded children.
51
+ const decoded = fromRlp(rlp) as `0x${string}`[];
52
+ const node = {
53
+ rows: Array(16)
54
+ .fill(0)
55
+ .map(() => Array(32).fill(0)),
56
+ row_exist: Array(16).fill(false),
57
+ node_type: 0,
58
+ };
59
+
60
+ if (decoded.length === 17) {
61
+ for (let i = 0; i < 16; i++) {
62
+ if (decoded[i] !== '0x') {
63
+ node.row_exist[i] = true;
64
+ node.rows[i] = padTo(toBytes(decoded[i]), 32);
65
+ }
66
+ }
67
+ } else if (decoded.length === 2) {
68
+ const keyBytes = toBytes(decoded[0]);
69
+ const prefix = keyBytes[0];
70
+ if (prefix >> 4 >= 2) {
71
+ throw new Error('Unsupported: leaf node in proof path');
72
+ }
73
+ node.node_type = 1;
74
+ // Extension header format expected by the noir code: check out storage_proof types.nr.
75
+ node.rows[0][0] = prefix >> 4;
76
+ node.rows[0][8] = prefix & 0x0f;
77
+ node.rows[0][16] = keyBytes.length - 1;
78
+
79
+ for (let i = 1; i < keyBytes.length && i < 32; i++) {
80
+ node.rows[1][i - 1] = keyBytes[i];
81
+ }
82
+ node.rows[2] = padTo(toBytes(decoded[1]), 32);
83
+ node.row_exist[0] = node.row_exist[1] = node.row_exist[2] = true;
84
+ }
85
+ return node;
86
+ }
87
+
88
+ function parseProof(proof: `0x${string}`[], maxLen: number) {
89
+ const nodes = proof.slice(0, -1).slice(0, maxLen).map(parseNode);
90
+ while (nodes.length < maxLen) {
91
+ nodes.push({
92
+ rows: Array(16)
93
+ .fill(0)
94
+ .map(() => Array(32).fill(0)),
95
+ row_exist: Array(16).fill(false),
96
+ node_type: 0,
97
+ });
98
+ }
99
+ return nodes;
100
+ }
101
+
102
+ function nodeToLibFormat(node: { rows: number[][]; row_exist: boolean[]; node_type: number }) {
103
+ return {
104
+ rows: node.rows.map(bytesToU64s),
105
+ row_exist: node.row_exist,
106
+ node_type: String(node.node_type),
107
+ };
108
+ }
109
+
110
+ async function main() {
111
+ if (!RPC_URL) {
112
+ throw new Error('RPC_URL is not set');
113
+ }
114
+ console.log(`Fetching account proof for ${ADDRESS}`);
115
+
116
+ const client = createPublicClient({
117
+ chain: mainnet,
118
+ transport: http(RPC_URL),
119
+ });
120
+
121
+ const [blockNumber, proof, block] = await Promise.all([
122
+ client.getBlockNumber(),
123
+ client.getProof({
124
+ address: ADDRESS,
125
+ storageKeys: [],
126
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG,
127
+ }),
128
+ client.getBlock({
129
+ blockNumber: BLOCK_TAG === 'latest' ? undefined : BLOCK_TAG,
130
+ }),
131
+ ]);
132
+
133
+ console.log(`Block: ${blockNumber}, Account nodes: ${proof.accountProof.length}`);
134
+
135
+ // The -1 is because the last node in the proof is the leaf, which is excluded from path verification.
136
+ const accountPathLen = proof.accountProof.length - 1;
137
+ if (accountPathLen > MAX_ACCOUNT_PATH) {
138
+ throw new Error(
139
+ `Account proof path length ${accountPathLen} exceeds MAX_ACCOUNT_PATH ${MAX_ACCOUNT_PATH}. Increase the limit.`,
140
+ );
141
+ }
142
+
143
+ const nonce = toBytesAndLen(proof.nonce);
144
+ const balance = toBytesAndLen(proof.balance);
145
+
146
+ const data = {
147
+ block_number: String(blockNumber),
148
+ node_length: String(accountPathLen),
149
+ root: bytesToU64s(toBytes(block.stateRoot)),
150
+ nodes: parseProof(proof.accountProof, MAX_ACCOUNT_PATH).map(nodeToLibFormat),
151
+ account: {
152
+ address: toBytes(ADDRESS).map(String),
153
+ balance: padTo(balance.bytes, 32).map(String),
154
+ balance_length: String(balance.length),
155
+ code_hash: bytesToU64s(toBytes(proof.codeHash)),
156
+ nonce: padTo(nonce.bytes, 8).map(String),
157
+ nonce_length: String(nonce.length),
158
+ storage_hash: bytesToU64s(toBytes(proof.storageHash)),
159
+ },
160
+ };
161
+
162
+ fs.writeFileSync(join(__dirname, 'account_proof.json'), JSON.stringify(data, null, 2));
163
+ console.log('account_proof.json generated');
164
+ }
165
+
166
+ main().catch(console.error);
@@ -13,6 +13,7 @@ import { SimpleContractDataSource } from '../../fixtures/simple_contract_data_so
13
13
  import { PublicContractsDB, PublicTreesDB } from '../../public_db_sources.js';
14
14
  import { PublicPersistableStateManager } from '../../state_manager/state_manager.js';
15
15
  import { AvmSimulator } from '../avm_simulator.js';
16
+ import { CallDataArray } from '../calldata.js';
16
17
  import { BaseAvmSimulationTester } from './base_avm_simulation_tester.js';
17
18
  import { initContext, initExecutionEnvironment } from './initializers.js';
18
19
  import {
@@ -89,7 +90,7 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
89
90
  collectCallMetadata: true,
90
91
  });
91
92
  const environment = initExecutionEnvironment({
92
- calldata,
93
+ calldata: new CallDataArray(calldata),
93
94
  globals,
94
95
  address,
95
96
  sender,
@@ -105,7 +106,12 @@ export class AvmSimulationTester extends BaseAvmSimulationTester {
105
106
  if (result.reverted) {
106
107
  this.logger.error(`Error in ${fnName}:`);
107
108
  this.logger.error(
108
- resolveContractAssertionMessage(fnName, result.revertReason!, result.output, contractArtifact)!,
109
+ resolveContractAssertionMessage(
110
+ fnName,
111
+ result.revertReason!,
112
+ result.output.bestEffortReadAll(),
113
+ contractArtifact,
114
+ )!,
109
115
  );
110
116
  } else {
111
117
  this.logger.info(`Simulation of function ${fnName} succeeded!`);
@@ -19,6 +19,7 @@ import { AvmContext } from '../avm_context.js';
19
19
  import { AvmExecutionEnvironment } from '../avm_execution_environment.js';
20
20
  import { AvmMachineState } from '../avm_machine_state.js';
21
21
  import { AvmSimulator } from '../avm_simulator.js';
22
+ import { CallDataArray } from '../calldata.js';
22
23
  import { DEFAULT_TIMESTAMP } from './utils.js';
23
24
 
24
25
  /**
@@ -70,7 +71,7 @@ export function initExecutionEnvironment(overrides?: Partial<AvmExecutionEnviron
70
71
  overrides?.transactionFee ?? Fr.zero(),
71
72
  overrides?.globals ?? GlobalVariables.empty(),
72
73
  overrides?.isStaticCall ?? false,
73
- overrides?.calldata ?? [],
74
+ overrides?.calldata ?? new CallDataArray([]),
74
75
  overrides?.config ?? PublicSimulatorConfig.empty(),
75
76
  );
76
77
  }
@@ -1,3 +1,5 @@
1
+ import { MAX_ETH_ADDRESS_VALUE } from '@aztec/constants';
2
+
1
3
  import { NullifierCollisionError } from '../../side_effect_errors.js';
2
4
  import type { AvmContext } from '../avm_context.js';
3
5
  import { TypeTag, Uint1 } from '../avm_memory_types.js';
@@ -86,18 +88,11 @@ export class NullifierExists extends Instruction {
86
88
  static type: string = 'NULLIFIEREXISTS';
87
89
  static readonly opcode: Opcode = Opcode.NULLIFIEREXISTS;
88
90
  // Informs (de)serialization. See Instruction.deserialize.
89
- static readonly wireFormat = [
90
- OperandType.UINT8,
91
- OperandType.UINT8,
92
- OperandType.UINT16,
93
- OperandType.UINT16,
94
- OperandType.UINT16,
95
- ];
91
+ static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
96
92
 
97
93
  constructor(
98
94
  private addressingMode: number,
99
- private nullifierOffset: number,
100
- private addressOffset: number,
95
+ private siloedNullifierOffset: number,
101
96
  private existsOffset: number,
102
97
  ) {
103
98
  super();
@@ -111,13 +106,12 @@ export class NullifierExists extends Instruction {
111
106
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
112
107
  );
113
108
 
114
- const operands = [this.nullifierOffset, this.addressOffset, this.existsOffset];
115
- const [nullifierOffset, addressOffset, existsOffset] = addressing.resolve(operands, memory);
116
- memory.checkTags(TypeTag.FIELD, nullifierOffset, addressOffset);
109
+ const operands = [this.siloedNullifierOffset, this.existsOffset];
110
+ const [siloedNullifierOffset, existsOffset] = addressing.resolve(operands, memory);
111
+ memory.checkTag(TypeTag.FIELD, siloedNullifierOffset);
117
112
 
118
- const nullifier = memory.get(nullifierOffset).toFr();
119
- const address = memory.get(addressOffset).toAztecAddress();
120
- const exists = await context.persistableState.checkNullifierExists(address, nullifier);
113
+ const siloedNullifier = memory.get(siloedNullifierOffset).toFr();
114
+ const exists = await context.persistableState.checkSiloedNullifierExists(siloedNullifier);
121
115
 
122
116
  memory.set(existsOffset, exists ? new Uint1(1) : new Uint1(0));
123
117
  }
@@ -210,10 +204,9 @@ export class L1ToL2MessageExists extends Instruction {
210
204
  }
211
205
  }
212
206
 
213
- export class EmitUnencryptedLog extends Instruction {
214
- // TODO(#11124): rename unencrypted -> public
215
- static type: string = 'EMITUNENCRYPTEDLOG';
216
- static readonly opcode: Opcode = Opcode.EMITUNENCRYPTEDLOG;
207
+ export class EmitPublicLog extends Instruction {
208
+ static type: string = 'EMITPUBLICLOG';
209
+ static readonly opcode: Opcode = Opcode.EMITPUBLICLOG;
217
210
  // Informs (de)serialization. See Instruction.deserialize.
218
211
  static readonly wireFormat = [OperandType.UINT8, OperandType.UINT8, OperandType.UINT16, OperandType.UINT16];
219
212
 
@@ -282,6 +275,10 @@ export class SendL2ToL1Message extends Instruction {
282
275
  memory.checkTags(TypeTag.FIELD, recipientOffset, contentOffset);
283
276
 
284
277
  const recipient = memory.get(recipientOffset).toFr();
278
+
279
+ if (recipient.toBigInt() > MAX_ETH_ADDRESS_VALUE) {
280
+ throw new InstructionExecutionError(`SENDL2TOL1MSG: Recipient address is too large`);
281
+ }
285
282
  const content = memory.get(contentOffset).toFr();
286
283
  context.persistableState.writeL2ToL1Message(context.environment.address, recipient, content);
287
284
  }
@@ -67,9 +67,6 @@ export class GetContractInstance extends Instruction {
67
67
  }
68
68
  }
69
69
 
70
- const existsOffset = dstOffset;
71
- const memberValueOffset = dstOffset + 1;
72
- memory.set(existsOffset, new Uint1(exists ? 1 : 0));
73
- memory.set(memberValueOffset, memberValue);
70
+ memory.setSlice(dstOffset, [new Uint1(exists ? 1 : 0), memberValue]);
74
71
  }
75
72
  }
@@ -1,6 +1,7 @@
1
1
  import type { AvmContext } from '../avm_context.js';
2
2
  import type { AvmContractCallResult } from '../avm_contract_call_result.js';
3
3
  import { type Field, TypeTag, Uint1 } from '../avm_memory_types.js';
4
+ import { CallDataMemory, ReturnDataMemory } from '../calldata.js';
4
5
  import { Opcode, OperandType } from '../serialization/instruction_serialization.js';
5
6
  import { Addressing } from './addressing_mode.js';
6
7
  import { Instruction } from './instruction.js';
@@ -45,8 +46,8 @@ abstract class ExternalCall extends Instruction {
45
46
  memory.checkTag(TypeTag.UINT32, argsSizeOffset);
46
47
 
47
48
  const calldataSize = memory.get(argsSizeOffset).toNumber();
48
- // This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
49
- const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
+
50
+ const calldata = new CallDataMemory(memory, argsOffset, calldataSize);
50
51
 
51
52
  const callAddress = memory.getAs<Field>(addrOffset);
52
53
  // If we are already in a static call, we propagate the environment.
@@ -73,8 +74,8 @@ abstract class ExternalCall extends Instruction {
73
74
  const success = !nestedCallResults.reverted;
74
75
 
75
76
  // Save return/revert data for later.
76
- const fullReturnData = nestedCallResults.output;
77
- context.machineState.nestedReturndata = fullReturnData;
77
+ const returnData = nestedCallResults.output;
78
+ context.machineState.nestedReturndata = returnData;
78
79
 
79
80
  // Track the success status directly
80
81
  context.machineState.nestedCallSuccess = success;
@@ -89,7 +90,7 @@ abstract class ExternalCall extends Instruction {
89
90
  // (in Noir code).
90
91
  if (!success) {
91
92
  context.machineState.collectedRevertInfo = {
92
- revertDataRepresentative: fullReturnData,
93
+ revertDataRepresentative: returnData.bestEffortReadAll(),
93
94
  recursiveRevertReason: nestedCallResults.revertReason!,
94
95
  };
95
96
  }
@@ -195,7 +196,7 @@ export class Return extends Instruction {
195
196
  memory.checkTag(TypeTag.UINT32, returnSizeOffset);
196
197
  const returnSize = memory.get(returnSizeOffset).toNumber();
197
198
 
198
- const output = memory.getSlice(returnOffset, returnSize).map(word => word.toFr());
199
+ const output = new ReturnDataMemory(memory, returnOffset, returnSize);
199
200
 
200
201
  context.machineState.return(output);
201
202
  }
@@ -243,7 +244,7 @@ export class Revert extends Instruction {
243
244
 
244
245
  memory.checkTag(TypeTag.UINT32, retSizeOffset);
245
246
  const retSize = memory.get(retSizeOffset).toNumber();
246
- const output = memory.getSlice(returnOffset, retSize).map(word => word.toFr());
247
+ const output = new ReturnDataMemory(memory, returnOffset, retSize);
247
248
 
248
249
  context.machineState.revert(output);
249
250
  }
@@ -242,7 +242,7 @@ export class ReturndataSize extends Instruction {
242
242
  const operands = [this.dstOffset];
243
243
  const [dstOffset] = addressing.resolve(operands, memory);
244
244
 
245
- memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length));
245
+ memory.set(dstOffset, new Uint32(context.machineState.nestedReturndata.length()));
246
246
  }
247
247
  }
248
248
 
@@ -5,7 +5,9 @@ import { Opcode, OperandType } from '../serialization/instruction_serialization.
5
5
  import { Addressing } from './addressing_mode.js';
6
6
  import { Instruction } from './instruction.js';
7
7
 
8
- abstract class BaseStorageInstruction extends Instruction {
8
+ export class SStore extends Instruction {
9
+ static readonly type: string = 'SSTORE';
10
+ static readonly opcode = Opcode.SSTORE;
9
11
  // Informs (de)serialization. See Instruction.deserialize.
10
12
  public static readonly wireFormat: OperandType[] = [
11
13
  OperandType.UINT8,
@@ -15,21 +17,12 @@ abstract class BaseStorageInstruction extends Instruction {
15
17
  ];
16
18
 
17
19
  constructor(
18
- protected addressingMode: number,
19
- protected aOffset: number,
20
- protected bOffset: number,
20
+ private addressingMode: number,
21
+ private srcOffset: number,
22
+ private slotOffset: number,
21
23
  ) {
22
24
  super();
23
25
  }
24
- }
25
-
26
- export class SStore extends BaseStorageInstruction {
27
- static readonly type: string = 'SSTORE';
28
- static readonly opcode = Opcode.SSTORE;
29
-
30
- constructor(addressingMode: number, srcOffset: number, slotOffset: number) {
31
- super(addressingMode, srcOffset, slotOffset);
32
- }
33
26
 
34
27
  public async execute(context: AvmContext): Promise<void> {
35
28
  if (context.environment.isStaticCall) {
@@ -43,7 +36,7 @@ export class SStore extends BaseStorageInstruction {
43
36
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
44
37
  );
45
38
 
46
- const operands = [this.aOffset, this.bOffset];
39
+ const operands = [this.srcOffset, this.slotOffset];
47
40
  const [srcOffset, slotOffset] = addressing.resolve(operands, memory);
48
41
  // We read before tag checking since it's needed for gas cost calculation
49
42
  const slot = memory.get(slotOffset).toFr();
@@ -60,12 +53,25 @@ export class SStore extends BaseStorageInstruction {
60
53
  }
61
54
  }
62
55
 
63
- export class SLoad extends BaseStorageInstruction {
56
+ export class SLoad extends Instruction {
64
57
  static readonly type: string = 'SLOAD';
65
58
  static readonly opcode = Opcode.SLOAD;
59
+ // Informs (de)serialization. See Instruction.deserialize.
60
+ public static readonly wireFormat: OperandType[] = [
61
+ OperandType.UINT8,
62
+ OperandType.UINT8,
63
+ OperandType.UINT16,
64
+ OperandType.UINT16,
65
+ OperandType.UINT16,
66
+ ];
66
67
 
67
- constructor(addressingMode: number, slotOffset: number, dstOffset: number) {
68
- super(addressingMode, slotOffset, dstOffset);
68
+ constructor(
69
+ private addressingMode: number,
70
+ private slotOffset: number,
71
+ private contractAddressOffset: number,
72
+ private dstOffset: number,
73
+ ) {
74
+ super();
69
75
  }
70
76
 
71
77
  public async execute(context: AvmContext): Promise<void> {
@@ -76,12 +82,14 @@ export class SLoad extends BaseStorageInstruction {
76
82
  this.baseGasCost(addressing.indirectOperandsCount(), addressing.relativeOperandsCount()),
77
83
  );
78
84
 
79
- const operands = [this.aOffset, this.bOffset];
80
- const [slotOffset, dstOffset] = addressing.resolve(operands, memory);
85
+ const operands = [this.slotOffset, this.contractAddressOffset, this.dstOffset];
86
+ const [slotOffset, contractAddressOffset, dstOffset] = addressing.resolve(operands, memory);
81
87
  memory.checkTag(TypeTag.FIELD, slotOffset);
88
+ memory.checkTag(TypeTag.FIELD, contractAddressOffset);
82
89
 
83
90
  const slot = memory.get(slotOffset).toFr();
84
- const value = await context.persistableState.readStorage(context.environment.address, slot);
91
+ const contractAddress = memory.get(contractAddressOffset).toAztecAddress();
92
+ const value = await context.persistableState.readStorage(contractAddress, slot);
85
93
  memory.set(dstOffset, new Field(value));
86
94
  }
87
95
  }
@@ -19,7 +19,7 @@ import {
19
19
  EcAdd,
20
20
  EmitNoteHash,
21
21
  EmitNullifier,
22
- EmitUnencryptedLog,
22
+ EmitPublicLog,
23
23
  Eq,
24
24
  FieldDiv,
25
25
  GetContractInstance,
@@ -129,7 +129,7 @@ export const INSTRUCTION_SET = new Map<Opcode, InstructionDeserializer>([
129
129
  [L1ToL2MessageExists.opcode, Instruction.fromBuffer.bind(L1ToL2MessageExists)], // Messages
130
130
 
131
131
  // Accrued Substate
132
- [EmitUnencryptedLog.opcode, Instruction.fromBuffer.bind(EmitUnencryptedLog)],
132
+ [EmitPublicLog.opcode, Instruction.fromBuffer.bind(EmitPublicLog)],
133
133
  [SendL2ToL1Message.opcode, Instruction.fromBuffer.bind(SendL2ToL1Message)],
134
134
  [GetContractInstance.opcode, Instruction.fromBuffer.bind(GetContractInstance)],
135
135
 
@@ -70,7 +70,7 @@ export enum Opcode {
70
70
  EMITNULLIFIER,
71
71
  L1TOL2MSGEXISTS,
72
72
  GETCONTRACTINSTANCE,
73
- EMITUNENCRYPTEDLOG,
73
+ EMITPUBLICLOG,
74
74
  SENDL2TOL1MSG,
75
75
  // External calls
76
76
  CALL,
@@ -1,20 +1,21 @@
1
- import type { Fr } from '@aztec/foundation/curves/bn254';
2
1
  import { FunctionSelector } from '@aztec/stdlib/abi';
3
2
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
3
 
4
+ import type { CallData } from './avm/calldata.js';
5
5
  import type { PublicContractsDBInterface } from './db_interfaces.js';
6
6
 
7
7
  export async function getPublicFunctionDebugName(
8
8
  db: PublicContractsDBInterface,
9
9
  contractAddress: AztecAddress,
10
- calldata: Fr[],
10
+ calldata: CallData,
11
11
  ): Promise<string> {
12
12
  // Public function is dispatched and therefore the target function is passed in the first argument.
13
- if (!calldata[0]) {
13
+ const selectorField = calldata.read(0);
14
+ if (!selectorField) {
14
15
  return `<calldata[0] undefined> (Contract Address: ${contractAddress})`;
15
16
  }
16
- const fallbackName = `<calldata[0]:${calldata[0].toString()}> (Contract Address: ${contractAddress})`;
17
- const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
17
+ const fallbackName = `<calldata[0]:${selectorField.toString()}> (Contract Address: ${contractAddress})`;
18
+ const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
18
19
  if (!selector) {
19
20
  return fallbackName;
20
21
  }
@@ -32,13 +33,14 @@ export async function getPublicFunctionDebugName(
32
33
  export async function getPublicFunctionSelectorAndName(
33
34
  db: PublicContractsDBInterface,
34
35
  contractAddress: AztecAddress,
35
- calldata: Fr[],
36
+ calldata: CallData,
36
37
  ): Promise<{ functionSelector?: FunctionSelector; functionName?: string }> {
37
38
  // Public function is dispatched and therefore the target function is passed in the first argument.
38
- if (!calldata[0]) {
39
+ const selectorField = calldata.read(0);
40
+ if (!selectorField) {
39
41
  return {};
40
42
  }
41
- const selector = FunctionSelector.fromFieldOrUndefined(calldata[0]);
43
+ const selector = FunctionSelector.fromFieldOrUndefined(selectorField);
42
44
  if (!selector) {
43
45
  return {};
44
46
  }
@@ -7,6 +7,7 @@ import {
7
7
  type TelemetryClient,
8
8
  type Tracer,
9
9
  type UpDownCounter,
10
+ createUpDownCounterWithDefault,
10
11
  } from '@aztec/telemetry-client';
11
12
 
12
13
  import type { ExecutorMetricsInterface } from './executor_metrics_interface.js';
@@ -25,7 +26,9 @@ export class ExecutorMetrics implements ExecutorMetricsInterface {
25
26
  this.tracer = client.getTracer(name);
26
27
  const meter = client.getMeter(name);
27
28
 
28
- this.fnCount = meter.createUpDownCounter(Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT);
29
+ this.fnCount = createUpDownCounterWithDefault(meter, Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT, {
30
+ [Attributes.OK]: [true, false],
31
+ });
29
32
 
30
33
  this.fnDuration = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_DURATION);
31
34
 
@@ -1,4 +1,4 @@
1
- import { GeneratorIndex } from '@aztec/constants';
1
+ import { DomainSeparator } from '@aztec/constants';
2
2
  import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
3
3
  import { Fr } from '@aztec/foundation/curves/bn254';
4
4
  import type { Logger } from '@aztec/foundation/log';
@@ -326,6 +326,6 @@ async function removeLiquidity(
326
326
  async function computePartialNoteValidityCommitment(partialNote: { commitment: Fr }, completer: AztecAddress) {
327
327
  return await poseidon2HashWithSeparator(
328
328
  [partialNote.commitment, completer],
329
- GeneratorIndex.PARTIAL_NOTE_VALIDITY_COMMITMENT,
329
+ DomainSeparator.PARTIAL_NOTE_VALIDITY_COMMITMENT,
330
330
  );
331
331
  }