Skip to content

Commit

Permalink
benchmarks: change signature curve used in identity benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ authored and ahmadkaouk committed Jun 4, 2024
1 parent 2d3b6ee commit 58a13b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 2 additions & 0 deletions substrate/frame/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down
23 changes: 14 additions & 9 deletions substrate/frame/identity/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -137,6 +137,7 @@ fn bounded_username<T: Config>(username: Vec<u8>, suffix: Vec<u8>) -> Username<T
where
<T as frame_system::Config>::AccountId: From<sp_runtime::AccountId32>,
T::OffchainSignature: From<MultiSignature>,
T::SigningPublicKey: From<sp_core::ecdsa::Public>,
)]
mod benchmarks {
use super::*;
Expand Down Expand Up @@ -627,18 +628,22 @@ mod benchmarks {
let bounded_username = bounded_username::<T>(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::<T>(
Event::<T>::UsernameSet {
Expand Down

0 comments on commit 58a13b0

Please sign in to comment.