Skip to content

Commit

Permalink
add filter to all runtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofdeepanshu committed Sep 19, 2023
1 parent a5dc1b1 commit 2854089
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 9 deletions.
23 changes: 23 additions & 0 deletions runtime/astar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,29 @@ impl pallet_xc_asset_config::Config for Runtime {
type WeightInfo = pallet_xc_asset_config::weights::SubstrateWeight<Self>;
}

#[derive(Default)]
pub struct DispatchPrecompileFilter;

impl InstanceFilter<RuntimeCall> for DispatchPrecompileFilter {
fn filter(&self, c: &RuntimeCall) -> bool {
match c {
RuntimeCall::Utility(pallet_utility::Call::batch { 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,
Expand Down
10 changes: 7 additions & 3 deletions runtime/astar/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

//! The Astar Network EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm.
use astar_primitives::precompiles::BlockAllDispatchValidate;
use crate::{DispatchPrecompileFilter, RuntimeCall};
use astar_primitives::precompiles::DispatchFilterValidate;
use pallet_evm::{
ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileResult, PrecompileSet,
Expand Down Expand Up @@ -75,7 +76,7 @@ where
DappsStakingWrapper<R>: Precompile,
BatchPrecompile<R>: Precompile,
XcmPrecompile<R, C>: Precompile,
Dispatch<R, BlockAllDispatchValidate>: Precompile,
Dispatch<R, DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>>: Precompile,
R: pallet_evm::Config
+ pallet_assets::Config
+ pallet_xcm::Config
Expand Down Expand Up @@ -107,7 +108,10 @@ where
a if a == hash(9) => Some(Blake2F::execute(handle)),
// nor Ethereum precompiles :
a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<R, BlockAllDispatchValidate>::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<
R,
DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>,
>::execute(handle)),
a if a == hash(1026) => Some(ECRecoverPublicKey::execute(handle)),
a if a == hash(1027) => Some(Ed25519Verify::execute(handle)),
// Astar precompiles (starts from 0x5000):
Expand Down
23 changes: 23 additions & 0 deletions runtime/local/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,29 @@ impl pallet_sudo::Config for Runtime {
type WeightInfo = pallet_sudo::weights::SubstrateWeight<Runtime>;
}

#[derive(Default)]
pub struct DispatchPrecompileFilter;

impl InstanceFilter<RuntimeCall> for DispatchPrecompileFilter {
fn filter(&self, c: &RuntimeCall) -> bool {
match c {
RuntimeCall::Utility(pallet_utility::Call::batch { 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,
Expand Down
10 changes: 7 additions & 3 deletions runtime/local/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

//! The Local EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm.
use astar_primitives::precompiles::BlockAllDispatchValidate;
use crate::{DispatchPrecompileFilter, RuntimeCall};
use astar_primitives::precompiles::DispatchFilterValidate;
use pallet_evm::{
ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileResult, PrecompileSet,
Expand Down Expand Up @@ -73,7 +74,7 @@ where
DappsStakingWrapper<R>: Precompile,
BatchPrecompile<R>: Precompile,
XvmPrecompile<R, pallet_xvm::Pallet<R>>: Precompile,
Dispatch<R, BlockAllDispatchValidate>: Precompile,
Dispatch<R, DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>>: Precompile,
R: pallet_evm::Config
+ pallet_xvm::Config
+ pallet_assets::Config
Expand Down Expand Up @@ -104,7 +105,10 @@ where
a if a == hash(9) => Some(Blake2F::execute(handle)),
// nor Ethereum precompiles :
a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<R, BlockAllDispatchValidate>::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<
R,
DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>,
>::execute(handle)),
a if a == hash(1026) => Some(ECRecoverPublicKey::execute(handle)),
a if a == hash(1027) => Some(Ed25519Verify::execute(handle)),
// Astar precompiles (starts from 0x5000):
Expand Down
23 changes: 23 additions & 0 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,29 @@ impl pallet_xc_asset_config::Config for Runtime {
type WeightInfo = pallet_xc_asset_config::weights::SubstrateWeight<Self>;
}

#[derive(Default)]
pub struct DispatchPrecompileFilter;

impl InstanceFilter<RuntimeCall> for DispatchPrecompileFilter {
fn filter(&self, c: &RuntimeCall) -> bool {
match c {
RuntimeCall::Utility(pallet_utility::Call::batch { 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,
Expand Down
10 changes: 7 additions & 3 deletions runtime/shiden/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

//! The Shiden Network EVM precompiles. This can be compiled with ``#[no_std]`, ready for Wasm.
use astar_primitives::precompiles::BlockAllDispatchValidate;
use crate::{DispatchPrecompileFilter, RuntimeCall};
use astar_primitives::precompiles::DispatchFilterValidate;
use pallet_evm::{
ExitRevert, IsPrecompileResult, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileResult, PrecompileSet,
Expand Down Expand Up @@ -75,7 +76,7 @@ where
DappsStakingWrapper<R>: Precompile,
BatchPrecompile<R>: Precompile,
XcmPrecompile<R, C>: Precompile,
Dispatch<R, BlockAllDispatchValidate>: Precompile,
Dispatch<R, DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>>: Precompile,
R: pallet_evm::Config
+ pallet_assets::Config
+ pallet_xcm::Config
Expand Down Expand Up @@ -107,7 +108,10 @@ where
a if a == hash(9) => Some(Blake2F::execute(handle)),
// nor Ethereum precompiles :
a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<R, BlockAllDispatchValidate>::execute(handle)),
a if a == hash(1025) => Some(Dispatch::<
R,
DispatchFilterValidate<RuntimeCall, DispatchPrecompileFilter>,
>::execute(handle)),
a if a == hash(1026) => Some(ECRecoverPublicKey::execute(handle)),
a if a == hash(1027) => Some(Ed25519Verify::execute(handle)),
// Astar precompiles (starts from 0x5000):
Expand Down

0 comments on commit 2854089

Please sign in to comment.