Skip to main content

sp1_core_machine/syscall/instructions/
columns.rs

1use sp1_derive::AlignedBorrow;
2use sp1_hypercube::{air::PV_DIGEST_NUM_WORDS, Word};
3use std::mem::size_of;
4use struct_reflection::{StructReflection, StructReflectionHelper};
5
6use crate::{
7    adapter::{register::r_type::RTypeReader, state::CPUState},
8    operations::{IsZeroOperation, SP1FieldWordRangeChecker, U16toU8Operation},
9    SupervisorMode, TrustMode, UserMode,
10};
11
12pub const NUM_SYSCALL_INSTR_COLS_USER: usize = size_of::<SyscallInstrColumns<u8, UserMode>>();
13pub const NUM_SYSCALL_INSTR_COLS_SUPERVISOR: usize =
14    size_of::<SyscallInstrColumns<u8, SupervisorMode>>();
15
16#[derive(AlignedBorrow, Default, Debug, Clone, Copy, StructReflection)]
17#[repr(C)]
18pub struct SyscallInstrColumns<T, M: TrustMode> {
19    /// The current shard, timestamp, program counter of the CPU.
20    pub state: CPUState<T>,
21
22    /// The adapter to read program and register information.
23    pub adapter: RTypeReader<T>,
24
25    /// The next program counter.
26    pub next_pc: [T; 3],
27
28    /// Whether the current instruction is a halt instruction. This is verified by the
29    /// is_halt_check operation.
30    pub is_halt: T,
31
32    /// The result of register op_a.
33    pub op_a_value: Word<T>,
34
35    /// Lower byte of two limbs of `b`.
36    pub a_low_bytes: U16toU8Operation<T>,
37
38    /// Whether the current ecall is ENTER_UNCONSTRAINED.
39    pub is_enter_unconstrained: IsZeroOperation<T>,
40
41    /// Whether the current ecall is HINT_LEN.
42    pub is_hint_len: IsZeroOperation<T>,
43
44    /// Whether the current ecall is HALT.
45    pub is_halt_check: IsZeroOperation<T>,
46
47    /// Whether the current ecall is a COMMIT.
48    pub is_commit: IsZeroOperation<T>,
49
50    /// Whether the current ecall is a COMMIT_DEFERRED_PROOFS.
51    pub is_commit_deferred_proofs: IsZeroOperation<T>,
52
53    /// Field to store the word index passed into the COMMIT ecall.  
54    /// index_bitmap[word index] should be set to 1 and everything else set to 0.
55    pub index_bitmap: [T; PV_DIGEST_NUM_WORDS],
56
57    /// The expected public values digest.
58    pub expected_public_values_digest: [T; 4],
59
60    /// The check if `op_b` is a valid SP1Field.
61    pub op_b_range_check: SP1FieldWordRangeChecker<T>,
62
63    /// The check if `op_c` is a valid SP1Field.
64    pub op_c_range_check: SP1FieldWordRangeChecker<T>,
65
66    /// Whether the current instruction is a real instruction.
67    pub is_real: T,
68
69    /// Columns for handling syscall instructions in user mode.
70    pub user_mode_cols: M::SyscallInstrCols<T>,
71}