cairo_vm/vm/errors/
runner_errors.rs

1// The `(*.0).0` syntax of thiserror falsely triggers this clippy warning
2#![allow(clippy::explicit_auto_deref)]
3
4use crate::stdlib::{collections::HashSet, prelude::*};
5use crate::types::builtin_name::BuiltinName;
6use crate::types::layout_name::LayoutName;
7use thiserror::Error;
8
9use super::{memory_errors::MemoryError, trace_errors::TraceError};
10use crate::types::{errors::math_errors::MathError, relocatable::Relocatable};
11use crate::Felt252;
12
13#[derive(Debug, PartialEq, Error)]
14pub enum RunnerError {
15    #[error("Initialization failure: No execution base")]
16    NoExecBase,
17    #[error("Initialization failure: No program base")]
18    NoProgBase,
19    #[error("Missing main()")]
20    MissingMain,
21    #[error("Found None PC during VM initialization")]
22    NoPC,
23    #[error("Found None AP during VM initialization")]
24    NoAP,
25    #[error("Found None FP during VM initialization")]
26    NoFP,
27    #[error("Memory validation failed during VM initialization: {0}")]
28    MemoryValidationError(MemoryError),
29    #[error("Memory loading failed during state initialization: {0}")]
30    MemoryInitializationError(MemoryError),
31    #[error("Given builtins are not in appropiate order")]
32    DisorderedBuiltins,
33    #[error("Expected integer at address {:?} to be smaller than 2^{}, Got {}", (*.0).0, (*.0).1, (*.0).2)]
34    IntegerBiggerThanPowerOfTwo(Box<(Relocatable, u32, Felt252)>),
35    #[error("{0}")]
36    EcOpSameXCoordinate(Box<str>),
37    #[error("EcOpBuiltin: point {0:?} is not on the curve")]
38    PointNotOnCurve(Box<(Felt252, Felt252)>),
39    #[error("Builtin(s) {:?} not present in layout {}", (*.0).0, (*.0).1)]
40    NoBuiltinForInstance(Box<(HashSet<BuiltinName>, LayoutName)>),
41    #[error("end_run called twice.")]
42    EndRunCalledTwice,
43    #[error("end_run must be called before finalize_segments.")]
44    FinalizeNoEndRun,
45    #[error("end_run must be called before read_return_values.")]
46    ReadReturnValuesNoEndRun,
47    #[error("Error while finalizing segments: {0}")]
48    FinalizeSegements(MemoryError),
49    #[error("finalize_segments called but proof_mode is not enabled")]
50    FinalizeSegmentsNoProofMode,
51    #[error("Invalid stop pointer for {}: Stop pointer has value {} but builtin segment is {}", (*.0).0, (*.0).1, (*.0).2)]
52    InvalidStopPointerIndex(Box<(BuiltinName, Relocatable, usize)>),
53    #[error("Invalid stop pointer for {}. Expected: {}, found: {}", (*.0).0, (*.0).1, (*.0).2)]
54    InvalidStopPointer(Box<(BuiltinName, Relocatable, Relocatable)>),
55    #[error("No stop pointer found for builtin {0}")]
56    NoStopPointer(Box<BuiltinName>),
57    #[error("Running in proof-mode but no __start__ label found, try compiling with proof-mode")]
58    NoProgramStart,
59    #[error("Running in proof-mode but no __end__ label found, try compiling with proof-mode")]
60    NoProgramEnd,
61    #[error("Cannot add the return values to the public memory after segment finalization.")]
62    FailedAddingReturnValues,
63    #[error("Missing execution public memory")]
64    NoExecPublicMemory,
65    #[error(transparent)]
66    Memory(#[from] MemoryError),
67    #[error(transparent)]
68    Math(#[from] MathError),
69    #[error("{}: Expected integer at address {}", (*.0).0, (*.0).1)]
70    BuiltinExpectedInteger(Box<(BuiltinName, Relocatable)>),
71    #[error("Unexpected ret_fp_segment size")]
72    UnexpectedRetFpSegmentSize,
73    #[error("Unexpected ret_pc_segment size")]
74    UnexpectedRetPcSegmentSize,
75    #[error("Expected program base offset to be zero")]
76    ProgramBaseOffsetNotZero,
77    #[error("Expected execution base offset to be zero")]
78    ExecBaseOffsetNotZero,
79    #[error("Expected ret_fp offset to be zero")]
80    RetFpOffsetNotZero,
81    #[error("Expected ret_pc offset to be zero")]
82    RetPcOffsetNotZero,
83    #[error("Can't build a StrippedProgram from a Program without main")]
84    StrippedProgramNoMain,
85    #[error(transparent)]
86    Trace(#[from] TraceError),
87    #[error("EcOp builtin: Invalid Point")]
88    InvalidPoint,
89    #[error("Page ({0}) is not on the expected segment {1}")]
90    PageNotOnSegment(Relocatable, usize),
91    #[error("Expected integer at address {} to be smaller than 2^{}. Got: {}.", (*.0).0, (*.0).1, (*.0).2)]
92    WordExceedsModBuiltinWordBitLen(Box<(Relocatable, u32, Felt252)>),
93    #[error("{}: Expected n >= 1. Got: {}.", (*.0).0, (*.0).1)]
94    ModBuiltinNLessThanOne(Box<(BuiltinName, usize)>),
95    #[error("{}: Missing value at address {}.", (*.0).0, (*.0).1)]
96    ModBuiltinMissingValue(Box<(BuiltinName, Relocatable)>),
97    #[error("{}: n must be <= {}", (*.0).0, (*.0).1)]
98    FillMemoryMaxExceeded(Box<(BuiltinName, usize)>),
99    #[error("{0}: write_n_words value must be 0 after loop")]
100    WriteNWordsValueNotZero(BuiltinName),
101    #[error("add_mod and mul_mod builtins must have the same n_words and word_bit_len.")]
102    ModBuiltinsMismatchedInstanceDef,
103    #[error("At least one of add_mod and mul_mod must be given.")]
104    FillMemoryNoBuiltinSet,
105    #[error("Could not fill the values table, add_mod_index={0}, mul_mod_index={1}")]
106    FillMemoryCoudNotFillTable(usize, usize),
107    #[error("{}: {}", (*.0).0, (*.0).1)]
108    ModBuiltinSecurityCheck(Box<(BuiltinName, String)>),
109    #[error("{0} is missing")]
110    MissingBuiltin(BuiltinName),
111    #[error("The stop pointer of the missing builtin {0} must be 0")]
112    MissingBuiltinStopPtrNotZero(BuiltinName),
113    #[error("The number of steps in the Cairo PIE's execution resources does not match the number of steps in the RunResources")]
114    PieNStepsVsRunResourcesNStepsMismatch,
115    #[error("A Cairo PIE can not be ran in proof_mode")]
116    CairoPieProofMode,
117    #[error("{0}: Invalid additional data")]
118    InvalidAdditionalData(BuiltinName),
119    #[error("dynamic layout params is missing")]
120    MissingDynamicLayoutParams,
121    #[error("dynamic layout {0} ratio should be 0 when disabled")]
122    BadDynamicLayoutBuiltinRatio(BuiltinName),
123    #[error("Initialization failure: Cannot run with trace padding disabled without proof mode")]
124    DisableTracePaddingWithoutProofMode,
125}
126
127#[cfg(test)]
128mod tests {
129    use super::*;
130
131    #[test]
132    // Test to catch possible enum size regressions
133    fn test_runner_error_size() {
134        let size = crate::stdlib::mem::size_of::<RunnerError>();
135        assert!(size <= 32, "{size}")
136    }
137}