Skip to main content

edb_engine/eval/
mod.rs

1// EDB - Ethereum Debugger
2// Copyright (C) 2024 Zhuo Zhang and Wuqi Zhang
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! Expression evaluation system for EDB.
18//!
19//! This module provides a comprehensive expression evaluation system that enables
20//! real-time evaluation of Solidity-like expressions against debug snapshots.
21//! It supports variables, function calls, arithmetic operations, and blockchain context.
22//!
23//! # Main Components
24//!
25//! - [`ExpressionEvaluator`] - Main evaluator for parsing and executing expressions
26//! - [`handlers`] - Handler traits and implementations for different evaluation contexts
27//! - Common types and utilities for expression evaluation
28//!
29//! # Basic Usage
30//!
31//! ```rust,ignore
32//! use edb_engine::eval::{ExpressionEvaluator, handlers::EdbHandler};
33//!
34//! // Create evaluator with EDB handlers
35//! let handlers = EdbHandler::create_handlers(engine_context);
36//! let evaluator = ExpressionEvaluator::new(handlers);
37//!
38//! // Evaluate expressions
39//! let result = evaluator.eval("balances[msg.sender]", snapshot_id)?;
40//! let result = evaluator.eval("totalSupply() > 1000000", snapshot_id)?;
41//! let result = evaluator.eval("block.timestamp - lastUpdate > 3600", snapshot_id)?;
42//! ```
43//!
44//! # Supported Expressions
45//!
46//! - **Variables**: `balance`, `owner`, `this`
47//! - **Mappings/Arrays**: `balances[addr]`, `users[0]`
48//! - **Function Calls**: `balanceOf(user)`, `totalSupply()`
49//! - **Member Access**: `token.symbol`, `addr.balance`
50//! - **Arithmetic**: `+`, `-`, `*`, `/`, `%`, `**`
51//! - **Comparison**: `==`, `!=`, `<`, `<=`, `>`, `>=`
52//! - **Logical**: `&&`, `||`, `!`
53//! - **Ternary**: `condition ? true_value : false_value`
54//! - **Type Casting**: `uint256(value)`, `address(0x123...)`
55//! - **Blockchain Context**: `msg.sender`, `msg.value`, `block.number`, `tx.origin`
56
57mod common;
58pub use common::*;
59
60mod evaluator;
61pub mod handlers;
62mod utils;
63
64pub use evaluator::ExpressionEvaluator;