Skip to content

Commit d2d59ea

Browse files
committed
docs: foundry-evm-fuzz extensions
1 parent bd0e4a7 commit d2d59ea

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

crates/evm/networks/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Custom EVM Networks
2+
3+
The evm-networks crate defines custom network features that are shared across Foundry's tooling (`anvil`, `forge` and
4+
`cast`). Currently, it supports custom precompiles, with planned support for custom transaction types.
5+
6+
## Adding a Custom Network
7+
To add configuration support for a custom network (e.g. `my_network`), add a new field to the `NetworkConfigs` struct:
8+
```rust
9+
/// Enable my custom network features.
10+
#[arg(help_heading = "Networks", long)]
11+
#[serde(default)]
12+
pub my_network: bool,
13+
```
14+
This automatically enables::
15+
- `my_network = true` in foundry.toml
16+
- `--my-network` anvil CLI flag
17+
```
18+
Networks:
19+
--my-network
20+
Enable my custom network features
21+
22+
```
23+
If you'd like network features to be enabled automatically based on the chain ID, update the implementation of:
24+
```rust
25+
impl NetworkConfigs {
26+
pub fn with_chain_id(chain_id: u64) -> Self {
27+
// Enable custom network features here
28+
}
29+
}
30+
```
31+
32+
## Adding a custom precompile
33+
34+
- Create a module for your network-specific logic, e.g., `my_network/transfer`.
35+
- Implement the precompile logic as a function that accepts a `PrecompileInput` containing execution context and hooks for
36+
interacting with EVM state, and returns a `PrecompileResult`:
37+
```rust
38+
pub fn custom_precompile(
39+
input: alloy_evm::precompiles::PrecompileInput<'_>
40+
) -> revm::precompile::PrecompileResult {
41+
// Your logic here
42+
}
43+
```
44+
- Enable the precompile in the `NetworkConfigs` implementation by conditionally applying it to an address:
45+
```rust
46+
if self.my_network {
47+
precompiles.apply_precompile(&MY_NETWORK_TRANSFER_ADDRESS, move |_| {
48+
Some(my_network::transfer::custom_precompile())
49+
});
50+
}
51+
```

crates/evm/networks/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ pub struct NetworkConfigs {
2727
}
2828

2929
impl NetworkConfigs {
30-
pub fn celo(mut self, celo: bool) -> Self {
31-
self.celo = celo;
32-
self
33-
}
34-
3530
pub fn with_optimism() -> Self {
3631
Self { optimism: true, ..Default::default() }
3732
}

0 commit comments

Comments
 (0)