From ccbeaad4b4d0cee7321c4940cf709bf81ddf5207 Mon Sep 17 00:00:00 2001 From: Deepanshu Hooda Date: Tue, 26 Sep 2023 21:36:57 +0530 Subject: [PATCH] add transfer fn of pallet assets to whitelist --- runtime/astar/src/precompiles.rs | 1 + runtime/local/src/precompiles.rs | 1 + runtime/shibuya/src/precompiles.rs | 1 + runtime/shiden/src/precompiles.rs | 1 + .../src/dispatch_precompile_filter.rs | 24 ++++++++++++++++++- 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs index 3845c68fdf..ffe0e2cbd8 100644 --- a/runtime/astar/src/precompiles.rs +++ b/runtime/astar/src/precompiles.rs @@ -60,6 +60,7 @@ impl Contains for WhitelistedCalls { calls.iter().all(|call| WhitelistedCalls::contains(call)) } RuntimeCall::DappsStaking(_) => true, + RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, _ => false, } } diff --git a/runtime/local/src/precompiles.rs b/runtime/local/src/precompiles.rs index 6bf29d17f7..b2ccb203b3 100644 --- a/runtime/local/src/precompiles.rs +++ b/runtime/local/src/precompiles.rs @@ -56,6 +56,7 @@ impl Contains for WhitelistedCalls { | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { calls.iter().all(|call| WhitelistedCalls::contains(call)) } + RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, RuntimeCall::DappsStaking(_) => true, _ => false, } diff --git a/runtime/shibuya/src/precompiles.rs b/runtime/shibuya/src/precompiles.rs index 0965bcd57e..d87b7e31fa 100644 --- a/runtime/shibuya/src/precompiles.rs +++ b/runtime/shibuya/src/precompiles.rs @@ -59,6 +59,7 @@ impl Contains for WhitelistedCalls { | RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => { calls.iter().all(|call| WhitelistedCalls::contains(call)) } + RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, RuntimeCall::DappsStaking(_) => true, _ => false, } diff --git a/runtime/shiden/src/precompiles.rs b/runtime/shiden/src/precompiles.rs index 7dde89084c..9e714ecebf 100644 --- a/runtime/shiden/src/precompiles.rs +++ b/runtime/shiden/src/precompiles.rs @@ -59,6 +59,7 @@ impl Contains for WhitelistedCalls { calls.iter().all(|call| WhitelistedCalls::contains(call)) } RuntimeCall::DappsStaking(_) => true, + RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true, _ => false, } } diff --git a/tests/integration/src/dispatch_precompile_filter.rs b/tests/integration/src/dispatch_precompile_filter.rs index 61a42f6a41..1099d592f0 100644 --- a/tests/integration/src/dispatch_precompile_filter.rs +++ b/tests/integration/src/dispatch_precompile_filter.rs @@ -25,6 +25,7 @@ use frame_support::{ traits::Contains, }; use pallet_evm_precompile_dispatch::DispatchValidateT; +use parity_scale_codec::Compact; /// Whitelisted Calls are defined in the runtime #[test] @@ -77,22 +78,38 @@ fn filter_rejects_non_whitelisted_batch_calls() { #[test] fn filter_accepts_whitelisted_calls() { ExtBuilder::default().build().execute_with(|| { + // Dappstaking call works let contract = SmartContract::Evm(H160::repeat_byte(0x01)); let stake_call = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { contract_id: contract.clone(), }); assert!(WhitelistedCalls::contains(&stake_call)); + + // Pallet::Assets transfer call works + let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { + id: Compact(0), + target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), + amount: 100, + }); + assert!(WhitelistedCalls::contains(&transfer_call)); }); } #[test] fn filter_rejects_non_whitelisted_calls() { ExtBuilder::default().build().execute_with(|| { + // Random call from non whitelisted pallet doesn't work let transfer_call = RuntimeCall::Balances(BalancesCall::transfer { dest: MultiAddress::Id(CAT), value: 100_000_000_000, }); assert!(!WhitelistedCalls::contains(&transfer_call)); + + // Only `transfer` call from pallet assets work + // Other random call from Pallet Assets doesn't work + let thaw_asset_call = + RuntimeCall::Assets(pallet_assets::Call::thaw_asset { id: Compact(0) }); + assert!(!WhitelistedCalls::contains(&thaw_asset_call)); }) } @@ -106,8 +123,13 @@ fn filter_accepts_whitelisted_batch_all_calls() { let inner_call2 = RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker { contract_id: contract.clone(), }); + let transfer_call = RuntimeCall::Assets(pallet_assets::Call::transfer { + id: Compact(0), + target: MultiAddress::Address20(H160::repeat_byte(0x01).into()), + amount: 100, + }); let call = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![inner_call1, inner_call2], + calls: vec![inner_call1, inner_call2, transfer_call], }); assert!(WhitelistedCalls::contains(&call)); });