From 69b6fc06024a26b451e31ba5da501f653b835115 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Thu, 21 Sep 2023 18:16:30 +0530 Subject: [PATCH] remove BlockAll and refactor code --- primitives/src/precompiles.rs | 31 ------------------------------ runtime/astar/src/lib.rs | 26 +------------------------ runtime/astar/src/precompiles.rs | 27 +++++++++++++++++++++++++- runtime/local/src/lib.rs | 26 +------------------------ runtime/local/src/precompiles.rs | 28 ++++++++++++++++++++++++++- runtime/shibuya/src/lib.rs | 27 ++------------------------ runtime/shibuya/src/precompiles.rs | 28 ++++++++++++++++++++++++++- runtime/shiden/src/lib.rs | 26 +------------------------ runtime/shiden/src/precompiles.rs | 28 ++++++++++++++++++++++++++- 9 files changed, 112 insertions(+), 135 deletions(-) diff --git a/primitives/src/precompiles.rs b/primitives/src/precompiles.rs index ac4cabb213..7696c7d355 100644 --- a/primitives/src/precompiles.rs +++ b/primitives/src/precompiles.rs @@ -27,23 +27,6 @@ use frame_support::{ }; use pallet_evm_precompile_dispatch::DispatchValidateT; -/// Struct that blocks all runtime calls to Dispatch Precompile -pub struct BlockAllDispatchValidate; - -/// The default implementation of `DispatchValidateT`. -impl DispatchValidateT - for BlockAllDispatchValidate -{ - fn validate_before_dispatch( - _origin: &AccountId, - _call: &RuntimeCall, - ) -> Option { - Some(PrecompileFailure::Error { - exit_status: ExitError::Other("invalid call".into()), - }) - } -} - /// Struct that allows only whitelisted runtime calls to pass through dispatch precompile, /// Whitelisted calls are defined in runtime pub struct DispatchFilterValidate + Default>( @@ -71,17 +54,3 @@ impl; } -/// Filter that only allows whitelisted runtime call to pass through dispatch precompile -#[derive(Default)] -pub struct DispatchPrecompileFilter; - -impl InstanceFilter for DispatchPrecompileFilter { - fn filter(&self, c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Utility(pallet_utility::Call::batch { calls }) - | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { - for call in calls { - if !DispatchPrecompileFilter::default().filter(call) { - return false; - } - } - true - } - RuntimeCall::DappsStaking(_) => true, - _ => false, - } - } - fn is_superset(&self, _o: &Self) -> bool { - false - } -} - /// The type used to represent the kinds of proxying allowed. #[derive( Copy, diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs index bbc8a489a0..4605441770 100644 --- a/runtime/astar/src/precompiles.rs +++ b/runtime/astar/src/precompiles.rs @@ -18,8 +18,9 @@ //! The Astar Network EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm. -use crate::{DispatchPrecompileFilter, RuntimeCall}; +use crate::RuntimeCall; use astar_primitives::precompiles::DispatchFilterValidate; +use frame_support::traits::InstanceFilter; use pallet_evm::{ ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult, PrecompileSet, @@ -47,6 +48,30 @@ use xcm::latest::prelude::MultiLocation; /// to Erc20AssetsPrecompileSet pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// Filter that only allows whitelisted runtime call to pass through dispatch precompile +#[derive(Default)] +pub struct DispatchPrecompileFilter; + +impl InstanceFilter for DispatchPrecompileFilter { + fn filter(&self, c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Utility(pallet_utility::Call::batch { calls }) + | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { + for call in calls { + if !DispatchPrecompileFilter::default().filter(call) { + return false; + } + } + true + } + RuntimeCall::DappsStaking(_) => true, + _ => false, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} /// The PrecompileSet installed in the Astar runtime. #[derive(Debug, Default, Clone, Copy)] pub struct AstarNetworkPrecompiles(PhantomData<(R, C)>); diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index 39a7dd8c62..007495f29e 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -65,6 +65,7 @@ pub use astar_primitives::{ Index, Signature, }; +pub use crate::precompiles::DispatchPrecompileFilter; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -845,31 +846,6 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = pallet_sudo::weights::SubstrateWeight; } -/// Filter that only allows whitelisted runtime call to pass through dispatch precompile -#[derive(Default)] -pub struct DispatchPrecompileFilter; - -impl InstanceFilter for DispatchPrecompileFilter { - fn filter(&self, c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Utility(pallet_utility::Call::batch { calls }) - | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { - for call in calls { - if !DispatchPrecompileFilter::default().filter(call) { - return false; - } - } - true - } - RuntimeCall::DappsStaking(_) => true, - _ => false, - } - } - fn is_superset(&self, _o: &Self) -> bool { - false - } -} - /// The type used to represent the kinds of proxying allowed. #[derive( Copy, diff --git a/runtime/local/src/precompiles.rs b/runtime/local/src/precompiles.rs index d14eb53147..d0c56ab856 100644 --- a/runtime/local/src/precompiles.rs +++ b/runtime/local/src/precompiles.rs @@ -18,8 +18,9 @@ //! The Local EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm. -use crate::{DispatchPrecompileFilter, RuntimeCall}; +use crate::RuntimeCall; use astar_primitives::precompiles::DispatchFilterValidate; +use frame_support::traits::InstanceFilter; use pallet_evm::{ ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult, PrecompileSet, @@ -45,6 +46,31 @@ use sp_std::marker::PhantomData; /// to Erc20AssetsPrecompileSet pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// Filter that only allows whitelisted runtime call to pass through dispatch precompile +#[derive(Default)] +pub struct DispatchPrecompileFilter; + +impl InstanceFilter for DispatchPrecompileFilter { + fn filter(&self, c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Utility(pallet_utility::Call::batch { calls }) + | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { + for call in calls { + if !DispatchPrecompileFilter::default().filter(call) { + return false; + } + } + true + } + RuntimeCall::DappsStaking(_) => true, + _ => false, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + /// The PrecompileSet installed in the Local runtime. #[derive(Debug, Default, Clone, Copy)] pub struct LocalNetworkPrecompiles(PhantomData); diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index d9f154cb59..8eb6732218 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -74,6 +74,8 @@ pub use astar_primitives::{ Index, Signature, }; +pub use crate::precompiles::DispatchPrecompileFilter; + use pallet_evm_precompile_assets_erc20::AddressToAssetId; #[cfg(any(feature = "std", test))] @@ -1053,31 +1055,6 @@ impl pallet_sudo::Config for Runtime { type WeightInfo = pallet_sudo::weights::SubstrateWeight; } -/// Filter that only allows whitelisted runtime call to pass through dispatch precompile -#[derive(Default)] -pub struct DispatchPrecompileFilter; - -impl InstanceFilter for DispatchPrecompileFilter { - fn filter(&self, c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Utility(pallet_utility::Call::batch { calls }) - | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { - for call in calls { - if !DispatchPrecompileFilter::default().filter(call) { - return false; - } - } - true - } - RuntimeCall::DappsStaking(_) => true, - _ => false, - } - } - fn is_superset(&self, _o: &Self) -> bool { - false - } -} - parameter_types! { // One storage item; key size 32, value size 8. pub const ProxyDepositBase: Balance = deposit(1, 8); diff --git a/runtime/shibuya/src/precompiles.rs b/runtime/shibuya/src/precompiles.rs index 5c869a6253..7c0ed550d5 100644 --- a/runtime/shibuya/src/precompiles.rs +++ b/runtime/shibuya/src/precompiles.rs @@ -18,8 +18,9 @@ //! The Shibuya Network EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm. -use crate::{DispatchPrecompileFilter, RuntimeCall}; +use crate::RuntimeCall; use astar_primitives::precompiles::DispatchFilterValidate; +use frame_support::traits::InstanceFilter; use pallet_evm::{ ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult, PrecompileSet, @@ -48,6 +49,31 @@ use xcm::latest::prelude::MultiLocation; /// to Erc20AssetsPrecompileSet pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// Filter that only allows whitelisted runtime call to pass through dispatch precompile +#[derive(Default)] +pub struct DispatchPrecompileFilter; + +impl InstanceFilter for DispatchPrecompileFilter { + fn filter(&self, c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Utility(pallet_utility::Call::batch { calls }) + | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { + for call in calls { + if !DispatchPrecompileFilter::default().filter(call) { + return false; + } + } + true + } + RuntimeCall::DappsStaking(_) => true, + _ => false, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + /// The PrecompileSet installed in the Shiden runtime. #[derive(Debug, Default, Clone, Copy)] pub struct ShibuyaNetworkPrecompiles(PhantomData<(R, C)>); diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs index 12fa796b32..4d93b3b0ff 100644 --- a/runtime/shiden/src/lib.rs +++ b/runtime/shiden/src/lib.rs @@ -67,6 +67,7 @@ use sp_runtime::{ }; use sp_std::prelude::*; +pub use crate::precompiles::DispatchPrecompileFilter; pub use astar_primitives::{ evm::EvmRevertCodeHandler, xcm::AssetLocationIdConverter, AccountId, Address, AssetId, Balance, BlockNumber, Hash, Header, Index, Signature, @@ -832,31 +833,6 @@ impl pallet_xc_asset_config::Config for Runtime { type WeightInfo = pallet_xc_asset_config::weights::SubstrateWeight; } -/// Filter that only allows whitelisted runtime call to pass through dispatch precompile -#[derive(Default)] -pub struct DispatchPrecompileFilter; - -impl InstanceFilter for DispatchPrecompileFilter { - fn filter(&self, c: &RuntimeCall) -> bool { - match c { - RuntimeCall::Utility(pallet_utility::Call::batch { calls }) - | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { - for call in calls { - if !DispatchPrecompileFilter::default().filter(call) { - return false; - } - } - true - } - RuntimeCall::DappsStaking(_) => true, - _ => false, - } - } - fn is_superset(&self, _o: &Self) -> bool { - false - } -} - /// The type used to represent the kinds of proxying allowed. #[derive( Copy, diff --git a/runtime/shiden/src/precompiles.rs b/runtime/shiden/src/precompiles.rs index f03bd02f34..9c242bd9d9 100644 --- a/runtime/shiden/src/precompiles.rs +++ b/runtime/shiden/src/precompiles.rs @@ -18,8 +18,9 @@ //! The Shiden Network EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm. -use crate::{DispatchPrecompileFilter, RuntimeCall}; +use crate::RuntimeCall; use astar_primitives::precompiles::DispatchFilterValidate; +use frame_support::traits::InstanceFilter; use pallet_evm::{ ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult, PrecompileSet, @@ -47,6 +48,31 @@ use xcm::latest::prelude::MultiLocation; /// to Erc20AssetsPrecompileSet pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// Filter that only allows whitelisted runtime call to pass through dispatch precompile +#[derive(Default)] +pub struct DispatchPrecompileFilter; + +impl InstanceFilter for DispatchPrecompileFilter { + fn filter(&self, c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Utility(pallet_utility::Call::batch { calls }) + | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { + for call in calls { + if !DispatchPrecompileFilter::default().filter(call) { + return false; + } + } + true + } + RuntimeCall::DappsStaking(_) => true, + _ => false, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + /// The PrecompileSet installed in the Shiden runtime. #[derive(Debug, Default, Clone, Copy)] pub struct ShidenNetworkPrecompiles(PhantomData<(R, C)>);