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_no_std::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("Failed to convert string to FieldElement")]
32    FailedStringConversion,
33    #[error("EcOpBuiltin: m should be at most {0}")]
34    EcOpBuiltinScalarLimit(Box<Felt252>),
35    #[error("Given builtins are not in appropiate order")]
36    DisorderedBuiltins,
37    #[error("Expected integer at address {:?} to be smaller than 2^{}, Got {}", (*.0).0, (*.0).1, (*.0).2)]
38    IntegerBiggerThanPowerOfTwo(Box<(Relocatable, u32, Felt252)>),
39    #[error("{0}")]
40    EcOpSameXCoordinate(Box<str>),
41    #[error("EcOpBuiltin: point {0:?} is not on the curve")]
42    PointNotOnCurve(Box<(Felt252, Felt252)>),
43    #[error("Builtin(s) {:?} not present in layout {}", (*.0).0, (*.0).1)]
44    NoBuiltinForInstance(Box<(HashSet<BuiltinName>, LayoutName)>),
45    #[error("end_run called twice.")]
46    EndRunCalledTwice,
47    #[error("end_run must be called before finalize_segments.")]
48    FinalizeNoEndRun,
49    #[error("end_run must be called before read_return_values.")]
50    ReadReturnValuesNoEndRun,
51    #[error("Error while finalizing segments: {0}")]
52    FinalizeSegements(MemoryError),
53    #[error("finalize_segments called but proof_mode is not enabled")]
54    FinalizeSegmentsNoProofMode,
55    #[error("Invalid stop pointer for {}: Stop pointer has value {} but builtin segment is {}", (*.0).0, (*.0).1, (*.0).2)]
56    InvalidStopPointerIndex(Box<(BuiltinName, Relocatable, usize)>),
57    #[error("Invalid stop pointer for {}. Expected: {}, found: {}", (*.0).0, (*.0).1, (*.0).2)]
58    InvalidStopPointer(Box<(BuiltinName, Relocatable, Relocatable)>),
59    #[error("No stop pointer found for builtin {0}")]
60    NoStopPointer(Box<BuiltinName>),
61    #[error("Running in proof-mode but no __start__ label found, try compiling with proof-mode")]
62    NoProgramStart,
63    #[error("Running in proof-mode but no __end__ label found, try compiling with proof-mode")]
64    NoProgramEnd,
65    #[error("Could not convert slice to array")]
66    SliceToArrayError,
67    #[error("Cannot add the return values to the public memory after segment finalization.")]
68    FailedAddingReturnValues,
69    #[error("Missing execution public memory")]
70    NoExecPublicMemory,
71    #[error("Coulnd't parse prime from felt lib")]
72    CouldntParsePrime,
73    #[error("Could not convert vec with Maybe Relocatables into u64 array")]
74    MaybeRelocVecToU64ArrayError,
75    #[error("Expected Integer value, got Relocatable instead")]
76    FoundNonInt,
77    #[error(transparent)]
78    Memory(#[from] MemoryError),
79    #[error(transparent)]
80    Math(#[from] MathError),
81    #[error("keccak_builtin: Failed to get first input address")]
82    KeccakNoFirstInput,
83    #[error("{}: Expected integer at address {}", (*.0).0, (*.0).1)]
84    BuiltinExpectedInteger(Box<(BuiltinName, Relocatable)>),
85    #[error("keccak_builtin: Failed to convert input cells to u64 values")]
86    KeccakInputCellsNotU64,
87    #[error("Unexpected ret_fp_segment size")]
88    UnexpectedRetFpSegmentSize,
89    #[error("Unexpected ret_pc_segment size")]
90    UnexpectedRetPcSegmentSize,
91    #[error("Expected program base offset to be zero")]
92    ProgramBaseOffsetNotZero,
93    #[error("Expected execution base offset to be zero")]
94    ExecBaseOffsetNotZero,
95    #[error("Expected ret_fp offset to be zero")]
96    RetFpOffsetNotZero,
97    #[error("Expected ret_pc offset to be zero")]
98    RetPcOffsetNotZero,
99    #[error("Can't build a StrippedProgram from a Program without main")]
100    StrippedProgramNoMain,
101    #[error(transparent)]
102    Trace(#[from] TraceError),
103    #[error("EcOp builtin: Invalid Point")]
104    InvalidPoint,
105    #[error("Page ({0}) is not on the expected segment {1}")]
106    PageNotOnSegment(Relocatable, usize),
107    #[error("Expected integer at address {} to be smaller than 2^{}. Got: {}.", (*.0).0, (*.0).1, (*.0).2)]
108    WordExceedsModBuiltinWordBitLen(Box<(Relocatable, u32, Felt252)>),
109    #[error("{}: Expected n >= 1. Got: {}.", (*.0).0, (*.0).1)]
110    ModBuiltinNLessThanOne(Box<(BuiltinName, usize)>),
111    #[error("{}: Missing value at address {}.", (*.0).0, (*.0).1)]
112    ModBuiltinMissingValue(Box<(BuiltinName, Relocatable)>),
113    #[error("{}: n must be <= {}", (*.0).0, (*.0).1)]
114    FillMemoryMaxExceeded(Box<(BuiltinName, usize)>),
115    #[error("{0}: write_n_words value must be 0 after loop")]
116    WriteNWordsValueNotZero(BuiltinName),
117    #[error("add_mod and mul_mod builtins must have the same n_words and word_bit_len.")]
118    ModBuiltinsMismatchedInstanceDef,
119    #[error("At least one of add_mod and mul_mod must be given.")]
120    FillMemoryNoBuiltinSet,
121    #[error("Could not fill the values table, add_mod_index={0}, mul_mod_index={1}")]
122    FillMemoryCoudNotFillTable(usize, usize),
123    #[error("{}: {}", (*.0).0, (*.0).1)]
124    ModBuiltinSecurityCheck(Box<(BuiltinName, String)>),
125    #[error("{0} is missing")]
126    MissingBuiltin(BuiltinName),
127    #[error("The stop pointer of the missing builtin {0} must be 0")]
128    MissingBuiltinStopPtrNotZero(BuiltinName),
129    #[error("The number of steps in the Cairo PIE's execution resources does not match the number of steps in the RunResources")]
130    PieNStepsVsRunResourcesNStepsMismatch,
131    #[error("A Cairo PIE can not be ran in proof_mode")]
132    CairoPieProofMode,
133    #[error("{0}: Invalid additional data")]
134    InvalidAdditionalData(BuiltinName),
135    #[error("dynamic layout params is missing")]
136    MissingDynamicLayoutParams,
137    #[error("dynamic layout {0} ratio should be 0 when disabled")]
138    BadDynamicLayoutBuiltinRatio(BuiltinName),
139}
140
141#[cfg(test)]
142mod tests {
143    use super::*;
144
145    #[test]
146    // Test to catch possible enum size regressions
147    fn test_runner_error_size() {
148        let size = crate::stdlib::mem::size_of::<RunnerError>();
149        assert!(size <= 32, "{size}")
150    }
151}