Skip to main content

sp1_core_executor/
errors.rs

1//! Error types for the SP1 executor.
2
3use deepsize2::DeepSizeOf;
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7use crate::Opcode;
8
9/// Trap conditions that the [``Executor``] can throw.
10#[derive(Error, Debug, Serialize, Deserialize, PartialEq, Eq, Clone, Copy, DeepSizeOf)]
11pub enum TrapError {
12    /// Page permission check fails.
13    #[error("Page permission violation error, code: {0}")]
14    PagePermissionViolation(u64),
15}
16
17/// Errors that the executor can throw.
18#[derive(Clone, Error, Debug, Serialize, Deserialize, PartialEq, Eq)]
19pub enum ExecutionError {
20    /// The execution failed with an invalid memory access.
21    #[error("invalid memory access for opcode {0} and address {1}")]
22    InvalidMemoryAccess(Opcode, u64),
23
24    /// The address for an untrusted program instruction is not aligned to 4 bytes.
25    #[error("invalid memory access for untrusted program at address {0}, not aligned to 4 bytes")]
26    InvalidMemoryAccessUntrustedProgram(u64),
27
28    /// The execution failed with an unimplemented syscall.
29    #[error("unimplemented syscall {0}")]
30    UnsupportedSyscall(u32),
31
32    /// The execution failed with a breakpoint.
33    #[error("breakpoint encountered")]
34    Breakpoint(),
35
36    /// The execution failed with an exceeded cycle limit.
37    #[error("exceeded cycle limit of {0}")]
38    ExceededCycleLimit(u64),
39
40    /// The execution failed because the syscall was called in unconstrained mode.
41    #[error("syscall called in unconstrained mode")]
42    InvalidSyscallUsage(u64),
43
44    /// The execution failed with an unimplemented feature.
45    #[error("got unimplemented as opcode")]
46    Unimplemented(),
47
48    /// The program ended in unconstrained mode.
49    #[error("program ended in unconstrained mode")]
50    EndInUnconstrained(),
51
52    /// The unconstrained cycle limit was exceeded.
53    #[error("unconstrained cycle limit exceeded")]
54    UnconstrainedCycleLimitExceeded(u64),
55
56    /// The program ended with an unexpected status code.
57    #[error("Unexpected exit code: {0}")]
58    UnexpectedExitCode(u32),
59
60    /// Page protect is off, and the instruction is not found.
61    #[error("Instruction not found, page protect/ untrusted program set to off")]
62    InstructionNotFound(),
63
64    /// The sharding state is invalid.
65    #[error("Running executor in non-sharding state, but got a shard boundary or trace end")]
66    InvalidShardingState(),
67
68    /// Trap occurred without a valid handler.
69    #[error("Trap occurred without proper handling")]
70    UnhandledTrap(TrapError),
71
72    /// SP1 program consumes too much memory.
73    #[error("SP1 program consumes too much memory")]
74    TooMuchMemory(),
75
76    /// A generic error.
77    #[error("{0}")]
78    Other(String),
79}