diff --git a/Cargo.lock b/Cargo.lock index cc5d54757c..1e087df004 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6461,7 +6461,7 @@ dependencies = [ [[package]] name = "pallet-crowdloan-rewards" version = "0.6.0" -source = "git+https://github.com/purestake/crowdloan-rewards?branch=moonbeam-polkadot-v0.9.10#56f4e9cdb9e27efcd3337a2dcbcde2f4fdd47c2a" +source = "git+https://github.com/purestake/crowdloan-rewards?branch=moonbeam-polkadot-v0.9.10#db39c7878fa5d9a1bd5a88eb64ebfca547d67799" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", diff --git a/precompiles/crowdloan-rewards/src/mock.rs b/precompiles/crowdloan-rewards/src/mock.rs index 7bae1a3dfd..e2f0aad7a3 100644 --- a/precompiles/crowdloan-rewards/src/mock.rs +++ b/precompiles/crowdloan-rewards/src/mock.rs @@ -29,7 +29,7 @@ use frame_support::{ parameter_types, traits::{Everything, GenesisBuild, OnFinalize, OnInitialize}, }; -use frame_system::RawOrigin; +use frame_system::{EnsureSigned, RawOrigin}; use pallet_evm::{AddressMapping, EnsureAddressNever, EnsureAddressRoot, PrecompileSet}; use serde::{Deserialize, Serialize}; use sp_core::H256; @@ -249,6 +249,7 @@ impl pallet_crowdloan_rewards::Config for Test { type RewardCurrency = Balances; type RelayChainAccountId = [u8; 32]; type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; + type RewardAddressChangeOrigin = EnsureSigned; type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber; type VestingBlockProvider = cumulus_pallet_parachain_system::RelaychainBlockNumberProvider; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index cb9c83a953..00d7def3f2 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -59,7 +59,7 @@ use xcm_builder::{ use xcm_executor::traits::JustTry; -use frame_system::{EnsureOneOf, EnsureRoot}; +use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned}; pub use moonbeam_core_primitives::{ AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header, Index, Signature, @@ -759,6 +759,7 @@ impl pallet_crowdloan_rewards::Config for Runtime { type MinimumReward = MinimumReward; type RewardCurrency = Balances; type RelayChainAccountId = AccountId32; + type RewardAddressChangeOrigin = EnsureSigned; type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber; type VestingBlockProvider = diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 95e77e3721..cbc08d23ce 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -608,8 +608,11 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() { let public2 = pair2.public(); // signature is new_account || previous_account - let mut message = AccountId::from(DAVE).encode(); + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut AccountId::from(DAVE).encode()); message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); + let signature1 = pair1.sign(&message); let signature2 = pair2.sign(&message); diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 6315042689..3a64704506 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -40,7 +40,7 @@ use frame_support::{ }, PalletId, }; -use frame_system::{EnsureOneOf, EnsureRoot}; +use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned}; pub use moonbeam_core_primitives::{ AccountId, AccountIndex, Address, Balance, BlockNumber, DigestItem, Hash, Header, Index, Signature, @@ -707,6 +707,7 @@ impl pallet_crowdloan_rewards::Config for Runtime { type MinimumReward = MinimumReward; type RewardCurrency = Balances; type RelayChainAccountId = AccountId32; + type RewardAddressChangeOrigin = EnsureSigned; type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber; type VestingBlockProvider = diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 58f41c6526..26884309a8 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -610,8 +610,10 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() { let public2 = pair2.public(); // signature is new_account || previous_account - let mut message = AccountId::from(DAVE).encode(); + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut AccountId::from(DAVE).encode()); message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); let signature1 = pair1.sign(&message); let signature2 = pair2.sign(&message); diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 559f59f6c6..4c6ddc5b57 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -40,7 +40,7 @@ use frame_support::{ }, PalletId, }; -use frame_system::{EnsureOneOf, EnsureRoot}; +use frame_system::{EnsureOneOf, EnsureRoot, EnsureSigned}; pub use moonbeam_core_primitives::{ AccountId, AccountIndex, Address, Balance, BlockNumber, DigestItem, Hash, Header, Index, Signature, @@ -698,6 +698,7 @@ impl pallet_crowdloan_rewards::Config for Runtime { type MinimumReward = MinimumReward; type RewardCurrency = Balances; type RelayChainAccountId = AccountId32; + type RewardAddressChangeOrigin = EnsureSigned; type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; type VestingBlockNumber = cumulus_primitives_core::relay_chain::BlockNumber; type VestingBlockProvider = diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index a41c6f9e60..eb3228e7b6 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -595,8 +595,10 @@ fn initialize_crowdloan_address_and_change_with_relay_key_sig() { let public2 = pair2.public(); // signature is new_account || previous_account - let mut message = AccountId::from(DAVE).encode(); + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut AccountId::from(DAVE).encode()); message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); let signature1 = pair1.sign(&message); let signature2 = pair2.sign(&message); diff --git a/tests/tests/test-crowdloan.ts b/tests/tests/test-crowdloan.ts index 88bd22d7fa..4294ff2f0d 100644 --- a/tests/tests/test-crowdloan.ts +++ b/tests/tests/test-crowdloan.ts @@ -3,7 +3,7 @@ import { KeyringPair } from "@polkadot/keyring/types"; import { expect } from "chai"; import Web3 from "web3"; import { Account } from "web3-core"; -import { formatBalance } from "@polkadot/util"; +import { formatBalance, stringToU8a } from "@polkadot/util"; import type { SubmittableExtrinsic } from "@polkadot/api/promise/types"; import { blake2AsHex, randomAsHex } from "@polkadot/util-crypto"; @@ -823,7 +823,12 @@ describeDevMoonbeam("Crowdloan", (context) => { ).toHuman() as any ).to.be.null; - let message = new Uint8Array([...toAssociateAccount.addressRaw, ...firstAccount.addressRaw]); + let message = new Uint8Array([ + ...stringToU8a(""), + ...toAssociateAccount.addressRaw, + ...firstAccount.addressRaw, + ...stringToU8a(""), + ]); // Construct the signatures let signature1 = {};