foundry_evm_symbolic/
runtime.rs1use super::{abi::*, *};
2
3mod address;
4mod bytes;
5mod calldata;
6mod cheatcodes;
7mod control;
8mod evm;
9mod executor_view;
10mod expr;
11mod folded_slots;
12mod memory;
13mod precompiles;
14mod solver;
15mod state;
16mod symbols;
17
18pub(crate) use address::*;
19pub(crate) use bytes::*;
20pub(crate) use calldata::*;
21pub(crate) use cheatcodes::*;
22pub(crate) use control::*;
23pub(crate) use evm::*;
24pub use executor_view::ExecutorView;
25pub(crate) use expr::*;
26pub(crate) use folded_slots::*;
27pub(crate) use memory::*;
28pub(crate) use precompiles::*;
29pub(crate) use solver::{BranchFeasibility, SmtLibSubprocessSolver};
30pub(crate) use state::*;
31pub(crate) use symbols::*;
32
33#[derive(Clone, Copy, Debug, PartialEq, Eq)]
35pub struct SymbolicBranchTarget {
36 address: Address,
38 pc: usize,
40 opcode: u8,
42 result: bool,
44}
45
46impl SymbolicBranchTarget {
47 pub const fn new(address: Address, pc: usize, opcode: u8, result: bool) -> Self {
48 Self { address, pc, opcode, result }
49 }
50
51 pub(crate) const fn result(self) -> bool {
52 self.result
53 }
54
55 pub(crate) fn matches(self, address: Address, pc: usize, opcode: u8) -> bool {
56 self.address == address && self.pc == pc && self.opcode == opcode
57 }
58}
59
60pub struct SymbolicRunInput<'a> {
61 pub executor: ExecutorView<'a>,
64 pub target: Address,
66 pub sender: Address,
68 pub function: &'a Function,
70 pub value: U256,
72 pub ffi_enabled: bool,
74 pub collect_success_input: bool,
76 pub corpus_seeds: Vec<SymbolicConcreteInput>,
78 pub branch_target: Option<SymbolicBranchTarget>,
80}
81
82#[derive(Debug, Error)]
88pub enum SymbolicError {
89 #[error("missing account {0}")]
91 MissingAccount(Address),
92 #[error("missing code for account {0}")]
94 MissingCode(Address),
95 #[error("backend error: {0}")]
97 Backend(String),
98 #[error("unsupported ABI type for symbolic execution: {0}")]
100 UnsupportedAbi(String),
101 #[error("symbolic calldata variant limit exceeded ({0})")]
103 CalldataVariantLimit(usize),
104 #[error("unsupported symbolic execution feature: {0}")]
106 Unsupported(&'static str),
107 #[error("unsupported opcode 0x{0:02x}")]
109 UnsupportedOpcode(u8),
110 #[error("invalid bytecode: {0}")]
112 InvalidBytecode(&'static str),
113 #[error("invalid jump destination {0}")]
115 InvalidJump(usize),
116 #[error("stack underflow")]
118 StackUnderflow,
119 #[error("stack overflow")]
121 StackOverflow,
122 #[error("solver error: {0}")]
124 Solver(String),
125 #[error("solver returned unknown")]
127 SolverUnknown,
128 #[error("symbolic execution timeout exceeded ({0}s)")]
130 Timeout(u32),
131 #[error("symbolic solver query limit exceeded ({0})")]
133 SolverQueryLimit(usize),
134 #[error(transparent)]
136 Abi(#[from] alloy_dyn_abi::Error),
137}
138
139impl SymbolicError {
140 pub(super) const fn stop_reason(&self) -> SymbolicStopReason {
141 match self {
142 Self::Unsupported(_)
143 | Self::CalldataVariantLimit(_)
144 | Self::UnsupportedOpcode(_)
145 | Self::SolverQueryLimit(_) => SymbolicStopReason::Stuck,
146 Self::SolverUnknown | Self::Timeout(_) => SymbolicStopReason::Timeout,
147 Self::Solver(_)
148 | Self::MissingAccount(_)
149 | Self::MissingCode(_)
150 | Self::Backend(_)
151 | Self::UnsupportedAbi(_)
152 | Self::InvalidBytecode(_)
153 | Self::InvalidJump(_)
154 | Self::StackUnderflow
155 | Self::StackOverflow
156 | Self::Abi(_) => SymbolicStopReason::Error,
157 }
158 }
159}
160
161impl fmt::Display for SymbolicRunResult {
162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163 match self {
164 Self::Safe { stats, .. } => write!(f, "safe after {} paths", stats.paths),
165 Self::Counterexample { stats, .. } => {
166 write!(f, "counterexample after {} paths", stats.paths)
167 }
168 Self::Incomplete { kind, reason, .. } => {
169 write!(f, "incomplete symbolic execution ({kind:?}): {reason}")
170 }
171 }
172 }
173}