Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling proxy.proxy from smart contracts in moonbase #2148

Merged
merged 5 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions precompiles/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ where
}
}

#[derive(Debug)]
pub struct OnlyIsProxyAndProxy<Runtime>(PhantomData<Runtime>);

impl<Runtime> SelectorFilter for OnlyIsProxyAndProxy<Runtime>
where
Runtime: pallet_proxy::Config + pallet_evm::Config + frame_system::Config,
<<Runtime as pallet_proxy::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin:
From<Option<Runtime::AccountId>>,
<Runtime as pallet_proxy::Config>::ProxyType: Decode + EvmProxyCallFilter,
<Runtime as frame_system::Config>::RuntimeCall:
Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo,
<<Runtime as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin:
From<Option<Runtime::AccountId>>,
<Runtime as frame_system::Config>::RuntimeCall: From<ProxyCall<Runtime>>,
{
fn is_allowed(_caller: H160, selector: Option<u32>) -> bool {
match selector {
None => false,
Some(selector) => {
ProxyPrecompileCall::<Runtime>::is_proxy_selectors().contains(&selector)
|| ProxyPrecompileCall::<Runtime>::proxy_selectors().contains(&selector)
|| ProxyPrecompileCall::<Runtime>::proxy_force_type_selectors()
.contains(&selector)
}
}
}

fn description() -> String {
"Allowed for all callers only for selectors 'is_proxy', 'proxy', 'proxy_force_type'".into()
}
}

pub const CALL_DATA_LIMIT: u32 = 2u32.pow(16);

type GetCallDataLimit = ConstU32<CALL_DATA_LIMIT>;
Expand Down
2 changes: 1 addition & 1 deletion precompiles/proxy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub type Precompiles<R> = PrecompileSetBuilder<
ProxyPrecompile<R>,
(
SubcallWithMaxNesting<1>,
CallableByContract<crate::OnlyIsProxy<R>>,
CallableByContract<crate::OnlyIsProxyAndProxy<R>>,
),
>,
),
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbase/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use pallet_evm_precompile_democracy::DemocracyPrecompile;
use pallet_evm_precompile_modexp::Modexp;
use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile;
use pallet_evm_precompile_preimage::PreimagePrecompile;
use pallet_evm_precompile_proxy::{OnlyIsProxy, ProxyPrecompile};
use pallet_evm_precompile_proxy::{OnlyIsProxyAndProxy, ProxyPrecompile};
use pallet_evm_precompile_randomness::RandomnessPrecompile;
use pallet_evm_precompile_referenda::ReferendaPrecompile;
use pallet_evm_precompile_relay_encoder::RelayEncoderPrecompile;
Expand Down Expand Up @@ -173,7 +173,7 @@ type MoonbasePrecompilesAt<R> = (
AddressU64<2059>,
ProxyPrecompile<R>,
(
CallableByContract<OnlyIsProxy<R>>,
CallableByContract<OnlyIsProxyAndProxy<R>>,
SubcallWithMaxNesting<0>,
// Batch is the only precompile allowed to call Proxy.
CallableByPrecompile<OnlyFrom<AddressU64<2056>>>,
Copy link
Contributor

@nanocryk nanocryk Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do do we want to allow proxy calls from any kind of precompile?

No, it just conflicts with the filters declared with the PrecompileSetBuilder. No idea why this check is still done in the precompile, as it was necessary before we had opt-in checks in PrecompileSetBuilder.

Expand Down