### Basic EVM Execution Source: https://bluealloy.github.io/revm/print.html Demonstrates the basic setup and execution of a transaction using the `Evm` struct. ```APIDOC ## Basic EVM Execution ### Description This snippet shows how to initialize and use the `Evm` struct to execute a transaction. ### Method `transact(tx)` ### Endpoint N/A (SDK method) ### Parameters - `tx`: The transaction to be executed. ### Request Example ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet(); let out = evm.transact(tx); ``` ### Response - `out`: The result of the transaction execution, including status and state changes. ``` -------------------------------- ### Implementing a Custom Inspector Source: https://bluealloy.github.io/revm/inspector.html Example of implementing the `Inspector` trait to track gas usage and the number of calls made during EVM execution. ```APIDOC ## Custom Inspector Implementation ### Description This example demonstrates how to implement the `Inspector` trait to create a custom inspector that tracks gas consumption and the number of contract calls. ### Code ```rust #[derive(Default)] struct MyInspector { gas_used: u64, call_count: usize, } impl Inspector for MyInspector { fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) { self.gas_used += interp.gas.spent(); } fn call(&mut self, _context: &mut CTX, _inputs: &mut CallInputs) -> Option { self.call_count += 1; None // Don't override the call } } ``` ``` -------------------------------- ### Capturing EVM Logs Source: https://bluealloy.github.io/revm/inspector.html Example of how to capture and process EVM `Log` events within the `log` callback, printing details like address, topics, and data. ```rust fn log(&mut self, _interp: &mut Interpreter, _ctx: &mut CTX, log: Log) { println!("LOG emitted from: {:?}", log.address); println!("Topics: {:?}", log.topics()); println!("Data: {}", hex::encode(log.data.data)); } ``` -------------------------------- ### Accessing Interpreter State in `step` Source: https://bluealloy.github.io/revm/inspector.html Example of how to access the interpreter's program counter, opcode, stack, and memory size within the `step` callback. ```rust fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) { let pc = interp.bytecode.pc(); let opcode = interp.bytecode.opcode(); let stack_len = interp.stack.len(); let memory_size = interp.memory.size(); println!("PC: {}, Opcode: 0x{:02x}, Stack: {}, Memory: {}", pc, opcode, stack_len, memory_size); } ``` -------------------------------- ### Capture and Process EVM Events (Rust) Source: https://bluealloy.github.io/revm/print.html Implement the `log` method to capture and process EVM log events. This example prints the event's address, topics, and data. ```rust __ fn log(&mut self, _interp: &mut Interpreter, _ctx: &mut CTX, log: Log) { println!("LOG emitted from: {:?}", log.address); println!("Topics: {:?}", log.topics()); println!("Data: {}", hex::encode(log.data.data)); } ``` -------------------------------- ### Accessing Interpreter State in `step` Source: https://bluealloy.github.io/revm/inspector.html Example of how to access detailed interpreter state, such as program counter, opcode, stack, and memory, within the `step` callback. ```APIDOC ## Accessing Interpreter State ### Description This snippet shows how to access and utilize the interpreter's internal state within the `step` callback of the `Inspector` trait. It logs the current program counter, opcode, stack length, and memory size. ### Code ```rust fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) { let pc = interp.bytecode.pc(); let opcode = interp.bytecode.opcode(); let stack_len = interp.stack.len(); let memory_size = interp.memory.size(); println!("PC: {}, Opcode: 0x{:02x}, Stack: {}, Memory: {}", pc, opcode, stack_len, memory_size); } ``` ``` -------------------------------- ### Capturing EVM Events with `log` Source: https://bluealloy.github.io/revm/inspector.html Example of using the `log` callback in the `Inspector` trait to capture and process EVM log events. ```APIDOC ## Capturing EVM Events ### Description This snippet shows how to implement the `log` callback within the `Inspector` trait to capture and process EVM log events. It prints the address emitting the log, its topics, and the data payload. ### Code ```rust fn log(&mut self, _interp: &mut Interpreter, _ctx: &mut CTX, log: Log) { println!("LOG emitted from: {:?}", log.address); println!("Topics: {:?}", log.topics()); println!("Data: {}", hex::encode(log.data.data)); } ``` ``` -------------------------------- ### Custom Inspector Implementation Source: https://bluealloy.github.io/revm/inspector.html Example of a custom inspector that tracks gas used and the number of calls made during execution. It overrides the `step` and `call` methods. ```rust #[derive(Default)] struct MyInspector { gas_used: u64, call_count: usize, } impl Inspector for MyInspector { fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) { self.gas_used += interp.gas.spent(); } fn call(&mut self, _context: &mut CTX, _inputs: &mut CallInputs) -> Option { self.call_count += 1; None // Don't override the call } } ``` -------------------------------- ### Custom Inspector Implementation Source: https://bluealloy.github.io/revm/print.html Example of implementing the Inspector trait to track gas used and count calls. The `call` method returns `None` to indicate no override of the call behavior. ```rust struct MyInspector { gas_used: u64, call_count: usize, } impl Inspector for MyInspector { fn step(&mut self, interp: &mut Interpreter, _context: &mut CTX) { self.gas_used += interp.gas.spent(); } fn call(&mut self, _context: &mut CTX, _inputs: &mut CallInputs) -> Option { self.call_count += 1; None // Don't override the call } } ``` -------------------------------- ### Basic EVM Execution Source: https://bluealloy.github.io/revm/architecture.html Demonstrates how to initialize and run a basic EVM transaction using the `ExecuteEvm` trait. ```APIDOC ## Basic EVM Execution ### Description This section shows how to set up and execute a transaction using the `ExecuteEvm` trait. ### Method `transact(tx)` ### Endpoint N/A (SDK Method) ### Parameters - `tx` (Transaction): The transaction to be executed. ### Request Example ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet(); let out = evm.transact(tx); ``` ### Response - `out` (ExecutionResult): The result of the transaction execution, including status, changed state, and potential errors. ``` -------------------------------- ### Using an Inspector with EVM Source: https://bluealloy.github.io/revm/inspector.html Demonstrates how to build an EVM instance with a custom inspector and execute transactions while collecting inspection data. ```APIDOC ## Using Inspector with EVM ### Description This example shows how to integrate a custom `Inspector` with the REVM EVM. It initializes the EVM with the inspector, executes a transaction, and then accesses the collected data from the inspector. ### Code ```rust let inspector = MyInspector::default(); let mut evm = Context::mainnet() .with_db(db) .build_mainnet_with_inspector(inspector); // Execute with inspection let result = evm.inspect_one_tx(tx)?; println!("Gas used: {}", evm.inspector.gas_used); println!("Calls made: {}", evm.inspector.call_count); ``` ``` -------------------------------- ### Executing with a Custom Inspector Source: https://bluealloy.github.io/revm/inspector.html Demonstrates how to build an EVM instance with a custom inspector and execute a transaction, then access the inspector's collected data. ```rust let inspector = MyInspector::default(); let mut evm = Context::mainnet() .with_db(db) .build_mainnet_with_inspector(inspector); // Execute with inspection let result = evm.inspect_one_tx(tx)?; println!("Gas used: {}", evm.inspector.gas_used); println!("Calls made: {}", evm.inspector.call_count); ``` -------------------------------- ### Revme Help Command Source: https://bluealloy.github.io/revm/print.html Displays the available commands and options for the Revme binary. Use this to understand the primary functionalities. ```bash revme --help ``` -------------------------------- ### Revme CLI Help Source: https://bluealloy.github.io/revm/revme.html Displays the available commands and options for the Revme CLI. Use this to understand the different functionalities Revme offers. ```bash $: revme --help Usage: revme Commands: statetest Execute Ethereum state tests evm Run arbitrary EVM bytecode bytecode Print the structure of an EVM bytecode bench Run bench from specified list help Print this message or the help of the given subcommand(s) Options: -h, --help Print help ``` -------------------------------- ### EVM Execution with Inspection Source: https://bluealloy.github.io/revm/print.html Illustrates how to enable and use the inspection API for transaction tracing and observation. ```APIDOC ## EVM Execution with Inspection ### Description This snippet demonstrates how to configure the `Evm` with an inspector to enable detailed tracing during transaction execution. ### Method `inspect_tx(tx)` ### Endpoint N/A (SDK method) ### Parameters - `tx`: The transaction to be inspected. - `inspector`: An inspector object used for tracing and observation. ### Request Example ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector); let _ = evm.inspect_tx(tx); ``` ### Response - `_`: The result of the inspection, typically containing tracing information. ``` -------------------------------- ### Run Legacy State Tests Source: https://bluealloy.github.io/revm/revme.html Execute legacy Ethereum state tests by first cloning the legacytests repository and then pointing Revme to the specific test directory. This is for older hardfork compatibility. ```bash git clone https://github.com/ethereum/legacytests cargo run --release -p revme -- statetest legacytests/Cancun/GeneralStateTests ``` -------------------------------- ### EVM Execution with Commit Source: https://bluealloy.github.io/revm/architecture.html Illustrates how to execute a transaction and automatically commit state changes to the database using the `ExecuteCommitEvm` trait. ```APIDOC ## EVM Execution with Commit ### Description This section demonstrates executing a transaction and committing the resulting state changes directly to the database. ### Method `transact_commit(tx)` ### Endpoint N/A (SDK Method) ### Parameters - `tx` (Transaction): The transaction to be executed and committed. ### Request Example ```rust // Assuming 'db' is a mutable reference to a type implementing DatabaseCommit trait let mut evm = Context::mainnet().with_block(block).build_mainnet(); let status = evm.transact_commit(tx, db); ``` ### Response - `status` (ExecutionStatus): The status of the execution and commit operation. ``` -------------------------------- ### EVM Execution with Commit Source: https://bluealloy.github.io/revm/print.html Shows how to execute a transaction and automatically commit state changes to the database. ```APIDOC ## EVM Execution with Commit ### Description This snippet shows how to use the `ExecuteCommitEvm` trait to run transactions and automatically persist state changes to the database. ### Method `transact_commit(tx)` ### Endpoint N/A (SDK method) ### Parameters - `tx`: The transaction to be executed and committed. ### Request Example ```rust // Assuming `evm` is an instance that implements `ExecuteCommitEvm` let status = evm.transact_commit(tx); ``` ### Response - `status`: The status of the execution and commit operation. ``` -------------------------------- ### EVM Execution with Inspection Source: https://bluealloy.github.io/revm/architecture.html Explains how to execute a transaction with detailed tracing and observation capabilities using the `InspectEvm` trait. ```APIDOC ## EVM Execution with Inspection ### Description This section details how to execute transactions while enabling detailed tracing and observation using inspectors. ### Method `inspect_tx(tx)` ### Endpoint N/A (SDK Method) ### Parameters - `tx` (Transaction): The transaction to be inspected. - `inspector` (Inspector): An inspector implementation to observe execution. ### Request Example ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector); let _ = evm.inspect_tx(tx); ``` ### Response - The return value depends on the specific inspection method used and the inspector's implementation. Typically, it involves observing execution events. ``` -------------------------------- ### Running EEST Tests Source: https://bluealloy.github.io/revm/print.html Executes Ethereum Foundation's state tests (EEST) using a provided script. Set the REVM_STATETEST_STABLE environment variable to use stable fixtures. ```bash ./scripts/run-tests.sh ``` -------------------------------- ### Basic EVM Transaction Execution Source: https://bluealloy.github.io/revm/architecture.html Instantiates and runs a basic Ethereum transaction using the mainnet context. Requires a pre-configured block and transaction. ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet(); let out = evm.transact(tx); ``` -------------------------------- ### Run State Tests with Revme Source: https://bluealloy.github.io/revm/revme.html Execute Ethereum state tests using Revme. Specify the folder path containing the test suites. This command is useful for verifying EVM implementation against standard Ethereum tests. ```bash cargo run --release -p revme -- statetest folder_path ``` -------------------------------- ### Clone and Build Revm Project Source: https://bluealloy.github.io/revm/dev.html Clone the Revm repository from GitHub and build the project using Cargo. Ensure you have the latest Rust version and necessary build tools like clang if using specific feature flags. ```bash git clone https://github.com/bluealloy/revm.git cd revm cargo build --release ``` -------------------------------- ### EVM Transaction Execution with Inspector Source: https://bluealloy.github.io/revm/architecture.html Instantiates an EVM with an inspector for detailed tracing and executes a transaction. The inspector must be provided during EVM construction. ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector); let _ = evm.inspect_tx(tx); ``` -------------------------------- ### Execute EVM Transactions Source: https://bluealloy.github.io/revm/index.html Use the Execution API to create an EVM instance, process transactions, and optionally generate traces with an inspector. ```rust let mut evm = Context::mainnet().with_block(block).build_mainnet(); let out = evm.transact(tx); ``` ```rust let mut evm = evm.with_inspector(tracer); let out = evm.inspect_tx(tx); ``` -------------------------------- ### EVM Execution with Inspection and Commit Source: https://bluealloy.github.io/revm/architecture.html Covers executing transactions with both detailed tracing and automatic state commit using the `InspectCommitEvm` trait. ```APIDOC ## EVM Execution with Inspection and Commit ### Description This section describes executing transactions with both detailed tracing and automatic state commit capabilities. ### Method `inspect_commit()` / `inspect_replay_commit(tx)` ### Endpoint N/A (SDK Method) ### Parameters - `tx` (Transaction): The transaction to be inspected and committed. - `inspector` (Inspector): An inspector implementation to observe execution. - `db` (DatabaseCommit): A database that supports committing state changes. ### Request Example ```rust // Example for inspect_commit (assuming context and inspector are set up) let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector); let _ = evm.inspect_commit(db); // Example for inspect_replay_commit let mut evm = Context::mainnet().with_block(block).build_mainnet().with_inspector(inspector); let _ = evm.inspect_replay_commit(tx, db); ``` ### Response - The return value depends on the specific inspection and commit method used. It typically involves execution status and potentially state changes. ``` -------------------------------- ### Overriding Call Execution Source: https://bluealloy.github.io/revm/inspector.html Shows how to override a specific call by returning a custom `CallOutcome` from the `call` callback. If `None` is returned, normal execution proceeds. ```rust fn call(&mut self, _context: &mut CTX, inputs: &mut CallInputs) -> Option { if inputs.target_address == SPECIAL_ADDRESS { // Override this call with custom logic return Some(CallOutcome::new( InterpreterResult::new(InstructionResult::Return, Bytes::from("custom")), 0..0 )); } None // Let normal execution continue } ``` -------------------------------- ### Overriding Call Behavior with `call` Source: https://bluealloy.github.io/revm/inspector.html Demonstrates how to use the `call` callback in the `Inspector` trait to intercept and override the default behavior of contract calls. ```APIDOC ## Overriding Call Behavior ### Description This example illustrates how to use the `call` method of the `Inspector` trait to intercept contract calls. If a specific condition is met (e.g., calling a `SPECIAL_ADDRESS`), it returns a custom `CallOutcome`, effectively overriding the default execution. ### Code ```rust fn call(&mut self, _context: &mut CTX, inputs: &mut CallInputs) -> Option { if inputs.target_address == SPECIAL_ADDRESS { // Override this call with custom logic return Some(CallOutcome::new( InterpreterResult::new(InstructionResult::Return, Bytes::from("custom")), 0..0 )); } None // Let normal execution continue } ``` ``` -------------------------------- ### Modify Execution with Custom Call Outcomes (Rust) Source: https://bluealloy.github.io/revm/print.html Implement custom logic for specific addresses by returning a `CallOutcome`. If the condition is not met, return `None` to allow normal execution. ```rust __ fn call(&mut self, _context: &mut CTX, inputs: &mut CallInputs) -> Option { if inputs.target_address == SPECIAL_ADDRESS { // Override this call with custom logic return Some(CallOutcome::new( InterpreterResult::new(InstructionResult::Return, Bytes::from("custom")), 0..0 )); } None // Let normal execution continue } ``` -------------------------------- ### Inspector Trait Definition Source: https://bluealloy.github.io/revm/inspector.html Defines the callbacks invoked during EVM execution for tracing and observation. Implement this trait to customize inspection behavior. ```rust pub trait Inspector { // Opcode-level tracing fn step(&mut self, interp: &mut Interpreter, context: &mut CTX) {} fn step_end(&mut self, interp: &mut Interpreter, context: &mut CTX) {} // Call and creation tracing fn call(&mut self, context: &mut CTX, inputs: &mut CallInputs) -> Option { None } fn call_end(&mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome) {} fn create(&mut self, context: &mut CTX, inputs: &mut CreateInputs) -> Option { None } fn create_end(&mut self, context: &mut CTX, inputs: &CreateInputs, outcome: &mut CreateOutcome) {} // Event tracing fn log(&mut self, context: &mut CTX, log: Log) {} fn log_full(&mut self, interp: &mut Interpreter, context: &mut CTX, log: Log) { self.log(context, log) } fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) {} } ``` -------------------------------- ### Inspector Trait Definition Source: https://bluealloy.github.io/revm/inspector.html The `Inspector` trait defines the callbacks that are invoked during EVM execution. Users can implement this trait to hook into various stages of the transaction lifecycle. ```APIDOC ## Inspector Trait ### Description The `Inspector` trait provides a mechanism for observing and tracing EVM execution. It defines callbacks that are invoked at various points during the transaction lifecycle, allowing for detailed analysis and custom tooling. ### Methods - **`step(&mut self, interp: &mut Interpreter, context: &mut CTX)`**: Called before each opcode execution. - **`step_end(&mut self, interp: &mut Interpreter, context: &mut CTX)`**: Called after each opcode execution. - **`call(&mut self, context: &mut CTX, inputs: &mut CallInputs) -> Option`**: Called before a contract call. Returning `Some(CallOutcome)` overrides the default call behavior. - **`call_end(&mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome)`**: Called after a contract call. - **`create(&mut self, context: &mut CTX, inputs: &mut CreateInputs) -> Option`**: Called before a contract creation. Returning `Some(CreateOutcome)` overrides the default creation behavior. - **`create_end(&mut self, context: &mut CTX, inputs: &CreateInputs, outcome: &mut CreateOutcome)`**: Called after a contract creation. - **`log(&mut self, context: &mut CTX, log: Log)`**: Called when an EVM log is emitted. - **`log_full(&mut self, interp: &mut Interpreter, context: &mut CTX, log: Log)`**: A more detailed version of `log` that also provides interpreter context. - **`selfdestruct(&mut self, contract: Address, target: Address, value: U256)`**: Called when a contract self-destructs. ``` -------------------------------- ### Inspector Trait Definition Source: https://bluealloy.github.io/revm/print.html Defines the callbacks invoked during EVM execution for tracing and inspection. Implement this trait to observe and potentially modify EVM behavior. ```rust pub trait Inspector { // Opcode-level tracing fn step(&mut self, interp: &mut Interpreter, context: &mut CTX) {} fn step_end(&mut self, interp: &mut Interpreter, context: &mut CTX) {} // Call and creation tracing fn call(&mut self, context: &mut CTX, inputs: &mut CallInputs) -> Option { None } fn call_end(&mut self, context: &mut CTX, inputs: &CallInputs, outcome: &mut CallOutcome) {} fn create(&mut self, context: &mut CTX, inputs: &mut CreateInputs) -> Option { None } fn create_end(&mut self, context: &mut CTX, inputs: &CreateInputs, outcome: &mut CreateOutcome) {} // Event tracing fn log(&mut self, context: &mut CTX, log: Log) {} fn log_full(&mut self, interp: &mut Interpreter, context: &mut CTX, log: Log) { self.log(context, log) } fn selfdestruct(&mut self, contract: Address, target: Address, value: U256) {} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.