miden_air/trace/decoder/mod.rs
1use core::ops::Range;
2
3use miden_core::{Felt, ONE, ZERO, operations::Operation, utils::range};
4
5use super::DECODER_AUX_TRACE_OFFSET;
6
7// CONSTANTS
8// ================================================================================================
9
10/// Index of the column holding code block IDs (which are row addresses from the hasher table).
11pub const ADDR_COL_IDX: usize = 0;
12
13/// Index at which operation bit columns start in the decoder trace.
14pub const OP_BITS_OFFSET: usize = ADDR_COL_IDX + 1;
15
16/// Number of columns needed to hold a binary representation of opcodes.
17pub const NUM_OP_BITS: usize = Operation::OP_BITS;
18
19/// Location of operation bits columns in the decoder trace.
20pub const OP_BITS_RANGE: Range<usize> = range(OP_BITS_OFFSET, NUM_OP_BITS);
21
22// Note: "hasher state" columns are shared between decoding operations and holding
23// the hasher state during MAST node hashing.
24
25/// Index at which hasher state columns start in the decoder trace.
26pub const HASHER_STATE_OFFSET: usize = OP_BITS_RANGE.end;
27
28/// Number of hasher columns in the decoder trace.
29pub const NUM_HASHER_COLUMNS: usize = 8;
30
31/// Number of helper registers available to user ops.
32pub const NUM_USER_OP_HELPERS: usize = 6;
33
34/// Index at which helper registers available to user ops start.
35/// The first two helper registers are used by the decoder itself.
36pub const USER_OP_HELPERS_OFFSET: usize = HASHER_STATE_OFFSET + 2;
37
38/// Location of hasher columns in the decoder trace.
39pub const HASHER_STATE_RANGE: Range<usize> = range(HASHER_STATE_OFFSET, NUM_HASHER_COLUMNS);
40
41/// Index of the in_span column in the decoder trace.
42pub const IN_SPAN_COL_IDX: usize = HASHER_STATE_RANGE.end;
43
44/// Index of the operation group count column in the decoder trace.
45pub const GROUP_COUNT_COL_IDX: usize = IN_SPAN_COL_IDX + 1;
46
47/// Index of the operation index column in the decoder trace.
48pub const OP_INDEX_COL_IDX: usize = GROUP_COUNT_COL_IDX + 1;
49
50/// Index at which operation batch flag columns start in the decoder trace.
51pub const OP_BATCH_FLAGS_OFFSET: usize = OP_INDEX_COL_IDX + 1;
52
53/// Number of operation batch flag columns.
54pub const NUM_OP_BATCH_FLAGS: usize = 3;
55
56/// Location of operation batch flag columns in the decoder trace.
57pub const OP_BATCH_FLAGS_RANGE: Range<usize> = range(OP_BATCH_FLAGS_OFFSET, NUM_OP_BATCH_FLAGS);
58
59/// Operation batch consists of 8 operation groups.
60pub const OP_BATCH_8_GROUPS: [Felt; NUM_OP_BATCH_FLAGS] = [ONE, ZERO, ZERO];
61
62/// Operation batch consists of 4 operation groups.
63pub const OP_BATCH_4_GROUPS: [Felt; NUM_OP_BATCH_FLAGS] = [ZERO, ONE, ZERO];
64
65/// Operation batch consists of 2 operation groups.
66pub const OP_BATCH_2_GROUPS: [Felt; NUM_OP_BATCH_FLAGS] = [ZERO, ZERO, ONE];
67
68/// Operation batch consists of 1 operation group.
69pub const OP_BATCH_1_GROUPS: [Felt; NUM_OP_BATCH_FLAGS] = [ZERO, ONE, ONE];
70
71/// Index at which the op bits extra columns start in the decoder trace.
72pub const OP_BITS_EXTRA_COLS_OFFSET: usize = OP_BATCH_FLAGS_RANGE.end;
73
74/// Number of columns needed for degree reduction of the operation flags.
75pub const NUM_OP_BITS_EXTRA_COLS: usize = 2;
76
77/// Location of the operation bits extra columns (for degree reduction) in the decoder trace.
78pub const OP_BITS_EXTRA_COLS_RANGE: Range<usize> =
79 range(OP_BITS_EXTRA_COLS_OFFSET, NUM_OP_BITS_EXTRA_COLS);
80
81/// Index of a flag column which indicates whether an ending block is a body of a loop.
82pub const IS_LOOP_BODY_FLAG_COL_IDX: usize = HASHER_STATE_RANGE.start + 4;
83
84/// Index of a flag column which indicates whether an ending block is a LOOP block.
85pub const IS_LOOP_FLAG_COL_IDX: usize = HASHER_STATE_RANGE.start + 5;
86
87/// Index of a flag column which indicates whether an ending block is a CALL or DYNCALL block.
88pub const IS_CALL_FLAG_COL_IDX: usize = HASHER_STATE_RANGE.start + 6;
89
90/// Index of a flag column which indicates whether an ending block is a SYSCALL block.
91pub const IS_SYSCALL_FLAG_COL_IDX: usize = HASHER_STATE_RANGE.start + 7;
92
93// --- Column accessors in the auxiliary columns --------------------------------------------------
94
95/// Running product column representing block stack table.
96pub const P1_COL_IDX: usize = DECODER_AUX_TRACE_OFFSET;
97
98/// Running product column representing block hash table
99pub const P2_COL_IDX: usize = DECODER_AUX_TRACE_OFFSET + 1;
100
101/// Running product column representing op group table.
102pub const P3_COL_IDX: usize = DECODER_AUX_TRACE_OFFSET + 2;
103
104// --- GLOBALLY-INDEXED DECODER COLUMN ACCESSORS --------------------------------------------------
105pub const DECODER_OP_BITS_OFFSET: usize = super::DECODER_TRACE_OFFSET + OP_BITS_OFFSET;
106pub const DECODER_USER_OP_HELPERS_OFFSET: usize =
107 super::DECODER_TRACE_OFFSET + USER_OP_HELPERS_OFFSET;