From f20f18b53913644cfebdec40eb6632b9a6d2665c Mon Sep 17 00:00:00 2001 From: Hussein Ait-Lahcen Date: Wed, 19 Jan 2022 15:14:24 +0100 Subject: [PATCH] Add tag for polkadotjs signature in crowdloan (#514) The public polkadotjs api signRaw is wrapping the message in this tag. --- frame/crowdloan-rewards/src/lib.rs | 6 +++++- frame/crowdloan-rewards/src/mocks.rs | 9 ++++----- .../tests/tx/crowdloanRewards/txCrowdloanRewardsTests.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/frame/crowdloan-rewards/src/lib.rs b/frame/crowdloan-rewards/src/lib.rs index b74c466e55d..2cb481053ce 100644 --- a/frame/crowdloan-rewards/src/lib.rs +++ b/frame/crowdloan-rewards/src/lib.rs @@ -411,8 +411,12 @@ pub mod pallet { relay_account: RelayChainAccountId, proof: &MultiSignature, ) -> bool { - let mut msg = prefix.to_vec(); + let wrapped_prefix: &[u8] = b""; + let wrapped_postfix: &[u8] = b""; + let mut msg = wrapped_prefix.to_vec(); + msg.append(&mut prefix.to_vec()); msg.append(&mut reward_account.using_encoded(|x| hex::encode(x).as_bytes().to_vec())); + msg.append(&mut wrapped_postfix.to_vec()); proof.verify(&msg[..], &relay_account.into()) } diff --git a/frame/crowdloan-rewards/src/mocks.rs b/frame/crowdloan-rewards/src/mocks.rs index 0334f9ac4d6..e57c319e0a4 100644 --- a/frame/crowdloan-rewards/src/mocks.rs +++ b/frame/crowdloan-rewards/src/mocks.rs @@ -167,12 +167,11 @@ impl ClaimKey { } } -pub fn relay_proof( - relay_account: &RelayKey, - reward_account: AccountId, -) -> Proof { - let mut msg = PROOF_PREFIX.to_vec(); +fn relay_proof(relay_account: &RelayKey, reward_account: AccountId) -> Proof { + let mut msg = b"".to_vec(); + msg.append(&mut PROOF_PREFIX.to_vec()); msg.append(&mut reward_account.using_encoded(|x| hex::encode(x).as_bytes().to_vec())); + msg.append(&mut b"".to_vec()); Proof::RelayChain(relay_account.public().into(), relay_account.sign(&msg).into()) } diff --git a/integration-tests/runtime-tests/src/tests/tx/crowdloanRewards/txCrowdloanRewardsTests.ts b/integration-tests/runtime-tests/src/tests/tx/crowdloanRewards/txCrowdloanRewardsTests.ts index 6869e26b583..750c427b68f 100644 --- a/integration-tests/runtime-tests/src/tests/tx/crowdloanRewards/txCrowdloanRewardsTests.ts +++ b/integration-tests/runtime-tests/src/tests/tx/crowdloanRewards/txCrowdloanRewardsTests.ts @@ -11,7 +11,7 @@ const toHexString = bytes => // The prefix is defined as pallet config const proofMessage = (account: IKeyringPair) => - "picasso-" + toHexString(account.publicKey); + "picasso-" + toHexString(account.publicKey) + ""; const ethAccount = (seed: number) => web3.eth.accounts.privateKeyToAccount("0x" + seed.toString(16).padStart(64, '0'))