@aztec/simulator 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7

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 +7 -5
  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_simulator.d.ts +3 -2
  35. package/dest/public/avm/avm_simulator.d.ts.map +1 -1
  36. package/dest/public/avm/avm_simulator.js +6 -5
  37. package/dest/public/avm/calldata.d.ts +51 -0
  38. package/dest/public/avm/calldata.d.ts.map +1 -0
  39. package/dest/public/avm/calldata.js +64 -0
  40. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts +2 -0
  41. package/dest/public/avm/fixtures/account_proof_fetcher.d.ts.map +1 -0
  42. package/dest/public/avm/fixtures/account_proof_fetcher.js +152 -0
  43. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts +1 -1
  44. package/dest/public/avm/fixtures/avm_simulation_tester.d.ts.map +1 -1
  45. package/dest/public/avm/fixtures/avm_simulation_tester.js +3 -2
  46. package/dest/public/avm/fixtures/initializers.d.ts +1 -1
  47. package/dest/public/avm/fixtures/initializers.d.ts.map +1 -1
  48. package/dest/public/avm/fixtures/initializers.js +2 -1
  49. package/dest/public/avm/opcodes/accrued_substate.d.ts +4 -5
  50. package/dest/public/avm/opcodes/accrued_substate.d.ts.map +1 -1
  51. package/dest/public/avm/opcodes/accrued_substate.js +15 -16
  52. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  53. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  54. package/dest/public/avm/opcodes/external_calls.js +7 -7
  55. package/dest/public/avm/opcodes/memory.js +1 -1
  56. package/dest/public/avm/serialization/bytecode_serialization.js +3 -3
  57. package/dest/public/avm/serialization/instruction_serialization.d.ts +2 -2
  58. package/dest/public/avm/serialization/instruction_serialization.d.ts.map +1 -1
  59. package/dest/public/avm/serialization/instruction_serialization.js +1 -1
  60. package/dest/public/contracts_db_checkpoint.d.ts +2 -2
  61. package/dest/public/contracts_db_checkpoint.d.ts.map +1 -1
  62. package/dest/public/contracts_db_checkpoint.js +1 -1
  63. package/dest/public/debug_fn_name.d.ts +4 -4
  64. package/dest/public/debug_fn_name.d.ts.map +1 -1
  65. package/dest/public/debug_fn_name.js +7 -5
  66. package/dest/public/executor_metrics.d.ts +1 -1
  67. package/dest/public/executor_metrics.d.ts.map +1 -1
  68. package/dest/public/executor_metrics.js +7 -2
  69. package/dest/public/fixtures/amm_test.js +2 -2
  70. package/dest/public/fixtures/bulk_test.d.ts +1 -1
  71. package/dest/public/fixtures/bulk_test.d.ts.map +1 -1
  72. package/dest/public/fixtures/bulk_test.js +4 -4
  73. package/dest/public/fixtures/custom_bytecode_tests.d.ts +3 -1
  74. package/dest/public/fixtures/custom_bytecode_tests.d.ts.map +1 -1
  75. package/dest/public/fixtures/custom_bytecode_tests.js +61 -1
  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 +16 -56
  79. package/dest/public/fixtures/public_tx_simulation_tester.d.ts +6 -5
  80. package/dest/public/fixtures/public_tx_simulation_tester.d.ts.map +1 -1
  81. package/dest/public/fixtures/public_tx_simulation_tester.js +37 -10
  82. package/dest/public/fixtures/utils.d.ts +2 -2
  83. package/dest/public/fixtures/utils.d.ts.map +1 -1
  84. package/dest/public/fixtures/utils.js +10 -10
  85. package/dest/public/hinting_db_sources.d.ts +5 -5
  86. package/dest/public/hinting_db_sources.d.ts.map +1 -1
  87. package/dest/public/hinting_db_sources.js +7 -6
  88. package/dest/public/public_db_sources.d.ts +6 -5
  89. package/dest/public/public_db_sources.d.ts.map +1 -1
  90. package/dest/public/public_db_sources.js +14 -14
  91. package/dest/public/public_processor/guarded_merkle_tree.d.ts +5 -5
  92. package/dest/public/public_processor/guarded_merkle_tree.d.ts.map +1 -1
  93. package/dest/public/public_processor/guarded_merkle_tree.js +5 -5
  94. package/dest/public/public_processor/public_processor.d.ts +8 -4
  95. package/dest/public/public_processor/public_processor.d.ts.map +1 -1
  96. package/dest/public/public_processor/public_processor.js +75 -50
  97. package/dest/public/public_processor/public_processor_metrics.d.ts +5 -2
  98. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  99. package/dest/public/public_processor/public_processor_metrics.js +28 -4
  100. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts +3 -2
  101. package/dest/public/public_tx_simulator/contract_provider_for_cpp.d.ts.map +1 -1
  102. package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +4 -3
  103. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +5 -5
  104. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  105. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +10 -11
  106. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts +4 -4
  107. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.d.ts.map +1 -1
  108. package/dest/public/public_tx_simulator/cpp_public_tx_simulator_with_hinted_dbs.js +7 -7
  109. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts +4 -4
  110. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.d.ts.map +1 -1
  111. package/dest/public/public_tx_simulator/cpp_vs_ts_public_tx_simulator.js +6 -6
  112. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts +3 -2
  113. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.d.ts.map +1 -1
  114. package/dest/public/public_tx_simulator/dumping_cpp_public_tx_simulator.js +2 -2
  115. package/dest/public/public_tx_simulator/factories.d.ts +3 -2
  116. package/dest/public/public_tx_simulator/factories.d.ts.map +1 -1
  117. package/dest/public/public_tx_simulator/factories.js +4 -4
  118. package/dest/public/public_tx_simulator/public_tx_context.d.ts +10 -5
  119. package/dest/public/public_tx_simulator/public_tx_context.d.ts.map +1 -1
  120. package/dest/public/public_tx_simulator/public_tx_context.js +16 -18
  121. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts +9 -4
  122. package/dest/public/public_tx_simulator/public_tx_simulator.d.ts.map +1 -1
  123. package/dest/public/public_tx_simulator/public_tx_simulator.js +23 -15
  124. package/dest/public/side_effect_trace.d.ts +4 -4
  125. package/dest/public/side_effect_trace.d.ts.map +1 -1
  126. package/dest/public/side_effect_trace.js +3 -3
  127. package/dest/public/state_manager/state_manager.d.ts +10 -4
  128. package/dest/public/state_manager/state_manager.d.ts.map +1 -1
  129. package/dest/public/state_manager/state_manager.js +12 -5
  130. package/dest/public/test_executor_metrics.d.ts +8 -2
  131. package/dest/public/test_executor_metrics.d.ts.map +1 -1
  132. package/dest/public/test_executor_metrics.js +24 -2
  133. package/package.json +15 -16
  134. package/src/private/acvm/acvm.ts +4 -3
  135. package/src/private/acvm_native.ts +11 -5
  136. package/src/private/acvm_wasm.ts +7 -3
  137. package/src/private/circuit_recording/circuit_recorder.ts +7 -5
  138. package/src/private/circuit_recording/file_circuit_recorder.ts +7 -2
  139. package/src/private/circuit_recording/memory_circuit_recorder.ts +6 -4
  140. package/src/private/factory.ts +7 -4
  141. package/src/public/avm/avm_context.ts +2 -2
  142. package/src/public/avm/avm_contract_call_result.ts +8 -6
  143. package/src/public/avm/avm_execution_environment.ts +9 -4
  144. package/src/public/avm/avm_gas.ts +2 -2
  145. package/src/public/avm/avm_machine_state.ts +6 -5
  146. package/src/public/avm/avm_simulator.ts +9 -6
  147. package/src/public/avm/calldata.ts +101 -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/external_calls.ts +9 -8
  154. package/src/public/avm/opcodes/memory.ts +1 -1
  155. package/src/public/avm/serialization/bytecode_serialization.ts +2 -2
  156. package/src/public/avm/serialization/instruction_serialization.ts +1 -1
  157. package/src/public/contracts_db_checkpoint.ts +1 -1
  158. package/src/public/debug_fn_name.ts +10 -8
  159. package/src/public/executor_metrics.ts +4 -1
  160. package/src/public/fixtures/amm_test.ts +2 -2
  161. package/src/public/fixtures/bulk_test.ts +2 -4
  162. package/src/public/fixtures/custom_bytecode_tests.ts +139 -1
  163. package/src/public/fixtures/opcode_spammer.ts +18 -55
  164. package/src/public/fixtures/public_tx_simulation_tester.ts +47 -6
  165. package/src/public/fixtures/utils.ts +17 -12
  166. package/src/public/fuzzing/avm_fuzzer_simulator.ts +1 -1
  167. package/src/public/hinting_db_sources.ts +9 -7
  168. package/src/public/public_db_sources.ts +27 -19
  169. package/src/public/public_processor/guarded_merkle_tree.ts +6 -6
  170. package/src/public/public_processor/public_processor.ts +112 -67
  171. package/src/public/public_processor/public_processor_metrics.ts +22 -4
  172. package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +8 -4
  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 +21 -16
  179. package/src/public/public_tx_simulator/public_tx_simulator.ts +28 -15
  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
  }
