|
| 1 | +--- |
| 2 | +description: This skill should be used when the user asks about "EVM customizations", "base fee redirect", "fee sink", "mint precompile", "native token minting", "contract size limit", "EvEvmFactory", "EvHandler", or wants to understand how ev-reth modifies EVM execution behavior. |
| 3 | +--- |
| 4 | + |
| 5 | +# EVM Customizations Onboarding |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +EVM customizations live in `crates/ev-revm/` and `crates/ev-precompiles/`. These modify how the EVM executes transactions. |
| 10 | + |
| 11 | +## Key Files |
| 12 | + |
| 13 | +### EVM Factory |
| 14 | +- `crates/ev-revm/src/factory.rs` - `EvEvmFactory` wraps `EthEvmFactory` |
| 15 | +- `crates/ev-revm/src/evm.rs` - `EvEvm`, `DefaultEvEvm` implementations |
| 16 | +- `crates/ev-revm/src/config.rs` - EVM configuration structs |
| 17 | + |
| 18 | +### Handlers |
| 19 | +- `crates/ev-revm/src/handler.rs` - `EvHandler` for execution handling |
| 20 | +- `crates/ev-revm/src/base_fee.rs` - `BaseFeeRedirect` logic |
| 21 | + |
| 22 | +### Precompiles |
| 23 | +- `crates/ev-precompiles/src/mint.rs` - `MintPrecompile` at address 0xF100 |
| 24 | + |
| 25 | +### Shared |
| 26 | +- `crates/common/src/constants.rs` - Shared constants |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +### EvEvmFactory |
| 31 | + |
| 32 | +Wraps Reth's `EthEvmFactory` to inject custom behavior. See `crates/ev-revm/src/factory.rs:103-108`: |
| 33 | + |
| 34 | +```rust |
| 35 | +pub struct EvEvmFactory<F> { |
| 36 | + inner: F, |
| 37 | + redirect: Option<BaseFeeRedirectSettings>, |
| 38 | + mint_precompile: Option<MintPrecompileSettings>, |
| 39 | + contract_size_limit: Option<ContractSizeLimitSettings>, |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +### Base Fee Redirect |
| 44 | + |
| 45 | +Instead of burning base fees, redirects them to a configurable address. See `crates/ev-revm/src/factory.rs:27-49`: |
| 46 | + |
| 47 | +```rust |
| 48 | +pub struct BaseFeeRedirectSettings { |
| 49 | + redirect: BaseFeeRedirect, // Contains fee_sink address |
| 50 | + activation_height: u64, // When redirect activates |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +The `EvHandler` overrides `reward_beneficiary` (in `handler.rs:126-141`) to credit the sink address with base fees before paying the standard tip to the block producer. |
| 55 | + |
| 56 | +### Mint Precompile (0xF100) |
| 57 | + |
| 58 | +Custom precompile for native token minting/burning at address `0xF100`. See `crates/ev-precompiles/src/mint.rs`. |
| 59 | + |
| 60 | +**INativeToken Interface** (5 functions): |
| 61 | +```solidity |
| 62 | +interface INativeToken { |
| 63 | + function mint(address to, uint256 amount) external; |
| 64 | + function burn(address from, uint256 amount) external; |
| 65 | + function addToAllowList(address account) external; |
| 66 | + function removeFromAllowList(address account) external; |
| 67 | + function allowlist(address account) external view returns (bool); |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +Settings in `crates/ev-revm/src/factory.rs:52-74`: |
| 72 | +```rust |
| 73 | +pub struct MintPrecompileSettings { |
| 74 | + admin: Address, // Who can mint/burn and manage allowlist |
| 75 | + activation_height: u64, // When precompile activates |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Contract Size Limits |
| 80 | + |
| 81 | +Override EIP-170 default (24KB) contract size limit. See `crates/ev-revm/src/factory.rs:77-99`: |
| 82 | + |
| 83 | +```rust |
| 84 | +pub struct ContractSizeLimitSettings { |
| 85 | + limit: usize, // Custom limit in bytes |
| 86 | + activation_height: u64, // When limit changes |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Configuration Flow |
| 91 | + |
| 92 | +1. Chainspec defines settings in `extras` field |
| 93 | +2. `EvolveChainSpecParser` parses into config structs |
| 94 | +3. `EvEvmFactory` receives settings at construction |
| 95 | +4. Settings applied during EVM execution based on block height |
| 96 | + |
| 97 | +## Key Design Decisions |
| 98 | + |
| 99 | +1. **Configurable Activation** - All features have activation heights for upgrades |
| 100 | +2. **Wrapper Pattern** - `EvEvmFactory` wraps standard factory, minimizing changes |
| 101 | +3. **Admin Control** - Mint precompile requires admin authorization (or allowlist) |
| 102 | +4. **Fee Preservation** - Base fees collected rather than burned (for bridging) |
| 103 | + |
| 104 | +## Development Commands |
| 105 | + |
| 106 | +```bash |
| 107 | +cargo test -p ev-revm # Test EVM crate |
| 108 | +cargo test -p ev-precompiles # Test precompiles |
| 109 | +``` |
| 110 | + |
| 111 | +## Exploration Starting Points |
| 112 | + |
| 113 | +1. Start with `crates/ev-revm/src/factory.rs` for the wrapper pattern |
| 114 | +2. Read `crates/ev-revm/src/handler.rs:126-141` for `reward_beneficiary` override |
| 115 | +3. Read `crates/ev-precompiles/src/mint.rs` for precompile implementation |
| 116 | +4. Check `crates/ev-revm/src/base_fee.rs` for redirect logic |
| 117 | +5. See `crates/node/src/config.rs` for how settings are configured |
0 commit comments