From 453c1e346cfd1bb02332a6e7be685e277b5d35fc Mon Sep 17 00:00:00 2001 From: Daniele Rogora Date: Fri, 4 Jul 2025 14:34:48 +0200 Subject: [PATCH 1/2] Enable treasury payments and add tests --- Cargo.lock | 1 + runtime/Cargo.toml | 1 + runtime/src/configs/xcm.rs | 31 +++++++++++++++++++++++++---- runtime/src/tests/constants_test.rs | 18 +++++++++++++++++ zombienet-config/devnet.toml | 1 + 5 files changed, 48 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 366afd2..235ed69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22446,6 +22446,7 @@ dependencies = [ "frame-try-runtime", "hex", "hex-literal", + "log", "num_enum 0.5.11", "pallet-aura", "pallet-authorship", diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b084db0..2f38c53 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -20,6 +20,7 @@ scale-info = {workspace = true, features = ["derive"]} hex-literal = {workspace = true} serde_json = { workspace = true, features = ["alloc"] } num_enum = { workspace = true } +log = { workspace = true } # Substrate frame-benchmarking = {workspace = true, optional = true} diff --git a/runtime/src/configs/xcm.rs b/runtime/src/configs/xcm.rs index b5a3a54..bbcccc3 100644 --- a/runtime/src/configs/xcm.rs +++ b/runtime/src/configs/xcm.rs @@ -45,9 +45,9 @@ use sp_runtime::{ }; use xcm::latest::prelude::*; use xcm_builder::{ - AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, - AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, - DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, + AccountKey20Aliases, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, + AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, + DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, NativeAsset, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SignedAccountKey20AsNative, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, @@ -166,7 +166,10 @@ pub type Barrier = TrailingSetTopicAsId< TakeWeightCredit, AllowKnownQueryResponses, WithComputedOrigin< - (AllowTopLevelPaidExecutionFrom,), + ( + AllowTopLevelPaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, + ), UniversalLocation, ConstU32<8>, >, @@ -402,3 +405,23 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type PriceForSiblingDelivery = PriceForSiblingParachainDelivery; type WeightInfo = weights::cumulus_pallet_xcmp_queue::ZKVEvmWeight; } + +#[test] +fn xcm_executor_constants() { + use hex_literal::hex; + use xcm::latest::Junctions::X1; + + let loc = Location { + parents: 0, + interior: X1([AccountId32 { + network: None, + id: hex!("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d").into(), + }] + .into()), + }; + assert_eq!( + LocationAccountId32ToAccountId::convert_location(&loc) + .expect("Cannot convert accountid32; qed"), + hex!("04a99fd6822c8558854ccde39a5684e7a56da27d").into() + ); +} diff --git a/runtime/src/tests/constants_test.rs b/runtime/src/tests/constants_test.rs index cb76297..38f9f35 100644 --- a/runtime/src/tests/constants_test.rs +++ b/runtime/src/tests/constants_test.rs @@ -209,6 +209,10 @@ mod runtime_tests { mod xcm_tests { use super::*; use configs::xcm::*; + use hex_literal::hex; + use xcm::latest::prelude::*; + use xcm::opaque::latest::Junctions::X1; + use xcm_executor::traits::ConvertLocation; #[test] fn xcm_executor_constants() { @@ -225,4 +229,18 @@ mod xcm_tests { 100 ); } + + #[test] + fn relay_treasury_account() { + let loc = Location { + parents: 1, + interior: X1([PalletInstance(14)].into()), // TODO: replace with the value taken + // directly from zkv_runtime? + }; + assert_eq!( + LocationAccountId32ToAccountId::convert_location(&loc) + .expect("Location is not convertible; qed"), + hex!("f260e064445be1b5e12e5cef1e1c11fc4c4b4963").into(), + ); + } } diff --git a/zombienet-config/devnet.toml b/zombienet-config/devnet.toml index 4d5f94d..6f74a22 100644 --- a/zombienet-config/devnet.toml +++ b/zombienet-config/devnet.toml @@ -10,6 +10,7 @@ name = "alice" validator = true ws_port = 9955 rpc_port = 8855 +args = ["-lxcm=trace"] [[relaychain.nodes]] name = "bob" From 4fd043e5d6c8a6364534d22c8634caa04320160f Mon Sep 17 00:00:00 2001 From: Daniele Rogora Date: Mon, 7 Jul 2025 17:59:03 +0200 Subject: [PATCH 2/2] Restrict unpaid exec to relay treasury --- Cargo.lock | 1 - Cargo.toml | 18 ------------------ runtime/Cargo.toml | 1 - runtime/src/configs/xcm.rs | 14 +++++++++++--- runtime/src/tests/constants_test.rs | 4 ++-- zombienet-config/devnet.toml | 2 -- 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 235ed69..366afd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22446,7 +22446,6 @@ dependencies = [ "frame-try-runtime", "hex", "hex-literal", - "log", "num_enum 0.5.11", "pallet-aura", "pallet-authorship", diff --git a/Cargo.toml b/Cargo.toml index dd254d0..cf65c62 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -163,7 +163,6 @@ pallet-evm-precompile-blake2 = {git = "https://github.com/moonbeam-foundation/fr pallet-evm-precompile-batch = {git = "https://github.com/moonbeam-foundation/moonbeam", tag = "runtime-3701", default-features = false} pallet-evm-precompile-balances-erc20 = {git = "https://github.com/moonbeam-foundation/moonbeam", tag = "runtime-3701", default-features = false} -#ethereum = {version = "0.15.0", default-features = false, features = ["with-codec"]} ethereum = {git = "https://github.com/rust-ethereum/ethereum", rev = "3be0d8fd4c2ad1ba216b69ef65b9382612efc8ba"} # Moonbeam @@ -255,29 +254,15 @@ substrate-wasm-builder = { version = "25.0.1" } cumulus-primitives-storage-weight-reclaim = { version = "9.1.0" } substrate-prometheus-endpoint = { version = "0.17.2" } -#[patch."https://github.com/rust-ethereum/ethereum"] -#ethereum = {version = "0.15.0"} - # XCM xcm = { version = "15.1.0", package = "staging-xcm" } -#[patch."https://github.com/rust-ethereum/ethereum"] -#ethereum = { git = "https://github.com/rust-ethereum/ethereum", rev = "3be0d8f" } - -#[patch."https://github.com/moonbeam-foundation/frontier"] -#fp-ethereum = {git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-stable2412"} -#fp-evm = {git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-stable2412"} -#fp-rpc = {git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-stable2412"} -#fp-self-contained = {git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-stable2412"} -#pallet-evm = {git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-stable2412"} - [patch."https://github.com/moonbeam-foundation/polkadot-sdk"] staging-xcm-builder = { version = "18.2.1" } xcm-executor = { version = "18.0.3", package = "staging-xcm-executor" } pallet-staking = { version = "39.1.0" } cumulus-primitives-core = { version = "0.17.0" } polkadot-runtime-common = { version = "18.1.0" } -#pallet-election-provider-multi-phase = { version = "38.2.0" } sc-block-builder = { version = "0.43.0" } sc-chain-spec = { version = "41.0.0" } sc-cli = { version = "0.50.2" } @@ -351,9 +336,6 @@ substrate-wasm-builder = { version = "25.0.1" } cumulus-primitives-storage-weight-reclaim = { version = "9.1.0" } substrate-prometheus-endpoint = { version = "0.17.2" } -#[patch."https://github.com/rust-ethereum/ethereum"] -#ethereum = {version = "0.15.0"} - # XCM xcm = { version = "15.1.0", package = "staging-xcm" } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 2f38c53..b084db0 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -20,7 +20,6 @@ scale-info = {workspace = true, features = ["derive"]} hex-literal = {workspace = true} serde_json = { workspace = true, features = ["alloc"] } num_enum = { workspace = true } -log = { workspace = true } # Substrate frame-benchmarking = {workspace = true, optional = true} diff --git a/runtime/src/configs/xcm.rs b/runtime/src/configs/xcm.rs index bbcccc3..383684b 100644 --- a/runtime/src/configs/xcm.rs +++ b/runtime/src/configs/xcm.rs @@ -159,6 +159,14 @@ impl Contains for ParentRelayChain { } } +pub struct ParentsTreasury; +impl Contains for ParentsTreasury { + fn contains(location: &Location) -> bool { + // match the relay chain and any account on it + matches!(location.unpack(), (1, [PalletInstance(14)])) + } +} + pub type Barrier = TrailingSetTopicAsId< DenyThenTry< DenyReserveTransferToRelayChain, @@ -168,7 +176,7 @@ pub type Barrier = TrailingSetTopicAsId< WithComputedOrigin< ( AllowTopLevelPaidExecutionFrom, - AllowExplicitUnpaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom, ), UniversalLocation, ConstU32<8>, @@ -180,7 +188,7 @@ pub type Barrier = TrailingSetTopicAsId< pub type TrustedTeleporters = ConcreteAssetFromSystem; -pub type WaivedLocations = (Equals, Equals); +pub type WaivedLocations = (Equals, Equals, ParentsTreasury); pub struct RemoteEVMCall; impl CallDispatcher for RemoteEVMCall { @@ -407,7 +415,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { } #[test] -fn xcm_executor_constants() { +fn alice_pubkey_conversion() { use hex_literal::hex; use xcm::latest::Junctions::X1; diff --git a/runtime/src/tests/constants_test.rs b/runtime/src/tests/constants_test.rs index 38f9f35..f066511 100644 --- a/runtime/src/tests/constants_test.rs +++ b/runtime/src/tests/constants_test.rs @@ -232,10 +232,10 @@ mod xcm_tests { #[test] fn relay_treasury_account() { + // TODO: replace with zkv_runtime::TreasuryPalletIdx::get() on next zkVerify tag? let loc = Location { parents: 1, - interior: X1([PalletInstance(14)].into()), // TODO: replace with the value taken - // directly from zkv_runtime? + interior: X1([PalletInstance(14)].into()), // 14 is the index of the treasury pallet in zkv-runtime }; assert_eq!( LocationAccountId32ToAccountId::convert_location(&loc) diff --git a/zombienet-config/devnet.toml b/zombienet-config/devnet.toml index 6f74a22..e84b24f 100644 --- a/zombienet-config/devnet.toml +++ b/zombienet-config/devnet.toml @@ -10,7 +10,6 @@ name = "alice" validator = true ws_port = 9955 rpc_port = 8855 -args = ["-lxcm=trace"] [[relaychain.nodes]] name = "bob" @@ -37,7 +36,6 @@ name = "zkv-para-evm-parachain-collator01" command = "./target/release/zkv-para-evm-node" ws_port = 9933 rpc_port = 8833 -#args = ["--rpc-max-connections 10000 -ltrace"] args = ["-lxcm=trace", "--rpc-max-connections 10000"] [[parachains.collators]]