Skip to content

Commit ffbfd89

Browse files
Merge pull request #116 from catalyst-network/core-functionality
EVM updated to extend REVM
2 parents b13474f + de37a37 commit ffbfd89

File tree

6 files changed

+2006
-335
lines changed

6 files changed

+2006
-335
lines changed

crates/catalyst-runtime-evm/Cargo.toml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,29 @@ version = "0.1.0"
44
edition = "2021"
55
description = "Ethereum Virtual Machine runtime for Catalyst Network"
66
license = "MIT OR Apache-2.0"
7+
authors = ["Catalyst Team"]
8+
repository = "https://github.com/catalyst-network/catalyst-node-rust"
9+
documentation = "https://docs.rs/catalyst-runtime-evm"
10+
readme = "README.md"
11+
keywords = ["blockchain", "evm", "ethereum", "catalyst", "runtime"]
12+
categories = ["cryptography::cryptocurrencies", "development-tools"]
713

814
[dependencies]
15+
# Core Catalyst dependencies
916
catalyst-core = { path = "../catalyst-core" }
10-
# catalyst-storage = { path = "../catalyst-storage" } # Comment out for now
1117

12-
# EVM implementation - use compatible versions without problematic features
18+
# EVM implementation - use compatible versions
1319
revm = { version = "3.5", default-features = false, features = ["std", "serde"] }
1420
revm-primitives = { version = "1.3", default-features = false, features = ["std", "serde"] }
1521

16-
# Ethereum types
22+
# Ethereum types and utilities
1723
ethereum-types = "0.14"
1824
ethabi = "18.0"
19-
keccak-hash = "0.10"
25+
rlp = "0.5"
2026

2127
# Cryptographic functions
22-
sha2 = "0.10"
28+
sha3 = "0.10"
29+
keccak-hash = "0.10"
2330

2431
# Async support
2532
tokio = { version = "1.0", features = ["full"] }
@@ -39,10 +46,36 @@ hex = "0.4"
3946

4047
[dev-dependencies]
4148
tokio-test = "0.4"
49+
criterion = "0.5"
50+
tempfile = "3.0"
51+
env_logger = "0.10"
4252

4353
[features]
44-
default = []
45-
# Optional features that can be enabled later
54+
default = ["std"]
55+
std = ["revm/std", "revm-primitives/std"]
56+
57+
# Optional features for advanced functionality
4658
optimism = ["revm/optimism"]
47-
# Remove kzg feature since it's not available
48-
# kzg = ["revm/blst"]
59+
ethereum-tests = []
60+
debug-mode = []
61+
62+
# Catalyst-specific features
63+
cross-runtime = []
64+
confidential-tx = []
65+
dfs-integration = []
66+
67+
[[bench]]
68+
name = "evm_execution"
69+
harness = false
70+
71+
[[example]]
72+
name = "deploy_contract"
73+
required-features = ["std"]
74+
75+
[[example]]
76+
name = "cross_runtime_call"
77+
required-features = ["cross-runtime"]
78+
79+
[package.metadata.docs.rs]
80+
all-features = true
81+
rustdoc-args = ["--cfg", "docsrs"]
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
# Catalyst Runtime EVM
2+
3+
A high-performance Ethereum Virtual Machine runtime for the Catalyst Network, built on top of REVM with Catalyst-specific extensions.
4+
5+
## Overview
6+
7+
The Catalyst EVM runtime provides full Ethereum compatibility while adding unique features like cross-runtime calls, distributed file system integration, and confidential transactions. It serves as one of the pluggable runtime environments in Catalyst's multi-runtime architecture.
8+
9+
## Features
10+
11+
### 🔗 **Ethereum Compatibility**
12+
- Full EVM bytecode execution via REVM
13+
- Support for all Ethereum hard forks (up to Shanghai)
14+
- Compatible with existing Ethereum tooling (Hardhat, Truffle, Foundry)
15+
- Standard precompiles (ecrecover, sha256, ripemd160, identity)
16+
17+
### 🚀 **Catalyst Extensions**
18+
- **Cross-Runtime Calls**: Execute code in other runtimes (SVM, Native WASM)
19+
- **DFS Integration**: Store and retrieve files from distributed file system
20+
- **Confidential Transactions**: Privacy-preserving transactions with zero-knowledge proofs
21+
- **Dynamic Gas Pricing**: Network-aware fee calculation
22+
- **Advanced Debugging**: Comprehensive execution tracing
23+
24+
### **Performance**
25+
- Built on REVM for maximum performance
26+
- Optimized gas metering
27+
- Efficient state management
28+
- Concurrent execution support
29+
30+
## Architecture
31+
32+
```
33+
┌─────────────────────────────────────────┐
34+
│ Catalyst EVM Runtime │
35+
├─────────────────────────────────────────┤
36+
│ ┌─────────────┐ ┌─────────────────┐ │
37+
│ │ REVM │ │ Catalyst │ │
38+
│ │ Core │ │ Extensions │ │
39+
│ │ │ │ │ │
40+
│ │ • Opcodes │ │ • Cross-Runtime │ │
41+
│ │ • Gas │ │ • DFS Ops │ │
42+
│ │ • Storage │ │ • Confidential │ │
43+
│ └─────────────┘ └─────────────────┘ │
44+
├─────────────────────────────────────────┤
45+
│ Catalyst Database │
46+
└─────────────────────────────────────────┘
47+
```
48+
49+
## Usage
50+
51+
### Basic Setup
52+
53+
```rust
54+
use catalyst_runtime_evm::{CatalystEvmRuntime, CatalystEvmConfig, CatalystFeatures};
55+
56+
// Configure the runtime
57+
let config = CatalystEvmConfig {
58+
evm_config: EvmConfig {
59+
chain_id: 31337,
60+
block_gas_limit: 30_000_000,
61+
base_fee: U256::from(1_000_000_000u64),
62+
enable_eip1559: true,
63+
enable_london: true,
64+
enable_berlin: true,
65+
max_code_size: 49152,
66+
view_gas_limit: 50_000_000,
67+
},
68+
catalyst_features: CatalystFeatures {
69+
cross_runtime_enabled: true,
70+
confidential_tx_enabled: false,
71+
dfs_integration: true,
72+
catalyst_gas_model: true,
73+
},
74+
};
75+
76+
// Create the runtime
77+
let database = CatalystDatabase::new();
78+
let mut runtime = CatalystEvmRuntime::new(database, config);
79+
```
80+
81+
### Execute a Transaction
82+
83+
```rust
84+
use catalyst_runtime_evm::{EvmTransaction, BlockEnv};
85+
86+
// Create a transaction
87+
let tx = EvmTransaction {
88+
from: Address::from_str("0x742d35Cc6527C3c7Bb91B6B4d0e71b46C7E3e8F4").unwrap(),
89+
to: Some(Address::from_str("0x8ba1f109551bD432803012645Hac136c2Bb25F00c").unwrap()),
90+
value: U256::from(1_000_000_000_000_000_000u64), // 1 ETH
91+
data: vec![],
92+
gas_limit: 21000,
93+
gas_price: U256::from(20_000_000_000u64), // 20 gwei
94+
gas_priority_fee: Some(U256::from(1_000_000_000u64)), // 1 gwei tip
95+
nonce: 0,
96+
chain_id: 31337,
97+
access_list: None,
98+
};
99+
100+
// Set up block environment
101+
let block_env = BlockEnv {
102+
number: U256::from(1),
103+
coinbase: Address::zero(),
104+
timestamp: U256::from(1640995200), // 2022-01-01
105+
gas_limit: U256::from(30_000_000),
106+
basefee: U256::from(1_000_000_000u64),
107+
difficulty: U256::zero(),
108+
prevrandao: Some(H256::random().into()),
109+
};
110+
111+
// Execute the transaction
112+
let result = runtime.execute_transaction(&tx, &block_env).await?;
113+
114+
if result.success() {
115+
println!("Transaction executed successfully!");
116+
println!("Gas used: {}", result.gas_used());
117+
println!("Return data: {:?}", result.return_data());
118+
} else {
119+
println!("Transaction failed");
120+
}
121+
```
122+
123+
### Deploy a Contract
124+
125+
```rust
126+
use catalyst_runtime_evm::ContractDeployer;
127+
128+
let mut deployer = ContractDeployer::new();
129+
130+
// Deploy a simple contract
131+
let bytecode = hex::decode("608060405234801561001057600080fd5b50...")?;
132+
let constructor_args = vec![];
133+
134+
let contract_address = deployer.deploy_contract(
135+
deployer_address,
136+
bytecode,
137+
constructor_args,
138+
None, // Use CREATE instead of CREATE2
139+
)?;
140+
141+
println!("Contract deployed at: {:?}", contract_address);
142+
```
143+
144+
### Cross-Runtime Calls
145+
146+
```rust
147+
// Call Solana runtime from EVM contract
148+
let cross_runtime_call = CrossRuntimeCall {
149+
target_runtime: RuntimeType::SVM,
150+
method: "transfer".to_string(),
151+
parameters: serde_json::to_vec(&transfer_params)?,
152+
gas_used: 0, // Will be calculated during execution
153+
};
154+
155+
// This would be triggered by a precompile call in your Solidity contract
156+
```
157+
158+
## Testing
159+
160+
Run the test suite:
161+
162+
```bash
163+
cargo test
164+
```
165+
166+
Run with logging:
167+
168+
```bash
169+
RUST_LOG=debug cargo test -- --nocapture
170+
```
171+
172+
Benchmark performance:
173+
174+
```bash
175+
cargo bench
176+
```
177+
178+
## Configuration Options
179+
180+
### EVM Configuration
181+
182+
| Option | Default | Description |
183+
|--------|---------|-------------|
184+
| `chain_id` | 31337 | Network chain identifier |
185+
| `block_gas_limit` | 30,000,000 | Maximum gas per block |
186+
| `base_fee` | 1 gwei | Base fee for EIP-1559 |
187+
| `max_code_size` | 48KB | Maximum contract size |
188+
189+
### Catalyst Features
190+
191+
| Feature | Default | Description |
192+
|---------|---------|-------------|
193+
| `cross_runtime_enabled` | false | Enable calls to other runtimes |
194+
| `confidential_tx_enabled` | false | Enable privacy features |
195+
| `dfs_integration` | false | Enable distributed file system |
196+
| `catalyst_gas_model` | false | Use Catalyst dynamic pricing |
197+
198+
## Precompiles
199+
200+
### Standard Ethereum Precompiles
201+
- `0x01`: ECRECOVER - Elliptic curve signature recovery
202+
- `0x02`: SHA256 - SHA-256 hash function
203+
- `0x03`: RIPEMD160 - RIPEMD-160 hash function
204+
- `0x04`: IDENTITY - Identity function (data copy)
205+
206+
### Catalyst Extension Precompiles
207+
- `0x1000`: CROSS_RUNTIME_CALL - Call other runtime environments
208+
- `0x1001`: DFS_STORE - Store files in distributed file system
209+
- `0x1002`: DFS_RETRIEVE - Retrieve files from DFS
210+
- `0x1003`: COMMITMENT_VERIFY - Verify confidential transaction proofs
211+
212+
## Integration with Catalyst Consensus
213+
214+
The EVM runtime integrates seamlessly with Catalyst's collaborative consensus:
215+
216+
1. **Transaction Collection**: Consensus producers collect pending transactions
217+
2. **Execution**: EVM runtime processes transactions in deterministic order
218+
3. **State Updates**: Results are committed to the global state
219+
4. **Verification**: Other producers verify execution results
220+
5. **Finalization**: Consensus finalizes the new state
221+
222+
## Performance Characteristics
223+
224+
- **Transaction Throughput**: 1000+ TPS (depending on complexity)
225+
- **Gas Costs**: Compatible with Ethereum mainnet pricing
226+
- **Memory Usage**: ~100MB base + state size
227+
- **Cold Start Time**: <100ms
228+
- **Cross-Runtime Call Overhead**: ~5000 gas
229+
230+
## Development
231+
232+
### Building
233+
234+
```bash
235+
cargo build --release
236+
```
237+
238+
### Running Tests
239+
240+
```bash
241+
# Unit tests
242+
cargo test
243+
244+
# Integration tests
245+
cargo test --test integration
246+
247+
# With coverage
248+
cargo tarpaulin --out Html
249+
```
250+
251+
### Contributing
252+
253+
1. Fork the repository
254+
2. Create a feature branch
255+
3. Add tests for new functionality
256+
4. Ensure all tests pass
257+
5. Submit a pull request
258+
259+
### Code Style
260+
261+
This crate follows standard Rust conventions:
262+
263+
```bash
264+
# Format code
265+
cargo fmt
266+
267+
# Check for issues
268+
cargo clippy
269+
270+
# Security audit
271+
cargo audit
272+
```
273+
274+
## Roadmap
275+
276+
### Phase 1 (Current)
277+
- ✅ Basic EVM execution via REVM
278+
- ✅ Gas metering and fee calculation
279+
- ✅ Contract deployment support
280+
- ✅ Standard precompiles
281+
282+
### Phase 2
283+
- 🔄 Cross-runtime communication
284+
- 🔄 DFS integration
285+
- 🔄 Advanced debugging tools
286+
- 🔄 Performance optimizations
287+
288+
### Phase 3
289+
- ⏳ Confidential transactions
290+
- ⏳ Zero-knowledge proof integration
291+
- ⏳ Enterprise features
292+
- ⏳ Additional EVM improvements
293+
294+
## Security Considerations
295+
296+
- **Sandboxing**: Each execution is isolated
297+
- **Gas Limits**: Prevent infinite loops and DoS attacks
298+
- **Memory Safety**: Rust's memory safety prevents buffer overflows
299+
- **Deterministic Execution**: Consistent results across all nodes
300+
- **Access Controls**: Precompiles validate permissions
301+
302+
## License
303+
304+
This project is licensed under MIT OR Apache-2.0.
305+
306+
## Links
307+
308+
- [Catalyst Network](https://github.com/catalyst-network)
309+
- [REVM](https://github.com/bluealloy/revm)
310+
- [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf)
311+
- [EIP Specifications](https://eips.ethereum.org/)

0 commit comments

Comments
 (0)