From e0043dbf232718370f0b3a4d42d2e0e97ecc9fd8 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Wed, 29 Nov 2023 13:12:56 -0500 Subject: [PATCH 01/10] Update claims mocked address type, begins support for multi-address claim --- pallets/claims/Cargo.toml | 7 +- pallets/claims/src/lib.rs | 1103 ++----------------------------------- 2 files changed, 55 insertions(+), 1055 deletions(-) diff --git a/pallets/claims/Cargo.toml b/pallets/claims/Cargo.toml index db036f0e8..59f3af5ba 100644 --- a/pallets/claims/Cargo.toml +++ b/pallets/claims/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pallet-ecdsa-claims" +name = "pallet-airdrop-claims" version = { workspace = true } authors = { workspace = true } edition = { workspace = true } @@ -12,7 +12,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] } - +pallet-evm = { workspace = true } rustc-hex = { workspace = true } scale-info = { workspace = true } serde = { workspace = true } @@ -22,6 +22,7 @@ frame-system = { workspace = true } libsecp256k1 = { workspace = true } pallet-balances = { workspace = true } pallet-vesting = { workspace = true } +sp-core = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } sp-std = { workspace = true } @@ -42,11 +43,13 @@ std = [ "scale-info/std", "frame-support/std", "frame-system/std", + "sp-core/std", "sp-runtime/std", "sp-std/std", "sp-io/std", "libsecp256k1/std", "pallet-vesting/std", "pallet-balances/std", + "pallet-evm/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 748838efe..b5e0e9233 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -18,18 +18,29 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(clippy::all)] +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + use frame_support::{ ensure, traits::{Currency, Get, IsSubType, VestingSchedule}, weights::Weight, }; pub use pallet::*; +use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; use scale_info::{ prelude::{format, string::String}, TypeInfo, }; use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; +use sp_core::H160; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; use sp_runtime::{ traits::{CheckedSub, DispatchInfoOf, SignedExtension, Zero}, @@ -91,15 +102,25 @@ impl WeightInfo for TestWeightInfo { } } +#[derive( + Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize, +)] +pub enum ClaimerType { + /// Claimer is Ethereum address + EthereumAddress, + /// Claimer is Substrate address + SubstrateAddress(A), +} + /// The kind of statement an account needs to make for a claim to be valid. #[derive( Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize, )] pub enum StatementKind { - /// Statement required to be made by non-SAFT holders. + /// Statement required to be made by non-SAFE holders. Regular, - /// Statement required to be made by SAFT holders. - Saft, + /// Statement required to be made by SAFE holders. + Safe, } impl StatementKind { @@ -110,7 +131,7 @@ impl StatementKind { &b"I hereby agree to the terms of the statement whose SHA-256 multihash is \ Qmc1XYqT6S39WNp2UeiRUrZichUWUPpGEThDE6dAb3f6Ny. (This may be found at the URL: \ https://statement.polkadot.network/regular.html)"[..], - StatementKind::Saft => + StatementKind::Safe => &b"I hereby agree to the terms of the statement whose SHA-256 multihash is \ QmXEkMahfhHJPzT3RjkXiZVFi77ZeVeuxtAjhojGRNYckz. (This may be found at the URL: \ https://statement.polkadot.network/saft.html)"[..], @@ -161,6 +182,14 @@ impl<'de> Deserialize<'de> for EthereumAddress { } } +impl From for H160 { + fn from(a: EthereumAddress) -> Self { + let mut r = Self::default(); + r.0.copy_from_slice(&a.0); + r + } +} + #[derive(Encode, Decode, Clone, TypeInfo)] pub struct EcdsaSignature(pub [u8; 65]); @@ -195,6 +224,7 @@ pub mod pallet { #[pallet::constant] type Prefix: Get<&'static [u8]>; type MoveClaimOrigin: EnsureOrigin; + type AddressMapping: AddressMapping; /// RuntimeOrigin permitted to call force_ extrinsics type ForceOrigin: EnsureOrigin; type WeightInfo: WeightInfo; @@ -276,6 +306,7 @@ pub mod pallet { .iter() .map(|(a, b, _, _)| (a.clone(), b.clone())) .for_each(|(a, b)| { + println!("a: {:?}, b: {:?}", a, b); Claims::::insert(a, b); }); // build `Total` @@ -354,7 +385,7 @@ pub mod pallet { #[pallet::call_index(0)] pub fn claim( origin: OriginFor, - dest: T::AccountId, + dest: Option, ethereum_signature: EcdsaSignature, ) -> DispatchResult { ensure_none(origin)?; @@ -395,6 +426,7 @@ pub mod pallet { ensure_root(origin)?; >::mutate(|t| *t += value); + println!("mint_claim: who: {:?}, value: {:?}", who, value); >::insert(who, value); if let Some(vs) = vesting_schedule { >::insert(who, vs); @@ -436,13 +468,14 @@ pub mod pallet { #[pallet::call_index(2)] pub fn claim_attest( origin: OriginFor, - dest: T::AccountId, + dest: Option, ethereum_signature: EcdsaSignature, statement: Vec, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); + println!("claim_attest: data: {:?}", data); let signer = Self::eth_recover(ðereum_signature, &data, &statement) .ok_or(Error::::InvalidEthereumSignature)?; if let Some(s) = Signing::::get(signer) { @@ -483,7 +516,7 @@ pub mod pallet { if let Some(s) = Signing::::get(signer) { ensure!(s.to_text() == &statement[..], Error::::InvalidStatement); } - Self::process_claim(signer, who.clone())?; + Self::process_claim(signer, Some(who.clone()))?; Preclaims::::remove(&who); Ok(()) } @@ -617,11 +650,20 @@ impl Pallet { Some(res) } - fn process_claim(signer: EthereumAddress, dest: T::AccountId) -> sp_runtime::DispatchResult { + fn process_claim( + signer: EthereumAddress, + dest: Option, + ) -> sp_runtime::DispatchResult { + println!("process_claim: signer: {:?}, dest: {:?}", signer, dest); let balance_due = >::get(&signer).ok_or(Error::::SignerHasNoClaim)?; let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::::PotUnderflow)?; + let dest = match dest { + Some(d) => d, + None => T::AddressMapping::into_account_id(H160::from(signer)), + }; + let vesting = Vesting::::get(&signer); if vesting.is_some() && T::VestingSchedule::vesting_balance(&dest).is_some() { return Err(Error::::VestedBalanceExists.into()) @@ -763,1048 +805,3 @@ mod secp_utils { EcdsaSignature(r) } } - -#[cfg(test)] -mod tests { - use super::*; - use frame_support::pallet_prelude::DispatchError; - use hex_literal::hex; - use parity_scale_codec::Encode; - use secp_utils::*; - use sp_core::H256; - use sp_runtime::TokenError::Frozen; - use sp_std::convert::TryFrom; - // The testing primitives are very useful for avoiding having to work with signatures - // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. - use crate::{pallet as pallet_ecdsa_claims, pallet::Call as ClaimsCall}; - use frame_support::{ - assert_err, assert_noop, assert_ok, - dispatch::{DispatchError::BadOrigin, GetDispatchInfo, Pays}, - ord_parameter_types, parameter_types, - traits::{ExistenceRequirement, OnFinalize, OnInitialize, WithdrawReasons}, - }; - use pallet_balances; - use sp_runtime::{ - traits::{BlakeTwo256, Identity, IdentityLookup}, - transaction_validity::TransactionLongevity, - BuildStorage, - }; - - type Block = frame_system::mocking::MockBlock; - - frame_support::construct_runtime!( - pub enum Test - { - System: frame_system, - Balances: pallet_balances, - Vesting: pallet_vesting, - Claims: pallet_ecdsa_claims, - } - ); - - parameter_types! { - pub const BlockHashCount: u32 = 250; - } - impl frame_system::Config for Test { - type BaseCallFilter = frame_support::traits::Everything; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Block = Block; - type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; - type Nonce = u64; - type Hash = H256; - type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type RuntimeEvent = RuntimeEvent; - type BlockHashCount = BlockHashCount; - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); - type MaxConsumers = frame_support::traits::ConstU32<16>; - } - - parameter_types! { - pub const ExistentialDeposit: u64 = 1; - } - - impl pallet_balances::Config for Test { - type Balance = u64; - type RuntimeEvent = RuntimeEvent; - type DustRemoval = (); - type ExistentialDeposit = ExistentialDeposit; - type AccountStore = System; - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; - type WeightInfo = (); - type RuntimeHoldReason = RuntimeHoldReason; - type MaxHolds = (); - type FreezeIdentifier = (); - type MaxFreezes = (); - } - - parameter_types! { - pub const MinVestedTransfer: u64 = 1; - pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = - WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); - } - - impl pallet_vesting::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Currency = Balances; - type BlockNumberToBalance = Identity; - type MinVestedTransfer = MinVestedTransfer; - type WeightInfo = (); - type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; - const MAX_VESTING_SCHEDULES: u32 = 28; - } - - parameter_types! { - pub Prefix: &'static [u8] = b"Pay RUSTs to the TEST account:"; - } - ord_parameter_types! { - pub const Six: u64 = 6; - } - - impl Config for Test { - type RuntimeEvent = RuntimeEvent; - type VestingSchedule = Vesting; - type ForceOrigin = frame_system::EnsureRoot; - type Prefix = Prefix; - type MoveClaimOrigin = frame_system::EnsureSignedBy; - type WeightInfo = TestWeightInfo; - } - - pub fn run_to_block(n: u64) { - while System::block_number() < n { - Claims::on_finalize(System::block_number()); - Balances::on_finalize(System::block_number()); - System::on_finalize(System::block_number()); - System::set_block_number(System::block_number() + 1); - System::on_initialize(System::block_number()); - } - } - - fn alice() -> libsecp256k1::SecretKey { - libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap() - } - fn bob() -> libsecp256k1::SecretKey { - libsecp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap() - } - fn dave() -> libsecp256k1::SecretKey { - libsecp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap() - } - fn eve() -> libsecp256k1::SecretKey { - libsecp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap() - } - fn frank() -> libsecp256k1::SecretKey { - libsecp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap() - } - - // This function basically just builds a genesis storage key/value store according to - // our desired mockup. - pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - // We use default for brevity, but you can configure as desired if needed. - pallet_balances::GenesisConfig::::default() - .assimilate_storage(&mut t) - .unwrap(); - pallet_ecdsa_claims::GenesisConfig:: { - claims: vec![ - (eth(&alice()), 100, None, None), - (eth(&dave()), 200, None, Some(StatementKind::Regular)), - (eth(&eve()), 300, Some(42), Some(StatementKind::Saft)), - (eth(&frank()), 400, Some(43), None), - ], - vesting: vec![(eth(&alice()), (50, 10, 1))], - expiry: None, - } - .assimilate_storage(&mut t) - .unwrap(); - t.into() - } - - fn total_claims() -> u64 { - 100 + 200 + 300 + 400 - } - - #[test] - fn basic_setup_works() { - new_test_ext().execute_with(|| { - assert_eq!(Claims::total(), total_claims()); - assert_eq!(Claims::claims(ð(&alice())), Some(100)); - assert_eq!(Claims::claims(ð(&dave())), Some(200)); - assert_eq!(Claims::claims(ð(&eve())), Some(300)); - assert_eq!(Claims::claims(ð(&frank())), Some(400)); - assert_eq!(Claims::claims(&EthereumAddress::default()), None); - assert_eq!(Claims::vesting(ð(&alice())), Some((50, 10, 1))); - }); - } - - #[test] - fn serde_works() { - let x = EthereumAddress(hex!["0123456789abcdef0123456789abcdef01234567"]); - let y = serde_json::to_string(&x).unwrap(); - assert_eq!(y, "\"0x0123456789abcdef0123456789abcdef01234567\""); - let z: EthereumAddress = serde_json::from_str(&y).unwrap(); - assert_eq!(x, z); - } - - #[test] - fn claiming_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&42), 100); - assert_eq!(Vesting::vesting_balance(&42), Some(50)); - assert_eq!(Claims::total(), total_claims() - 100); - }); - } - - #[test] - fn basic_claim_moving_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::move_claim(RuntimeOrigin::signed(1), eth(&alice()), eth(&bob()), None), - BadOrigin - ); - assert_ok!(Claims::move_claim( - RuntimeOrigin::signed(6), - eth(&alice()), - eth(&bob()), - None - )); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim - ); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&bob(), &42u64.encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&42), 100); - assert_eq!(Vesting::vesting_balance(&42), Some(50)); - assert_eq!(Claims::total(), total_claims() - 100); - }); - } - - #[test] - fn claim_attest_moving_works() { - new_test_ext().execute_with(|| { - assert_ok!(Claims::move_claim( - RuntimeOrigin::signed(6), - eth(&dave()), - eth(&bob()), - None - )); - let s = sig::(&bob(), &42u64.encode(), StatementKind::Regular.to_text()); - assert_ok!(Claims::claim_attest( - RuntimeOrigin::none(), - 42, - s, - StatementKind::Regular.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&42), 200); - }); - } - - #[test] - fn attest_moving_works() { - new_test_ext().execute_with(|| { - assert_ok!(Claims::move_claim( - RuntimeOrigin::signed(6), - eth(&eve()), - eth(&bob()), - Some(42) - )); - assert_ok!(Claims::attest( - RuntimeOrigin::signed(42), - StatementKind::Saft.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&42), 300); - }); - } - - #[test] - fn claiming_does_not_bypass_signing() { - new_test_ext().execute_with(|| { - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - )); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&dave(), &42u64.encode(), &[][..]) - ), - Error::::InvalidStatement, - ); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&eve(), &42u64.encode(), &[][..]) - ), - Error::::InvalidStatement, - ); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&frank(), &42u64.encode(), &[][..]) - )); - }); - } - - #[test] - fn attest_claiming_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - let s = sig::(&dave(), &42u64.encode(), StatementKind::Saft.to_text()); - let r = Claims::claim_attest( - RuntimeOrigin::none(), - 42, - s.clone(), - StatementKind::Saft.to_text().to_vec(), - ); - assert_noop!(r, Error::::InvalidStatement); - - let r = Claims::claim_attest( - RuntimeOrigin::none(), - 42, - s, - StatementKind::Regular.to_text().to_vec(), - ); - assert_noop!(r, Error::::SignerHasNoClaim); - // ^^^ we use ecdsa_recover, so an invalid signature just results in a random signer id - // being recovered, which realistically will never have a claim. - - let s = sig::(&dave(), &42u64.encode(), StatementKind::Regular.to_text()); - assert_ok!(Claims::claim_attest( - RuntimeOrigin::none(), - 42, - s, - StatementKind::Regular.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&42), 200); - assert_eq!(Claims::total(), total_claims() - 200); - - let s = sig::(&dave(), &42u64.encode(), StatementKind::Regular.to_text()); - let r = Claims::claim_attest( - RuntimeOrigin::none(), - 42, - s, - StatementKind::Regular.to_text().to_vec(), - ); - assert_noop!(r, Error::::SignerHasNoClaim); - }); - } - - #[test] - fn attesting_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::attest(RuntimeOrigin::signed(69), StatementKind::Saft.to_text().to_vec()), - Error::::SenderHasNoClaim - ); - assert_noop!( - Claims::attest( - RuntimeOrigin::signed(42), - StatementKind::Regular.to_text().to_vec() - ), - Error::::InvalidStatement - ); - assert_ok!(Claims::attest( - RuntimeOrigin::signed(42), - StatementKind::Saft.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&42), 300); - assert_eq!(Claims::total(), total_claims() - 300); - }); - } - - #[test] - fn claim_cannot_clobber_preclaim() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - // Alice's claim is 100 - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&42), 100); - // Eve's claim is 300 through Account 42 - assert_ok!(Claims::attest( - RuntimeOrigin::signed(42), - StatementKind::Saft.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&42), 100 + 300); - assert_eq!(Claims::total(), total_claims() - 400); - }); - } - - #[test] - fn valid_attest_transactions_are_free() { - new_test_ext().execute_with(|| { - let p = PrevalidateAttests::::new(); - let c = RuntimeCall::Claims(ClaimsCall::attest { - statement: StatementKind::Saft.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - assert_eq!(di.pays_fee, Pays::No); - let r = p.validate(&42, &c, &di, 20); - assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default())); - }); - } - - #[test] - fn invalid_attest_transactions_are_recognized() { - new_test_ext().execute_with(|| { - let p = PrevalidateAttests::::new(); - let c = RuntimeCall::Claims(ClaimsCall::attest { - statement: StatementKind::Regular.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - let r = p.validate(&42, &c, &di, 20); - assert!(r.is_err()); - let c = RuntimeCall::Claims(ClaimsCall::attest { - statement: StatementKind::Saft.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - let r = p.validate(&69, &c, &di, 20); - assert!(r.is_err()); - }); - } - - #[test] - fn cannot_bypass_attest_claiming() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - let s = sig::(&dave(), &42u64.encode(), &[]); - let r = Claims::claim(RuntimeOrigin::none(), 42, s.clone()); - assert_noop!(r, Error::::InvalidStatement); - }); - } - - #[test] - fn add_claim_works() { - new_test_ext().execute_with(|| { - assert_noop!( - Claims::mint_claim(RuntimeOrigin::signed(42), eth(&bob()), 200, None, None), - sp_runtime::traits::BadOrigin, - ); - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 69, - sig::(&bob(), &69u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim, - ); - assert_ok!(Claims::mint_claim(RuntimeOrigin::root(), eth(&bob()), 200, None, None)); - assert_eq!(Claims::total(), total_claims() + 200); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 69, - sig::(&bob(), &69u64.encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&69), 200); - assert_eq!(Vesting::vesting_balance(&69), None); - assert_eq!(Claims::total(), total_claims()); - }); - } - - #[test] - fn add_claim_with_vesting_works() { - new_test_ext().execute_with(|| { - assert_noop!( - Claims::mint_claim( - RuntimeOrigin::signed(42), - eth(&bob()), - 200, - Some((50, 10, 1)), - None - ), - sp_runtime::traits::BadOrigin, - ); - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 69, - sig::(&bob(), &69u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim, - ); - assert_ok!(Claims::mint_claim( - RuntimeOrigin::root(), - eth(&bob()), - 200, - Some((50, 10, 1)), - None - )); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 69, - sig::(&bob(), &69u64.encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&69), 200); - assert_eq!(Vesting::vesting_balance(&69), Some(50)); - - // Make sure we can not transfer the vested balance. - assert_err!( - >::transfer( - &69, - &80, - 180, - ExistenceRequirement::AllowDeath - ), - DispatchError::Token(Frozen), - ); - }); - } - - #[test] - fn add_claim_with_statement_works() { - new_test_ext().execute_with(|| { - assert_noop!( - Claims::mint_claim( - RuntimeOrigin::signed(42), - eth(&bob()), - 200, - None, - Some(StatementKind::Regular) - ), - sp_runtime::traits::BadOrigin, - ); - assert_eq!(Balances::free_balance(42), 0); - let signature = sig::(&bob(), &69u64.encode(), StatementKind::Regular.to_text()); - assert_noop!( - Claims::claim_attest( - RuntimeOrigin::none(), - 69, - signature.clone(), - StatementKind::Regular.to_text().to_vec() - ), - Error::::SignerHasNoClaim - ); - assert_ok!(Claims::mint_claim( - RuntimeOrigin::root(), - eth(&bob()), - 200, - None, - Some(StatementKind::Regular) - )); - assert_noop!( - Claims::claim_attest(RuntimeOrigin::none(), 69, signature.clone(), vec![],), - Error::::SignerHasNoClaim - ); - assert_ok!(Claims::claim_attest( - RuntimeOrigin::none(), - 69, - signature.clone(), - StatementKind::Regular.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&69), 200); - }); - } - - #[test] - fn origin_signed_claiming_fail() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_err!( - Claims::claim( - RuntimeOrigin::signed(42), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - ), - sp_runtime::traits::BadOrigin, - ); - }); - } - - #[test] - fn double_claiming_doesnt_work() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - )); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim - ); - }); - } - - #[test] - fn claiming_while_vested_doesnt_work() { - new_test_ext().execute_with(|| { - CurrencyOf::::make_free_balance_be(&69, total_claims()); - assert_eq!(Balances::free_balance(69), total_claims()); - // A user is already vested - assert_ok!(::VestingSchedule::add_vesting_schedule( - &69, - total_claims(), - 100, - 10 - )); - assert_ok!(Claims::mint_claim( - RuntimeOrigin::root(), - eth(&bob()), - 200, - Some((50, 10, 1)), - None - )); - // New total - assert_eq!(Claims::total(), total_claims() + 200); - - // They should not be able to claim - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 69, - sig::(&bob(), &69u64.encode(), &[][..]) - ), - Error::::VestedBalanceExists, - ); - }); - } - - #[test] - fn non_sender_sig_doesnt_work() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &69u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim - ); - }); - } - - #[test] - fn non_claimant_doesnt_work() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(42), 0); - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&bob(), &69u64.encode(), &[][..]) - ), - Error::::SignerHasNoClaim - ); - }); - } - - #[test] - fn real_eth_sig_works() { - new_test_ext().execute_with(|| { - // "Pay RUSTs to the TEST account:2a00000000000000" - let sig = hex!["444023e89b67e67c0562ed0305d252a5dd12b2af5ac51d6d3cb69a0b486bc4b3191401802dc29d26d586221f7256cd3329fe82174bdf659baea149a40e1c495d1c"]; - let sig = EcdsaSignature(sig); - let who = 42u64.using_encoded(to_ascii_hex); - let signer = Claims::eth_recover(&sig, &who, &[][..]).unwrap(); - assert_eq!(signer.0, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]); - }); - } - - #[test] - fn validate_unsigned_works() { - use sp_runtime::traits::ValidateUnsigned; - let source = sp_runtime::transaction_validity::TransactionSource::External; - - new_test_ext().execute_with(|| { - assert_eq!( - >::validate_unsigned( - source, - &ClaimsCall::claim { - dest: 1, - ethereum_signature: sig::(&alice(), &1u64.encode(), &[][..]) - } - ), - Ok(ValidTransaction { - priority: 100, - requires: vec![], - provides: vec![("claims", eth(&alice())).encode()], - longevity: TransactionLongevity::max_value(), - propagate: true, - }) - ); - assert_eq!( - >::validate_unsigned( - source, - &ClaimsCall::claim { dest: 0, ethereum_signature: EcdsaSignature([0; 65]) } - ), - InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(), - ); - assert_eq!( - >::validate_unsigned( - source, - &ClaimsCall::claim { - dest: 1, - ethereum_signature: sig::(&bob(), &1u64.encode(), &[][..]) - } - ), - InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), - ); - let s = sig::(&dave(), &1u64.encode(), StatementKind::Regular.to_text()); - let call = ClaimsCall::claim_attest { - dest: 1, - ethereum_signature: s, - statement: StatementKind::Regular.to_text().to_vec(), - }; - assert_eq!( - >::validate_unsigned(source, &call), - Ok(ValidTransaction { - priority: 100, - requires: vec![], - provides: vec![("claims", eth(&dave())).encode()], - longevity: TransactionLongevity::max_value(), - propagate: true, - }) - ); - assert_eq!( - >::validate_unsigned( - source, - &ClaimsCall::claim_attest { - dest: 1, - ethereum_signature: EcdsaSignature([0; 65]), - statement: StatementKind::Regular.to_text().to_vec() - } - ), - InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(), - ); - - let s = sig::(&bob(), &1u64.encode(), StatementKind::Regular.to_text()); - let call = ClaimsCall::claim_attest { - dest: 1, - ethereum_signature: s, - statement: StatementKind::Regular.to_text().to_vec(), - }; - assert_eq!( - >::validate_unsigned(source, &call), - InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), - ); - - let s = sig::(&dave(), &1u64.encode(), StatementKind::Saft.to_text()); - let call = ClaimsCall::claim_attest { - dest: 1, - ethereum_signature: s, - statement: StatementKind::Regular.to_text().to_vec(), - }; - assert_eq!( - >::validate_unsigned(source, &call), - InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), - ); - - let s = sig::(&dave(), &1u64.encode(), StatementKind::Saft.to_text()); - let call = ClaimsCall::claim_attest { - dest: 1, - ethereum_signature: s, - statement: StatementKind::Saft.to_text().to_vec(), - }; - assert_eq!( - >::validate_unsigned(source, &call), - InvalidTransaction::Custom(ValidityError::InvalidStatement.into()).into(), - ); - }); - } - - #[test] - fn test_unclaimed_returned_to_destination() { - new_test_ext().execute_with(|| { - let original_total_claims = Total::::get(); - let claim_of_alice = 100; - assert_ok!(Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&alice(), &42u64.encode(), &[][..]) - )); - assert_eq!(Total::::get(), original_total_claims - claim_of_alice); - - // force set the expiry config - assert_ok!(Claims::force_set_expiry_config(RuntimeOrigin::root(), 5, 100)); - - // run to after expiry block - run_to_block(7); - assert_eq!(Total::::get(), 0); - // the dest account should receive the remaining pot balance - assert_eq!(Balances::free_balance(100), original_total_claims - claim_of_alice); - - // all further claims should fail with PotUnderflow error since the funds have been - // emptied - assert_noop!( - Claims::claim( - RuntimeOrigin::none(), - 42, - sig::(&frank(), &42u64.encode(), &[][..]) - ), - Error::::PotUnderflow - ); - }); - } -} - -#[cfg(feature = "runtime-benchmarks")] -mod benchmarking { - use super::*; - use crate::claims::Call; - use frame_benchmarking::{account, benchmarks}; - use frame_support::dispatch::UnfilteredDispatchable; - use frame_system::RawOrigin; - use secp_utils::*; - use sp_runtime::{traits::ValidateUnsigned, DispatchResult}; - - const SEED: u32 = 0; - - const MAX_CLAIMS: u32 = 10_000; - const VALUE: u32 = 1_000_000; - - fn create_claim(input: u32) -> DispatchResult { - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); - let eth_address = eth(&secret_key); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - super::Pallet::::mint_claim( - RawOrigin::Root.into(), - eth_address, - VALUE.into(), - vesting, - None, - )?; - Ok(()) - } - - fn create_claim_attest(input: u32) -> DispatchResult { - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); - let eth_address = eth(&secret_key); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - super::Pallet::::mint_claim( - RawOrigin::Root.into(), - eth_address, - VALUE.into(), - vesting, - Some(Default::default()), - )?; - Ok(()) - } - - benchmarks! { - // Benchmark `claim` including `validate_unsigned` logic. - claim { - let c = MAX_CLAIMS; - - for i in 0 .. c / 2 { - create_claim::(c)?; - create_claim_attest::(u32::MAX - c)?; - } - - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap(); - let eth_address = eth(&secret_key); - let account: T::AccountId = account("user", c, SEED); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - let signature = sig::(&secret_key, &account.encode(), &[][..]); - super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?; - assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - let source = sp_runtime::transaction_validity::TransactionSource::External; - let call_enc = Call::::claim { - dest: account.clone(), - ethereum_signature: signature.clone() - }.encode(); - }: { - let call = as Decode>::decode(&mut &*call_enc) - .expect("call is encoded above, encoding must be correct"); - super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; - call.dispatch_bypass_filter(RawOrigin::None.into())?; - } - verify { - assert_eq!(Claims::::get(eth_address), None); - } - - // Benchmark `mint_claim` when there already exists `c` claims in storage. - mint_claim { - let c = MAX_CLAIMS; - - for i in 0 .. c / 2 { - create_claim::(c)?; - create_claim_attest::(u32::MAX - c)?; - } - - let eth_address = account("eth_address", 0, SEED); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - let statement = StatementKind::Regular; - }: _(RawOrigin::Root, eth_address, VALUE.into(), vesting, Some(statement)) - verify { - assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - } - - // Benchmark `claim_attest` including `validate_unsigned` logic. - claim_attest { - let c = MAX_CLAIMS; - - for i in 0 .. c / 2 { - create_claim::(c)?; - create_claim_attest::(u32::MAX - c)?; - } - - // Crate signature - let attest_c = u32::MAX - c; - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); - let eth_address = eth(&secret_key); - let account: T::AccountId = account("user", c, SEED); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - let statement = StatementKind::Regular; - let signature = sig::(&secret_key, &account.encode(), statement.to_text()); - super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?; - assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - let call_enc = Call::::claim_attest { - dest: account.clone(), - ethereum_signature: signature.clone(), - statement: StatementKind::Regular.to_text().to_vec() - }.encode(); - let source = sp_runtime::transaction_validity::TransactionSource::External; - }: { - let call = as Decode>::decode(&mut &*call_enc) - .expect("call is encoded above, encoding must be correct"); - super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; - call.dispatch_bypass_filter(RawOrigin::None.into())?; - } - verify { - assert_eq!(Claims::::get(eth_address), None); - } - - // Benchmark `attest` including prevalidate logic. - attest { - let c = MAX_CLAIMS; - - for i in 0 .. c / 2 { - create_claim::(c)?; - create_claim_attest::(u32::MAX - c)?; - } - - let attest_c = u32::MAX - c; - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); - let eth_address = eth(&secret_key); - let account: T::AccountId = account("user", c, SEED); - let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); - let statement = StatementKind::Regular; - let signature = sig::(&secret_key, &account.encode(), statement.to_text()); - super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?; - Preclaims::::insert(&account, eth_address); - assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - - let call = super::Call::::attest { statement: StatementKind::Regular.to_text().to_vec() }; - // We have to copy the validate statement here because of trait issues... :( - let validate = |who: &T::AccountId, call: &super::Call| -> DispatchResult { - if let Call::attest{ statement: attested_statement } = call { - let signer = Preclaims::::get(who).ok_or("signer has no claim")?; - if let Some(s) = Signing::::get(signer) { - ensure!(&attested_statement[..] == s.to_text(), "invalid statement"); - } - } - Ok(()) - }; - let call_enc = call.encode(); - }: { - let call = as Decode>::decode(&mut &*call_enc) - .expect("call is encoded above, encoding must be correct"); - validate(&account, &call)?; - call.dispatch_bypass_filter(RawOrigin::Signed(account).into())?; - } - verify { - assert_eq!(Claims::::get(eth_address), None); - } - - move_claim { - let c = MAX_CLAIMS; - - for i in 0 .. c / 2 { - create_claim::(c)?; - create_claim_attest::(u32::MAX - c)?; - } - - let attest_c = u32::MAX - c; - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); - let eth_address = eth(&secret_key); - - let new_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap(); - let new_eth_address = eth(&new_secret_key); - - let account: T::AccountId = account("user", c, SEED); - Preclaims::::insert(&account, eth_address); - - assert!(Claims::::contains_key(eth_address)); - assert!(!Claims::::contains_key(new_eth_address)); - }: _(RawOrigin::Root, eth_address, new_eth_address, Some(account)) - verify { - assert!(!Claims::::contains_key(eth_address)); - assert!(Claims::::contains_key(new_eth_address)); - } - - // Benchmark the time it takes to do `repeat` number of keccak256 hashes - #[extra] - keccak256 { - let i in 0 .. 10_000; - let bytes = (i).encode(); - }: { - for index in 0 .. i { - let _hash = keccak_256(&bytes); - } - } - - // Benchmark the time it takes to do `repeat` number of `eth_recover` - #[extra] - eth_recover { - let i in 0 .. 1_000; - // Crate signature - let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&i.encode())).unwrap(); - let account: T::AccountId = account("user", i, SEED); - let signature = sig::(&secret_key, &account.encode(), &[][..]); - let data = account.using_encoded(to_ascii_hex); - let extra = StatementKind::default().to_text(); - }: { - for _ in 0 .. i { - assert!(super::Pallet::::eth_recover(&signature, &data, extra).is_some()); - } - } - - impl_benchmark_test_suite!( - Pallet, - crate::claims::tests::new_test_ext(), - crate::claims::tests::Test, - ); - } -} From c720da162081cc3e88dbfb42d4e4c669234628ac Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Wed, 29 Nov 2023 13:15:11 -0500 Subject: [PATCH 02/10] Update codeowners other missed file additions --- .github/CODEOWNERS | 2 +- Cargo.lock | 45 +- Cargo.toml | 2 +- pallets/claims/src/benchmarking.rs | 226 +++++++++ pallets/claims/src/mock.rs | 164 +++++++ pallets/claims/src/tests.rs | 729 +++++++++++++++++++++++++++++ standalone/runtime/Cargo.toml | 4 +- 7 files changed, 1146 insertions(+), 26 deletions(-) create mode 100644 pallets/claims/src/benchmarking.rs create mode 100644 pallets/claims/src/mock.rs create mode 100644 pallets/claims/src/tests.rs diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 62a755648..95cb4adf1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @drewstone @1xstj @tbraun96 +* @drewstone @1xstj @tbraun96 @salman01zp diff --git a/Cargo.lock b/Cargo.lock index f2e4ad561..bf3bb9620 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8108,6 +8108,28 @@ dependencies = [ "zeroize", ] +[[package]] +name = "pallet-airdrop-claims" +version = "0.5.0" +dependencies = [ + "frame-support", + "frame-system", + "hex-literal 0.3.4", + "libsecp256k1", + "pallet-balances", + "pallet-evm", + "pallet-vesting", + "parity-scale-codec", + "rustc-hex", + "scale-info", + "serde", + "serde_json", + "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", + "sp-io 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", + "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", + "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", +] + [[package]] name = "pallet-aura" version = "4.0.0-dev" @@ -8382,27 +8404,6 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", ] -[[package]] -name = "pallet-ecdsa-claims" -version = "0.5.0" -dependencies = [ - "frame-support", - "frame-system", - "hex-literal 0.3.4", - "libsecp256k1", - "pallet-balances", - "pallet-vesting", - "parity-scale-codec", - "rustc-hex", - "scale-info", - "serde", - "serde_json", - "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-io 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", -] - [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" @@ -15553,6 +15554,7 @@ dependencies = [ "hex-literal 0.3.4", "log", "num_enum 0.5.11", + "pallet-airdrop-claims", "pallet-aura", "pallet-authorship", "pallet-bags-list", @@ -15567,7 +15569,6 @@ dependencies = [ "pallet-dkg-proposal-handler", "pallet-dkg-proposals", "pallet-dynamic-fee", - "pallet-ecdsa-claims", "pallet-election-provider-multi-phase", "pallet-elections-phragmen", "pallet-eth2-light-client", diff --git a/Cargo.toml b/Cargo.toml index 0b511507d..e4248d0a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ webb-relayer-gadget-cli = { git = "https://github.com/webb-tools/dkg-substrate.g tangle-runtime = { package = "tangle-standalone-runtime", path = "standalone/runtime" } # Tangle Dependencies -pallet-ecdsa-claims = { path = "pallets/claims", default-features = false } +pallet-airdrop-claims = { path = "pallets/claims", default-features = false } pallet-jobs = { path = "pallets/jobs", default-features = false } pallet-roles = { path = "pallets/roles", default-features = false } diff --git a/pallets/claims/src/benchmarking.rs b/pallets/claims/src/benchmarking.rs new file mode 100644 index 000000000..7529bc794 --- /dev/null +++ b/pallets/claims/src/benchmarking.rs @@ -0,0 +1,226 @@ +use super::*; +use crate::claimsPalletClaimsPallet::Call; +use frame_benchmarking::{account, benchmarks}; +use frame_support::dispatch::UnfilteredDispatchable; +use frame_system::RawOrigin; +use secp_utils::*; +use sp_runtime::{traits::ValidateUnsigned, DispatchResult}; + +const SEED: u32 = 0; + +const MAX_CLAIMS: u32 = 10_000; +const VALUE: u32 = 1_000_000; + +fn create_claim(input: u32) -> DispatchResult { + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); + let eth_address = eth(&secret_key); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + super::Pallet::::mint_claim( + RawOrigin::Root.into(), + eth_address, + VALUE.into(), + vesting, + None, + )?; + Ok(()) +} + +fn create_claim_attest(input: u32) -> DispatchResult { + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); + let eth_address = eth(&secret_key); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + super::Pallet::::mint_claim( + RawOrigin::Root.into(), + eth_address, + VALUE.into(), + vesting, + Some(Default::default()), + )?; + Ok(()) +} + +benchmarks! { + // Benchmark `claim` including `validate_unsigned` logic. + claim { + let c = MAX_CLAIMS; + + for i in 0 .. c / 2 { + create_claim::(c)?; + create_claim_attest::(u32::MAX - c)?; + } + + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap(); + let eth_address = eth(&secret_key); + let account: T::AccountId = account("user", c, SEED); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + let signature = sig::(&secret_key, &account.encode(), &[][..]); + super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?; + assert_eq!(ClaimsPallet::::get(eth_address), Some(VALUE.into())); + let source = sp_runtime::transaction_validity::TransactionSource::External; + let call_enc = Call::::claim { + dest: account.clone(), + ethereum_signature: signature.clone() + }.encode(); + }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); + super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; + call.dispatch_bypass_filter(RawOrigin::None.into())?; + } + verify { + assert_eq!(ClaimsPallet::::get(eth_address), None); + } + + // Benchmark `mint_claim` when there already exists `c` claims in storage. + mint_claim { + let c = MAX_CLAIMS; + + for i in 0 .. c / 2 { + create_claim::(c)?; + create_claim_attest::(u32::MAX - c)?; + } + + let eth_address = account("eth_address", 0, SEED); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + let statement = StatementKind::Regular; + }: _(RawOrigin::Root, eth_address, VALUE.into(), vesting, Some(statement)) + verify { + assert_eq!(ClaimsPallet::::get(eth_address), Some(VALUE.into())); + } + + // Benchmark `claim_attest` including `validate_unsigned` logic. + claim_attest { + let c = MAX_CLAIMS; + + for i in 0 .. c / 2 { + create_claim::(c)?; + create_claim_attest::(u32::MAX - c)?; + } + + // Crate signature + let attest_c = u32::MAX - c; + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let eth_address = eth(&secret_key); + let account: T::AccountId = account("user", c, SEED); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + let statement = StatementKind::Regular; + let signature = sig::(&secret_key, &account.encode(), statement.to_text()); + super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?; + assert_eq!(ClaimsPallet::::get(eth_address), Some(VALUE.into())); + let call_enc = Call::::claim_attest { + dest: account.clone(), + ethereum_signature: signature.clone(), + statement: StatementKind::Regular.to_text().to_vec() + }.encode(); + let source = sp_runtime::transaction_validity::TransactionSource::External; + }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); + super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; + call.dispatch_bypass_filter(RawOrigin::None.into())?; + } + verify { + assert_eq!(ClaimsPallet::::get(eth_address), None); + } + + // Benchmark `attest` including prevalidate logic. + attest { + let c = MAX_CLAIMS; + + for i in 0 .. c / 2 { + create_claim::(c)?; + create_claim_attest::(u32::MAX - c)?; + } + + let attest_c = u32::MAX - c; + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let eth_address = eth(&secret_key); + let account: T::AccountId = account("user", c, SEED); + let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); + let statement = StatementKind::Regular; + let signature = sig::(&secret_key, &account.encode(), statement.to_text()); + super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?; + PreclaimsPalletClaimsPallet::::insert(&account, eth_address); + assert_eq!(ClaimsPallet::::get(eth_address), Some(VALUE.into())); + + let call = super::Call::::attest { statement: StatementKind::Regular.to_text().to_vec() }; + // We have to copy the validate statement here because of trait issues... :( + let validate = |who: &T::AccountId, call: &super::Call| -> DispatchResult { + if let Call::attest{ statement: attested_statement } = call { + let signer = PreclaimsPalletClaimsPallet::::get(who).ok_or("signer has no claim")?; + if let Some(s) = Signing::::get(signer) { + ensure!(&attested_statement[..] == s.to_text(), "invalid statement"); + } + } + Ok(()) + }; + let call_enc = call.encode(); + }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); + validate(&account, &call)?; + call.dispatch_bypass_filter(RawOrigin::Signed(account).into())?; + } + verify { + assert_eq!(ClaimsPallet::::get(eth_address), None); + } + + move_claim { + let c = MAX_CLAIMS; + + for i in 0 .. c / 2 { + create_claim::(c)?; + create_claim_attest::(u32::MAX - c)?; + } + + let attest_c = u32::MAX - c; + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let eth_address = eth(&secret_key); + + let new_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap(); + let new_eth_address = eth(&new_secret_key); + + let account: T::AccountId = account("user", c, SEED); + PreclaimsPalletClaimsPallet::::insert(&account, eth_address); + + assert!(ClaimsPallet::::contains_key(eth_address)); + assert!(!ClaimsPallet::::contains_key(new_eth_address)); + }: _(RawOrigin::Root, eth_address, new_eth_address, Some(account)) + verify { + assert!(!ClaimsPallet::::contains_key(eth_address)); + assert!(ClaimsPallet::::contains_key(new_eth_address)); + } + + // Benchmark the time it takes to do `repeat` number of keccak256 hashes + #[extra] + keccak256 { + let i in 0 .. 10_000; + let bytes = (i).encode(); + }: { + for index in 0 .. i { + let _hash = keccak_256(&bytes); + } + } + + // Benchmark the time it takes to do `repeat` number of `eth_recover` + #[extra] + eth_recover { + let i in 0 .. 1_000; + // Crate signature + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&i.encode())).unwrap(); + let account: T::AccountId = account("user", i, SEED); + let signature = sig::(&secret_key, &account.encode(), &[][..]); + let data = account.using_encoded(to_ascii_hex); + let extra = StatementKind::default().to_text(); + }: { + for _ in 0 .. i { + assert!(super::Pallet::::eth_recover(&signature, &data, extra).is_some()); + } + } + + impl_benchmark_test_suite!( + Pallet, + crate::claimsPalletClaimsPallet::tests::new_test_ext(), + crate::claimsPalletClaimsPallet::tests::Test, + ); +} diff --git a/pallets/claims/src/mock.rs b/pallets/claims/src/mock.rs new file mode 100644 index 000000000..733cd049b --- /dev/null +++ b/pallets/claims/src/mock.rs @@ -0,0 +1,164 @@ +use super::*; +use pallet_evm::HashedAddressMapping; +use secp_utils::*; +use sp_core::H256; +use sp_std::convert::TryFrom; +// The testing primitives are very useful for avoiding having to work with signatures +// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. +use crate::pallet as pallet_airdrop_claims; +use frame_support::{ + ord_parameter_types, parameter_types, + traits::{OnFinalize, OnInitialize, WithdrawReasons}, +}; +use pallet_balances; +use sp_runtime::{ + traits::{BlakeTwo256, Identity, IdentityLookup}, + AccountId32, BuildStorage, +}; + +type Block = frame_system::mocking::MockBlock; + +frame_support::construct_runtime!( + pub enum Test + { + System: frame_system, + Balances: pallet_balances, + VestingPallet: pallet_vesting, + ClaimsPallet: pallet_airdrop_claims, + } +); + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} +impl frame_system::Config for Test { + type BaseCallFilter = frame_support::traits::Everything; + type BlockWeights = (); + type BlockLength = (); + type DbWeight = (); + type Block = Block; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId32; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub const ExistentialDeposit: u64 = 1; +} + +impl pallet_balances::Config for Test { + type Balance = u64; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type WeightInfo = (); + type RuntimeHoldReason = RuntimeHoldReason; + type MaxHolds = (); + type FreezeIdentifier = (); + type MaxFreezes = (); +} + +parameter_types! { + pub const MinVestedTransfer: u64 = 1; + pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons = + WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE); +} + +impl pallet_vesting::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type BlockNumberToBalance = Identity; + type MinVestedTransfer = MinVestedTransfer; + type WeightInfo = (); + type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons; + const MAX_VESTING_SCHEDULES: u32 = 28; +} + +parameter_types! { + pub Prefix: &'static [u8] = b"Pay RUSTs to the TEST account:"; +} +ord_parameter_types! { + pub const Six: AccountId32 = get_account_id(6); +} + +impl Config for Test { + type RuntimeEvent = RuntimeEvent; + type VestingSchedule = VestingPallet; + type ForceOrigin = frame_system::EnsureRoot; + type AddressMapping = HashedAddressMapping; + type Prefix = Prefix; + type MoveClaimOrigin = frame_system::EnsureSignedBy; + type WeightInfo = TestWeightInfo; +} + +pub fn run_to_block(n: u64) { + while System::block_number() < n { + ClaimsPallet::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + } +} + +pub fn alice() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap() +} +pub fn bob() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap() +} +pub fn dave() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap() +} +pub fn eve() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap() +} +pub fn frank() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap() +} + +pub fn get_account_id(id: u8) -> AccountId32 { + AccountId32::new([id; 32]) +} + +// This function basically just builds a genesis storage key/value store according to +// our desired mockup. +pub fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + // We use default for brevity, but you can configure as desired if needed. + pallet_balances::GenesisConfig::::default() + .assimilate_storage(&mut t) + .unwrap(); + pallet_airdrop_claims::GenesisConfig:: { + claims: vec![ + (eth(&alice()), 100, None, None), + (eth(&dave()), 200, None, Some(StatementKind::Regular)), + (eth(&eve()), 300, Some(get_account_id(42)), Some(StatementKind::Safe)), + (eth(&frank()), 400, Some(get_account_id(43)), None), + ], + vesting: vec![(eth(&alice()), (50, 10, 1))], + expiry: None, + } + .assimilate_storage(&mut t) + .unwrap(); + t.into() +} diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs new file mode 100644 index 000000000..095ee6d96 --- /dev/null +++ b/pallets/claims/src/tests.rs @@ -0,0 +1,729 @@ +use super::*; +use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::DispatchError}; +use hex_literal::hex; +use parity_scale_codec::Encode; +use secp_utils::*; +use sp_runtime::TokenError::Frozen; + +// The testing primitives are very useful for avoiding having to work with signatures +// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. +use crate::{mock::new_test_ext, pallet::Call as ClaimsCall}; +use frame_support::{ + assert_err, assert_noop, assert_ok, + dispatch::{DispatchError::BadOrigin, Pays}, + traits::ExistenceRequirement, +}; +use sp_runtime::transaction_validity::TransactionLongevity; + +use crate::mock::*; + +fn total_claims() -> u64 { + 100 + 200 + 300 + 400 +} + +#[test] +fn basic_setup_works() { + new_test_ext().execute_with(|| { + assert_eq!(ClaimsPallet::total(), total_claims()); + assert_eq!(ClaimsPallet::claims(ð(&alice())), Some(100)); + assert_eq!(ClaimsPallet::claims(ð(&dave())), Some(200)); + assert_eq!(ClaimsPallet::claims(ð(&eve())), Some(300)); + assert_eq!(ClaimsPallet::claims(ð(&frank())), Some(400)); + assert_eq!(ClaimsPallet::claims(&EthereumAddress::default()), None); + assert_eq!(ClaimsPallet::vesting(ð(&alice())), Some((50, 10, 1))); + }); +} + +#[test] +fn serde_works() { + let x = EthereumAddress(hex!["0123456789abcdef0123456789abcdef01234567"]); + let y = serde_json::to_string(&x).unwrap(); + assert_eq!(y, "\"0x0123456789abcdef0123456789abcdef01234567\""); + let z: EthereumAddress = serde_json::from_str(&y).unwrap(); + assert_eq!(x, z); +} + +#[test] +fn claiming_works() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 100); + assert_eq!(VestingPallet::vesting_balance(&get_account_id(42)), Some(50)); + assert_eq!(ClaimsPallet::total(), total_claims() - 100); + }); +} + +#[test] +fn basic_claim_moving_works() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::move_claim( + RuntimeOrigin::signed(get_account_id(1)), + eth(&alice()), + eth(&bob()), + None + ), + BadOrigin + ); + assert_ok!(ClaimsPallet::move_claim( + RuntimeOrigin::signed(get_account_id(6)), + eth(&alice()), + eth(&bob()), + None + )); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim + ); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&bob(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 100); + assert_eq!(VestingPallet::vesting_balance(&get_account_id(42)), Some(50)); + assert_eq!(ClaimsPallet::total(), total_claims() - 100); + }); +} + +#[test] +fn claim_attest_moving_works() { + new_test_ext().execute_with(|| { + assert_ok!(ClaimsPallet::move_claim( + RuntimeOrigin::signed(get_account_id(6)), + eth(&dave()), + eth(&bob()), + None + )); + let s = sig::( + &bob(), + &Some(get_account_id(42)).encode(), + StatementKind::Regular.to_text(), + ); + assert_ok!(ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(42)), + s, + StatementKind::Regular.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 200); + }); +} + +#[test] +fn attest_moving_works() { + new_test_ext().execute_with(|| { + assert_ok!(ClaimsPallet::move_claim( + RuntimeOrigin::signed(get_account_id(6)), + eth(&eve()), + eth(&bob()), + Some(get_account_id(42)) + )); + assert_ok!(ClaimsPallet::attest( + RuntimeOrigin::signed(get_account_id(42)), + StatementKind::Safe.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 300); + }); +} + +#[test] +fn claiming_does_not_bypass_signing() { + new_test_ext().execute_with(|| { + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&dave(), &Some(get_account_id(42)).encode(), &[][..]) + ), + Error::::InvalidStatement, + ); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&eve(), &Some(get_account_id(42)).encode(), &[][..]) + ), + Error::::InvalidStatement, + ); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&frank(), &Some(get_account_id(42)).encode(), &[][..]) + )); + }); +} + +#[test] +fn attest_claiming_works() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + let s = + sig::(&dave(), &Some(get_account_id(42)).encode(), StatementKind::Safe.to_text()); + let r = ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(42)), + s.clone(), + StatementKind::Safe.to_text().to_vec(), + ); + assert_noop!(r, Error::::InvalidStatement); + + let r = ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(42)), + s, + StatementKind::Regular.to_text().to_vec(), + ); + assert_noop!(r, Error::::SignerHasNoClaim); + // ^^^ we use ecdsa_recover, so an invalid signature just results in a random signer id + // being recovered, which realistically will never have a claim. + + let s = sig::( + &dave(), + &Some(get_account_id(42)).encode(), + StatementKind::Regular.to_text(), + ); + assert_ok!(ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(42)), + s, + StatementKind::Regular.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 200); + assert_eq!(ClaimsPallet::total(), total_claims() - 200); + + let s = sig::( + &dave(), + &Some(get_account_id(42)).encode(), + StatementKind::Regular.to_text(), + ); + let r = ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(42)), + s, + StatementKind::Regular.to_text().to_vec(), + ); + assert_noop!(r, Error::::SignerHasNoClaim); + }); +} + +#[test] +fn attesting_works() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::attest( + RuntimeOrigin::signed(get_account_id(69)), + StatementKind::Safe.to_text().to_vec() + ), + Error::::SenderHasNoClaim + ); + assert_noop!( + ClaimsPallet::attest( + RuntimeOrigin::signed(get_account_id(42)), + StatementKind::Regular.to_text().to_vec() + ), + Error::::InvalidStatement + ); + assert_ok!(ClaimsPallet::attest( + RuntimeOrigin::signed(get_account_id(42)), + StatementKind::Safe.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 300); + assert_eq!(ClaimsPallet::total(), total_claims() - 300); + }); +} + +#[test] +fn claim_cannot_clobber_preclaim() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + // Alice's claim is 100 + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 100); + // Eve's claim is 300 through Account 42 + assert_ok!(ClaimsPallet::attest( + RuntimeOrigin::signed(get_account_id(42)), + StatementKind::Safe.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(&get_account_id(42)), 100 + 300); + assert_eq!(ClaimsPallet::total(), total_claims() - 400); + }); +} + +#[test] +fn valid_attest_transactions_are_free() { + new_test_ext().execute_with(|| { + let p = PrevalidateAttests::::new(); + let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { + statement: StatementKind::Safe.to_text().to_vec(), + }); + let di = c.get_dispatch_info(); + assert_eq!(di.pays_fee, Pays::No); + let r = p.validate(&get_account_id(42), &c, &di, 20); + assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default())); + }); +} + +#[test] +fn invalid_attest_transactions_are_recognized() { + new_test_ext().execute_with(|| { + let p = PrevalidateAttests::::new(); + let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { + statement: StatementKind::Regular.to_text().to_vec(), + }); + let di = c.get_dispatch_info(); + let r = p.validate(&get_account_id(42), &c, &di, 20); + assert!(r.is_err()); + let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { + statement: StatementKind::Safe.to_text().to_vec(), + }); + let di = c.get_dispatch_info(); + let r = p.validate(&get_account_id(69), &c, &di, 20); + assert!(r.is_err()); + }); +} + +#[test] +fn cannot_bypass_attest_claiming() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + let s = sig::(&dave(), &Some(get_account_id(42)).encode(), &[]); + let r = ClaimsPallet::claim(RuntimeOrigin::none(), Some(get_account_id(42)), s.clone()); + assert_noop!(r, Error::::InvalidStatement); + }); +} + +#[test] +fn add_claim_works() { + new_test_ext().execute_with(|| { + assert_noop!( + ClaimsPallet::mint_claim( + RuntimeOrigin::signed(get_account_id(42)), + eth(&bob()), + 200, + None, + None + ), + sp_runtime::traits::BadOrigin, + ); + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(69)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim, + ); + assert_ok!(ClaimsPallet::mint_claim(RuntimeOrigin::root(), eth(&bob()), 200, None, None)); + assert_eq!(ClaimsPallet::total(), total_claims() + 200); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(69)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + )); + assert_eq!(Balances::free_balance(get_account_id(69)), 200); + assert_eq!(VestingPallet::vesting_balance(&get_account_id(69)), None); + assert_eq!(ClaimsPallet::total(), total_claims()); + }); +} + +#[test] +fn add_claim_with_vesting_works() { + new_test_ext().execute_with(|| { + assert_noop!( + ClaimsPallet::mint_claim( + RuntimeOrigin::signed(get_account_id(42)), + eth(&bob()), + 200, + Some((50, 10, 1)), + None + ), + sp_runtime::traits::BadOrigin, + ); + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(69)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim, + ); + assert_ok!(ClaimsPallet::mint_claim( + RuntimeOrigin::root(), + eth(&bob()), + 200, + Some((50, 10, 1)), + None + )); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(69)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + )); + assert_eq!(Balances::free_balance(get_account_id(69)), 200); + assert_eq!(VestingPallet::vesting_balance(&get_account_id(69)), Some(50)); + + // Make sure we can not transfer the vested balance. + assert_err!( + >::transfer( + &get_account_id(69), + &get_account_id(80), + 180, + ExistenceRequirement::AllowDeath + ), + DispatchError::Token(Frozen), + ); + }); +} + +#[test] +fn add_claim_with_statement_works() { + new_test_ext().execute_with(|| { + assert_noop!( + ClaimsPallet::mint_claim( + RuntimeOrigin::signed(get_account_id(42)), + eth(&bob()), + 200, + None, + Some(StatementKind::Regular) + ), + sp_runtime::traits::BadOrigin, + ); + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + let signature = sig::( + &bob(), + &Some(get_account_id(69)).encode(), + StatementKind::Regular.to_text(), + ); + + assert_noop!( + ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(69)), + signature.clone(), + StatementKind::Regular.to_text().to_vec() + ), + Error::::SignerHasNoClaim + ); + assert_ok!(ClaimsPallet::mint_claim( + RuntimeOrigin::root(), + eth(&bob()), + 200, + None, + Some(StatementKind::Regular) + )); + assert_noop!( + ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(69)), + signature.clone(), + vec![], + ), + Error::::SignerHasNoClaim + ); + assert_ok!(ClaimsPallet::claim_attest( + RuntimeOrigin::none(), + Some(get_account_id(69)), + signature.clone(), + StatementKind::Regular.to_text().to_vec() + )); + assert_eq!(Balances::free_balance(get_account_id(69)), 200); + }); +} + +#[test] +fn origin_signed_claiming_fail() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_err!( + ClaimsPallet::claim( + RuntimeOrigin::signed(get_account_id(42)), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + ), + sp_runtime::traits::BadOrigin, + ); + }); +} + +#[test] +fn double_claiming_doesnt_work() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim + ); + }); +} + +#[test] +fn claiming_while_vested_doesnt_work() { + new_test_ext().execute_with(|| { + CurrencyOf::::make_free_balance_be(&get_account_id(69), total_claims()); + assert_eq!(Balances::free_balance(get_account_id(69)), total_claims()); + // A user is already vested + assert_ok!(::VestingSchedule::add_vesting_schedule( + &get_account_id(69), + total_claims(), + 100, + 10 + )); + assert_ok!(ClaimsPallet::mint_claim( + RuntimeOrigin::root(), + eth(&bob()), + 200, + Some((50, 10, 1)), + None + )); + // New total + assert_eq!(ClaimsPallet::total(), total_claims() + 200); + + // They should not be able to claim + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(69)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + ), + Error::::VestedBalanceExists, + ); + }); +} + +#[test] +fn non_sender_sig_doesnt_work() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(69)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim + ); + }); +} + +#[test] +fn non_claimant_doesnt_work() { + new_test_ext().execute_with(|| { + assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + ), + Error::::SignerHasNoClaim + ); + }); +} + +#[test] +fn real_eth_sig_works() { + new_test_ext().execute_with(|| { + // "Pay RUSTs to the TEST account:2a00000000000000" + let sig = hex!["444023e89b67e67c0562ed0305d252a5dd12b2af5ac51d6d3cb69a0b486bc4b3191401802dc29d26d586221f7256cd3329fe82174bdf659baea149a40e1c495d1c"]; + let sig = EcdsaSignature(sig); + let who = 42u64.using_encoded(to_ascii_hex); + let signer = ClaimsPallet::eth_recover(&sig, &who, &[][..]).unwrap(); + assert_eq!(signer.0, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]); + }); +} + +#[test] +fn validate_unsigned_works() { + use sp_runtime::traits::ValidateUnsigned; + let source = sp_runtime::transaction_validity::TransactionSource::External; + + new_test_ext().execute_with(|| { + assert_eq!( + >::validate_unsigned( + source, + &ClaimsCall::claim { + dest: Some(get_account_id(1)), + ethereum_signature: sig::( + &alice(), + &Some(get_account_id(1)).encode(), + &[][..] + ) + } + ), + Ok(ValidTransaction { + priority: 100, + requires: vec![], + provides: vec![("claims", eth(&alice())).encode()], + longevity: TransactionLongevity::max_value(), + propagate: true, + }) + ); + assert_eq!( + >::validate_unsigned( + source, + &ClaimsCall::claim { + dest: Some(get_account_id(0)), + ethereum_signature: EcdsaSignature([0; 65]) + } + ), + InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(), + ); + assert_eq!( + >::validate_unsigned( + source, + &ClaimsCall::claim { + dest: Some(get_account_id(1)), + ethereum_signature: sig::( + &bob(), + &Some(get_account_id(1)).encode(), + &[][..] + ) + } + ), + InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), + ); + let s = sig::( + &dave(), + &Some(get_account_id(1)).encode(), + StatementKind::Regular.to_text(), + ); + let call = ClaimsCall::claim_attest { + dest: Some(get_account_id(1)), + ethereum_signature: s, + statement: StatementKind::Regular.to_text().to_vec(), + }; + assert_eq!( + >::validate_unsigned(source, &call), + Ok(ValidTransaction { + priority: 100, + requires: vec![], + provides: vec![("claims", eth(&dave())).encode()], + longevity: TransactionLongevity::max_value(), + propagate: true, + }) + ); + assert_eq!( + >::validate_unsigned( + source, + &ClaimsCall::claim_attest { + dest: Some(get_account_id(1)), + ethereum_signature: EcdsaSignature([0; 65]), + statement: StatementKind::Regular.to_text().to_vec() + } + ), + InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(), + ); + + let s = sig::( + &bob(), + &Some(get_account_id(1)).encode(), + StatementKind::Regular.to_text(), + ); + let call = ClaimsCall::claim_attest { + dest: Some(get_account_id(1)), + ethereum_signature: s, + statement: StatementKind::Regular.to_text().to_vec(), + }; + assert_eq!( + >::validate_unsigned(source, &call), + InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), + ); + + let s = + sig::(&dave(), &Some(get_account_id(1)).encode(), StatementKind::Safe.to_text()); + let call = ClaimsCall::claim_attest { + dest: Some(get_account_id(1)), + ethereum_signature: s, + statement: StatementKind::Regular.to_text().to_vec(), + }; + assert_eq!( + >::validate_unsigned(source, &call), + InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), + ); + + let s = + sig::(&dave(), &Some(get_account_id(1)).encode(), StatementKind::Safe.to_text()); + let call = ClaimsCall::claim_attest { + dest: Some(get_account_id(1)), + ethereum_signature: s, + statement: StatementKind::Safe.to_text().to_vec(), + }; + assert_eq!( + >::validate_unsigned(source, &call), + InvalidTransaction::Custom(ValidityError::InvalidStatement.into()).into(), + ); + }); +} + +#[test] +fn test_unclaimed_returned_to_destination() { + new_test_ext().execute_with(|| { + let original_total_claims = Total::::get(); + let claim_of_alice = 100; + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + )); + assert_eq!(Total::::get(), original_total_claims - claim_of_alice); + + // force set the expiry config + assert_ok!(ClaimsPallet::force_set_expiry_config( + RuntimeOrigin::root(), + 5, + get_account_id(100) + )); + + // run to after expiry block + run_to_block(7); + assert_eq!(Total::::get(), 0); + // the dest account should receive the remaining pot balance + assert_eq!( + Balances::free_balance(get_account_id(100)), + original_total_claims - claim_of_alice + ); + + // all further claims should fail with PotUnderflow error since the funds have been + // emptied + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_account_id(42)), + sig::(&frank(), &Some(get_account_id(42)).encode(), &[][..]) + ), + Error::::PotUnderflow + ); + }); +} diff --git a/standalone/runtime/Cargo.toml b/standalone/runtime/Cargo.toml index 781bce0dc..3a9516ac5 100644 --- a/standalone/runtime/Cargo.toml +++ b/standalone/runtime/Cargo.toml @@ -30,7 +30,7 @@ pallet-dkg-proposal-handler = { workspace = true } pallet-dkg-proposals = { workspace = true } # Webb Substrate Dependencies -pallet-ecdsa-claims = { workspace = true } +pallet-airdrop-claims = { workspace = true } # Substrate dependencies sp-api = { workspace = true } @@ -208,7 +208,7 @@ std = [ "pallet-preimage/std", "pallet-nomination-pools/std", "pallet-treasury/std", - "pallet-ecdsa-claims/std", + "pallet-airdrop-claims/std", "pallet-identity/std", "pallet-bridge-registry/std", From 3cb39502a23d5385c561789e7a00310121696975 Mon Sep 17 00:00:00 2001 From: drewstone Date: Thu, 30 Nov 2023 16:40:34 -0500 Subject: [PATCH 03/10] Begin adding multiaddress types (#328) --- Cargo.lock | 1 + Cargo.toml | 2 + pallets/claims/Cargo.toml | 2 + pallets/claims/src/lib.rs | 387 ++++++------------- pallets/claims/src/mock.rs | 14 +- pallets/claims/src/tests.rs | 362 +++++++---------- pallets/claims/src/utils/ethereum_address.rs | 61 +++ pallets/claims/src/utils/mod.rs | 61 +++ 8 files changed, 396 insertions(+), 494 deletions(-) create mode 100644 pallets/claims/src/utils/ethereum_address.rs create mode 100644 pallets/claims/src/utils/mod.rs diff --git a/Cargo.lock b/Cargo.lock index bf3bb9620..401393d9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8122,6 +8122,7 @@ dependencies = [ "parity-scale-codec", "rustc-hex", "scale-info", + "schnorrkel", "serde", "serde_json", "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", diff --git a/Cargo.toml b/Cargo.toml index e4248d0a9..e74b27678 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -309,5 +309,7 @@ rpc-trace = { path = "client/rpc/trace" } rpc-txpool = { path = "client/rpc/txpool" } evm-tracer = { path = "standalone/runtime/evm_tracer", default-features = false } +schnorrkel = { verison = "11.4", default-features = false } + [profile.release] panic = "unwind" diff --git a/pallets/claims/Cargo.toml b/pallets/claims/Cargo.toml index 59f3af5ba..82eda1d7c 100644 --- a/pallets/claims/Cargo.toml +++ b/pallets/claims/Cargo.toml @@ -16,6 +16,7 @@ pallet-evm = { workspace = true } rustc-hex = { workspace = true } scale-info = { workspace = true } serde = { workspace = true } +schnorrkel = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } @@ -51,5 +52,6 @@ std = [ "pallet-vesting/std", "pallet-balances/std", "pallet-evm/std", + "schnorrkel/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index b5e0e9233..2e81bc7d9 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -24,33 +24,38 @@ mod mock; #[cfg(test)] mod tests; +mod utils; + #[cfg(feature = "runtime-benchmarks")] mod benchmarking; +use crate::utils::{ + ethereum_address::{EcdsaSignature, EthereumAddress}, + MultiAddress, MultiAddressSignature, +}; use frame_support::{ ensure, - traits::{Currency, Get, IsSubType, VestingSchedule}, + traits::{Currency, Defensive, Get, IsSubType, VestingSchedule}, weights::Weight, }; pub use pallet::*; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; use scale_info::{ - prelude::{format, string::String}, TypeInfo, }; use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; use sp_core::H160; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; use sp_runtime::{ - traits::{CheckedSub, DispatchInfoOf, SignedExtension, Zero}, + traits::{CheckedSub, SignedExtension, Zero}, transaction_validity::{ - InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, + InvalidTransaction, TransactionValidity, ValidTransaction, }, - RuntimeDebug, + AccountId32, RuntimeDebug, }; use sp_std::{convert::TryInto, fmt::Debug, prelude::*, vec}; - +use utils::Sr25519Signature; /// Custom validity errors used in Polkadot while validating transactions. #[repr(u8)] pub enum ValidityError { @@ -102,16 +107,6 @@ impl WeightInfo for TestWeightInfo { } } -#[derive( - Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize, -)] -pub enum ClaimerType { - /// Claimer is Ethereum address - EthereumAddress, - /// Claimer is Substrate address - SubstrateAddress(A), -} - /// The kind of statement an account needs to make for a claim to be valid. #[derive( Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize, @@ -145,66 +140,6 @@ impl Default for StatementKind { } } -/// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account). -/// -/// This gets serialized to the 0x-prefixed hex representation. -#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] -pub struct EthereumAddress([u8; 20]); - -impl Serialize for EthereumAddress { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let hex: String = rustc_hex::ToHex::to_hex(&self.0[..]); - serializer.serialize_str(&format!("0x{}", hex)) - } -} - -impl<'de> Deserialize<'de> for EthereumAddress { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let base_string = String::deserialize(deserializer)?; - let offset = if base_string.starts_with("0x") { 2 } else { 0 }; - let s = &base_string[offset..]; - if s.len() != 40 { - Err(serde::de::Error::custom( - "Bad length of Ethereum address (should be 42 including '0x')", - ))?; - } - let raw: Vec = rustc_hex::FromHex::from_hex(s) - .map_err(|e| serde::de::Error::custom(format!("{:?}", e)))?; - let mut r = Self::default(); - r.0.copy_from_slice(&raw); - Ok(r) - } -} - -impl From for H160 { - fn from(a: EthereumAddress) -> Self { - let mut r = Self::default(); - r.0.copy_from_slice(&a.0); - r - } -} - -#[derive(Encode, Decode, Clone, TypeInfo)] -pub struct EcdsaSignature(pub [u8; 65]); - -impl PartialEq for EcdsaSignature { - fn eq(&self, other: &Self) -> bool { - &self.0[..] == &other.0[..] - } -} - -impl sp_std::fmt::Debug for EcdsaSignature { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { - write!(f, "EcdsaSignature({:?})", &self.0[..]) - } -} - #[frame_support::pallet] pub mod pallet { use super::*; @@ -234,13 +169,17 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// Someone claimed some native tokens. - Claimed { who: T::AccountId, ethereum_address: EthereumAddress, amount: BalanceOf }, + Claimed { recipient: T::AccountId, source: MultiAddress, amount: BalanceOf }, } #[pallet::error] pub enum Error { /// Invalid Ethereum signature. InvalidEthereumSignature, + /// Invalid Native (sr25519) signature + InvalidNativeSignature, + /// Invalid Native account decoding + InvalidNativeAccount, /// Ethereum address has no claim. SignerHasNoClaim, /// Account ID sending transaction has no claim. @@ -256,7 +195,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn claims)] - pub(super) type Claims = StorageMap<_, Identity, EthereumAddress, BalanceOf>; + pub(super) type Claims = StorageMap<_, Identity, MultiAddress, BalanceOf>; #[pallet::storage] #[pallet::getter(fn total)] @@ -265,7 +204,7 @@ pub mod pallet { /// Expiry block and account to deposit expired funds #[pallet::storage] #[pallet::getter(fn expiry_time)] - pub(super) type ExpiryConfig = StorageValue<_, (BlockNumberFor, T::AccountId)>; + pub(super) type ExpiryConfig = StorageValue<_, (BlockNumberFor, MultiAddress)>; /// Vesting schedule for a claim. /// First balance is the total amount that should be held for vesting. @@ -274,22 +213,17 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn vesting)] pub(super) type Vesting = - StorageMap<_, Identity, EthereumAddress, (BalanceOf, BalanceOf, BlockNumberFor)>; + StorageMap<_, Identity, MultiAddress, (BalanceOf, BalanceOf, BlockNumberFor)>; /// The statement kind that must be signed, if any. #[pallet::storage] - pub(super) type Signing = StorageMap<_, Identity, EthereumAddress, StatementKind>; - - /// Pre-claimed Ethereum accounts, by the Account ID that they are claimed to. - #[pallet::storage] - pub(super) type Preclaims = StorageMap<_, Identity, T::AccountId, EthereumAddress>; + pub(super) type Signing = StorageMap<_, Identity, MultiAddress, StatementKind>; #[pallet::genesis_config] pub struct GenesisConfig { - pub claims: - Vec<(EthereumAddress, BalanceOf, Option, Option)>, - pub vesting: Vec<(EthereumAddress, (BalanceOf, BalanceOf, BlockNumberFor))>, - pub expiry: Option<(BlockNumberFor, T::AccountId)>, + pub claims: Vec<(MultiAddress, BalanceOf, Option)>, + pub vesting: Vec<(MultiAddress, (BalanceOf, BalanceOf, BlockNumberFor))>, + pub expiry: Option<(BlockNumberFor, MultiAddress)>, } impl Default for GenesisConfig { @@ -302,18 +236,13 @@ pub mod pallet { impl BuildGenesisConfig for GenesisConfig { fn build(&self) { // build `Claims` - self.claims - .iter() - .map(|(a, b, _, _)| (a.clone(), b.clone())) - .for_each(|(a, b)| { - println!("a: {:?}, b: {:?}", a, b); - Claims::::insert(a, b); - }); + self.claims.iter().map(|(a, b, _)| (a.clone(), b.clone())).for_each(|(a, b)| { + println!("a: {:?}, b: {:?}", a, b); + Claims::::insert(a, b); + }); // build `Total` Total::::put( - self.claims - .iter() - .fold(Zero::zero(), |acc: BalanceOf, &(_, b, _, _)| acc + b), + self.claims.iter().fold(Zero::zero(), |acc: BalanceOf, &(_, b, _)| acc + b), ); // build `Vesting` self.vesting.iter().for_each(|(k, v)| { @@ -322,17 +251,10 @@ pub mod pallet { // build `Signing` self.claims .iter() - .filter_map(|(a, _, _, s)| Some((a.clone(), s.clone()?))) + .filter_map(|(a, _, s)| Some((a.clone(), s.clone()?))) .for_each(|(a, s)| { Signing::::insert(a, s); }); - // build `Preclaims` - self.claims - .iter() - .filter_map(|(a, _, i, _)| Some((i.clone()?, a.clone()))) - .for_each(|(i, a)| { - Preclaims::::insert(i, a); - }); // build expiryConfig ExpiryConfig::::set(self.expiry.clone()) } @@ -347,7 +269,12 @@ pub mod pallet { if current_block > expiry_config.0 { let unclaimed_amount = Total::::take(); frame_support::log::info!("Claims : Expiry block passed, sweeping remaining amount of {:?} to destination", unclaimed_amount); - CurrencyOf::::deposit_creating(&expiry_config.1, unclaimed_amount); + let expiry_destination = + match Self::convert_multi_address_to_account_id(expiry_config.1) { + Ok(a) => a, + Err(_) => return, + }; + CurrencyOf::::deposit_creating(&expiry_destination, unclaimed_amount); // clear the expiry detail ExpiryConfig::::take(); } @@ -357,7 +284,7 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Make a claim to collect your native tokens. + /// Make a claim to collect your tokens. /// /// The dispatch origin for this call must be _None_. /// @@ -385,16 +312,14 @@ pub mod pallet { #[pallet::call_index(0)] pub fn claim( origin: OriginFor, - dest: Option, - ethereum_signature: EcdsaSignature, + dest: Option, + signature: MultiAddressSignature, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); - let signer = Self::eth_recover(ðereum_signature, &data, &[][..]) - .ok_or(Error::::InvalidEthereumSignature)?; + let signer = Self::get_signer_multi_address(dest.clone(), signature, data, vec![])?; ensure!(Signing::::get(&signer).is_none(), Error::::InvalidStatement); - Self::process_claim(signer, dest)?; Ok(()) } @@ -418,7 +343,7 @@ pub mod pallet { #[pallet::call_index(1)] pub fn mint_claim( origin: OriginFor, - who: EthereumAddress, + who: MultiAddress, value: BalanceOf, vesting_schedule: Option<(BalanceOf, BalanceOf, BlockNumberFor)>, statement: Option, @@ -427,9 +352,9 @@ pub mod pallet { >::mutate(|t| *t += value); println!("mint_claim: who: {:?}, value: {:?}", who, value); - >::insert(who, value); + >::insert(who.clone(), value); if let Some(vs) = vesting_schedule { - >::insert(who, vs); + >::insert(who.clone(), vs); } if let Some(s) = statement { Signing::::insert(who, s); @@ -468,79 +393,35 @@ pub mod pallet { #[pallet::call_index(2)] pub fn claim_attest( origin: OriginFor, - dest: Option, - ethereum_signature: EcdsaSignature, + dest: Option, + signature: MultiAddressSignature, statement: Vec, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); println!("claim_attest: data: {:?}", data); - let signer = Self::eth_recover(ðereum_signature, &data, &statement) - .ok_or(Error::::InvalidEthereumSignature)?; - if let Some(s) = Signing::::get(signer) { + let signer = Self::get_signer_multi_address(dest.clone(), signature, data, statement.clone())?; + println!("claim_attest: signer: {:?}", signer); + if let Some(s) = Signing::::get(signer.clone()) { ensure!(s.to_text() == &statement[..], Error::::InvalidStatement); } Self::process_claim(signer, dest)?; Ok(()) } - /// Attest to a statement, needed to finalize the claims process. - /// - /// WARNING: Insecure unless your chain includes `PrevalidateAttests` as a - /// `SignedExtension`. - /// - /// Unsigned Validation: - /// A call to attest is deemed valid if the sender has a `Preclaim` registered - /// and provides a `statement` which is expected for the account. - /// - /// Parameters: - /// - `statement`: The identity of the statement which is being attested to in the - /// signature. - /// - /// - /// The weight of this call is invariant over the input parameters. - /// Weight includes logic to do pre-validation on `attest` call. - /// - /// Total Complexity: O(1) - /// - #[pallet::weight(( - 3, - DispatchClass::Normal, - Pays::No - ))] - #[pallet::call_index(3)] - pub fn attest(origin: OriginFor, statement: Vec) -> DispatchResult { - let who = ensure_signed(origin)?; - let signer = Preclaims::::get(&who).ok_or(Error::::SenderHasNoClaim)?; - if let Some(s) = Signing::::get(signer) { - ensure!(s.to_text() == &statement[..], Error::::InvalidStatement); - } - Self::process_claim(signer, Some(who.clone()))?; - Preclaims::::remove(&who); - Ok(()) - } - #[pallet::weight({4})] #[pallet::call_index(4)] pub fn move_claim( origin: OriginFor, - old: EthereumAddress, - new: EthereumAddress, - maybe_preclaim: Option, + old: MultiAddress, + new: MultiAddress, ) -> DispatchResultWithPostInfo { T::MoveClaimOrigin::try_origin(origin).map(|_| ()).or_else(ensure_root)?; Claims::::take(&old).map(|c| Claims::::insert(&new, c)); Vesting::::take(&old).map(|c| Vesting::::insert(&new, c)); Signing::::take(&old).map(|c| Signing::::insert(&new, c)); - maybe_preclaim.map(|preclaim| { - Preclaims::::mutate(&preclaim, |maybe_o| { - if maybe_o.as_ref().map_or(false, |o| o == &old) { - *maybe_o = Some(new) - } - }) - }); Ok(Pays::No.into()) } @@ -551,7 +432,7 @@ pub mod pallet { pub fn force_set_expiry_config( origin: OriginFor, expiry_block: BlockNumberFor, - dest: T::AccountId, + dest: MultiAddress, ) -> DispatchResult { T::ForceOrigin::ensure_origin(origin)?; ExpiryConfig::::set(Some((expiry_block, dest))); @@ -570,19 +451,30 @@ pub mod pallet { // // The weight of this logic is included in the `claim` dispatchable. // - Call::claim { dest: account, ethereum_signature } => { + Call::claim { dest: account, signature } => { let data = account.using_encoded(to_ascii_hex); - (Self::eth_recover(ðereum_signature, &data, &[][..]), None) + match signature { + MultiAddressSignature::EVM(ethereum_signature) => + (Self::eth_recover(ðereum_signature, &data, &[][..]), None), + MultiAddressSignature::Native(sr25519_signature) => + (Self::sr25519_recover(&sr25519_signature, &data, &[][..]), None), + } }, // // The weight of this logic is included in the `claim_attest` dispatchable. // - Call::claim_attest { dest: account, ethereum_signature, statement } => { + Call::claim_attest { dest: account, signature, statement } => { let data = account.using_encoded(to_ascii_hex); - ( - Self::eth_recover(ðereum_signature, &data, &statement), - Some(statement.as_slice()), - ) + match signature { + MultiAddressSignature::EVM(ethereum_signature) => ( + Self::eth_recover(ðereum_signature, &data, &statement[..]), + Some(statement.as_slice()), + ), + MultiAddressSignature::Native(sr25519_signature) => ( + Self::sr25519_recover(&sr25519_signature, &data, &statement[..]), + Some(statement.as_slice()), + ), + } }, _ => return Err(InvalidTransaction::Call.into()), }; @@ -595,7 +487,7 @@ pub mod pallet { ensure!(>::contains_key(&signer), e); let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into()); - match Signing::::get(signer) { + match Signing::::get(signer.clone()) { None => ensure!(maybe_statement.is_none(), e), Some(s) => ensure!(Some(s.to_text()) == maybe_statement, e), } @@ -642,41 +534,51 @@ impl Pallet { // Attempts to recover the Ethereum address from a message signature signed by using // the Ethereum RPC's `personal_sign` and `eth_sign`. - fn eth_recover(s: &EcdsaSignature, what: &[u8], extra: &[u8]) -> Option { + fn eth_recover(s: &EcdsaSignature, what: &[u8], extra: &[u8]) -> Option { let msg = keccak_256(&Self::ethereum_signable_message(what, extra)); let mut res = EthereumAddress::default(); res.0 .copy_from_slice(&keccak_256(&secp256k1_ecdsa_recover(&s.0, &msg).ok()?[..])[12..]); - Some(res) + Some(MultiAddress::EVM(res)) + } + + // Attempts to recover the Substrate address from a message signature signed by using + // the Substrate RPC's `sign`. + fn sr25519_recover(_s: &Sr25519Signature, what: &[u8], extra: &[u8]) -> Option { + let _msg = keccak_256(&Self::ethereum_signable_message(what, extra)); + let res = AccountId32::new([0; 32]); + Some(MultiAddress::Native(res)) } fn process_claim( - signer: EthereumAddress, - dest: Option, + signer: MultiAddress, + dest: Option, ) -> sp_runtime::DispatchResult { println!("process_claim: signer: {:?}, dest: {:?}", signer, dest); let balance_due = >::get(&signer).ok_or(Error::::SignerHasNoClaim)?; let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::::PotUnderflow)?; - let dest = match dest { + let recipient = match dest { Some(d) => d, - None => T::AddressMapping::into_account_id(H160::from(signer)), + None => signer.clone(), }; + let recipient = Self::convert_multi_address_to_account_id(recipient)?; + let vesting = Vesting::::get(&signer); - if vesting.is_some() && T::VestingSchedule::vesting_balance(&dest).is_some() { + if vesting.is_some() && T::VestingSchedule::vesting_balance(&recipient).is_some() { return Err(Error::::VestedBalanceExists.into()) } // We first need to deposit the balance to ensure that the account exists. - CurrencyOf::::deposit_creating(&dest, balance_due); + CurrencyOf::::deposit_creating(&recipient, balance_due); // Check if this claim should have a vesting schedule. if let Some(vs) = vesting { // This can only fail if the account already has a vesting schedule, // but this is checked above. - T::VestingSchedule::add_vesting_schedule(&dest, vs.0, vs.1, vs.2) + T::VestingSchedule::add_vesting_schedule(&recipient, vs.0, vs.1, vs.2) .expect("No other vesting schedule exists, as checked above; qed"); } @@ -686,94 +588,39 @@ impl Pallet { Signing::::remove(&signer); // Let's deposit an event to let the outside world know this happened. - Self::deposit_event(Event::::Claimed { - who: dest, - ethereum_address: signer, - amount: balance_due, - }); - - Ok(()) - } -} + Self::deposit_event(Event::::Claimed { recipient, source: signer, amount: balance_due }); -/// Validate `attest` calls prior to execution. Needed to avoid a DoS attack since they are -/// otherwise free to place on chain. -#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)] -#[scale_info(skip_type_params(T))] -pub struct PrevalidateAttests(sp_std::marker::PhantomData) -where - ::RuntimeCall: IsSubType>; - -impl Debug for PrevalidateAttests -where - ::RuntimeCall: IsSubType>, -{ - #[cfg(feature = "std")] - fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { - write!(f, "PrevalidateAttests") - } - - #[cfg(not(feature = "std"))] - fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { Ok(()) } -} -impl PrevalidateAttests -where - ::RuntimeCall: IsSubType>, -{ - /// Create new `SignedExtension` to check runtime version. - pub fn new() -> Self { - Self(sp_std::marker::PhantomData) - } -} + fn get_signer_multi_address( + _dest: Option, + signature: MultiAddressSignature, + data: Vec, + statement: Vec, + ) -> Result> { + let signer = match signature { + MultiAddressSignature::EVM(ethereum_signature) => + Self::eth_recover(ðereum_signature, &data, &statement[..]) + .ok_or(Error::::InvalidEthereumSignature)?, + MultiAddressSignature::Native(sr25519_signature) => + Self::sr25519_recover(&sr25519_signature, &data, &statement[..]) + .ok_or(Error::::InvalidNativeSignature)?, + }; -impl SignedExtension for PrevalidateAttests -where - ::RuntimeCall: IsSubType>, -{ - type AccountId = T::AccountId; - type Call = ::RuntimeCall; - type AdditionalSigned = (); - type Pre = (); - const IDENTIFIER: &'static str = "PrevalidateAttests"; - - fn additional_signed(&self) -> Result { - Ok(()) + Ok(signer) } - fn pre_dispatch( - self, - who: &Self::AccountId, - call: &Self::Call, - info: &DispatchInfoOf, - len: usize, - ) -> Result { - Ok(self.validate(who, call, info, len).map(|_| ())?) - } + fn convert_multi_address_to_account_id(dest: MultiAddress) -> Result> { + let account = match dest { + MultiAddress::EVM(a) => T::AddressMapping::into_account_id(H160::from(a)), + MultiAddress::Native(a) => match Decode::decode(&mut a.encode().as_slice()) { + Ok(a) => a, + Err(_) => return Err(Error::::InvalidNativeAccount), + }, + }; - // - // The weight of this logic is included in the `attest` dispatchable. - // - fn validate( - &self, - who: &Self::AccountId, - call: &Self::Call, - _info: &DispatchInfoOf, - _len: usize, - ) -> TransactionValidity { - if let Some(local_call) = call.is_sub_type() { - if let Call::attest { statement: attested_statement } = local_call { - let signer = Preclaims::::get(who) - .ok_or(InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()))?; - if let Some(s) = Signing::::get(signer) { - let e = InvalidTransaction::Custom(ValidityError::InvalidStatement.into()); - ensure!(&attested_statement[..] == s.to_text(), e); - } - } - } - Ok(ValidTransaction::default()) + Ok(account) } } @@ -784,16 +631,16 @@ mod secp_utils { pub fn public(secret: &libsecp256k1::SecretKey) -> libsecp256k1::PublicKey { libsecp256k1::PublicKey::from_secret_key(secret) } - pub fn eth(secret: &libsecp256k1::SecretKey) -> EthereumAddress { + pub fn eth(secret: &libsecp256k1::SecretKey) -> MultiAddress { let mut res = EthereumAddress::default(); res.0.copy_from_slice(&keccak_256(&public(secret).serialize()[1..65])[12..]); - res + MultiAddress::EVM(res) } pub fn sig( secret: &libsecp256k1::SecretKey, what: &[u8], extra: &[u8], - ) -> EcdsaSignature { + ) -> MultiAddressSignature { let msg = keccak_256(&>::ethereum_signable_message( &to_ascii_hex(what)[..], extra, @@ -802,6 +649,6 @@ mod secp_utils { let mut r = [0u8; 65]; r[0..64].copy_from_slice(&sig.serialize()[..]); r[64] = recovery_id.serialize(); - EcdsaSignature(r) + MultiAddressSignature::EVM(EcdsaSignature(r)) } } diff --git a/pallets/claims/src/mock.rs b/pallets/claims/src/mock.rs index 733cd049b..27c25816d 100644 --- a/pallets/claims/src/mock.rs +++ b/pallets/claims/src/mock.rs @@ -97,7 +97,7 @@ parameter_types! { pub Prefix: &'static [u8] = b"Pay RUSTs to the TEST account:"; } ord_parameter_types! { - pub const Six: AccountId32 = get_account_id(6); + pub const Six: AccountId32 = get_multi_address_account_id(6).to_account_id_32(); } impl Config for Test { @@ -136,8 +136,8 @@ pub fn frank() -> libsecp256k1::SecretKey { libsecp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap() } -pub fn get_account_id(id: u8) -> AccountId32 { - AccountId32::new([id; 32]) +pub fn get_multi_address_account_id(id: u8) -> MultiAddress { + MultiAddress::Native(AccountId32::new([id; 32])) } // This function basically just builds a genesis storage key/value store according to @@ -150,10 +150,10 @@ pub fn new_test_ext() -> sp_io::TestExternalities { .unwrap(); pallet_airdrop_claims::GenesisConfig:: { claims: vec![ - (eth(&alice()), 100, None, None), - (eth(&dave()), 200, None, Some(StatementKind::Regular)), - (eth(&eve()), 300, Some(get_account_id(42)), Some(StatementKind::Safe)), - (eth(&frank()), 400, Some(get_account_id(43)), None), + (eth(&alice()), 100, None), + (eth(&dave()), 200, Some(StatementKind::Regular)), + (eth(&eve()), 300, Some(StatementKind::Safe)), + (eth(&frank()), 400, None), ], vesting: vec![(eth(&alice()), (50, 10, 1))], expiry: None, diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index 095ee6d96..f4410068b 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -29,11 +29,26 @@ fn basic_setup_works() { assert_eq!(ClaimsPallet::claims(ð(&dave())), Some(200)); assert_eq!(ClaimsPallet::claims(ð(&eve())), Some(300)); assert_eq!(ClaimsPallet::claims(ð(&frank())), Some(400)); - assert_eq!(ClaimsPallet::claims(&EthereumAddress::default()), None); + assert_eq!(ClaimsPallet::claims(&MultiAddress::EVM(EthereumAddress::default())), None); assert_eq!(ClaimsPallet::vesting(ð(&alice())), Some((50, 10, 1))); }); } +#[test] +fn eth_signature_works() { + new_test_ext().execute_with(|| { + let data = Some(get_multi_address_account_id(42)).encode(); + let s = sig::(&alice(), &data, &[][..]); + let sig = match s { + MultiAddressSignature::EVM(s) => s, + _ => panic!("should be evm signature"), + }; + + assert_eq!(ClaimsPallet::eth_recover(&sig, &to_ascii_hex(&data), &[][..]), Some(eth(&alice()))); + assert!(ClaimsPallet::eth_recover(&sig, &Some(get_multi_address_account_id(43)).encode(), &[][..]) != Some(eth(&alice()))); + }); +} + #[test] fn serde_works() { let x = EthereumAddress(hex!["0123456789abcdef0123456789abcdef01234567"]); @@ -46,14 +61,14 @@ fn serde_works() { #[test] fn claiming_works() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 100); - assert_eq!(VestingPallet::vesting_balance(&get_account_id(42)), Some(50)); + assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); + assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -61,37 +76,35 @@ fn claiming_works() { #[test] fn basic_claim_moving_works() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_noop!( ClaimsPallet::move_claim( - RuntimeOrigin::signed(get_account_id(1)), + RuntimeOrigin::signed(get_multi_address_account_id(1).to_account_id_32()), eth(&alice()), eth(&bob()), - None ), BadOrigin ); assert_ok!(ClaimsPallet::move_claim( - RuntimeOrigin::signed(get_account_id(6)), + RuntimeOrigin::signed(get_multi_address_account_id(6).to_account_id_32()), eth(&alice()), eth(&bob()), - None )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim ); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&bob(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&bob(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 100); - assert_eq!(VestingPallet::vesting_balance(&get_account_id(42)), Some(50)); + assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); + assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -100,40 +113,22 @@ fn basic_claim_moving_works() { fn claim_attest_moving_works() { new_test_ext().execute_with(|| { assert_ok!(ClaimsPallet::move_claim( - RuntimeOrigin::signed(get_account_id(6)), + RuntimeOrigin::signed(get_multi_address_account_id(6).to_account_id_32()), eth(&dave()), eth(&bob()), - None )); let s = sig::( &bob(), - &Some(get_account_id(42)).encode(), + &Some(get_multi_address_account_id(42)).encode(), StatementKind::Regular.to_text(), ); assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(42)), + Some(get_multi_address_account_id(42)), s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 200); - }); -} - -#[test] -fn attest_moving_works() { - new_test_ext().execute_with(|| { - assert_ok!(ClaimsPallet::move_claim( - RuntimeOrigin::signed(get_account_id(6)), - eth(&eve()), - eth(&bob()), - Some(get_account_id(42)) - )); - assert_ok!(ClaimsPallet::attest( - RuntimeOrigin::signed(get_account_id(42)), - StatementKind::Safe.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 300); + assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); }); } @@ -142,29 +137,29 @@ fn claiming_does_not_bypass_signing() { new_test_ext().execute_with(|| { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&dave(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, ); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&eve(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&eve(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, ); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&frank(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); }); } @@ -172,12 +167,16 @@ fn claiming_does_not_bypass_signing() { #[test] fn attest_claiming_works() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); - let s = - sig::(&dave(), &Some(get_account_id(42)).encode(), StatementKind::Safe.to_text()); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); + let data = Some(get_multi_address_account_id(42)).encode(); + let s = sig::( + &dave(), + &data, + StatementKind::Safe.to_text(), + ); let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(42)), + Some(get_multi_address_account_id(42)), s.clone(), StatementKind::Safe.to_text().to_vec(), ); @@ -185,7 +184,7 @@ fn attest_claiming_works() { let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(42)), + Some(get_multi_address_account_id(42)), s, StatementKind::Regular.to_text().to_vec(), ); @@ -195,26 +194,26 @@ fn attest_claiming_works() { let s = sig::( &dave(), - &Some(get_account_id(42)).encode(), + &Some(get_multi_address_account_id(42)).encode(), StatementKind::Regular.to_text(), ); assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(42)), + Some(get_multi_address_account_id(42)), s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 200); + assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); assert_eq!(ClaimsPallet::total(), total_claims() - 200); let s = sig::( &dave(), - &Some(get_account_id(42)).encode(), + &Some(get_multi_address_account_id(42)).encode(), StatementKind::Regular.to_text(), ); let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(42)), + Some(get_multi_address_account_id(42)), s, StatementKind::Regular.to_text().to_vec(), ); @@ -222,93 +221,16 @@ fn attest_claiming_works() { }); } -#[test] -fn attesting_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); - assert_noop!( - ClaimsPallet::attest( - RuntimeOrigin::signed(get_account_id(69)), - StatementKind::Safe.to_text().to_vec() - ), - Error::::SenderHasNoClaim - ); - assert_noop!( - ClaimsPallet::attest( - RuntimeOrigin::signed(get_account_id(42)), - StatementKind::Regular.to_text().to_vec() - ), - Error::::InvalidStatement - ); - assert_ok!(ClaimsPallet::attest( - RuntimeOrigin::signed(get_account_id(42)), - StatementKind::Safe.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 300); - assert_eq!(ClaimsPallet::total(), total_claims() - 300); - }); -} - -#[test] -fn claim_cannot_clobber_preclaim() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); - // Alice's claim is 100 - assert_ok!(ClaimsPallet::claim( - RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) - )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 100); - // Eve's claim is 300 through Account 42 - assert_ok!(ClaimsPallet::attest( - RuntimeOrigin::signed(get_account_id(42)), - StatementKind::Safe.to_text().to_vec() - )); - assert_eq!(Balances::free_balance(&get_account_id(42)), 100 + 300); - assert_eq!(ClaimsPallet::total(), total_claims() - 400); - }); -} - -#[test] -fn valid_attest_transactions_are_free() { - new_test_ext().execute_with(|| { - let p = PrevalidateAttests::::new(); - let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { - statement: StatementKind::Safe.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - assert_eq!(di.pays_fee, Pays::No); - let r = p.validate(&get_account_id(42), &c, &di, 20); - assert_eq!(r, TransactionValidity::Ok(ValidTransaction::default())); - }); -} - -#[test] -fn invalid_attest_transactions_are_recognized() { - new_test_ext().execute_with(|| { - let p = PrevalidateAttests::::new(); - let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { - statement: StatementKind::Regular.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - let r = p.validate(&get_account_id(42), &c, &di, 20); - assert!(r.is_err()); - let c = RuntimeCall::ClaimsPallet(ClaimsCall::attest { - statement: StatementKind::Safe.to_text().to_vec(), - }); - let di = c.get_dispatch_info(); - let r = p.validate(&get_account_id(69), &c, &di, 20); - assert!(r.is_err()); - }); -} - #[test] fn cannot_bypass_attest_claiming() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); - let s = sig::(&dave(), &Some(get_account_id(42)).encode(), &[]); - let r = ClaimsPallet::claim(RuntimeOrigin::none(), Some(get_account_id(42)), s.clone()); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); + let s = sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[]); + let r = ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + s.clone(), + ); assert_noop!(r, Error::::InvalidStatement); }); } @@ -318,7 +240,7 @@ fn add_claim_works() { new_test_ext().execute_with(|| { assert_noop!( ClaimsPallet::mint_claim( - RuntimeOrigin::signed(get_account_id(42)), + RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), eth(&bob()), 200, None, @@ -326,12 +248,12 @@ fn add_claim_works() { ), sp_runtime::traits::BadOrigin, ); - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(69)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(69)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, ); @@ -339,11 +261,11 @@ fn add_claim_works() { assert_eq!(ClaimsPallet::total(), total_claims() + 200); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(69)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(69)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_account_id(69)), 200); - assert_eq!(VestingPallet::vesting_balance(&get_account_id(69)), None); + assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); + assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), None); assert_eq!(ClaimsPallet::total(), total_claims()); }); } @@ -353,7 +275,7 @@ fn add_claim_with_vesting_works() { new_test_ext().execute_with(|| { assert_noop!( ClaimsPallet::mint_claim( - RuntimeOrigin::signed(get_account_id(42)), + RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), eth(&bob()), 200, Some((50, 10, 1)), @@ -361,12 +283,12 @@ fn add_claim_with_vesting_works() { ), sp_runtime::traits::BadOrigin, ); - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(69)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(69)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, ); @@ -379,17 +301,17 @@ fn add_claim_with_vesting_works() { )); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(69)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(69)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_account_id(69)), 200); - assert_eq!(VestingPallet::vesting_balance(&get_account_id(69)), Some(50)); + assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); + assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), Some(50)); // Make sure we can not transfer the vested balance. assert_err!( >::transfer( - &get_account_id(69), - &get_account_id(80), + &get_multi_address_account_id(69).to_account_id_32(), + &get_multi_address_account_id(80).to_account_id_32(), 180, ExistenceRequirement::AllowDeath ), @@ -403,7 +325,7 @@ fn add_claim_with_statement_works() { new_test_ext().execute_with(|| { assert_noop!( ClaimsPallet::mint_claim( - RuntimeOrigin::signed(get_account_id(42)), + RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), eth(&bob()), 200, None, @@ -411,17 +333,17 @@ fn add_claim_with_statement_works() { ), sp_runtime::traits::BadOrigin, ); - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); let signature = sig::( &bob(), - &Some(get_account_id(69)).encode(), + &Some(get_multi_address_account_id(69)).encode(), StatementKind::Regular.to_text(), ); assert_noop!( ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(69)), + Some(get_multi_address_account_id(69)), signature.clone(), StatementKind::Regular.to_text().to_vec() ), @@ -437,7 +359,7 @@ fn add_claim_with_statement_works() { assert_noop!( ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(69)), + Some(get_multi_address_account_id(69)), signature.clone(), vec![], ), @@ -445,23 +367,23 @@ fn add_claim_with_statement_works() { ); assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), - Some(get_account_id(69)), + Some(get_multi_address_account_id(69)), signature.clone(), StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(get_account_id(69)), 200); + assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); }); } #[test] fn origin_signed_claiming_fail() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_err!( ClaimsPallet::claim( - RuntimeOrigin::signed(get_account_id(42)), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), sp_runtime::traits::BadOrigin, ); @@ -471,17 +393,17 @@ fn origin_signed_claiming_fail() { #[test] fn double_claiming_doesnt_work() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim ); @@ -491,11 +413,11 @@ fn double_claiming_doesnt_work() { #[test] fn claiming_while_vested_doesnt_work() { new_test_ext().execute_with(|| { - CurrencyOf::::make_free_balance_be(&get_account_id(69), total_claims()); - assert_eq!(Balances::free_balance(get_account_id(69)), total_claims()); + CurrencyOf::::make_free_balance_be(&get_multi_address_account_id(69).to_account_id_32(), total_claims()); + assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), total_claims()); // A user is already vested assert_ok!(::VestingSchedule::add_vesting_schedule( - &get_account_id(69), + &get_multi_address_account_id(69).to_account_id_32(), total_claims(), 100, 10 @@ -514,8 +436,8 @@ fn claiming_while_vested_doesnt_work() { assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(69)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(69)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::VestedBalanceExists, ); @@ -525,12 +447,12 @@ fn claiming_while_vested_doesnt_work() { #[test] fn non_sender_sig_doesnt_work() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim ); @@ -540,12 +462,12 @@ fn non_sender_sig_doesnt_work() { #[test] fn non_claimant_doesnt_work() { new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(get_account_id(42)), 0); + assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&bob(), &Some(get_account_id(69)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim ); @@ -560,7 +482,7 @@ fn real_eth_sig_works() { let sig = EcdsaSignature(sig); let who = 42u64.using_encoded(to_ascii_hex); let signer = ClaimsPallet::eth_recover(&sig, &who, &[][..]).unwrap(); - assert_eq!(signer.0, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]); + assert_eq!(signer.to_ethereum_address().unwrap().0, hex!["6d31165d5d932d571f3b44695653b46dcc327e84"]); }); } @@ -574,10 +496,10 @@ fn validate_unsigned_works() { >::validate_unsigned( source, &ClaimsCall::claim { - dest: Some(get_account_id(1)), - ethereum_signature: sig::( + dest: Some(get_multi_address_account_id(1)), + signature: sig::( &alice(), - &Some(get_account_id(1)).encode(), + &Some(get_multi_address_account_id(1)).encode(), &[][..] ) } @@ -594,8 +516,8 @@ fn validate_unsigned_works() { >::validate_unsigned( source, &ClaimsCall::claim { - dest: Some(get_account_id(0)), - ethereum_signature: EcdsaSignature([0; 65]) + dest: Some(get_multi_address_account_id(0)), + signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])) } ), InvalidTransaction::Custom(ValidityError::InvalidEthereumSignature.into()).into(), @@ -604,10 +526,10 @@ fn validate_unsigned_works() { >::validate_unsigned( source, &ClaimsCall::claim { - dest: Some(get_account_id(1)), - ethereum_signature: sig::( + dest: Some(get_multi_address_account_id(1)), + signature: sig::( &bob(), - &Some(get_account_id(1)).encode(), + &Some(get_multi_address_account_id(1)).encode(), &[][..] ) } @@ -616,12 +538,12 @@ fn validate_unsigned_works() { ); let s = sig::( &dave(), - &Some(get_account_id(1)).encode(), + &Some(get_multi_address_account_id(1)).encode(), StatementKind::Regular.to_text(), ); let call = ClaimsCall::claim_attest { - dest: Some(get_account_id(1)), - ethereum_signature: s, + dest: Some(get_multi_address_account_id(1)), + signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; assert_eq!( @@ -638,8 +560,8 @@ fn validate_unsigned_works() { >::validate_unsigned( source, &ClaimsCall::claim_attest { - dest: Some(get_account_id(1)), - ethereum_signature: EcdsaSignature([0; 65]), + dest: Some(get_multi_address_account_id(1)), + signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])), statement: StatementKind::Regular.to_text().to_vec() } ), @@ -648,12 +570,12 @@ fn validate_unsigned_works() { let s = sig::( &bob(), - &Some(get_account_id(1)).encode(), + &Some(get_multi_address_account_id(1)).encode(), StatementKind::Regular.to_text(), ); let call = ClaimsCall::claim_attest { - dest: Some(get_account_id(1)), - ethereum_signature: s, + dest: Some(get_multi_address_account_id(1)), + signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; assert_eq!( @@ -661,11 +583,14 @@ fn validate_unsigned_works() { InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), ); - let s = - sig::(&dave(), &Some(get_account_id(1)).encode(), StatementKind::Safe.to_text()); + let s = sig::( + &dave(), + &Some(get_multi_address_account_id(1)).encode(), + StatementKind::Safe.to_text(), + ); let call = ClaimsCall::claim_attest { - dest: Some(get_account_id(1)), - ethereum_signature: s, + dest: Some(get_multi_address_account_id(1)), + signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; assert_eq!( @@ -673,11 +598,14 @@ fn validate_unsigned_works() { InvalidTransaction::Custom(ValidityError::SignerHasNoClaim.into()).into(), ); - let s = - sig::(&dave(), &Some(get_account_id(1)).encode(), StatementKind::Safe.to_text()); + let s = sig::( + &dave(), + &Some(get_multi_address_account_id(1)).encode(), + StatementKind::Safe.to_text(), + ); let call = ClaimsCall::claim_attest { - dest: Some(get_account_id(1)), - ethereum_signature: s, + dest: Some(get_multi_address_account_id(1)), + signature: s, statement: StatementKind::Safe.to_text().to_vec(), }; assert_eq!( @@ -694,8 +622,8 @@ fn test_unclaimed_returned_to_destination() { let claim_of_alice = 100; assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&alice(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_eq!(Total::::get(), original_total_claims - claim_of_alice); @@ -703,7 +631,7 @@ fn test_unclaimed_returned_to_destination() { assert_ok!(ClaimsPallet::force_set_expiry_config( RuntimeOrigin::root(), 5, - get_account_id(100) + get_multi_address_account_id(100) )); // run to after expiry block @@ -711,7 +639,7 @@ fn test_unclaimed_returned_to_destination() { assert_eq!(Total::::get(), 0); // the dest account should receive the remaining pot balance assert_eq!( - Balances::free_balance(get_account_id(100)), + Balances::free_balance(get_multi_address_account_id(100).to_account_id_32()), original_total_claims - claim_of_alice ); @@ -720,8 +648,8 @@ fn test_unclaimed_returned_to_destination() { assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), - Some(get_account_id(42)), - sig::(&frank(), &Some(get_account_id(42)).encode(), &[][..]) + Some(get_multi_address_account_id(42)), + sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::PotUnderflow ); diff --git a/pallets/claims/src/utils/ethereum_address.rs b/pallets/claims/src/utils/ethereum_address.rs new file mode 100644 index 000000000..60f814b35 --- /dev/null +++ b/pallets/claims/src/utils/ethereum_address.rs @@ -0,0 +1,61 @@ +use super::*; + +/// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account). +/// +/// This gets serialized to the 0x-prefixed hex representation. +#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] +pub struct EthereumAddress(pub [u8; 20]); + +impl Serialize for EthereumAddress { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let hex: String = rustc_hex::ToHex::to_hex(&self.0[..]); + serializer.serialize_str(&format!("0x{}", hex)) + } +} + +impl<'de> Deserialize<'de> for EthereumAddress { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let base_string = String::deserialize(deserializer)?; + let offset = if base_string.starts_with("0x") { 2 } else { 0 }; + let s = &base_string[offset..]; + if s.len() != 40 { + Err(serde::de::Error::custom( + "Bad length of Ethereum address (should be 42 including '0x')", + ))?; + } + let raw: Vec = rustc_hex::FromHex::from_hex(s) + .map_err(|e| serde::de::Error::custom(format!("{:?}", e)))?; + let mut r = Self::default(); + r.0.copy_from_slice(&raw); + Ok(r) + } +} + +impl From for H160 { + fn from(a: EthereumAddress) -> Self { + let mut r = Self::default(); + r.0.copy_from_slice(&a.0); + r + } +} + +#[derive(Clone, Copy, Eq, Encode, Decode, TypeInfo)] +pub struct EcdsaSignature(pub [u8; 65]); + +impl PartialEq for EcdsaSignature { + fn eq(&self, other: &Self) -> bool { + &self.0[..] == &other.0[..] + } +} + +impl sp_std::fmt::Debug for EcdsaSignature { + fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { + write!(f, "EcdsaSignature({:?})", &self.0[..]) + } +} diff --git a/pallets/claims/src/utils/mod.rs b/pallets/claims/src/utils/mod.rs new file mode 100644 index 000000000..637db603e --- /dev/null +++ b/pallets/claims/src/utils/mod.rs @@ -0,0 +1,61 @@ +use pallet_evm::{AddressMapping, HashedAddressMapping}; +use parity_scale_codec::{Decode, Encode}; +use scale_info::{ + prelude::{format, string::String}, + TypeInfo, +}; +#[cfg(feature = "std")] +use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; +use sp_core::{H160}; +use sp_runtime::{traits::BlakeTwo256, AccountId32, RuntimeDebug}; +use sp_std::prelude::*; + +pub mod ethereum_address; + +use ethereum_address::{EcdsaSignature, EthereumAddress}; + +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize)] +pub enum MultiAddress { + /// Claimer is Ethereum address + EVM(EthereumAddress), + /// Claimer is Substrate address + Native(AccountId32), +} + +impl MultiAddress { + pub fn to_account_id_32(&self) -> AccountId32 { + match self { + MultiAddress::EVM(ethereum_address) => + HashedAddressMapping::::into_account_id(H160::from(ethereum_address.0)), + MultiAddress::Native(substrate_address) => substrate_address.clone(), + } + } + + pub fn to_ethereum_address(&self) -> Option { + match self { + MultiAddress::EVM(ethereum_address) => Some(ethereum_address.clone()), + MultiAddress::Native(_) => None, + } + } +} + +#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)] +pub enum MultiAddressSignature { + EVM(EcdsaSignature), + Native(Sr25519Signature), +} + +#[derive(Clone, Copy, Eq, Encode, Decode, TypeInfo)] +pub struct Sr25519Signature(pub [u8; 65]); + +impl PartialEq for Sr25519Signature { + fn eq(&self, other: &Self) -> bool { + &self.0[..] == &other.0[..] + } +} + +impl sp_std::fmt::Debug for Sr25519Signature { + fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { + write!(f, "Sr25519Signature({:?})", &self.0[..]) + } +} From 0be3852345386db45be8eed9b386a64556e9b9f7 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Thu, 30 Nov 2023 23:15:00 -0500 Subject: [PATCH 04/10] Fix all tests, implement sr25519 sign/verify, need to test --- pallets/claims/src/lib.rs | 115 +++++++++++++++++++---------- pallets/claims/src/mock.rs | 14 +++- pallets/claims/src/tests.rs | 127 ++++++++++++++++++++++++++------ pallets/claims/src/utils/mod.rs | 20 +---- 4 files changed, 196 insertions(+), 80 deletions(-) diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 2e81bc7d9..99a357a44 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -35,26 +35,22 @@ use crate::utils::{ }; use frame_support::{ ensure, - traits::{Currency, Defensive, Get, IsSubType, VestingSchedule}, + traits::{Currency, Get, VestingSchedule}, weights::Weight, }; pub use pallet::*; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; -use scale_info::{ - TypeInfo, -}; -use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; +use scale_info::TypeInfo; +use serde::{self, Deserialize, Serialize}; use sp_core::H160; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; use sp_runtime::{ traits::{CheckedSub, SignedExtension, Zero}, - transaction_validity::{ - InvalidTransaction, TransactionValidity, ValidTransaction, - }, + transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction}, AccountId32, RuntimeDebug, }; -use sp_std::{convert::TryInto, fmt::Debug, prelude::*, vec}; +use sp_std::{convert::TryInto, prelude::*, vec}; use utils::Sr25519Signature; /// Custom validity errors used in Polkadot while validating transactions. #[repr(u8)] @@ -313,12 +309,13 @@ pub mod pallet { pub fn claim( origin: OriginFor, dest: Option, + signer: Option, signature: MultiAddressSignature, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); - let signer = Self::get_signer_multi_address(dest.clone(), signature, data, vec![])?; + let signer = Self::get_signer_multi_address(signer.clone(), signature, data, vec![])?; ensure!(Signing::::get(&signer).is_none(), Error::::InvalidStatement); Self::process_claim(signer, dest)?; Ok(()) @@ -351,7 +348,6 @@ pub mod pallet { ensure_root(origin)?; >::mutate(|t| *t += value); - println!("mint_claim: who: {:?}, value: {:?}", who, value); >::insert(who.clone(), value); if let Some(vs) = vesting_schedule { >::insert(who.clone(), vs); @@ -394,15 +390,15 @@ pub mod pallet { pub fn claim_attest( origin: OriginFor, dest: Option, + signer: Option, signature: MultiAddressSignature, statement: Vec, ) -> DispatchResult { ensure_none(origin)?; let data = dest.using_encoded(to_ascii_hex); - println!("claim_attest: data: {:?}", data); - let signer = Self::get_signer_multi_address(dest.clone(), signature, data, statement.clone())?; - println!("claim_attest: signer: {:?}", signer); + let signer = + Self::get_signer_multi_address(signer.clone(), signature, data, statement.clone())?; if let Some(s) = Signing::::get(signer.clone()) { ensure!(s.to_text() == &statement[..], Error::::InvalidStatement); } @@ -451,29 +447,31 @@ pub mod pallet { // // The weight of this logic is included in the `claim` dispatchable. // - Call::claim { dest: account, signature } => { + Call::claim { dest: account, signer, signature } => { let data = account.using_encoded(to_ascii_hex); - match signature { - MultiAddressSignature::EVM(ethereum_signature) => - (Self::eth_recover(ðereum_signature, &data, &[][..]), None), - MultiAddressSignature::Native(sr25519_signature) => - (Self::sr25519_recover(&sr25519_signature, &data, &[][..]), None), + match Self::get_signer_multi_address( + signer.clone(), + signature.clone(), + data, + vec![], + ) { + Ok(signer) => (Some(signer), None), + Err(_) => (None, None), } }, // // The weight of this logic is included in the `claim_attest` dispatchable. // - Call::claim_attest { dest: account, signature, statement } => { + Call::claim_attest { dest: account, signer, signature, statement } => { let data = account.using_encoded(to_ascii_hex); - match signature { - MultiAddressSignature::EVM(ethereum_signature) => ( - Self::eth_recover(ðereum_signature, &data, &statement[..]), - Some(statement.as_slice()), - ), - MultiAddressSignature::Native(sr25519_signature) => ( - Self::sr25519_recover(&sr25519_signature, &data, &statement[..]), - Some(statement.as_slice()), - ), + match Self::get_signer_multi_address( + signer.clone(), + signature.clone(), + data, + statement.clone(), + ) { + Ok(signer) => (Some(signer), Some(statement.as_slice())), + Err(_) => (None, None), } }, _ => return Err(InvalidTransaction::Call.into()), @@ -542,10 +540,24 @@ impl Pallet { Some(MultiAddress::EVM(res)) } + // Constructs the message that PolkadotJS would sign. + fn polkadotjs_signable_message(what: &[u8], extra: &[u8]) -> Vec { + let prefix = T::Prefix::get(); + let mut v = prefix.to_vec(); + v.extend_from_slice(what); + v.extend_from_slice(extra); + v + } + // Attempts to recover the Substrate address from a message signature signed by using // the Substrate RPC's `sign`. - fn sr25519_recover(_s: &Sr25519Signature, what: &[u8], extra: &[u8]) -> Option { - let _msg = keccak_256(&Self::ethereum_signable_message(what, extra)); + fn sr25519_recover( + addr: MultiAddress, + s: &Sr25519Signature, + what: &[u8], + extra: &[u8], + ) -> Option { + let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra)); let res = AccountId32::new([0; 32]); Some(MultiAddress::Native(res)) } @@ -558,12 +570,12 @@ impl Pallet { let balance_due = >::get(&signer).ok_or(Error::::SignerHasNoClaim)?; let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::::PotUnderflow)?; - + // If there is a destination, then we need to transfer the balance to it. let recipient = match dest { Some(d) => d, None => signer.clone(), }; - + // Convert the destination recipient to an account ID. let recipient = Self::convert_multi_address_to_account_id(recipient)?; let vesting = Vesting::::get(&signer); @@ -594,7 +606,7 @@ impl Pallet { } fn get_signer_multi_address( - _dest: Option, + signer: Option, signature: MultiAddressSignature, data: Vec, statement: Vec, @@ -603,14 +615,17 @@ impl Pallet { MultiAddressSignature::EVM(ethereum_signature) => Self::eth_recover(ðereum_signature, &data, &statement[..]) .ok_or(Error::::InvalidEthereumSignature)?, - MultiAddressSignature::Native(sr25519_signature) => - Self::sr25519_recover(&sr25519_signature, &data, &statement[..]) - .ok_or(Error::::InvalidNativeSignature)?, + MultiAddressSignature::Native(sr25519_signature) => { + ensure!(signer.is_none(), Error::::InvalidNativeAccount); + Self::sr25519_recover(signer.unwrap(), &sr25519_signature, &data, &statement[..]) + .ok_or(Error::::InvalidNativeSignature)? + }, }; Ok(signer) } + /// Convert a MultiAddress to an AccountId fn convert_multi_address_to_account_id(dest: MultiAddress) -> Result> { let account = match dest { MultiAddress::EVM(a) => T::AddressMapping::into_account_id(H160::from(a)), @@ -652,3 +667,27 @@ mod secp_utils { MultiAddressSignature::EVM(EcdsaSignature(r)) } } + +#[cfg(any(test, feature = "runtime-benchmarks"))] +mod sr25519_utils { + use super::*; + use sp_core::{sr25519, Pair}; + + pub fn public(pair: &sr25519::Pair) -> sr25519::Public { + pair.public() + } + + pub fn sub(pair: &sr25519::Pair) -> MultiAddress { + MultiAddress::Native(pair.public().into()) + } + + pub fn sig( + pair: &sr25519::Pair, + what: &[u8], + extra: &[u8], + ) -> MultiAddressSignature { + let sig = pair + .sign(&>::polkadotjs_signable_message(&to_ascii_hex(what)[..], extra)); + MultiAddressSignature::Native(Sr25519Signature(sig)) + } +} diff --git a/pallets/claims/src/mock.rs b/pallets/claims/src/mock.rs index 27c25816d..faec7962e 100644 --- a/pallets/claims/src/mock.rs +++ b/pallets/claims/src/mock.rs @@ -1,11 +1,11 @@ use super::*; use pallet_evm::HashedAddressMapping; use secp_utils::*; -use sp_core::H256; +use sp_core::{sr25519, Pair, H256}; use sp_std::convert::TryFrom; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. -use crate::pallet as pallet_airdrop_claims; +use crate::{pallet as pallet_airdrop_claims, sr25519_utils::sub}; use frame_support::{ ord_parameter_types, parameter_types, traits::{OnFinalize, OnInitialize, WithdrawReasons}, @@ -140,6 +140,14 @@ pub fn get_multi_address_account_id(id: u8) -> MultiAddress { MultiAddress::Native(AccountId32::new([id; 32])) } +pub fn alice_sr25519() -> sr25519::Pair { + sr25519::Pair::from_string(&format!("//Alice"), None).expect("static values are valid; qed") +} + +pub fn bob_sr25519() -> sr25519::Pair { + sr25519::Pair::from_string(&format!("//Bob"), None).expect("static values are valid; qed") +} + // This function basically just builds a genesis storage key/value store according to // our desired mockup. pub fn new_test_ext() -> sp_io::TestExternalities { @@ -154,6 +162,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { (eth(&dave()), 200, Some(StatementKind::Regular)), (eth(&eve()), 300, Some(StatementKind::Safe)), (eth(&frank()), 400, None), + (sub(&alice_sr25519()), 500, None), + (sub(&bob_sr25519()), 600, None), ], vesting: vec![(eth(&alice()), (50, 10, 1))], expiry: None, diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index f4410068b..7440bda3c 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -1,5 +1,5 @@ use super::*; -use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::DispatchError}; +use frame_support::pallet_prelude::DispatchError; use hex_literal::hex; use parity_scale_codec::Encode; use secp_utils::*; @@ -9,8 +9,7 @@ use sp_runtime::TokenError::Frozen; // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use crate::{mock::new_test_ext, pallet::Call as ClaimsCall}; use frame_support::{ - assert_err, assert_noop, assert_ok, - dispatch::{DispatchError::BadOrigin, Pays}, + assert_err, assert_noop, assert_ok, dispatch::DispatchError::BadOrigin, traits::ExistenceRequirement, }; use sp_runtime::transaction_validity::TransactionLongevity; @@ -18,7 +17,7 @@ use sp_runtime::transaction_validity::TransactionLongevity; use crate::mock::*; fn total_claims() -> u64 { - 100 + 200 + 300 + 400 + 100 + 200 + 300 + 400 + 500 + 600 } #[test] @@ -44,8 +43,17 @@ fn eth_signature_works() { _ => panic!("should be evm signature"), }; - assert_eq!(ClaimsPallet::eth_recover(&sig, &to_ascii_hex(&data), &[][..]), Some(eth(&alice()))); - assert!(ClaimsPallet::eth_recover(&sig, &Some(get_multi_address_account_id(43)).encode(), &[][..]) != Some(eth(&alice()))); + assert_eq!( + ClaimsPallet::eth_recover(&sig, &to_ascii_hex(&data), &[][..]), + Some(eth(&alice())) + ); + assert!( + ClaimsPallet::eth_recover( + &sig, + &Some(get_multi_address_account_id(43)).encode(), + &[][..] + ) != Some(eth(&alice())) + ); }); } @@ -65,10 +73,17 @@ fn claiming_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 100 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), + Some(50) + ); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -94,6 +109,7 @@ fn basic_claim_moving_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -101,10 +117,17 @@ fn basic_claim_moving_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&bob(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 100); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 100 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(42).to_account_id_32()), + Some(50) + ); assert_eq!(ClaimsPallet::total(), total_claims() - 100); }); } @@ -125,10 +148,14 @@ fn claim_attest_moving_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 200 + ); }); } @@ -138,12 +165,14 @@ fn claiming_does_not_bypass_signing() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&dave(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, @@ -152,6 +181,7 @@ fn claiming_does_not_bypass_signing() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&eve(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::InvalidStatement, @@ -159,6 +189,7 @@ fn claiming_does_not_bypass_signing() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); }); @@ -169,14 +200,11 @@ fn attest_claiming_works() { new_test_ext().execute_with(|| { assert_eq!(Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), 0); let data = Some(get_multi_address_account_id(42)).encode(); - let s = sig::( - &dave(), - &data, - StatementKind::Safe.to_text(), - ); + let s = sig::(&dave(), &data, StatementKind::Safe.to_text()); let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s.clone(), StatementKind::Safe.to_text().to_vec(), ); @@ -185,6 +213,7 @@ fn attest_claiming_works() { let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec(), ); @@ -200,10 +229,14 @@ fn attest_claiming_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(&get_multi_address_account_id(42).to_account_id_32()), + 200 + ); assert_eq!(ClaimsPallet::total(), total_claims() - 200); let s = sig::( @@ -214,6 +247,7 @@ fn attest_claiming_works() { let r = ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s, StatementKind::Regular.to_text().to_vec(), ); @@ -229,6 +263,7 @@ fn cannot_bypass_attest_claiming() { let r = ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, s.clone(), ); assert_noop!(r, Error::::InvalidStatement); @@ -253,6 +288,7 @@ fn add_claim_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, @@ -262,10 +298,17 @@ fn add_claim_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), None); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), + None + ); assert_eq!(ClaimsPallet::total(), total_claims()); }); } @@ -288,6 +331,7 @@ fn add_claim_with_vesting_works() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim, @@ -302,10 +346,17 @@ fn add_claim_with_vesting_works() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); - assert_eq!(VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), Some(50)); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); + assert_eq!( + VestingPallet::vesting_balance(&get_multi_address_account_id(69).to_account_id_32()), + Some(50) + ); // Make sure we can not transfer the vested balance. assert_err!( @@ -344,6 +395,7 @@ fn add_claim_with_statement_works() { ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), StatementKind::Regular.to_text().to_vec() ), @@ -360,6 +412,7 @@ fn add_claim_with_statement_works() { ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), vec![], ), @@ -368,10 +421,14 @@ fn add_claim_with_statement_works() { assert_ok!(ClaimsPallet::claim_attest( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, signature.clone(), StatementKind::Regular.to_text().to_vec() )); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), 200); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + 200 + ); }); } @@ -383,6 +440,7 @@ fn origin_signed_claiming_fail() { ClaimsPallet::claim( RuntimeOrigin::signed(get_multi_address_account_id(42).to_account_id_32()), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), sp_runtime::traits::BadOrigin, @@ -397,12 +455,14 @@ fn double_claiming_doesnt_work() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_noop!( ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -413,8 +473,14 @@ fn double_claiming_doesnt_work() { #[test] fn claiming_while_vested_doesnt_work() { new_test_ext().execute_with(|| { - CurrencyOf::::make_free_balance_be(&get_multi_address_account_id(69).to_account_id_32(), total_claims()); - assert_eq!(Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), total_claims()); + CurrencyOf::::make_free_balance_be( + &get_multi_address_account_id(69).to_account_id_32(), + total_claims(), + ); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(69).to_account_id_32()), + total_claims() + ); // A user is already vested assert_ok!(::VestingSchedule::add_vesting_schedule( &get_multi_address_account_id(69).to_account_id_32(), @@ -437,6 +503,7 @@ fn claiming_while_vested_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(69)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::VestedBalanceExists, @@ -452,6 +519,7 @@ fn non_sender_sig_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -467,6 +535,7 @@ fn non_claimant_doesnt_work() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&bob(), &Some(get_multi_address_account_id(69)).encode(), &[][..]) ), Error::::SignerHasNoClaim @@ -497,6 +566,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: sig::( &alice(), &Some(get_multi_address_account_id(1)).encode(), @@ -517,6 +587,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(0)), + signer: None, signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])) } ), @@ -527,6 +598,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: sig::( &bob(), &Some(get_multi_address_account_id(1)).encode(), @@ -543,6 +615,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -561,6 +634,7 @@ fn validate_unsigned_works() { source, &ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: MultiAddressSignature::EVM(EcdsaSignature([0; 65])), statement: StatementKind::Regular.to_text().to_vec() } @@ -575,6 +649,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -590,6 +665,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Regular.to_text().to_vec(), }; @@ -605,6 +681,7 @@ fn validate_unsigned_works() { ); let call = ClaimsCall::claim_attest { dest: Some(get_multi_address_account_id(1)), + signer: None, signature: s, statement: StatementKind::Safe.to_text().to_vec(), }; @@ -623,6 +700,7 @@ fn test_unclaimed_returned_to_destination() { assert_ok!(ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&alice(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) )); assert_eq!(Total::::get(), original_total_claims - claim_of_alice); @@ -649,6 +727,7 @@ fn test_unclaimed_returned_to_destination() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), + None, sig::(&frank(), &Some(get_multi_address_account_id(42)).encode(), &[][..]) ), Error::::PotUnderflow diff --git a/pallets/claims/src/utils/mod.rs b/pallets/claims/src/utils/mod.rs index 637db603e..b781302a9 100644 --- a/pallets/claims/src/utils/mod.rs +++ b/pallets/claims/src/utils/mod.rs @@ -6,7 +6,7 @@ use scale_info::{ }; #[cfg(feature = "std")] use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; -use sp_core::{H160}; +use sp_core::{sr25519::Signature, H160}; use sp_runtime::{traits::BlakeTwo256, AccountId32, RuntimeDebug}; use sp_std::prelude::*; @@ -39,23 +39,11 @@ impl MultiAddress { } } -#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub enum MultiAddressSignature { EVM(EcdsaSignature), Native(Sr25519Signature), } -#[derive(Clone, Copy, Eq, Encode, Decode, TypeInfo)] -pub struct Sr25519Signature(pub [u8; 65]); - -impl PartialEq for Sr25519Signature { - fn eq(&self, other: &Self) -> bool { - &self.0[..] == &other.0[..] - } -} - -impl sp_std::fmt::Debug for Sr25519Signature { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { - write!(f, "Sr25519Signature({:?})", &self.0[..]) - } -} +#[derive(Clone, Eq, Encode, PartialEq, Decode, TypeInfo, RuntimeDebug)] +pub struct Sr25519Signature(pub Signature); From a3388514476287c3bdd538512651242ead3eed72 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Mon, 4 Dec 2023 12:49:04 -0700 Subject: [PATCH 05/10] Updates build and work on substrate to evm test --- pallets/claims/src/lib.rs | 15 ++++-- pallets/claims/src/tests.rs | 51 ++++++++++++++++++++ pallets/claims/src/utils/ethereum_address.rs | 2 + 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 99a357a44..f38695d83 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -42,6 +42,7 @@ pub use pallet::*; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; +use schnorrkel::{signing_context, PublicKey, Signature}; use serde::{self, Deserialize, Serialize}; use sp_core::H160; use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; @@ -558,8 +559,16 @@ impl Pallet { extra: &[u8], ) -> Option { let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra)); - let res = AccountId32::new([0; 32]); - Some(MultiAddress::Native(res)) + let pk: PublicKey = match addr.clone() { + MultiAddress::EVM(_) => return None, + MultiAddress::Native(a) => PublicKey::from_bytes(&a.encode()).ok()?, + }; + let signature: Signature = Signature::from_bytes(&s.0.encode()).ok()?; + const SIGNING_CTX: &'static [u8] = b"substrate"; + match pk.verify_simple(SIGNING_CTX, &msg, &signature) { + Ok(_) => Some(addr), + Err(_) => None, + } } fn process_claim( @@ -616,7 +625,7 @@ impl Pallet { Self::eth_recover(ðereum_signature, &data, &statement[..]) .ok_or(Error::::InvalidEthereumSignature)?, MultiAddressSignature::Native(sr25519_signature) => { - ensure!(signer.is_none(), Error::::InvalidNativeAccount); + ensure!(!signer.is_none(), Error::::InvalidNativeAccount); Self::sr25519_recover(signer.unwrap(), &sr25519_signature, &data, &statement[..]) .ok_or(Error::::InvalidNativeSignature)? }, diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index 7440bda3c..af06ec025 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -734,3 +734,54 @@ fn test_unclaimed_returned_to_destination() { ); }); } + +#[test] +fn test_claim_from_substrate_address_to_evm() { + new_test_ext().execute_with(|| { + let original_total_claims = Total::::get(); + let claim_of_sub_alice = 500; + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + Some(sr25519_utils::sub(&alice_sr25519())), + sr25519_utils::sig::( + &alice_sr25519(), + &Some(get_multi_address_account_id(42)).encode(), + &[][..] + ) + )); + assert_eq!(Total::::get(), original_total_claims - claim_of_sub_alice); + + // force set the expiry config + assert_ok!(ClaimsPallet::force_set_expiry_config( + RuntimeOrigin::root(), + 5, + get_multi_address_account_id(100) + )); + + // run to after expiry block + run_to_block(7); + assert_eq!(Total::::get(), 0); + // the dest account should receive the remaining pot balance + assert_eq!( + Balances::free_balance(get_multi_address_account_id(100).to_account_id_32()), + original_total_claims - claim_of_sub_alice + ); + + // all further claims should fail with PotUnderflow error since the funds have been + // emptied + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + None, + sr25519_utils::sig::( + &bob_sr25519(), + &Some(get_multi_address_account_id(42)).encode(), + &[][..] + ) + ), + Error::::PotUnderflow + ); + }); +} diff --git a/pallets/claims/src/utils/ethereum_address.rs b/pallets/claims/src/utils/ethereum_address.rs index 60f814b35..c8e8dfc6c 100644 --- a/pallets/claims/src/utils/ethereum_address.rs +++ b/pallets/claims/src/utils/ethereum_address.rs @@ -1,5 +1,7 @@ use super::*; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + /// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account). /// /// This gets serialized to the 0x-prefixed hex representation. From 09acb285d1559d0537a510831e54222542d60a76 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Mon, 4 Dec 2023 12:51:09 -0700 Subject: [PATCH 06/10] Updates --- Cargo.toml | 5 ++--- pallets/claims/src/lib.rs | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e74b27678..80334d86e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ members = [ "standalone/runtime", "standalone/runtime/evm_tracer", "pallets/*", - "pallets/roles", + "pallets/roles", "pallets/jobs/rpc", "pallets/jobs/rpc/runtime-api", "precompiles/utils", @@ -68,6 +68,7 @@ syn = { version = "1.0" } hex = { version = "0.4.3", default-features = false } paste = "1.0.6" slices = "0.2.0" +schnorrkel = { verison = "11.4", default-features = false } # DKG Substrate Dependencies dkg-runtime-primitives = { git = "https://github.com/webb-tools/dkg-substrate.git", tag = "v0.4.7", default-features = false } @@ -309,7 +310,5 @@ rpc-trace = { path = "client/rpc/trace" } rpc-txpool = { path = "client/rpc/txpool" } evm-tracer = { path = "standalone/runtime/evm_tracer", default-features = false } -schnorrkel = { verison = "11.4", default-features = false } - [profile.release] panic = "unwind" diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index f38695d83..37da9d22e 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -563,7 +563,9 @@ impl Pallet { MultiAddress::EVM(_) => return None, MultiAddress::Native(a) => PublicKey::from_bytes(&a.encode()).ok()?, }; + println!("pk: {:?}", pk); let signature: Signature = Signature::from_bytes(&s.0.encode()).ok()?; + println!("signature: {:?}", signature); const SIGNING_CTX: &'static [u8] = b"substrate"; match pk.verify_simple(SIGNING_CTX, &msg, &signature) { Ok(_) => Some(addr), From 958fae75ec2c97785abfdbd4c45b3cdd23b285a0 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Mon, 4 Dec 2023 21:13:57 -0700 Subject: [PATCH 07/10] Tests using sr25519 signatures --- Cargo.toml | 1 + pallets/claims/src/lib.rs | 51 ++++++++++++----- pallets/claims/src/tests.rs | 58 +++++++++++++++++++- pallets/claims/src/utils/ethereum_address.rs | 3 + pallets/claims/src/utils/mod.rs | 5 +- standalone/runtime/src/lib.rs | 15 +++++ 6 files changed, 114 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80334d86e..01a8a2ed4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ members = [ "standalone/runtime", "standalone/runtime/evm_tracer", "pallets/*", + "pallets/claims", "pallets/roles", "pallets/jobs/rpc", "pallets/jobs/rpc/runtime-api", diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 37da9d22e..341be4863 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -44,8 +44,11 @@ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use schnorrkel::{signing_context, PublicKey, Signature}; use serde::{self, Deserialize, Serialize}; -use sp_core::H160; -use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256}; +use sp_core::{sr25519::Public, H160}; +use sp_io::{ + crypto::{secp256k1_ecdsa_recover, sr25519_verify}, + hashing::keccak_256, +}; use sp_runtime::{ traits::{CheckedSub, SignedExtension, Zero}, transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction}, @@ -234,7 +237,6 @@ pub mod pallet { fn build(&self) { // build `Claims` self.claims.iter().map(|(a, b, _)| (a.clone(), b.clone())).for_each(|(a, b)| { - println!("a: {:?}, b: {:?}", a, b); Claims::::insert(a, b); }); // build `Total` @@ -559,25 +561,36 @@ impl Pallet { extra: &[u8], ) -> Option { let msg = keccak_256(&Self::polkadotjs_signable_message(what, extra)); - let pk: PublicKey = match addr.clone() { + let public: Public = match addr.clone() { MultiAddress::EVM(_) => return None, - MultiAddress::Native(a) => PublicKey::from_bytes(&a.encode()).ok()?, + MultiAddress::Native(a) => { + let mut bytes = [0u8; 32]; + bytes.copy_from_slice(&addr.to_account_id_32().encode()); + Public(bytes) + }, }; - println!("pk: {:?}", pk); - let signature: Signature = Signature::from_bytes(&s.0.encode()).ok()?; - println!("signature: {:?}", signature); - const SIGNING_CTX: &'static [u8] = b"substrate"; - match pk.verify_simple(SIGNING_CTX, &msg, &signature) { - Ok(_) => Some(addr), - Err(_) => None, + match sr25519_verify(&s.0, &msg, &public) { + true => Some(addr), + false => None, } + // let pk: PublicKey = match addr.clone() { + // MultiAddress::EVM(_) => return None, + // MultiAddress::Native(a) => PublicKey::from_bytes(&a.encode()).ok()?, + // }; + // println!("pk: {:?}", pk); + // let signature: Signature = Signature::from_bytes(&s.0.encode()).ok()?; + // println!("signature: {:?}", signature); + // const SIGNING_CTX: &'static [u8] = b"substrate"; + // match pk.verify_simple(SIGNING_CTX, &msg, &signature) { + // Ok(_) => Some(addr), + // Err(_) => None, + // } } fn process_claim( signer: MultiAddress, dest: Option, ) -> sp_runtime::DispatchResult { - println!("process_claim: signer: {:?}, dest: {:?}", signer, dest); let balance_due = >::get(&signer).ok_or(Error::::SignerHasNoClaim)?; let new_total = Self::total().checked_sub(&balance_due).ok_or(Error::::PotUnderflow)?; @@ -682,6 +695,7 @@ mod secp_utils { #[cfg(any(test, feature = "runtime-benchmarks"))] mod sr25519_utils { use super::*; + use frame_support::assert_ok; use sp_core::{sr25519, Pair}; pub fn public(pair: &sr25519::Pair) -> sr25519::Public { @@ -697,8 +711,15 @@ mod sr25519_utils { what: &[u8], extra: &[u8], ) -> MultiAddressSignature { - let sig = pair - .sign(&>::polkadotjs_signable_message(&to_ascii_hex(what)[..], extra)); + let msg = keccak_256(&>::polkadotjs_signable_message( + &to_ascii_hex(what)[..], + extra, + )); + let sig = pair.sign(&msg); + let pk = schnorrkel::PublicKey::from_bytes(&pair.public().0).unwrap(); + let signature = Signature::from_bytes(&sig.0).unwrap(); + let res = pk.verify_simple(b"substrate", &msg, &signature); + assert_ok!(res); MultiAddressSignature::Native(Sr25519Signature(sig)) } } diff --git a/pallets/claims/src/tests.rs b/pallets/claims/src/tests.rs index af06ec025..4da9a833e 100644 --- a/pallets/claims/src/tests.rs +++ b/pallets/claims/src/tests.rs @@ -751,7 +751,24 @@ fn test_claim_from_substrate_address_to_evm() { ) )); assert_eq!(Total::::get(), original_total_claims - claim_of_sub_alice); - + assert_eq!( + Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), + 500 + ); + // Claim bob without providing signer value (needed for sr25519 signatures) + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + None, + sr25519_utils::sig::( + &bob_sr25519(), + &Some(get_multi_address_account_id(42)).encode(), + &[][..] + ) + ), + Error::::InvalidNativeAccount + ); // force set the expiry config assert_ok!(ClaimsPallet::force_set_expiry_config( RuntimeOrigin::root(), @@ -774,7 +791,7 @@ fn test_claim_from_substrate_address_to_evm() { ClaimsPallet::claim( RuntimeOrigin::none(), Some(get_multi_address_account_id(42)), - None, + Some(sr25519_utils::sub(&bob_sr25519())), sr25519_utils::sig::( &bob_sr25519(), &Some(get_multi_address_account_id(42)).encode(), @@ -785,3 +802,40 @@ fn test_claim_from_substrate_address_to_evm() { ); }); } + +#[test] +fn test_double_claim_fails_for_substrate_account() { + new_test_ext().execute_with(|| { + let original_total_claims = Total::::get(); + let claim_of_sub_alice = 500; + assert_ok!(ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + Some(sr25519_utils::sub(&alice_sr25519())), + sr25519_utils::sig::( + &alice_sr25519(), + &Some(get_multi_address_account_id(42)).encode(), + &[][..] + ) + )); + assert_eq!(Total::::get(), original_total_claims - claim_of_sub_alice); + assert_eq!( + Balances::free_balance(get_multi_address_account_id(42).to_account_id_32()), + 500 + ); + // Claim for Alice again and expect the proper error + assert_noop!( + ClaimsPallet::claim( + RuntimeOrigin::none(), + Some(get_multi_address_account_id(42)), + Some(sr25519_utils::sub(&alice_sr25519())), + sr25519_utils::sig::( + &alice_sr25519(), + &Some(get_multi_address_account_id(42)).encode(), + &[][..] + ) + ), + Error::::SignerHasNoClaim + ); + }); +} diff --git a/pallets/claims/src/utils/ethereum_address.rs b/pallets/claims/src/utils/ethereum_address.rs index c8e8dfc6c..cd3bc7573 100644 --- a/pallets/claims/src/utils/ethereum_address.rs +++ b/pallets/claims/src/utils/ethereum_address.rs @@ -1,5 +1,6 @@ use super::*; +#[cfg(feature = "std")] use serde::{Deserialize, Deserializer, Serialize, Serializer}; /// An Ethereum address (i.e. 20 bytes, used to represent an Ethereum account). @@ -8,6 +9,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, Default, RuntimeDebug, TypeInfo)] pub struct EthereumAddress(pub [u8; 20]); +#[cfg(feature = "std")] impl Serialize for EthereumAddress { fn serialize(&self, serializer: S) -> Result where @@ -18,6 +20,7 @@ impl Serialize for EthereumAddress { } } +#[cfg(feature = "std")] impl<'de> Deserialize<'de> for EthereumAddress { fn deserialize(deserializer: D) -> Result where diff --git a/pallets/claims/src/utils/mod.rs b/pallets/claims/src/utils/mod.rs index b781302a9..98c1d70ef 100644 --- a/pallets/claims/src/utils/mod.rs +++ b/pallets/claims/src/utils/mod.rs @@ -5,7 +5,7 @@ use scale_info::{ TypeInfo, }; #[cfg(feature = "std")] -use serde::{self, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{self, Deserialize, Serialize}; use sp_core::{sr25519::Signature, H160}; use sp_runtime::{traits::BlakeTwo256, AccountId32, RuntimeDebug}; use sp_std::prelude::*; @@ -14,7 +14,8 @@ pub mod ethereum_address; use ethereum_address::{EcdsaSignature, EthereumAddress}; -#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, Serialize, Deserialize)] +#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo)] +#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] pub enum MultiAddress { /// Claimer is Ethereum address EVM(EthereumAddress), diff --git a/standalone/runtime/src/lib.rs b/standalone/runtime/src/lib.rs index 887db12f4..f976b382f 100644 --- a/standalone/runtime/src/lib.rs +++ b/standalone/runtime/src/lib.rs @@ -1082,6 +1082,20 @@ impl pallet_eth2_light_client::Config for Runtime { type Currency = Balances; } +parameter_types! { + pub Prefix: &'static [u8] = b"Claim TNTs to the account:"; +} + +impl pallet_airdrop_claims::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type VestingSchedule = Vesting; + type ForceOrigin = frame_system::EnsureRoot; + type AddressMapping = HashedAddressMapping; + type Prefix = Prefix; + type MoveClaimOrigin = frame_system::EnsureRoot; + type WeightInfo = (); +} + pub struct BaseFilter; impl Contains for BaseFilter { fn contains(call: &RuntimeCall) -> bool { @@ -1192,6 +1206,7 @@ construct_runtime!( HotfixSufficients: pallet_hotfix_sufficients, Eth2Client: pallet_eth2_light_client, + Claims: pallet_airdrop_claims, } ); From a2ea8b2554af2efae6eb9e88255be39bc9714f74 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Mon, 4 Dec 2023 22:26:22 -0700 Subject: [PATCH 08/10] Update deps --- Cargo.lock | 1123 +++++++++++----------------------------------------- Cargo.toml | 8 +- 2 files changed, 242 insertions(+), 889 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 401393d9c..00af8a69f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -765,12 +765,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-std" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" - [[package]] name = "async-stream" version = "0.3.5" @@ -1726,23 +1720,6 @@ dependencies = [ "vec_map", ] -[[package]] -name = "clap" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" -dependencies = [ - "atty", - "bitflags 1.3.2", - "clap_derive 3.2.25", - "clap_lex 0.2.4", - "indexmap 1.9.3", - "once_cell", - "strsim 0.10.0", - "termcolor", - "textwrap 0.16.0", -] - [[package]] name = "clap" version = "4.4.2" @@ -1750,7 +1727,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" dependencies = [ "clap_builder", - "clap_derive 4.4.2", + "clap_derive", ] [[package]] @@ -1761,23 +1738,10 @@ checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" dependencies = [ "anstream", "anstyle", - "clap_lex 0.5.1", + "clap_lex", "strsim 0.10.0", ] -[[package]] -name = "clap_derive" -version = "3.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" -dependencies = [ - "heck 0.4.1", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "clap_derive" version = "4.4.2" @@ -1790,15 +1754,6 @@ dependencies = [ "syn 2.0.31", ] -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - [[package]] name = "clap_lex" version = "0.5.1" @@ -2967,7 +2922,7 @@ dependencies = [ "dkg-logging", "dkg-mock-blockchain", "dkg-primitives", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "futures 0.3.28", "hex", "itertools 0.10.5", @@ -3001,7 +2956,7 @@ dependencies = [ "tokio 1.32.0", "tokio-stream", "uuid 1.4.1", - "webb-proposals 0.6.0", + "webb-proposals", "wsts", ] @@ -3032,7 +2987,7 @@ dependencies = [ "bincode2", "bytes 1.4.0", "dkg-logging", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "futures 0.3.28", "humantime-serde", "log", @@ -3057,7 +3012,7 @@ dependencies = [ "chacha20poly1305", "clap 4.4.2", "curv-kzen", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "hex", "libsecp256k1", "log", @@ -3073,29 +3028,6 @@ dependencies = [ "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", ] -[[package]] -name = "dkg-runtime-primitives" -version = "0.0.1" -source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.4#43761d96bdcbee283deeda93ce074422d7cf4bca" -dependencies = [ - "ethabi", - "ethereum", - "ethereum-types", - "frame-support", - "frame-system", - "impl-trait-for-tuples", - "parity-scale-codec", - "scale-info", - "sp-api", - "sp-application-crypto 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-io 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "tiny-keccak", - "webb-proposals 0.6.0", -] - [[package]] name = "dkg-runtime-primitives" version = "0.0.1" @@ -3116,7 +3048,7 @@ dependencies = [ "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "tiny-keccak", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] @@ -3523,8 +3455,8 @@ dependencies = [ [[package]] name = "eth-types" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "derive_more", "ethereum-types", @@ -3543,15 +3475,14 @@ dependencies = [ [[package]] name = "eth2-to-substrate-relay" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "anyhow", - "async-std", "async-trait", "atomic_refcell", + "backoff", "bitvec", - "clap 3.2.25", "dotenvy", "env_logger 0.9.3", "eth-types", @@ -3571,19 +3502,20 @@ dependencies = [ "serde_json", "sp-core 16.0.0", "sp-keyring 18.0.0", - "thread", "tokio 1.32.0", "toml 0.5.11", + "tracing", "types", "warp", - "webb 0.5.25", + "webb 0.7.4", "webb-consensus-types", "webb-eth-rpc-client", "webb-eth2-pallet-init", "webb-finality-update-verify", + "webb-lc-relay-config", + "webb-lc-relayer-context", "webb-merkle-proof", - "webb-proposals 0.6.0", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer.git)", + "webb-proposals", "webb-tree-hash", ] @@ -8030,12 +7962,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" -[[package]] -name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - [[package]] name = "overload" version = "0.1.1" @@ -8233,7 +8159,7 @@ name = "pallet-bridge-registry" version = "1.0.0" source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7#e20c92d8c4e874162dd0245a82a5af4447bf9d4a" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "frame-support", "frame-system", "hex", @@ -8243,7 +8169,7 @@ dependencies = [ "serde", "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] @@ -8326,7 +8252,7 @@ name = "pallet-dkg-metadata" version = "0.2.0" source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7#e20c92d8c4e874162dd0245a82a5af4447bf9d4a" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "frame-benchmarking", "frame-support", "frame-system", @@ -8340,7 +8266,7 @@ dependencies = [ "sp-io 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] @@ -8348,7 +8274,7 @@ name = "pallet-dkg-proposal-handler" version = "0.1.0" source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7#e20c92d8c4e874162dd0245a82a5af4447bf9d4a" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "ethabi", "frame-benchmarking", "frame-support", @@ -8362,7 +8288,7 @@ dependencies = [ "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-staking", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] @@ -8370,7 +8296,7 @@ name = "pallet-dkg-proposals" version = "1.0.0" source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7#e20c92d8c4e874162dd0245a82a5af4447bf9d4a" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "frame-benchmarking", "frame-support", "frame-system", @@ -8463,8 +8389,10 @@ dependencies = [ [[package]] name = "pallet-eth2-light-client" version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ + "anyhow", + "async-trait", "bitvec", "derive_more", "eth-types", @@ -8472,6 +8400,7 @@ dependencies = [ "frame-support", "frame-system", "hex", + "lazy_static", "log", "pallet-balances", "parity-scale-codec", @@ -8479,49 +8408,45 @@ dependencies = [ "rlp-derive", "scale-info", "serde", + "serde_json", "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-runtime 24.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-std 8.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "tiny-keccak", "webb-bls", "webb-consensus-types", + "webb-eth2-pallet-init", "webb-eth2-ssz", + "webb-light-client-primitives", "webb-merkle-proof", - "webb-proposals 0.6.0", + "webb-proposals", "webb-tree-hash", "webb-tree-hash-derive", ] [[package]] name = "pallet-eth2-light-client-relayer-gadget" -version = "0.0.1" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "anyhow", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.4)", + "async-trait", + "backoff", "eth2-to-substrate-relay", "ethereum-types", - "pallet-eth2-light-client-relayer-gadget-cli", - "sc-keystore", - "sp-application-crypto 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-core 21.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "sp-keystore 0.27.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", - "subxt 0.29.0", + "subxt", "tokio 1.32.0", "tracing", "webb-eth2-pallet-init", - "webb-proposals 0.6.0", - "webb-relayer 0.5.7-dev", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-types 0.5.7-dev", + "webb-lc-relay-config", + "webb-lc-relayer-context", + "webb-proposals", ] [[package]] name = "pallet-eth2-light-client-relayer-gadget-cli" version = "0.0.1" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "clap 4.4.2", ] @@ -8829,7 +8754,7 @@ name = "pallet-evm-precompile-staking" version = "1.0.0" dependencies = [ "derive_more", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "fp-evm", "frame-election-provider-support", "frame-support", @@ -12451,18 +12376,6 @@ dependencies = [ "serde", ] -[[package]] -name = "scale-decode" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d823d4be477fc33321f93d08fb6c2698273d044f01362dc27573a750deb7c233" -dependencies = [ - "parity-scale-codec", - "scale-bits", - "scale-info", - "thiserror", -] - [[package]] name = "scale-decode" version = "0.7.0" @@ -12545,23 +12458,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "scale-value" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a5e7810815bd295da73e4216d1dfbced3c7c7c7054d70fa5f6e4c58123fff4" -dependencies = [ - "either", - "frame-metadata 15.1.0", - "parity-scale-codec", - "scale-bits", - "scale-decode 0.4.0", - "scale-info", - "serde", - "thiserror", - "yap 0.7.2", -] - [[package]] name = "scale-value" version = "0.10.0" @@ -12574,12 +12470,12 @@ dependencies = [ "frame-metadata 15.1.0", "parity-scale-codec", "scale-bits", - "scale-decode 0.7.0", + "scale-decode", "scale-encode", "scale-info", "serde", "thiserror", - "yap 0.10.0", + "yap", ] [[package]] @@ -12591,30 +12487,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "schemars" -version = "0.8.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763f8cd0d4c71ed8389c90cb8100cba87e763bd01a8e614d4f0af97bcd50a161" -dependencies = [ - "dyn-clone", - "schemars_derive", - "serde", - "serde_json", -] - -[[package]] -name = "schemars_derive" -version = "0.8.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0f696e21e10fa546b7ffb1c9672c6de8fbc7a81acf59524386d8639bf12737" -dependencies = [ - "proc-macro2", - "quote", - "serde_derive_internals", - "syn 1.0.109", -] - [[package]] name = "schnellru" version = "0.2.1" @@ -12913,17 +12785,6 @@ dependencies = [ "syn 2.0.31", ] -[[package]] -name = "serde_derive_internals" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "serde_json" version = "1.0.105" @@ -15166,39 +15027,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" -[[package]] -name = "subxt" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54639dba6a113584083968b6a8f457dedae612abe1bd214762101ca29f12e332" -dependencies = [ - "base58", - "blake2 0.10.6", - "derivative", - "frame-metadata 15.1.0", - "futures 0.3.28", - "getrandom 0.2.10", - "hex", - "impl-serde", - "jsonrpsee", - "parity-scale-codec", - "parking_lot 0.12.1", - "primitive-types", - "scale-bits", - "scale-decode 0.4.0", - "scale-info", - "scale-value 0.6.0", - "serde", - "serde_json", - "sp-core 16.0.0", - "sp-core-hashing 6.0.0", - "sp-runtime 18.0.0", - "subxt-macro 0.27.1", - "subxt-metadata 0.27.1", - "thiserror", - "tracing", -] - [[package]] name = "subxt" version = "0.29.0" @@ -15218,42 +15046,21 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-bits", - "scale-decode 0.7.0", + "scale-decode", "scale-encode", "scale-info", - "scale-value 0.10.0", + "scale-value", "serde", "serde_json", "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-core-hashing 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-runtime 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "subxt-macro 0.29.0", - "subxt-metadata 0.29.0", + "subxt-macro", + "subxt-metadata", "thiserror", "tracing", ] -[[package]] -name = "subxt-codegen" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e86cb719003f1cedf2710a6e55ca4c37aba4c989bbd3b81dd1c52af9e4827e" -dependencies = [ - "darling 0.14.4", - "frame-metadata 15.1.0", - "heck 0.4.1", - "hex", - "jsonrpsee", - "parity-scale-codec", - "proc-macro-error", - "proc-macro2", - "quote", - "scale-info", - "subxt-metadata 0.27.1", - "syn 1.0.109", - "tokio 1.32.0", -] - [[package]] name = "subxt-codegen" version = "0.29.0" @@ -15268,24 +15075,12 @@ dependencies = [ "proc-macro2", "quote", "scale-info", - "subxt-metadata 0.29.0", + "subxt-metadata", "syn 2.0.31", "thiserror", "tokio 1.32.0", ] -[[package]] -name = "subxt-macro" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74c08de402a78c4c06c3ee3702c80e519efdcb65911348e018b6998d04404916" -dependencies = [ - "darling 0.14.4", - "proc-macro-error", - "subxt-codegen 0.27.1", - "syn 1.0.109", -] - [[package]] name = "subxt-macro" version = "0.29.0" @@ -15294,22 +15089,10 @@ checksum = "e544e41e1c84b616632cd2f86862342868f62e11e4cd9062a9e3dbf5fc871f64" dependencies = [ "darling 0.20.3", "proc-macro-error", - "subxt-codegen 0.29.0", + "subxt-codegen", "syn 2.0.31", ] -[[package]] -name = "subxt-metadata" -version = "0.27.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2593ab5f53435e6352675af4f9851342607f37785d84c7a3fb3139550d3c35f0" -dependencies = [ - "frame-metadata 15.1.0", - "parity-scale-codec", - "scale-info", - "sp-core-hashing 6.0.0", -] - [[package]] name = "subxt-metadata" version = "0.29.0" @@ -15458,7 +15241,7 @@ dependencies = [ "clap 4.4.2", "dkg-gadget", "dkg-primitives", - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "fc-cli", "fc-consensus", "fc-db", @@ -15530,7 +15313,7 @@ dependencies = [ "tokio 1.32.0", "wasmer", "webb-consensus-types", - "webb-proposals 0.6.0", + "webb-proposals", "webb-relayer-gadget", "webb-relayer-gadget-cli", ] @@ -15539,7 +15322,7 @@ dependencies = [ name = "tangle-standalone-runtime" version = "0.5.0" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "evm-tracer", "fp-account", "fp-evm", @@ -15649,7 +15432,7 @@ dependencies = [ "tokio 1.32.0", "tracing", "webb 0.8.0", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] @@ -15742,12 +15525,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.48" @@ -15774,12 +15551,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" -[[package]] -name = "thread" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afe9c0e959dd1e7b871071b51bc674380d1889cd4fed9f4b3b1f5c1772d9f796" - [[package]] name = "thread_local" version = "1.1.7" @@ -16529,15 +16300,15 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if 1.0.0", "digest 0.10.7", - "rand 0.8.5", + "rand 0.4.6", "static_assertions", ] [[package]] name = "typed-builder" -version = "0.10.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89851716b67b937e393b3daa8423e67ddfc4bbbf1654bcf05488e95e0828db0c" +checksum = "64cba322cb9b7bc6ca048de49e83918223f35e7a86311267013afff257004870" dependencies = [ "proc-macro2", "quote", @@ -16546,22 +16317,20 @@ dependencies = [ [[package]] name = "typed-builder" -version = "0.14.0" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cba322cb9b7bc6ca048de49e83918223f35e7a86311267013afff257004870" +checksum = "7fe83c85a85875e8c4cb9ce4a890f05b23d38cd0d47647db7895d3d2a79566d2" dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", + "typed-builder-macro 0.15.2", ] [[package]] name = "typed-builder" -version = "0.15.2" +version = "0.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe83c85a85875e8c4cb9ce4a890f05b23d38cd0d47647db7895d3d2a79566d2" +checksum = "34085c17941e36627a879208083e25d357243812c30e7d7387c3b954f30ade16" dependencies = [ - "typed-builder-macro", + "typed-builder-macro 0.16.2", ] [[package]] @@ -16575,6 +16344,17 @@ dependencies = [ "syn 2.0.31", ] +[[package]] +name = "typed-builder-macro" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f03ca4cb38206e2bef0700092660bb74d696f808514dae47fa1467cbfe26e96e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.31", +] + [[package]] name = "typenum" version = "1.16.0" @@ -17694,25 +17474,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webb" -version = "0.5.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c76407deeefaeb1315e0024317c84f5562777cc0fa2d6dba0ef323dd043d4" -dependencies = [ - "async-trait", - "ethers", - "hex", - "parity-scale-codec", - "rand 0.8.5", - "scale-info", - "serde", - "serde_json", - "subxt 0.27.1", - "tempfile", - "thiserror", -] - [[package]] name = "webb" version = "0.7.4" @@ -17728,7 +17489,7 @@ dependencies = [ "scale-info", "serde", "serde_json", - "subxt 0.29.0", + "subxt", "tempfile", "thiserror", ] @@ -17752,8 +17513,8 @@ dependencies = [ [[package]] name = "webb-bls" -version = "0.2.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "ethereum-types", "hex", @@ -17771,8 +17532,8 @@ dependencies = [ [[package]] name = "webb-bridge-registry-backends" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" +version = "0.5.12-dev" +source = "git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev#91098198be9377ebaa18699e309426ff08ef921e" dependencies = [ "async-trait", "ethereum-types", @@ -17783,47 +17544,13 @@ dependencies = [ "tokio 1.32.0", "typed-builder 0.15.2", "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-utils", ] [[package]] -name = "webb-bridge-registry-backends" -version = "0.5.12-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev#91098198be9377ebaa18699e309426ff08ef921e" -dependencies = [ - "async-trait", - "ethereum-types", - "futures 0.3.28", - "hex", - "hex-literal 0.3.4", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "typed-builder 0.15.2", - "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-chains-info" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "anyhow", - "prettyplease 0.2.14", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn 2.0.31", - "toml 0.7.6", -] - -[[package]] -name = "webb-chains-info" +name = "webb-chains-info" version = "0.5.12-dev" source = "git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev#91098198be9377ebaa18699e309426ff08ef921e" dependencies = [ @@ -17839,8 +17566,8 @@ dependencies = [ [[package]] name = "webb-consensus-types" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "bitvec", "derive_more", @@ -17855,7 +17582,6 @@ dependencies = [ "tiny-keccak", "webb-eth2-serde-utils", "webb-eth2-ssz", - "webb-eth2-ssz-derive", "webb-merkle-proof", "webb-tree-hash", "webb-tree-hash-derive", @@ -17863,43 +17589,35 @@ dependencies = [ [[package]] name = "webb-eth-rpc-client" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "anyhow", - "async-std", - "atomic_refcell", "bitvec", - "clap 3.2.25", "dotenv", - "env_logger 0.9.3", "eth-types", "ethereum-types", "ethereum_hashing", "ethereum_ssz", "funty", - "futures 0.3.28", "hex", "lazy_static", "log", "merkle_proof", - "prometheus 0.9.0", "reqwest", "serde", "serde_json", - "thread", "tokio 1.32.0", "toml 0.5.11", "tree_hash", "types", - "warp", - "webb-finality-update-verify", + "webb-lc-relay-types", ] [[package]] name = "webb-eth2-hashing" -version = "0.3.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "lazy_static", "ring", @@ -17908,22 +17626,21 @@ dependencies = [ [[package]] name = "webb-eth2-pallet-init" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "anyhow", "async-trait", - "clap 3.2.25", + "clap 4.4.2", "dotenvy", "eth-types", "log", - "parity-scale-codec", "reqwest", "scale-info", "serde", "serde_json", "sp-keyring 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "subxt 0.29.0", + "subxt", "tokio 1.32.0", "toml 0.5.11", "types", @@ -17931,16 +17648,14 @@ dependencies = [ "webb-consensus-types", "webb-eth-rpc-client", "webb-merkle-proof", - "webb-proposals 0.6.0", - "webb-relayer-types 0.5.12-dev (git+https://github.com/webb-tools/relayer.git)", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer.git)", + "webb-proposals", "webb-tree-hash", ] [[package]] name = "webb-eth2-serde-utils" -version = "0.1.1" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "ethereum-types", "hex", @@ -17950,47 +17665,14 @@ dependencies = [ [[package]] name = "webb-eth2-ssz" -version = "0.4.1" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "ethereum-types", "itertools 0.10.5", "smallvec 1.11.0", ] -[[package]] -name = "webb-eth2-ssz-derive" -version = "0.3.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" -dependencies = [ - "darling 0.13.4", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "webb-event-watcher-traits" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "async-trait", - "backoff", - "futures 0.3.28", - "native-tls", - "sled", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tracing", - "tracing-test", - "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", -] - [[package]] name = "webb-event-watcher-traits" version = "0.5.12-dev" @@ -18006,30 +17688,11 @@ dependencies = [ "tracing", "tracing-test", "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-ew-dkg" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "async-trait", - "ethereum-types", - "hex", - "sled", - "tokio 1.32.0", - "tracing", - "webb 0.7.4", - "webb-event-watcher-traits 0.5.7-dev", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-context", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] @@ -18044,42 +17707,11 @@ dependencies = [ "tokio 1.32.0", "tracing", "webb 0.7.4", - "webb-event-watcher-traits 0.5.12-dev", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-ew-evm" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "ark-bls12-381", - "ark-bn254", - "ark-ff", - "ark-std", - "arkworks-native-gadgets", - "arkworks-setups", - "arkworks-utils", - "async-trait", - "ethereum-types", - "hex", - "native-tls", - "serde_json", - "sled", - "tokio 1.32.0", - "tracing", - "typed-builder 0.15.2", - "webb 0.7.4", - "webb-bridge-registry-backends 0.5.7-dev", - "webb-event-watcher-traits 0.5.7-dev", - "webb-proposal-signing-backends 0.5.7-dev", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-event-watcher-traits", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] @@ -18104,19 +17736,19 @@ dependencies = [ "tracing", "typed-builder 0.15.2", "webb 0.7.4", - "webb-bridge-registry-backends 0.5.12-dev", - "webb-event-watcher-traits 0.5.12-dev", - "webb-proposal-signing-backends 0.5.12-dev", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", + "webb-bridge-registry-backends", + "webb-event-watcher-traits", + "webb-proposal-signing-backends", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] name = "webb-finality-update-verify" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "anyhow", "bitvec", @@ -18128,31 +17760,71 @@ dependencies = [ ] [[package]] -name = "webb-merkle-proof" -version = "0.2.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +name = "webb-lc-relay-config" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ - "ethereum-types", - "lazy_static", - "webb-eth2-hashing", - "webb-safe-arith", + "dotenvy", + "reqwest", + "serde", + "toml 0.5.11", + "webb-eth-rpc-client", + "webb-eth2-pallet-init", ] [[package]] -name = "webb-price-oracle-backends" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" +name = "webb-lc-relay-types" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ - "async-trait", - "chrono", - "futures 0.3.28", + "anyhow", + "backoff", "reqwest", "serde", - "typed-builder 0.15.2", + "serde_json", + "tokio 1.32.0", + "tracing", + "typed-builder 0.16.2", "webb 0.7.4", - "webb-chains-info 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", +] + +[[package]] +name = "webb-lc-relayer-context" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" +dependencies = [ + "anyhow", + "subxt", + "tokio 1.32.0", + "tracing", + "webb-eth2-pallet-init", + "webb-lc-relay-config", +] + +[[package]] +name = "webb-light-client-primitives" +version = "0.1.0" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" +dependencies = [ + "eth-types", + "ethereum-types", + "frame-support", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "webb-proposals", +] + +[[package]] +name = "webb-merkle-proof" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" +dependencies = [ + "ethereum-types", + "lazy_static", + "webb-eth2-hashing", + "webb-safe-arith", ] [[package]] @@ -18167,32 +17839,9 @@ dependencies = [ "serde", "typed-builder 0.15.2", "webb 0.7.4", - "webb-chains-info 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-proposal-signing-backends" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "async-trait", - "ethereum-types", - "futures 0.3.28", - "hex", - "impl-trait-for-tuples", - "parking_lot 0.12.1", - "sled", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tracing", - "typed-builder 0.15.2", - "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-types 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-chains-info", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] @@ -18212,24 +17861,10 @@ dependencies = [ "tracing", "typed-builder 0.15.2", "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-types 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-proposals" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2ab97c42b53720c745a0a87eb734c3cb90a979ef0ddaae52c83bddb4bd858a" -dependencies = [ - "num-traits", - "parity-scale-codec", - "scale-info", - "schemars", - "tiny-keccak", - "typed-builder 0.10.0", + "webb-proposals", + "webb-relayer-store", + "webb-relayer-types", + "webb-relayer-utils", ] [[package]] @@ -18247,38 +17882,6 @@ dependencies = [ "typed-builder 0.14.0", ] -[[package]] -name = "webb-relayer" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "axum", - "config", - "dotenv", - "ethereum-types", - "serde_json", - "sled", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tower-http 0.3.5", - "tracing", - "url", - "webb 0.7.4", - "webb-bridge-registry-backends 0.5.7-dev", - "webb-event-watcher-traits 0.5.7-dev", - "webb-ew-dkg 0.5.7-dev", - "webb-ew-evm 0.5.7-dev", - "webb-proposal-signing-backends 0.5.7-dev", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-handlers 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-tx-queue 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", -] - [[package]] name = "webb-relayer" version = "0.5.12-dev" @@ -18297,43 +17900,18 @@ dependencies = [ "tracing", "url", "webb 0.7.4", - "webb-bridge-registry-backends 0.5.12-dev", - "webb-event-watcher-traits 0.5.12-dev", - "webb-ew-dkg 0.5.12-dev", - "webb-ew-evm 0.5.12-dev", - "webb-proposal-signing-backends 0.5.12-dev", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-handlers 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-tx-queue 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-config" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "anyhow", - "config", - "directories-next", - "ethereum-types", - "glob", - "serde", - "serde_json", - "serde_path_to_error", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt", - "tracing", - "tracing-subscriber 0.3.17", - "url", - "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-types 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-bridge-registry-backends", + "webb-event-watcher-traits", + "webb-ew-dkg", + "webb-ew-evm", + "webb-proposal-signing-backends", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-context", + "webb-relayer-handlers", + "webb-relayer-store", + "webb-relayer-tx-queue", + "webb-relayer-utils", ] [[package]] @@ -18355,30 +17933,10 @@ dependencies = [ "tracing-subscriber 0.3.17", "url", "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-types 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-context" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "http", - "native-tls", - "regex", - "serde", - "serde_json", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tracing", - "webb 0.7.4", - "webb-price-oracle-backends 0.5.7-dev", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-proposals", + "webb-relayer-store", + "webb-relayer-types", + "webb-relayer-utils", ] [[package]] @@ -18395,10 +17953,10 @@ dependencies = [ "tokio 1.32.0", "tracing", "webb 0.7.4", - "webb-price-oracle-backends 0.5.12-dev", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", + "webb-price-oracle-backends", + "webb-relayer-config", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] @@ -18406,17 +17964,17 @@ name = "webb-relayer-gadget" version = "0.0.1" source = "git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7#e20c92d8c4e874162dd0245a82a5af4447bf9d4a" dependencies = [ - "dkg-runtime-primitives 0.0.1 (git+https://github.com/webb-tools/dkg-substrate.git?tag=v0.4.7)", + "dkg-runtime-primitives", "ethereum-types", "sc-keystore", "sp-application-crypto 23.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "sp-keystore 0.27.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0)", "tracing", - "webb-relayer 0.5.12-dev", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-types 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", + "webb-relayer", + "webb-relayer-config", + "webb-relayer-context", + "webb-relayer-store", + "webb-relayer-types", ] [[package]] @@ -18427,19 +17985,6 @@ dependencies = [ "clap 4.4.2", ] -[[package]] -name = "webb-relayer-handler-utils" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "native-tls", - "serde", - "tokio 1.32.0", - "webb 0.7.4", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-tx-relay-utils 0.5.7-dev", -] - [[package]] name = "webb-relayer-handler-utils" version = "0.5.12-dev" @@ -18449,35 +17994,8 @@ dependencies = [ "serde", "tokio 1.32.0", "webb 0.7.4", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-tx-relay-utils 0.5.12-dev", -] - -[[package]] -name = "webb-relayer-handlers" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "axum", - "axum-client-ip", - "build-data", - "ethereum-types", - "futures 0.3.28", - "native-tls", - "serde", - "serde_json", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tokio-stream", - "tracing", - "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-handler-utils 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-tx-relay 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-relayer-store", + "webb-relayer-tx-relay-utils", ] [[package]] @@ -18498,30 +18016,13 @@ dependencies = [ "tokio-stream", "tracing", "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-handler-utils 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-tx-relay 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-store" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "hex", - "parking_lot 0.12.1", - "serde", - "serde_json", - "sled", - "tempfile", - "tracing", - "webb 0.7.4", - "webb-proposals 0.5.4", - "webb-relayer-utils 0.5.7-dev", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-context", + "webb-relayer-handler-utils", + "webb-relayer-store", + "webb-relayer-tx-relay", + "webb-relayer-utils", ] [[package]] @@ -18537,30 +18038,8 @@ dependencies = [ "tempfile", "tracing", "webb 0.7.4", - "webb-proposals 0.6.0", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-tx-queue" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "backoff", - "ethereum-types", - "futures 0.3.28", - "hex", - "rand 0.8.5", - "sled", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sp-runtime 24.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tracing", - "webb 0.7.4", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-types 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-proposals", + "webb-relayer-utils", ] [[package]] @@ -18579,34 +18058,10 @@ dependencies = [ "tokio 1.32.0", "tracing", "webb 0.7.4", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-types 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-tx-relay" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "chrono", - "ethereum-types", - "futures 0.3.28", - "once_cell", - "serde", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 1.32.0", - "tracing", - "webb 0.7.4", - "webb-chains-info 0.5.7-dev", - "webb-price-oracle-backends 0.5.7-dev", - "webb-proposals 0.5.4", - "webb-relayer-config 0.5.7-dev", - "webb-relayer-context 0.5.7-dev", - "webb-relayer-handler-utils 0.5.7-dev", - "webb-relayer-store 0.5.7-dev", - "webb-relayer-utils 0.5.7-dev", + "webb-relayer-context", + "webb-relayer-store", + "webb-relayer-types", + "webb-relayer-utils", ] [[package]] @@ -18623,22 +18078,14 @@ dependencies = [ "tokio 1.32.0", "tracing", "webb 0.7.4", - "webb-chains-info 0.5.12-dev", - "webb-price-oracle-backends 0.5.12-dev", - "webb-proposals 0.6.0", - "webb-relayer-config 0.5.12-dev", - "webb-relayer-context 0.5.12-dev", - "webb-relayer-handler-utils 0.5.12-dev", - "webb-relayer-store 0.5.12-dev", - "webb-relayer-utils 0.5.12-dev (git+https://github.com/webb-tools/relayer?tag=v0.5.12-dev)", -] - -[[package]] -name = "webb-relayer-tx-relay-utils" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "serde", + "webb-chains-info", + "webb-price-oracle-backends", + "webb-proposals", + "webb-relayer-config", + "webb-relayer-context", + "webb-relayer-handler-utils", + "webb-relayer-store", + "webb-relayer-utils", ] [[package]] @@ -18649,21 +18096,6 @@ dependencies = [ "serde", ] -[[package]] -name = "webb-relayer-types" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "ethereum-types", - "native-tls", - "serde", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-bip39", - "tracing", - "url", - "webb 0.7.4", -] - [[package]] name = "webb-relayer-types" version = "0.5.12-dev" @@ -18679,50 +18111,6 @@ dependencies = [ "webb 0.7.4", ] -[[package]] -name = "webb-relayer-types" -version = "0.5.12-dev" -source = "git+https://github.com/webb-tools/relayer.git#91098198be9377ebaa18699e309426ff08ef921e" -dependencies = [ - "ethereum-types", - "native-tls", - "serde", - "sp-core 21.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-bip39", - "tracing", - "url", - "webb 0.7.4", -] - -[[package]] -name = "webb-relayer-utils" -version = "0.5.7-dev" -source = "git+https://github.com/webb-tools/relayer?tag=v0.5.7-dev#2dd33881eb5ce419151b11fd939fd4b318095a7b" -dependencies = [ - "ark-std", - "async-trait", - "axum", - "backoff", - "config", - "derive_more", - "futures 0.3.28", - "glob", - "hex", - "hyper 0.14.27", - "libsecp256k1", - "prometheus 0.13.3", - "reqwest", - "serde", - "serde_bytes", - "serde_json", - "serde_path_to_error", - "sled", - "thiserror", - "url", - "webb 0.7.4", - "webb-proposals 0.5.4", -] - [[package]] name = "webb-relayer-utils" version = "0.5.12-dev" @@ -18749,47 +18137,18 @@ dependencies = [ "thiserror", "url", "webb 0.7.4", - "webb-proposals 0.6.0", -] - -[[package]] -name = "webb-relayer-utils" -version = "0.5.12-dev" -source = "git+https://github.com/webb-tools/relayer.git#91098198be9377ebaa18699e309426ff08ef921e" -dependencies = [ - "ark-std", - "async-trait", - "axum", - "backoff", - "config", - "derive_more", - "futures 0.3.28", - "glob", - "hex", - "hyper 0.14.27", - "libsecp256k1", - "prometheus 0.13.3", - "reqwest", - "serde", - "serde_bytes", - "serde_json", - "serde_path_to_error", - "sled", - "thiserror", - "url", - "webb 0.7.4", - "webb-proposals 0.6.0", + "webb-proposals", ] [[package]] name = "webb-safe-arith" -version = "0.1.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" [[package]] name = "webb-tree-hash" -version = "0.4.1" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "ethereum-types", "smallvec 1.11.0", @@ -18798,8 +18157,8 @@ dependencies = [ [[package]] name = "webb-tree-hash-derive" -version = "0.4.0" -source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.5#cb2c939005126ee62e832860f09bb8c14409d2bd" +version = "0.2.0-dev" +source = "git+https://github.com/webb-tools/pallet-eth2-light-client?tag=v0.4.6#1f035fac42feb724fdc15d79d5231a056e148c6d" dependencies = [ "darling 0.13.4", "quote", @@ -19563,12 +18922,6 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" -[[package]] -name = "yap" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc77f52dc9e9b10d55d3f4462c3b7fc393c4f17975d641542833ab2d3bc26ef" - [[package]] name = "yap" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index 01a8a2ed4..8fd61b2d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -288,10 +288,10 @@ tangle-primitives = { path = 'primitives', default-features = false } pallet-transaction-pause = { path = 'pallets/transaction-pause', default-features = false } # Light client dependencies -pallet-eth2-light-client = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.5" } -pallet-eth2-light-client-relayer-gadget = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.5" } -pallet-eth2-light-client-relayer-gadget-cli = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.5" } -webb-consensus-types = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.5" } +pallet-eth2-light-client = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.6" } +pallet-eth2-light-client-relayer-gadget = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.6" } +pallet-eth2-light-client-relayer-gadget-cli = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.6" } +webb-consensus-types = { git = "https://github.com/webb-tools/pallet-eth2-light-client", default-features = false, tag = "v0.4.6" } webb = { version = "0.8", default-features = false } webb-proposals = { git = "https://github.com/webb-tools/webb-rs.git", rev = "a960eaf", default-features = false, features = ["scale", "evm"] } From 11153921c62bebd2bba22b0534e535f576a4852e Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Tue, 5 Dec 2023 11:11:53 -0700 Subject: [PATCH 09/10] Clippy --- pallets/claims/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 341be4863..415813443 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -42,7 +42,6 @@ pub use pallet::*; use pallet_evm::AddressMapping; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; -use schnorrkel::{signing_context, PublicKey, Signature}; use serde::{self, Deserialize, Serialize}; use sp_core::{sr25519::Public, H160}; use sp_io::{ @@ -50,9 +49,9 @@ use sp_io::{ hashing::keccak_256, }; use sp_runtime::{ - traits::{CheckedSub, SignedExtension, Zero}, + traits::{CheckedSub, Zero}, transaction_validity::{InvalidTransaction, TransactionValidity, ValidTransaction}, - AccountId32, RuntimeDebug, + RuntimeDebug, }; use sp_std::{convert::TryInto, prelude::*, vec}; use utils::Sr25519Signature; @@ -565,7 +564,7 @@ impl Pallet { MultiAddress::EVM(_) => return None, MultiAddress::Native(a) => { let mut bytes = [0u8; 32]; - bytes.copy_from_slice(&addr.to_account_id_32().encode()); + bytes.copy_from_slice(&a.encode()); Public(bytes) }, }; From bfaa324498b5efeefc175ab8f7cec62b055522c8 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Tue, 5 Dec 2023 12:25:08 -0700 Subject: [PATCH 10/10] Allow dead code --- pallets/claims/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/pallets/claims/src/lib.rs b/pallets/claims/src/lib.rs index 6a5d9b5f5..855a00796 100644 --- a/pallets/claims/src/lib.rs +++ b/pallets/claims/src/lib.rs @@ -698,6 +698,7 @@ mod sr25519_utils { use schnorrkel::Signature; use sp_core::{sr25519, Pair}; + #[allow(dead_code)] pub fn public(pair: &sr25519::Pair) -> sr25519::Public { pair.public() }