Skip to content

Commit

Permalink
Add extra verification
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Jan 12, 2024
1 parent cc8f4a3 commit 8cb9e55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 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 template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fp-account = { workspace = true, features = ["serde"] }
fp-evm = { workspace = true, features = ["serde"] }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true, features = ["serde"] }
precompile-utils = { workspace = true }
# Frontier FRAME
pallet-base-fee = { workspace = true }
pallet-dynamic-fee = { workspace = true }
Expand Down Expand Up @@ -102,6 +103,7 @@ std = [
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"precompile-utils/std",
# Frontier FRAME
"pallet-base-fee/std",
"pallet-dynamic-fee/std",
Expand Down
19 changes: 16 additions & 3 deletions template/runtime/src/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use pallet_evm::{
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
};
use sp_core::H160;
use sp_std::marker::PhantomData;

use pallet_evm::{
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_modexp::Modexp;
use pallet_evm_precompile_sha3fips::Sha3FIPS256;
use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
use precompile_utils::prelude::revert;

pub struct FrontierPrecompiles<R>(PhantomData<R>);

Expand Down Expand Up @@ -40,6 +41,18 @@ where
R: pallet_evm::Config,
{
fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
let (code_addr, context_addr) = (handle.code_address(), handle.context().address);
// For chains that possess their own stateful precompiles, it is advisable to activate this verification measure.
// This measure prohibits the use of DELEGATECALL or CALLCODE for any precompiles other than the official Ethereum precompiles, which are inherently stateless.
if Self::used_addresses().contains(&code_addr)
&& code_addr > hash(9)
&& code_addr != context_addr
{
return Some(Err(revert(
"cannot be called with DELEGATECALL or CALLCODE",
)));
};

match handle.code_address() {
// Ethereum precompiles :
a if a == hash(1) => Some(ECRecover::execute(handle)),
Expand Down

0 comments on commit 8cb9e55

Please sign in to comment.