Skip to content

Commit

Permalink
switch to pallet-evm-precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardoaraujor committed Mar 10, 2023
1 parent 074f5bc commit d453727
Show file tree
Hide file tree
Showing 19 changed files with 656 additions and 189 deletions.
25 changes: 23 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"frame/ethereum",
"frame/evm",
"frame/evm-chain-id",
"frame/evm-precompile",
"frame/hotfix-sufficients",
"frame/evm/precompile/sha3fips",
"frame/evm/precompile/simple",
Expand Down Expand Up @@ -137,6 +138,7 @@ pallet-dynamic-fee = { version = "4.0.0-dev", path = "frame/dynamic-fee", defaul
pallet-ethereum = { version = "4.0.0-dev", path = "frame/ethereum", default-features = false }
pallet-evm = { version = "6.0.0-dev", path = "frame/evm", default-features = false }
pallet-evm-chain-id = { version = "1.0.0-dev", path = "frame/evm-chain-id", default-features = false }
pallet-evm-precompile = { version = "1.0.0-dev", path = "frame/evm-precompile", default-features = false }
pallet-evm-precompile-modexp = { version = "2.0.0-dev", path = "frame/evm/precompile/modexp", default-features = false }
pallet-evm-precompile-sha3fips = { version = "2.0.0-dev", path = "frame/evm/precompile/sha3fips", default-features = false }
pallet-evm-precompile-simple = { version = "2.0.0-dev", path = "frame/evm/precompile/simple", default-features = false }
Expand Down
1 change: 0 additions & 1 deletion frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ impl pallet_evm::Config for Test {
type OnChargeTransaction = ();
type OnCreate = ();
type FindAuthor = FindAuthorTruncated;
type PrecompileModifierOrigin = frame_system::EnsureRoot<Self::AccountId>;
}

parameter_types! {
Expand Down
68 changes: 68 additions & 0 deletions frame/evm-precompile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[package]
name = "pallet-evm-precompile"
version = "1.0.0-dev"
license = "Apache-2.0"
readme = "README.md"
description = "FRAME EVM Precompile pallet."
authors = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
scale-codec = { package = "parity-scale-codec", workspace = true }
scale-info = { workspace = true }
serde = { workspace = true, default-features = false }
# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

# Frontier
pallet-evm = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }

[dev-dependencies]
# Substrate
pallet-balances = { workspace = true, features = ["default"] }
pallet-timestamp = { workspace = true }
sp-io = { workspace = true }

# Frontier
fp-evm = { workspace = true }

[features]
default = ["std"]
std = [
"serde/std",
# Substrate
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"sp-std/std",
"sp-core/std",
"sp-runtime/std",
# Frontier
"pallet-evm/std",
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-simple/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-evm/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-evm/try-runtime",
]
12 changes: 12 additions & 0 deletions frame/evm-precompile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EVM Precompile Module

The EVM Precompile Module allows using Precompiles with arbitrary addresses, potentially more than one.

A `StorageMap` keeps track of the Precompiles on-chain, where:
- key: `H160`
- value: `PrecompileLabel`

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.

`OnChainPrecompiles` implements the `PrecompileSet` trait, where the Precompile addresses are routed to the appropriate `Precompile::execute` implementation according to the on-chan mapping.

44 changes: 44 additions & 0 deletions frame/evm-precompile/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use super::*;

#[allow(unused)]
use crate::Pallet as EVMPrecompile;
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite};
use frame_system::RawOrigin;

benchmarks! {
add_precompile {
let address = H160::from_low_u64_be(1);
let label = PrecompileLabel::new(
b"SomePrecompileLabel"
.to_vec()
.try_into()
.expect("less than 32 chars; qed"),
);

}: _(RawOrigin::Root, address, label.clone())
verify {
let read_precompile = EVMPrecompile::<T>::precompiles(address);
assert_eq!(read_precompile, label);
}

remove_precompile {
let address = H160::from_low_u64_be(1);
let label = PrecompileLabel::new(
b"SomePrecompileLabel"
.to_vec()
.try_into()
.expect("less than 32 chars; qed"),
);
EVMPrecompile::<T>::add_precompile(RawOrigin::Root.into(), address, label).unwrap();
}: _(RawOrigin::Root, address)
verify {
let read_precompile = EVMPrecompile::<T>::precompiles(address);
assert_eq!(read_precompile, PrecompileLabel::default());
}
}

impl_benchmark_test_suite!(
EVMPrecompile,
crate::tests::new_test_ext(),
crate::mock::Test
);
Loading

0 comments on commit d453727

Please sign in to comment.