-
Notifications
You must be signed in to change notification settings - Fork 10
feat(deps): bump revm #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3fc30a4
feat(deps): bump revm
Evalir 3c32f6c
chore: fix deps, remove eof things
Evalir 4ec5af7
chore: new generics
Evalir 7a4da88
fix: mutable db access is now explicit
Evalir aeb0092
chore: more misc fixes
Evalir 7ef8de5
chore: accomodating new generic
Evalir 522654f
no generics, just EthFrame
Evalir b25c897
chore: more alloy num changes
Evalir cfab075
chore: fix instruction overriding
Evalir 819dccb
chore: use replay_tx (need to avoid clone)
Evalir 6b7d78e
chore: clippy fmt
Evalir 3bb20f0
chore: clippy / fmt
Evalir 093f9c2
fix: correct docs link
Evalir 9e47987
chore: remove new examples
Evalir 48c8616
chore: clippy
Evalir 8147b36
chore: bump revm
Evalir c204f44
chore: cleanup
Evalir f34bbc7
chore: more cleanup
Evalir a0813ad
chore: delegate rpc header fill to inner consensus header
Evalir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # Trevm Examples | ||
Evalir marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This directory contains comprehensive examples demonstrating various aspects of the Trevm library. | ||
|
|
||
| ## Examples Overview | ||
|
|
||
| ### 1. `basic_transact.rs` | ||
| Basic contract interaction example showing: | ||
| - Contract deployment to memory database | ||
| - Simple contract call execution | ||
| - Basic transaction handling | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example basic_transact | ||
| ``` | ||
|
|
||
| ### 2. `fork_ref_transact.rs` | ||
| Mainnet forking example demonstrating: | ||
| - Querying real Ethereum state using AlloyDb | ||
| - Calling live contracts (Uniswap V2 pair) | ||
| - Reading storage slots from mainnet | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example fork_ref_transact --features alloy-db | ||
| ``` | ||
|
|
||
| ### 3. `trevm_basic_example.rs` | ||
| Simple Trevm usage showing: | ||
| - Type-safe transaction building | ||
| - Error handling patterns | ||
| - State management | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example trevm_basic_example | ||
| ``` | ||
|
|
||
| ### 4. `trevm_inspector_example.rs` | ||
| Advanced example with inspector integration: | ||
| - Contract deployment with tracing | ||
| - EIP-3155 tracer integration | ||
| - Multi-transaction workflow | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example trevm_inspector_example | ||
| ``` | ||
|
|
||
| ### 5. `trevm_block_driver_example.rs` | ||
| Block processing example showing: | ||
| - Custom BlockDriver implementation | ||
| - Multi-transaction batching | ||
| - Receipt generation | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example trevm_block_driver_example | ||
| ``` | ||
|
|
||
| ### 6. `tx_tracer_cli.rs` 🎯 | ||
| **CLI tool for tracing any Ethereum transaction:** | ||
| - Fetches transaction from mainnet | ||
| - Replays with detailed EIP-3155 tracing | ||
| - Shows state changes and execution details | ||
|
|
||
| **Run with:** | ||
| ```bash | ||
| cargo run --example tx_tracer_cli --features alloy-db -- <tx_hash> [rpc_url] | ||
| ``` | ||
|
|
||
| **Example usage:** | ||
| ```bash | ||
| # Trace a specific transaction | ||
| cargo run --example tx_tracer_cli --features alloy-db -- 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef | ||
|
|
||
| # Use custom RPC endpoint | ||
| cargo run --example tx_tracer_cli --features alloy-db -- 0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef https://mainnet.infura.io/v3/YOUR_KEY | ||
| ``` | ||
|
|
||
| ## Key Concepts Demonstrated | ||
|
|
||
| ### Typestate Pattern | ||
| All examples show how Trevm's typestate pattern prevents common EVM usage errors: | ||
| - Can't execute without configuration | ||
| - Can't apply state without successful execution | ||
| - Compile-time enforcement of correct state transitions | ||
|
|
||
| ### Error Handling | ||
| Examples demonstrate proper error handling: | ||
| - `accept_state()` for successful transactions | ||
| - `discard_error()` for failed transactions | ||
| - Type-safe error recovery | ||
|
|
||
| ### Database Integration | ||
| Various database backends: | ||
| - `InMemoryDB` for testing | ||
| - `AlloyDb` for mainnet forking | ||
| - `CacheDB` for performance optimization | ||
|
|
||
| ### Inspector Integration | ||
| Examples show how to integrate revm inspectors: | ||
| - `NoOpInspector` for basic usage | ||
| - `TracerEip3155` for detailed tracing | ||
| - Custom inspectors for specialized needs | ||
|
|
||
| ## Building and Running | ||
|
|
||
| All examples can be built with: | ||
| ```bash | ||
| cargo build --examples | ||
| ``` | ||
|
|
||
| For examples requiring network access (alloy-db feature): | ||
| ```bash | ||
| cargo build --examples --features alloy-db | ||
| ``` | ||
|
|
||
| ## Usage in Your Projects | ||
|
|
||
| These examples serve as templates for common Trevm usage patterns: | ||
|
|
||
| 1. **Testing contracts**: Use `trevm_basic_example.rs` pattern | ||
| 2. **Mainnet simulation**: Use `fork_ref_transact.rs` pattern | ||
| 3. **Transaction tracing**: Use `trevm_inspector_example.rs` pattern | ||
| 4. **Block processing**: Use `trevm_block_driver_example.rs` pattern | ||
| 5. **CLI tools**: Use `tx_tracer_cli.rs` pattern | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| //! Basic Trevm example demonstrating safe transaction execution | ||
|
|
||
| use revm::database::InMemoryDB; | ||
| use revm::{ | ||
| context::TxEnv, | ||
| primitives::{hex, Address, TxKind}, | ||
| }; | ||
| use trevm::{NoopBlock, NoopCfg, TrevmBuilder, Tx}; | ||
|
|
||
| struct MyTransaction { | ||
| caller: Address, | ||
| to: Address, | ||
| data: Vec<u8>, | ||
| } | ||
|
|
||
| impl Tx for MyTransaction { | ||
| fn fill_tx_env(&self, tx_env: &mut TxEnv) { | ||
| tx_env.caller = self.caller; | ||
| tx_env.kind = TxKind::Call(self.to); | ||
| tx_env.data = self.data.clone().into(); | ||
| } | ||
| } | ||
|
|
||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| // Trevm provides safe, guided workflow | ||
| let tx = MyTransaction { | ||
| caller: Address::with_last_byte(1), | ||
| to: Address::with_last_byte(2), | ||
| data: hex::decode("deadbeef")?, | ||
| }; | ||
|
|
||
| // Type-safe builder pattern | ||
| let result = TrevmBuilder::new() | ||
| .with_db(InMemoryDB::default()) | ||
| .build_trevm()? // EvmNeedsCfg | ||
| .fill_cfg(&NoopCfg) // EvmNeedsBlock | ||
| .fill_block(&NoopBlock) // EvmNeedsTx | ||
| .run_tx(&tx); // Result<EvmTransacted, EvmErrored> | ||
|
|
||
| // Safe error handling with type guarantees | ||
| match result { | ||
| Ok(transacted) => { | ||
| println!("Transaction succeeded!"); | ||
| let _final_evm = transacted.accept_state(); // EvmNeedsTx | ||
| // State automatically applied | ||
| } | ||
| Err(errored) => { | ||
| println!("Transaction failed: {:?}", errored.error()); | ||
| let _recovered_evm = errored.discard_error(); // EvmNeedsTx | ||
| // Can continue with next transaction | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this revm feature removed?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was removed as a feature and it's now included by default—but only activated on the
Osakaspec onwards. means we need to enable it/inject it ourselves wherever else we actually want to use the OpcodeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see bluealloy/revm#2601