Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Register origin #174

Closed

Conversation

yrong
Copy link

@yrong yrong commented Sep 3, 2024

No description provided.

@yrong yrong requested a review from vgeddes September 3, 2024 16:22
@alistair-singh
Copy link

Are we trying to avoid an SDK release? or a runtime release? or be fully decoupled from both?

@@ -55,6 +56,7 @@ pub type SnowbridgeExporter = EthereumBlobExporter<
// Ethereum Bridge
parameter_types! {
pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
pub storage EnableRegisterToken: bool = false;
Copy link
Author

@yrong yrong Sep 4, 2024

Choose a reason for hiding this comment

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

Set this flag to be true through System::set_storage when code has been audited.

@yrong
Copy link
Author

yrong commented Sep 4, 2024

Are we trying to avoid an SDK release? or a runtime release? or be fully decoupled from both?

Yeah, try to be fully decoupled from both. Mentioned in #174 (comment)

@acatangiu
Copy link

I'm not convinced the added complexity is worth it. Changing storage still requires root/whitelisted referenda.

It's also frowned upon in OpenGov any time we're "arbitrarily" changing storage using Root. You could create an ensure_root call to enable/disable this which would "look" better in OpenGov (not messing with storage directly).

But I would still not do it, more code to maintain for little to no added benefit. Still need root referenda. At least with runtime upgrade we could batch more things in same upgrade referenda.

@yrong
Copy link
Author

yrong commented Sep 4, 2024

I'm not convinced the added complexity is worth it. Changing storage still requires root/whitelisted referenda.

I would assume it's much easier to do a set_storage than upgrading pallet logic. If that's not the case, then yes the added complexity is not worthwhile.

@yrong
Copy link
Author

yrong commented Sep 4, 2024

But I would still not do it, more code to maintain for little to no added benefit. Still need root referenda. At least with runtime upgrade we could batch more things in same upgrade referenda.

That's a good point. @acatangiu Does that mean you're fine with the current impl the sudo call and we make a runtime upgrade to make it permissionless after audited?

@acatangiu
Copy link

But I would still not do it, more code to maintain for little to no added benefit. Still need root referenda. At least with runtime upgrade we could batch more things in same upgrade referenda.

That's a good point. @acatangiu Does that mean you're fine with the current impl the sudo call and we make a runtime upgrade to make it permissionless after audited?

yes, that will be good

@@ -134,6 +135,28 @@ where
No,
}

pub struct EnsureOriginWithControlFlag<T, F, A>(core::marker::PhantomData<(T, F, A)>);
Copy link

@acatangiu acatangiu Sep 5, 2024

Choose a reason for hiding this comment

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

not sure we need this somewhat complicated struct..

Instead of switching the boolean generic param on this struct, we can start with simple EnsureRoot struct, then after audit switch (in runtime config) to simple EnsureSigned struct.

@@ -188,6 +190,8 @@ impl snowbridge_pallet_system::Config for Runtime {
type Helper = ();
type DefaultPricingParameters = Parameters;
type InboundDeliveryCost = EthereumInboundQueue;
type RegisterTokenOrigin =
EnsureOriginWithControlFlag<Runtime, EnableRegisterToken, TreasuryAccount>;

Choose a reason for hiding this comment

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

does TreasuryAccount even have any funds on BridgeHub?

better to just make the tx free for Root rather than try to pay from Treasury account on BH

@@ -175,6 +198,8 @@ pub mod pallet {

#[cfg(feature = "runtime-benchmarks")]
type Helper: BenchmarkHelper<Self::RuntimeOrigin>;

type RegisterTokenOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = AccountIdOf<Self>>;
Copy link

@acatangiu acatangiu Sep 5, 2024

Choose a reason for hiding this comment

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

maybe

Suggested change
type RegisterTokenOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = AccountIdOf<Self>>;
type RegisterTokenOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::RuntimeOrigin>;

then you could:

let pays_fee = match origin {
	RawOrigin::Root => PaysFee::<T>::No,
	RawOrigin::Signed(who) => PaysFee::<T>::Yes(who),

and avoid having to use special account for Root case

@@ -617,12 +642,12 @@ pub mod pallet {
location: Box<VersionedLocation>,
metadata: AssetMetadata,
) -> DispatchResult {
ensure_root(origin)?;
let who = T::RegisterTokenOrigin::ensure_origin(origin)?;
Copy link

@vgeddes vgeddes Sep 6, 2024

Choose a reason for hiding this comment

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

I've realized that if we make token registration permissionless, the origin should be an XCM location (i.e Transact.OriginKind = Xcm), and we should verify that the origin location is an immediate parent of the token location.

Otherwise any random user can register a token with incorrect or misleading metadata.

For example if the token location is /Para(2048)/PalletInstance(7)/GeneralIndex(1), then the only origin location allowed to register it is /Para(2048)/PalletInstance(7).

Copy link

@alistair-singh alistair-singh Sep 6, 2024

Choose a reason for hiding this comment

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

How would you register a token like KILT?

  1. By sending an XCM directly from KILT parachain? That would require they setup an HRMP channel with bridge hub just for registration and they have an extrinsic/governance to send_xcm directly from the KILT origin.
  2. Impersonating KILT using governance from the relaychain.

I think we should just stick to root for now as all options require governance and we can change the registration model later.

Copy link

Choose a reason for hiding this comment

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

Yeah good point - another idea I had was to move the registration extrinsic to AH which of course can read the asset metadata directly from storage.

Copy link

@vgeddes vgeddes Sep 6, 2024

Choose a reason for hiding this comment

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

but for now, yes, we should stick with root

@alistair-singh alistair-singh force-pushed the polkadot-native-assets-custom-origin branch from 3f0c982 to dfa5f83 Compare September 6, 2024 12:44
@yrong yrong changed the title Custom origin with control flag Register origin Sep 6, 2024
Copy link

@vgeddes vgeddes left a comment

Choose a reason for hiding this comment

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

Needs substantial changes due to the vulnerability in #174 (comment)

@acatangiu
Copy link

Needs substantial changes due to the vulnerability in #174 (comment)

You can make it very simple for now, just have simple EnsureRoot struct that allows only root and we use that. We can defer finding the right permissionless filter for later. The important part now is to have configurable filter type in the pallet that we can change later without having to change the pallet.

@yrong yrong closed this Oct 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants