diff --git a/Cargo.lock b/Cargo.lock index 7ac303fd8..6ab026ba8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1354,7 +1354,6 @@ dependencies = [ "darwinia-precompile-bls12-381", "darwinia-precompile-state-storage", "dc-primitives", - "fp-evm", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -1404,6 +1403,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", + "precompile-utils", "scale-info", "smallvec", "sp-api", @@ -2413,7 +2413,6 @@ dependencies = [ "darwinia-precompile-bls12-381", "darwinia-precompile-state-storage", "dc-primitives", - "fp-evm", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -2463,6 +2462,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", + "precompile-utils", "scale-info", "smallvec", "sp-api", @@ -7239,7 +7239,6 @@ dependencies = [ "darwinia-precompile-bls12-381", "darwinia-precompile-state-storage", "dc-primitives", - "fp-evm", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -7289,6 +7288,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain", "polkadot-runtime-common", + "precompile-utils", "scale-info", "smallvec", "sp-api", diff --git a/runtime/crab/Cargo.toml b/runtime/crab/Cargo.toml index 68f73e061..82407bfcd 100644 --- a/runtime/crab/Cargo.toml +++ b/runtime/crab/Cargo.toml @@ -55,7 +55,6 @@ pallet-bridge-messages = { default-features = false, git = "https://github.com/d pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" } # frontier -fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-self-contained = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } @@ -68,7 +67,8 @@ pallet-evm-precompile-modexp = { default-features = false, git = "https://gith pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } # moonbeam -xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } +precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30"} +xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } # polkadot pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } @@ -163,7 +163,6 @@ std = [ "pallet-fee-market/std", # frontier - "fp-evm/std", "fp-rpc/std", "fp-self-contained/std", "pallet-base-fee/std", @@ -176,6 +175,7 @@ std = [ "pallet-evm-precompile-simple/std", # moonbeam + "precompile-utils/std", "xcm-primitives/std", # polkadot diff --git a/runtime/crab/src/pallets/evm.rs b/runtime/crab/src/pallets/evm.rs index c2f351188..e6c048dd8 100644 --- a/runtime/crab/src/pallets/evm.rs +++ b/runtime/crab/src/pallets/evm.rs @@ -32,6 +32,8 @@ use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}; +// moonbeam +use precompile_utils::prelude::*; // substrate use frame_support::{traits::FindAuthor, ConsensusEngineId}; use sp_core::crypto::ByteArray; @@ -124,7 +126,13 @@ where R: pallet_evm::Config, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - match handle.code_address() { + let (code_address, caller) = (handle.code_address(), handle.context().caller); + // Filter known precompile addresses except Ethereum officials + if self.is_precompile(code_address) && code_address > addr(9) && code_address != caller { + return Some(Err(revert("cannot be called with DELEGATECALL or CALLCODE"))); + }; + + match code_address { // Ethereum precompiles: a if a == addr(1) => Some(ECRecover::execute(handle)), a if a == addr(2) => Some(Sha256::execute(handle)), @@ -159,7 +167,7 @@ impl pallet_evm::Config for Runtime { type BlockGasLimit = BlockGasLimit; type BlockHashMapping = EthereumBlockHashMapping; type CallOrigin = EnsureAddressRoot; - type ChainId = ConstU64<43>; + type ChainId = ConstU64<44>; type Currency = Balances; type FeeCalculator = FixedGasPrice; type FindAuthor = FindAuthorTruncated; diff --git a/runtime/darwinia/Cargo.toml b/runtime/darwinia/Cargo.toml index 7d2958e03..01f3a8982 100644 --- a/runtime/darwinia/Cargo.toml +++ b/runtime/darwinia/Cargo.toml @@ -55,7 +55,6 @@ pallet-bridge-messages = { default-features = false, git = "https://github.com/d pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" } # frontier -fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-self-contained = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } @@ -68,7 +67,8 @@ pallet-evm-precompile-modexp = { default-features = false, git = "https://gith pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } # moonbeam -xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } +precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30"} +xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } # polkadot pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } @@ -163,7 +163,6 @@ std = [ "pallet-fee-market/std", # frontier - "fp-evm/std", "fp-rpc/std", "fp-self-contained/std", "pallet-base-fee/std", @@ -176,6 +175,7 @@ std = [ "pallet-evm-precompile-simple/std", # moonbeam + "precompile-utils/std", "xcm-primitives/std", # polkadot diff --git a/runtime/darwinia/src/pallets/evm.rs b/runtime/darwinia/src/pallets/evm.rs index a2d8de9be..e8bef3236 100644 --- a/runtime/darwinia/src/pallets/evm.rs +++ b/runtime/darwinia/src/pallets/evm.rs @@ -32,6 +32,8 @@ use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}; +// moonbeam +use precompile_utils::prelude::*; // substrate use frame_support::{traits::FindAuthor, ConsensusEngineId}; use sp_core::crypto::ByteArray; @@ -124,7 +126,13 @@ where R: pallet_evm::Config, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - match handle.code_address() { + let (code_address, caller) = (handle.code_address(), handle.context().caller); + // Filter known precompile addresses except Ethereum officials + if self.is_precompile(code_address) && code_address > addr(9) && code_address != caller { + return Some(Err(revert("cannot be called with DELEGATECALL or CALLCODE"))); + }; + + match code_address { // Ethereum precompiles: a if a == addr(1) => Some(ECRecover::execute(handle)), a if a == addr(2) => Some(Sha256::execute(handle)), @@ -159,7 +167,7 @@ impl pallet_evm::Config for Runtime { type BlockGasLimit = BlockGasLimit; type BlockHashMapping = EthereumBlockHashMapping; type CallOrigin = EnsureAddressRoot; - type ChainId = ConstU64<43>; + type ChainId = ConstU64<46>; type Currency = Balances; type FeeCalculator = FixedGasPrice; type FindAuthor = FindAuthorTruncated; diff --git a/runtime/pangolin/Cargo.toml b/runtime/pangolin/Cargo.toml index f4e4c58a8..ab98468f7 100644 --- a/runtime/pangolin/Cargo.toml +++ b/runtime/pangolin/Cargo.toml @@ -55,7 +55,6 @@ pallet-bridge-messages = { default-features = false, git = "https://github.com/d pallet-fee-market = { default-features = false, git = "https://github.com/darwinia-network/darwinia-messages-substrate", branch = "polkadot-v0.9.30" } # frontier -fp-evm = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-rpc = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } fp-self-contained = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } pallet-base-fee = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } @@ -68,7 +67,8 @@ pallet-evm-precompile-modexp = { default-features = false, git = "https://gith pallet-evm-precompile-simple = { default-features = false, git = "https://github.com/paritytech/frontier", branch = "polkadot-v0.9.30" } # moonbeam -xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } +precompile-utils = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30"} +xcm-primitives = { default-features = false, git = "https://github.com/darwinia-network/moonbeam", branch = "polkadot-v0.9.30" } # polkadot pallet-xcm = { default-features = false, git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.30" } @@ -163,7 +163,6 @@ std = [ "pallet-fee-market/std", # frontier - "fp-evm/std", "fp-rpc/std", "fp-self-contained/std", "pallet-base-fee/std", @@ -176,6 +175,7 @@ std = [ "pallet-evm-precompile-simple/std", # moonbeam + "precompile-utils/std", "xcm-primitives/std", # polkadot diff --git a/runtime/pangolin/src/pallets/evm.rs b/runtime/pangolin/src/pallets/evm.rs index 3d732e102..215e63681 100644 --- a/runtime/pangolin/src/pallets/evm.rs +++ b/runtime/pangolin/src/pallets/evm.rs @@ -32,6 +32,8 @@ use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_simple::{ECRecover, Identity, Ripemd160, Sha256}; +// moonbeam +use precompile_utils::prelude::*; // substrate use frame_support::{traits::FindAuthor, ConsensusEngineId}; use sp_core::crypto::ByteArray; @@ -124,7 +126,13 @@ where R: pallet_evm::Config, { fn execute(&self, handle: &mut impl PrecompileHandle) -> Option { - match handle.code_address() { + let (code_address, caller) = (handle.code_address(), handle.context().caller); + // Filter known precompile addresses except Ethereum officials + if self.is_precompile(code_address) && code_address > addr(9) && code_address != caller { + return Some(Err(revert("cannot be called with DELEGATECALL or CALLCODE"))); + }; + + match code_address { // Ethereum precompiles: a if a == addr(1) => Some(ECRecover::execute(handle)), a if a == addr(2) => Some(Sha256::execute(handle)),