-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
074f5bc
commit 04c4a73
Showing
19 changed files
with
656 additions
and
189 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
Oops, something went wrong.