Skip to content

Commit 51880de

Browse files
committed
feat(precompiles): add Token Duality precompile
Implements Celo-style token duality pattern allowing native tokens to function as ERC-20 compatible tokens without wrapping. Features: - Native token transfers via precompile at 0x00..00FD - Admin + allowlist authorization model - Per-call and per-block transfer rate limiting - Chainspec configuration for admin, caps and activation height The precompile provides the transfer mechanism; full ERC-20 compatibility requires a wrapper contract that calls this precompile and provides standard ERC-20 views and events.
1 parent 30cdb0b commit 51880de

File tree

7 files changed

+1745
-4
lines changed

7 files changed

+1745
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ revm-inspector = { version = "12.0.1" }
116116
# Core dependencies
117117
eyre = "0.6"
118118
tracing = "0.1"
119+
parking_lot = "0.12"
119120
tokio = { version = "1.38", features = ["full"] }
120121
serde = { version = "=1.0.228", default-features = false, features = ["derive"] }
121122
serde_json = "1.0"

crates/ev-precompiles/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ bytes = "1.5.0"
2424
eyre = "0.6.11"
2525
thiserror = "1.0.58"
2626
tracing = { workspace = true }
27+
parking_lot = { workspace = true }

crates/ev-precompiles/src/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,53 @@
1+
//! # Evolve Custom EVM Precompiles
2+
//!
3+
//! This crate provides precompiled contracts that extend the EVM with
4+
//! Evolve-specific functionality for sovereign rollups.
5+
//!
6+
//! ## Available Precompiles
7+
//!
8+
//! | Address | Name | Description |
9+
//! |---------|------|-------------|
10+
//! | `0xF100` | [`mint`] | Native token supply management (mint/burn) |
11+
//! | `0x00FD` | [`token_duality`] | Native token as ERC-20 (Celo-style transfer) |
12+
//!
13+
//! ## Architecture
14+
//!
15+
//! All precompiles follow the same pattern:
16+
//!
17+
//! 1. **Authorization**: Admin-based access control with runtime allowlist
18+
//! 2. **State Management**: Direct balance manipulation via `EvmInternals`
19+
//! 3. **Safety**: Checked arithmetic, zero-address validation, rate limiting
20+
//! 4. **Consistency**: Follows Reth/Revm precompile conventions
21+
//!
22+
//! ## Integration
23+
//!
24+
//! Precompiles are registered via `ev_revm::factory::EvEvmFactory` which
25+
//! wraps the standard `EthEvmFactory` and injects custom precompiles.
26+
//!
27+
//! ```ignore
28+
//! use ev_revm::factory::EvEvmFactory;
29+
//! use ev_precompiles::token_duality::TokenDualityConfig;
30+
//!
31+
//! let factory = EvEvmFactory::with_token_duality(
32+
//! EthEvmFactory::default(),
33+
//! None, // base fee redirect
34+
//! Some(mint_admin),
35+
//! Some(TokenDualityConfig::with_admin(token_admin)),
36+
//! );
37+
//! ```
38+
//!
39+
//! ## Security Considerations
40+
//!
41+
//! - All precompiles require explicit admin configuration
42+
//! - Rate limiting prevents abuse (per-call and per-block caps)
43+
//! - State changes are atomic (all-or-nothing)
44+
//! - No reentrancy risk (native execution)
45+
//!
46+
//! ## References
47+
//!
48+
//! - [Celo Token Duality](https://specs.celo.org/token_duality.html)
49+
//! - [Reth Precompiles](https://reth.rs)
50+
//! - [Revm Documentation](https://bluealloy.github.io/revm/)
51+
152
pub mod mint;
53+
pub mod token_duality;

0 commit comments

Comments
 (0)