@@ -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';
@@ -13,8 +14,8 @@ abstract class ExternalCall extends Instruction {
13
14
  OperandType.UINT16, // L2 gas offset
14
15
  OperandType.UINT16, // DA gas offset
15
16
  OperandType.UINT16, // Address offset
16
- OperandType.UINT16, // Args offset
17
17
  OperandType.UINT16, // Args size offset
18
+ OperandType.UINT16, // Args offset
18
19
  ];
19
20
 
20
21
  constructor(
@@ -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
 
@@ -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,
@@ -31,7 +31,7 @@ export class ContractsDbCheckpoint {
31
31
  return this.bytecodeCommitments.get(classId.toString());
32
32
  }
33
33
 
34
- public deepCopy(): ContractsDbCheckpoint {
34
+ public fork(): ContractsDbCheckpoint {
35
35
  const copy = new ContractsDbCheckpoint();
36
36
  this.instances.forEach((value, key) => copy.instances.set(key, value));
37
37
  this.classes.forEach((value, key) => copy.classes.set(key, value));
@@ -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
  }
@@ -30,9 +30,7 @@ export async function bulkTest(
30
30
  // for it to use as "expected" values when testing contract instance retrieval.
31
31
  const expectContractInstance = avmTestContract;
32
32
  const argsField = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
33
- const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8].map(x => new Fr(x));
34
- argsU8.push(new Fr(2n ** 128n + 9n)); // Trigger truncation from large (> 128 bits) value (canonical decomposition event)
35
- argsU8.push(new Fr(2n ** 125n + 10n)); // Trigger truncation from small (< 128 bits) value (no canonical decomposition event)
33
+ const argsU8 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(x => new Fr(x));
36
34
  const args = [
37
35
  argsField,
38
36
  argsU8,
@@ -62,7 +60,7 @@ export async function bulkTest(
62
60
  {
63
61
  address: avmTestContract.address,
64
62
  fnName: 'assert_calldata_copy',
65
- args: [argsField.slice(3), /* with_selector: */ true],
63
+ args: [argsField.slice(0, 3), /* with_selector: */ true],
66
64
  },
67
65
  {
68
66
  address: avmTestContract.address,
@@ -2,7 +2,7 @@ import { strict as assert } from 'assert';
2
2
 
3
3
  import { TypeTag } from '../avm/avm_memory_types.js';
4
4
  import { Addressing, AddressingMode } from '../avm/opcodes/addressing_mode.js';
5
- import { Add, CalldataCopy, Jump, Return, Set } from '../avm/opcodes/index.js';
5
+ import { Add, CalldataCopy, Cast, Jump, Return, Set } from '../avm/opcodes/index.js';
6
6
  import { encodeToBytecode } from '../avm/serialization/bytecode_serialization.js';
7
7
  import {
8
8
  MAX_OPCODE_VALUE,
@@ -208,6 +208,144 @@ export async function invalidTagValueAndInstructionTruncatedTest(tester: PublicT
208
208
  return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
209
209
  }
210
210
 
211
+ // Exercise SET truncation: set values whose widths exceed the target tag and
212
+ // rely on `buildFromTagTruncating` to truncate to the low bits of the tag.
213
+ // Covers sources larger than 128 bits (via SET_FF) and sources in (32, 128]
214
+ // bits (via SET_64) against destination tags U1/U8/U16/U32/U64/U128.
215
+ export async function setTruncationTest(tester: PublicTxSimulationTester) {
216
+ // 200-bit value: forces truncation for every target tag up to U128.
217
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
218
+ // 40-bit value: forces truncation for target tags up to U32.
219
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
220
+
221
+ const bytecode = encodeToBytecode([
222
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
223
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
224
+
225
+ // Source >128 bits (via SET_FF) truncated to smaller target tags.
226
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 1, TypeTag.UINT128, LARGE_FIELD_VALUE).as(
227
+ Opcode.SET_FF,
228
+ Set.wireFormatFF,
229
+ ),
230
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 2, TypeTag.UINT64, LARGE_FIELD_VALUE).as(
231
+ Opcode.SET_FF,
232
+ Set.wireFormatFF,
233
+ ),
234
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 3, TypeTag.UINT32, LARGE_FIELD_VALUE).as(
235
+ Opcode.SET_FF,
236
+ Set.wireFormatFF,
237
+ ),
238
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 4, TypeTag.UINT16, LARGE_FIELD_VALUE).as(
239
+ Opcode.SET_FF,
240
+ Set.wireFormatFF,
241
+ ),
242
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 5, TypeTag.UINT8, LARGE_FIELD_VALUE).as(
243
+ Opcode.SET_FF,
244
+ Set.wireFormatFF,
245
+ ),
246
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 6, TypeTag.UINT1, LARGE_FIELD_VALUE).as(
247
+ Opcode.SET_FF,
248
+ Set.wireFormatFF,
249
+ ),
250
+
251
+ // Source in (32, 128] bits (via SET_64) truncated to smaller target tags.
252
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 7, TypeTag.UINT32, LARGE_U64_VALUE).as(
253
+ Opcode.SET_64,
254
+ Set.wireFormat64,
255
+ ),
256
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 8, TypeTag.UINT16, LARGE_U64_VALUE).as(
257
+ Opcode.SET_64,
258
+ Set.wireFormat64,
259
+ ),
260
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 9, TypeTag.UINT8, LARGE_U64_VALUE).as(
261
+ Opcode.SET_64,
262
+ Set.wireFormat64,
263
+ ),
264
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.UINT1, LARGE_U64_VALUE).as(
265
+ Opcode.SET_64,
266
+ Set.wireFormat64,
267
+ ),
268
+
269
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
270
+ ]);
271
+
272
+ const txLabel = 'SetTruncation';
273
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
274
+ }
275
+
276
+ // Exercise CAST truncation: store a wide source value in memory then CAST it
277
+ // to smaller destination tags. Covers sources larger than 128 bits (FIELD
278
+ // source) and sources in (32, 128] bits (UINT64 source) against destination
279
+ // tags U1/U8/U16/U32/U64/U128.
280
+ export async function castTruncationTest(tester: PublicTxSimulationTester) {
281
+ // 200-bit source: stored as FIELD so that CASTs to any integer tag truncate.
282
+ const LARGE_FIELD_VALUE = (1n << 200n) + 0x1234567890abcdef1234567890abcdefn;
283
+ // 40-bit source: stored as UINT64 so CASTs to U1/U8/U16/U32 truncate.
284
+ const LARGE_U64_VALUE = (1n << 40n) + 0xdeadbeefn;
285
+
286
+ const bytecode = encodeToBytecode([
287
+ // Zero U32 at offset 0 — used as the Return copy-size slot.
288
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 0, TypeTag.UINT32, /*value=*/ 0).as(Opcode.SET_8, Set.wireFormat8),
289
+
290
+ // Store wide FIELD source at offset 10, then CAST to smaller tags.
291
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 10, TypeTag.FIELD, LARGE_FIELD_VALUE).as(
292
+ Opcode.SET_FF,
293
+ Set.wireFormatFF,
294
+ ),
295
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 11, TypeTag.UINT128).as(
296
+ Opcode.CAST_8,
297
+ Cast.wireFormat8,
298
+ ),
299
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 12, TypeTag.UINT64).as(
300
+ Opcode.CAST_8,
301
+ Cast.wireFormat8,
302
+ ),
303
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 13, TypeTag.UINT32).as(
304
+ Opcode.CAST_8,
305
+ Cast.wireFormat8,
306
+ ),
307
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 14, TypeTag.UINT16).as(
308
+ Opcode.CAST_8,
309
+ Cast.wireFormat8,
310
+ ),
311
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 15, TypeTag.UINT8).as(
312
+ Opcode.CAST_8,
313
+ Cast.wireFormat8,
314
+ ),
315
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 10, /*dstOffset=*/ 16, TypeTag.UINT1).as(
316
+ Opcode.CAST_8,
317
+ Cast.wireFormat8,
318
+ ),
319
+
320
+ // Store UINT64 source at offset 20, then CAST to smaller integer tags.
321
+ new Set(/*addressing_mode=*/ 0, /*dstOffset=*/ 20, TypeTag.UINT64, LARGE_U64_VALUE).as(
322
+ Opcode.SET_64,
323
+ Set.wireFormat64,
324
+ ),
325
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 21, TypeTag.UINT32).as(
326
+ Opcode.CAST_8,
327
+ Cast.wireFormat8,
328
+ ),
329
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 22, TypeTag.UINT16).as(
330
+ Opcode.CAST_8,
331
+ Cast.wireFormat8,
332
+ ),
333
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 23, TypeTag.UINT8).as(
334
+ Opcode.CAST_8,
335
+ Cast.wireFormat8,
336
+ ),
337
+ new Cast(/*addressing_mode=*/ 0, /*srcOffset=*/ 20, /*dstOffset=*/ 24, TypeTag.UINT1).as(
338
+ Opcode.CAST_8,
339
+ Cast.wireFormat8,
340
+ ),
341
+
342
+ new Return(/*addressing_mode=*/ 0, /*copySizeOffset=*/ 0, /*returnOffset=*/ 0),
343
+ ]);
344
+
345
+ const txLabel = 'CastTruncation';
346
+ return await deployAndExecuteCustomBytecode(bytecode, tester, txLabel);
347
+ }
348
+
211
349
  /**
212
350
  * Returns the offset of the tag in an instruction.
213
351
  * @details Loops over the wire format operand type entries until it finds the tag.