Skip to content

Commit 093d3a9

Browse files
switch to pallet-evm-precompile
1 parent 074f5bc commit 093d3a9

File tree

19 files changed

+656
-189
lines changed

19 files changed

+656
-189
lines changed

Cargo.lock

Lines changed: 23 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ members = [
55
"frame/ethereum",
66
"frame/evm",
77
"frame/evm-chain-id",
8+
"frame/evm-precompile",
89
"frame/hotfix-sufficients",
910
"frame/evm/precompile/sha3fips",
1011
"frame/evm/precompile/simple",
@@ -137,6 +138,7 @@ pallet-dynamic-fee = { version = "4.0.0-dev", path = "frame/dynamic-fee", defaul
137138
pallet-ethereum = { version = "4.0.0-dev", path = "frame/ethereum", default-features = false }
138139
pallet-evm = { version = "6.0.0-dev", path = "frame/evm", default-features = false }
139140
pallet-evm-chain-id = { version = "1.0.0-dev", path = "frame/evm-chain-id", default-features = false }
141+
pallet-evm-precompile = { version = "1.0.0-dev", path = "frame/evm-precompile", default-features = false }
140142
pallet-evm-precompile-modexp = { version = "2.0.0-dev", path = "frame/evm/precompile/modexp", default-features = false }
141143
pallet-evm-precompile-sha3fips = { version = "2.0.0-dev", path = "frame/evm/precompile/sha3fips", default-features = false }
142144
pallet-evm-precompile-simple = { version = "2.0.0-dev", path = "frame/evm/precompile/simple", default-features = false }

frame/ethereum/src/mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ impl pallet_evm::Config for Test {
169169
type OnChargeTransaction = ();
170170
type OnCreate = ();
171171
type FindAuthor = FindAuthorTruncated;
172-
type PrecompileModifierOrigin = frame_system::EnsureRoot<Self::AccountId>;
173172
}
174173

175174
parameter_types! {

frame/evm-precompile/Cargo.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[package]
2+
name = "pallet-evm-precompile"
3+
version = "1.0.0-dev"
4+
license = "Apache-2.0"
5+
readme = "README.md"
6+
description = "FRAME EVM Precompile pallet."
7+
authors = { workspace = true }
8+
edition = { workspace = true }
9+
repository = { workspace = true }
10+
11+
[package.metadata.docs.rs]
12+
targets = ["x86_64-unknown-linux-gnu"]
13+
14+
[dependencies]
15+
scale-codec = { package = "parity-scale-codec", workspace = true }
16+
scale-info = { workspace = true }
17+
serde = { workspace = true, default-features = false }
18+
# Substrate
19+
frame-benchmarking = { workspace = true, optional = true }
20+
frame-support = { workspace = true }
21+
frame-system = { workspace = true }
22+
sp-core = { workspace = true }
23+
sp-runtime = { workspace = true }
24+
sp-std = { workspace = true }
25+
26+
# Frontier
27+
pallet-evm = { workspace = true }
28+
pallet-evm-precompile-modexp = { workspace = true }
29+
pallet-evm-precompile-sha3fips = { workspace = true }
30+
pallet-evm-precompile-simple = { workspace = true }
31+
32+
[dev-dependencies]
33+
# Substrate
34+
pallet-balances = { workspace = true, features = ["default"] }
35+
pallet-timestamp = { workspace = true }
36+
sp-io = { workspace = true }
37+
38+
# Frontier
39+
fp-evm = { workspace = true }
40+
41+
[features]
42+
default = ["std"]
43+
std = [
44+
"serde/std",
45+
# Substrate
46+
"frame-benchmarking/std",
47+
"frame-support/std",
48+
"frame-system/std",
49+
"sp-std/std",
50+
"sp-core/std",
51+
"sp-runtime/std",
52+
# Frontier
53+
"pallet-evm/std",
54+
"pallet-evm-precompile-modexp/std",
55+
"pallet-evm-precompile-sha3fips/std",
56+
"pallet-evm-precompile-simple/std",
57+
]
58+
runtime-benchmarks = [
59+
"frame-benchmarking/runtime-benchmarks",
60+
"frame-support/runtime-benchmarks",
61+
"frame-system/runtime-benchmarks",
62+
"pallet-evm/runtime-benchmarks",
63+
]
64+
try-runtime = [
65+
"frame-support/try-runtime",
66+
"frame-system/try-runtime",
67+
"pallet-evm/try-runtime",
68+
]

frame/evm-precompile/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EVM Precompile Module
2+
3+
The EVM Precompile Module allows using Precompiles with arbitrary addresses, potentially more than one.
4+
5+
A `StorageMap` keeps track of the Precompiles on-chain, where:
6+
- key: `H160`
7+
- value: `PrecompileLabel`
8+
9+
A `PrecompileLabel` determines which functionality the Precompile has. It is declared as a `BoundedVec<u8, ConstU32<32>>`, which means the user is free to choose a label (e.g.: `b"Sha3FIPS512"`) that's up-to 32 bytes long.
10+
11+
`OnChainPrecompiles` implements the `PrecompileSet` trait, where the Precompile addresses are routed to the appropriate `Precompile::execute` implementation according to the on-chan mapping.
12+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use super::*;
2+
3+
#[allow(unused)]
4+
use crate::Pallet as EVMPrecompile;
5+
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
6+
use frame_system::RawOrigin;
7+
8+
benchmarks! {
9+
add_precompile {
10+
let address = H160::from_low_u64_be(1);
11+
let label = PrecompileLabel::new(
12+
b"SomePrecompileLabel"
13+
.to_vec()
14+
.try_into()
15+
.expect("less than 32 chars; qed"),
16+
);
17+
18+
}: _(RawOrigin::Root, address, label.clone())
19+
verify {
20+
let read_precompile = EVMPrecompile::<T>::precompiles(address);
21+
assert_eq!(read_precompile, label);
22+
}
23+
24+
remove_precompile {
25+
let address = H160::from_low_u64_be(1);
26+
let label = PrecompileLabel::new(
27+
b"SomePrecompileLabel"
28+
.to_vec()
29+
.try_into()
30+
.expect("less than 32 chars; qed"),
31+
);
32+
EVMPrecompile::<T>::add_precompile(RawOrigin::Root.into(), address, label).unwrap();
33+
}: _(RawOrigin::Root, address)
34+
verify {
35+
let read_precompile = EVMPrecompile::<T>::precompiles(address);
36+
assert_eq!(read_precompile, PrecompileLabel::default());
37+
}
38+
}
39+
40+
impl_benchmark_test_suite!(
41+
EVMPrecompile,
42+
crate::tests::new_test_ext(),
43+
crate::mock::Test
44+
);

0 commit comments

Comments
 (0)