36 for (
const auto&
event : events) {
37 const auto& bytecode = *
event.bytecode;
38 const auto id =
event.bytecode_id;
39 auto bytecode_at = [&bytecode](
size_t i) -> uint8_t {
return i < bytecode.size() ? bytecode[i] : 0; };
40 const uint32_t bytecode_len =
static_cast<uint32_t
>(bytecode.size());
42 for (uint32_t i = 0; i < bytecode_len; i++) {
43 const uint32_t remaining = bytecode_len - i;
45 const bool is_last = remaining == 1;
55 { C::bc_decomposition_sel, 1 },
56 { C::bc_decomposition_id,
id },
57 { C::bc_decomposition_pc, i },
58 { C::bc_decomposition_last_of_contract, is_last ? 1 : 0 },
59 { C::bc_decomposition_bytes_remaining, remaining },
60 { C::bc_decomposition_bytes_rem_inv,
FF(remaining).invert() },
61 { C::bc_decomposition_bytes_rem_min_one_inv, is_last ? 0 :
FF(remaining - 1).invert() },
62 { C::bc_decomposition_bytes_to_read, bytes_to_read },
64 { C::bc_decomposition_windows_min_remaining_inv,
66 { C::bc_decomposition_is_windows_eq_remaining, is_windows_eq_remaining ? 1 : 0 },
68 { C::bc_decomposition_bytes, bytecode_at(i) },
69 { C::bc_decomposition_bytes_pc_plus_1, bytecode_at(i + 1) },
70 { C::bc_decomposition_bytes_pc_plus_2, bytecode_at(i + 2) },
71 { C::bc_decomposition_bytes_pc_plus_3, bytecode_at(i + 3) },
72 { C::bc_decomposition_bytes_pc_plus_4, bytecode_at(i + 4) },
73 { C::bc_decomposition_bytes_pc_plus_5, bytecode_at(i + 5) },
74 { C::bc_decomposition_bytes_pc_plus_6, bytecode_at(i + 6) },
75 { C::bc_decomposition_bytes_pc_plus_7, bytecode_at(i + 7) },
76 { C::bc_decomposition_bytes_pc_plus_8, bytecode_at(i + 8) },
77 { C::bc_decomposition_bytes_pc_plus_9, bytecode_at(i + 9) },
78 { C::bc_decomposition_bytes_pc_plus_10, bytecode_at(i + 10) },
79 { C::bc_decomposition_bytes_pc_plus_11, bytecode_at(i + 11) },
80 { C::bc_decomposition_bytes_pc_plus_12, bytecode_at(i + 12) },
81 { C::bc_decomposition_bytes_pc_plus_13, bytecode_at(i + 13) },
82 { C::bc_decomposition_bytes_pc_plus_14, bytecode_at(i + 14) },
83 { C::bc_decomposition_bytes_pc_plus_15, bytecode_at(i + 15) },
84 { C::bc_decomposition_bytes_pc_plus_16, bytecode_at(i + 16) },
85 { C::bc_decomposition_bytes_pc_plus_17, bytecode_at(i + 17) },
86 { C::bc_decomposition_bytes_pc_plus_18, bytecode_at(i + 18) },
87 { C::bc_decomposition_bytes_pc_plus_19, bytecode_at(i + 19) },
88 { C::bc_decomposition_bytes_pc_plus_20, bytecode_at(i + 20) },
89 { C::bc_decomposition_bytes_pc_plus_21, bytecode_at(i + 21) },
90 { C::bc_decomposition_bytes_pc_plus_22, bytecode_at(i + 22) },
91 { C::bc_decomposition_bytes_pc_plus_23, bytecode_at(i + 23) },
92 { C::bc_decomposition_bytes_pc_plus_24, bytecode_at(i + 24) },
93 { C::bc_decomposition_bytes_pc_plus_25, bytecode_at(i + 25) },
94 { C::bc_decomposition_bytes_pc_plus_26, bytecode_at(i + 26) },
95 { C::bc_decomposition_bytes_pc_plus_27, bytecode_at(i + 27) },
96 { C::bc_decomposition_bytes_pc_plus_28, bytecode_at(i + 28) },
97 { C::bc_decomposition_bytes_pc_plus_29, bytecode_at(i + 29) },
98 { C::bc_decomposition_bytes_pc_plus_30, bytecode_at(i + 30) },
99 { C::bc_decomposition_bytes_pc_plus_31, bytecode_at(i + 31) },
100 { C::bc_decomposition_bytes_pc_plus_32, bytecode_at(i + 32) },
101 { C::bc_decomposition_bytes_pc_plus_33, bytecode_at(i + 33) },
102 { C::bc_decomposition_bytes_pc_plus_34, bytecode_at(i + 34) },
103 { C::bc_decomposition_bytes_pc_plus_35, bytecode_at(i + 35) },
104 { C::bc_decomposition_bytes_pc_plus_36, bytecode_at(i + 36) },
109 auto bytecode_field_at = [&](
size_t i) ->
FF {
112 if (bytecode_len - i >= 32) {
113 as_int = from_buffer<uint256_t>(bytecode, i);
115 std::vector<uint8_t> tail(bytecode.begin() +
static_cast<ssize_t
>(i), bytecode.end());
117 as_int = from_buffer<uint256_t>(tail, 0);
121 for (uint32_t i = 0; i < bytecode_len; i += 31) {
124 { C::bc_decomposition_sel_packed, 1 },
125 { C::bc_decomposition_packed_field, bytecode_field_at(i) },
214 for (
const auto&
event : events) {
216 const auto bytecode_size =
event.bytecode->size();
218 auto get_operand = [&](
size_t i) ->
FF {
219 return i <
event.instruction.operands.size() ?
static_cast<FF>(
event.instruction.operands[i]) : 0;
221 auto bytecode_at = [&](
size_t i) -> uint8_t {
return i < bytecode_size ? (*
event.bytecode)[i] : 0; };
223 const uint8_t wire_opcode = bytecode_at(
event.pc);
224 const bool wire_opcode_in_range =
227 uint32_t size_in_bytes = 0;
229 std::array<uint8_t, NUM_OP_DC_SELECTORS> op_dc_selectors{};
231 uint8_t tag_is_op2 = 0;
232 uint8_t tag_value = 0;
234 if (wire_opcode_in_range) {
236 size_in_bytes = wire_instr_spec.size_in_bytes;
237 exec_opcode = wire_instr_spec.exec_opcode;
238 op_dc_selectors = wire_instr_spec.op_dc_selectors;
240 if (wire_instr_spec.tag_operand_idx.has_value()) {
241 const auto tag_value_idx = wire_instr_spec.tag_operand_idx.value();
242 assert((tag_value_idx == 2 || tag_value_idx == 3) &&
243 "Current constraints support only tag for operand index equal to 2 or 3");
246 if (tag_value_idx == 2) {
248 tag_value =
static_cast<uint8_t
>(get_operand(1));
250 tag_value =
static_cast<uint8_t
>(get_operand(2));
255 const uint32_t bytes_remaining =
256 event.error ==
PC_OUT_OF_RANGE ? 0 :
static_cast<uint32_t
>(bytecode_size -
event.pc);
259 uint32_t instr_abs_diff = 0;
260 if (size_in_bytes <= bytes_to_read) {
261 instr_abs_diff = bytes_to_read - size_in_bytes;
263 instr_abs_diff = size_in_bytes - bytes_to_read - 1;
266 uint32_t bytecode_size_u32 =
static_cast<uint32_t
>(bytecode_size);
267 uint32_t pc_abs_diff =
268 bytecode_size_u32 >
event.pc ? bytecode_size_u32 -
event.pc - 1 :
event.pc - bytecode_size_u32;
272 { C::instr_fetching_sel, 1 },
273 { C::instr_fetching_bytecode_id, bytecode_id },
274 { C::instr_fetching_pc,
event.pc },
276 { C::instr_fetching_indirect,
event.instruction.indirect },
277 { C::instr_fetching_op1, get_operand(0) },
278 { C::instr_fetching_op2, get_operand(1) },
279 { C::instr_fetching_op3, get_operand(2) },
280 { C::instr_fetching_op4, get_operand(3) },
281 { C::instr_fetching_op5, get_operand(4) },
282 { C::instr_fetching_op6, get_operand(5) },
283 { C::instr_fetching_op7, get_operand(6) },
285 { C::instr_fetching_bd0, wire_opcode },
286 { C::instr_fetching_bd1, bytecode_at(
event.pc + 1) },
287 { C::instr_fetching_bd2, bytecode_at(
event.pc + 2) },
288 { C::instr_fetching_bd3, bytecode_at(
event.pc + 3) },
289 { C::instr_fetching_bd4, bytecode_at(
event.pc + 4) },
290 { C::instr_fetching_bd5, bytecode_at(
event.pc + 5) },
291 { C::instr_fetching_bd6, bytecode_at(
event.pc + 6) },
292 { C::instr_fetching_bd7, bytecode_at(
event.pc + 7) },
293 { C::instr_fetching_bd8, bytecode_at(
event.pc + 8) },
294 { C::instr_fetching_bd9, bytecode_at(
event.pc + 9) },
295 { C::instr_fetching_bd10, bytecode_at(
event.pc + 10) },
296 { C::instr_fetching_bd11, bytecode_at(
event.pc + 11) },
297 { C::instr_fetching_bd12, bytecode_at(
event.pc + 12) },
298 { C::instr_fetching_bd13, bytecode_at(
event.pc + 13) },
299 { C::instr_fetching_bd14, bytecode_at(
event.pc + 14) },
300 { C::instr_fetching_bd15, bytecode_at(
event.pc + 15) },
301 { C::instr_fetching_bd16, bytecode_at(
event.pc + 16) },
302 { C::instr_fetching_bd17, bytecode_at(
event.pc + 17) },
303 { C::instr_fetching_bd18, bytecode_at(
event.pc + 18) },
304 { C::instr_fetching_bd19, bytecode_at(
event.pc + 19) },
305 { C::instr_fetching_bd20, bytecode_at(
event.pc + 20) },
306 { C::instr_fetching_bd21, bytecode_at(
event.pc + 21) },
307 { C::instr_fetching_bd22, bytecode_at(
event.pc + 22) },
308 { C::instr_fetching_bd23, bytecode_at(
event.pc + 23) },
309 { C::instr_fetching_bd24, bytecode_at(
event.pc + 24) },
310 { C::instr_fetching_bd25, bytecode_at(
event.pc + 25) },
311 { C::instr_fetching_bd26, bytecode_at(
event.pc + 26) },
312 { C::instr_fetching_bd27, bytecode_at(
event.pc + 27) },
313 { C::instr_fetching_bd28, bytecode_at(
event.pc + 28) },
314 { C::instr_fetching_bd29, bytecode_at(
event.pc + 29) },
315 { C::instr_fetching_bd30, bytecode_at(
event.pc + 30) },
316 { C::instr_fetching_bd31, bytecode_at(
event.pc + 31) },
317 { C::instr_fetching_bd32, bytecode_at(
event.pc + 32) },
318 { C::instr_fetching_bd33, bytecode_at(
event.pc + 33) },
319 { C::instr_fetching_bd34, bytecode_at(
event.pc + 34) },
320 { C::instr_fetching_bd35, bytecode_at(
event.pc + 35) },
321 { C::instr_fetching_bd36, bytecode_at(
event.pc + 36) },
324 { C::instr_fetching_exec_opcode,
static_cast<uint32_t
>(exec_opcode) },
325 { C::instr_fetching_instr_size, size_in_bytes },
326 { C::instr_fetching_sel_has_tag, has_tag },
327 { C::instr_fetching_sel_tag_is_op2, tag_is_op2 },
330 { C::instr_fetching_sel_op_dc_0, op_dc_selectors.at(0) },
331 { C::instr_fetching_sel_op_dc_1, op_dc_selectors.at(1) },
332 { C::instr_fetching_sel_op_dc_2, op_dc_selectors.at(2) },
333 { C::instr_fetching_sel_op_dc_3, op_dc_selectors.at(3) },
334 { C::instr_fetching_sel_op_dc_4, op_dc_selectors.at(4) },
335 { C::instr_fetching_sel_op_dc_5, op_dc_selectors.at(5) },
336 { C::instr_fetching_sel_op_dc_6, op_dc_selectors.at(6) },
337 { C::instr_fetching_sel_op_dc_7, op_dc_selectors.at(7) },
338 { C::instr_fetching_sel_op_dc_8, op_dc_selectors.at(8) },
339 { C::instr_fetching_sel_op_dc_9, op_dc_selectors.at(9) },
340 { C::instr_fetching_sel_op_dc_10, op_dc_selectors.at(10) },
341 { C::instr_fetching_sel_op_dc_11, op_dc_selectors.at(11) },
342 { C::instr_fetching_sel_op_dc_12, op_dc_selectors.at(12) },
343 { C::instr_fetching_sel_op_dc_13, op_dc_selectors.at(13) },
344 { C::instr_fetching_sel_op_dc_14, op_dc_selectors.at(14) },
345 { C::instr_fetching_sel_op_dc_15, op_dc_selectors.at(15) },
346 { C::instr_fetching_sel_op_dc_16, op_dc_selectors.at(16) },
349 { C::instr_fetching_pc_out_of_range,
event.error ==
PC_OUT_OF_RANGE ? 1 : 0 },
352 { C::instr_fetching_tag_out_of_range,
event.error ==
TAG_OUT_OF_RANGE ? 1 : 0 },
353 { C::instr_fetching_sel_parsing_err,
event.error.has_value() ? 1 : 0 },
356 { C::instr_fetching_sel_pc_in_range,
event.error !=
PC_OUT_OF_RANGE ? 1 : 0 },
358 { C::instr_fetching_bytecode_size, bytecode_size },
359 { C::instr_fetching_bytes_to_read, bytes_to_read },
360 { C::instr_fetching_instr_abs_diff, instr_abs_diff },
361 { C::instr_fetching_pc_abs_diff, pc_abs_diff },
362 { C::instr_fetching_pc_size_in_bits,
364 { C::instr_fetching_tag_value, tag_value },