essential_state_read_vm/
error.rs1pub use crate::constraint::error::{StackError, StackResult};
4#[doc(inline)]
5use crate::{
6 asm::{self, Word},
7 constraint, Gas,
8};
9use thiserror::Error;
10
11pub type StateReadResult<T, E> = Result<T, StateReadError<E>>;
13
14pub type OpResult<T, E> = Result<T, OpError<E>>;
16
17pub type OpSyncResult<T> = Result<T, OpSyncError>;
19
20pub type OpAsyncResult<T, E> = Result<T, OpAsyncError<E>>;
22
23pub type StateMemoryResult<T> = Result<T, StateMemoryError>;
25
26#[derive(Debug, Error)]
28pub enum StateReadError<E> {
29 #[error("operation at index {0} failed: {1}")]
31 Op(usize, OpError<E>),
32 #[error("program counter {0} out of range (note: programs must end with `Halt`)")]
34 PcOutOfRange(usize),
35}
36
37#[derive(Debug, Error)]
39pub enum OpError<E> {
40 #[error("synchronous operation failed: {0}")]
42 Sync(#[from] OpSyncError),
43 #[error("asynchronous operation failed: {0}")]
45 Async(#[from] OpAsyncError<E>),
46 #[error("bytecode error: {0}")]
48 FromBytes(#[from] asm::FromBytesError),
49 #[error("{0}")]
51 OutOfGas(#[from] OutOfGasError),
52}
53
54#[derive(Debug, Error)]
56#[error(
57 "operation cost would exceed gas limit\n \
58 spent: {spent} gas\n \
59 op cost: {op_gas} gas\n \
60 limit: {limit} gas"
61)]
62pub struct OutOfGasError {
63 pub spent: Gas,
65 pub op_gas: Gas,
67 pub limit: Gas,
69}
70
71#[derive(Debug, Error)]
73pub enum OpSyncError {
74 #[error("constraint operation error: {0}")]
76 Constraint(#[from] constraint::error::OpError),
77 #[error("control flow operation error: {0}")]
79 TotalControlFlow(#[from] ControlFlowError),
80 #[error("state slots operation error: {0}")]
82 StateSlots(#[from] StateMemoryError),
83 #[error("the next program counter would overflow")]
85 PcOverflow,
86}
87
88#[derive(Debug, Error)]
90pub enum OpAsyncError<E> {
91 #[error("state read operation error: {0}")]
93 StateRead(E),
94 #[error("state slots error: {0}")]
96 Memory(#[from] StateMemoryError),
97 #[error("stack operation error: {0}")]
99 Stack(#[from] StackError),
100 #[error("the next program counter would overflow")]
102 PcOverflow,
103}
104
105#[derive(Debug, Error)]
107pub enum ControlFlowError {
108 #[error("invalid condition value {0}, expected 0 (false) or 1 (true)")]
112 InvalidJumpIfCondition(Word),
113}
114
115#[derive(Debug, Error)]
117pub enum StateMemoryError {
118 #[error("index out of bounds")]
120 IndexOutOfBounds,
121 #[error("operation would cause state slots to overflow")]
123 Overflow,
124}
125
126impl<E> From<core::convert::Infallible> for OpError<E> {
127 fn from(err: core::convert::Infallible) -> Self {
128 match err {}
129 }
130}
131
132impl From<StackError> for OpSyncError {
133 fn from(err: StackError) -> Self {
134 OpSyncError::Constraint(err.into())
135 }
136}