diff --git a/substrate/frame/identity/Cargo.toml b/substrate/frame/identity/Cargo.toml index 8c0052004ae3..5d06aec12097 100644 --- a/substrate/frame/identity/Cargo.toml +++ b/substrate/frame/identity/Cargo.toml @@ -26,6 +26,7 @@ frame-system = { path = "../system", default-features = false } sp-io = { path = "../../primitives/io", default-features = false } sp-runtime = { path = "../../primitives/runtime", default-features = false } sp-std = { path = "../../primitives/std", default-features = false } +sp-core = { path = "../../primitives/core", default-features = false, optional = true } [dev-dependencies] pallet-balances = { path = "../balances" } @@ -56,6 +57,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "sp-runtime/runtime-benchmarks", + "sp-core" ] try-runtime = [ "frame-support/try-runtime", diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 9cdf6cfcb302..ac1aeefdb7a0 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -29,10 +29,10 @@ use frame_support::{ traits::{EnsureOrigin, Get, OnFinalize, OnInitialize}, }; use frame_system::RawOrigin; -use sp_io::crypto::{sr25519_generate, sr25519_sign}; +use sp_io::crypto::{ecdsa_generate, ecdsa_sign_prehashed}; use sp_runtime::{ - traits::{Bounded, IdentifyAccount, One}, - MultiSignature, MultiSigner, + traits::{Bounded, One}, + MultiSignature, }; const SEED: u32 = 0; @@ -137,6 +137,7 @@ fn bounded_username(username: Vec, suffix: Vec) -> Username::AccountId: From, T::OffchainSignature: From, + T::SigningPublicKey: From, )] mod benchmarks { use super::*; @@ -627,18 +628,22 @@ mod benchmarks { let bounded_username = bounded_username::(username.clone(), suffix.clone()); let encoded_username = Encode::encode(&bounded_username.to_vec()); - let public = sr25519_generate(0.into(), None); - let who_account: T::AccountId = MultiSigner::Sr25519(public).into_account().into(); + let public = ecdsa_generate(0.into(), None); + let who_account: T::AccountId = + T::SigningPublicKey::from(public.clone()).into_account().into(); let who_lookup = T::Lookup::unlookup(who_account.clone()); - let signature = - MultiSignature::Sr25519(sr25519_sign(0.into(), &public, &encoded_username).unwrap()); + let encoded_username_hash = sp_io::hashing::keccak_256(&encoded_username); + let signature: T::OffchainSignature = MultiSignature::Ecdsa( + ecdsa_sign_prehashed(0.into(), &public, &encoded_username_hash).unwrap(), + ) + .into(); // Verify signature here to avoid surprise errors at runtime - assert!(signature.verify(&encoded_username[..], &public.into())); + assert!(signature.verify(&encoded_username[..], &who_account)); #[extrinsic_call] - _(RawOrigin::Signed(authority.clone()), who_lookup, username, Some(signature.into())); + _(RawOrigin::Signed(authority.clone()), who_lookup, username, Some(signature)); assert_has_event::( Event::::UsernameSet {