pallet-identity: Be more paranoid ;) (#12170)

* pallet-identity: Be more paranoid ;)

Check that a registrar is providing judgement for the correct identity.

* Fixes

* Fix alliance

* 🤦

* Fixes

* ...
This commit is contained in:
Bastian Köcher
2022-09-08 09:52:25 +01:00
committed by GitHub
parent 6ce4d45175
commit 972ac424f0
5 changed files with 163 additions and 40 deletions
+10 -2
View File
@@ -79,7 +79,7 @@ mod types;
pub mod weights;
use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency};
use sp_runtime::traits::{AppendZerosInput, Saturating, StaticLookup, Zero};
use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero};
use sp_std::prelude::*;
pub use weights::WeightInfo;
@@ -236,6 +236,8 @@ pub mod pallet {
NotSub,
/// Sub-account isn't owned by sender.
NotOwned,
/// The provided judgement was for a different identity.
JudgementForDifferentIdentity,
}
#[pallet::event]
@@ -746,6 +748,7 @@ pub mod pallet {
/// - `target`: the account whose identity the judgement is upon. This must be an account
/// with a registered identity.
/// - `judgement`: the judgement of the registrar of index `reg_index` about `target`.
/// - `identity`: The hash of the [`IdentityInfo`] for that the judgement is provided.
///
/// Emits `JudgementGiven` if successful.
///
@@ -765,6 +768,7 @@ pub mod pallet {
#[pallet::compact] reg_index: RegistrarIndex,
target: AccountIdLookupOf<T>,
judgement: Judgement<BalanceOf<T>>,
identity: T::Hash,
) -> DispatchResultWithPostInfo {
let sender = ensure_signed(origin)?;
let target = T::Lookup::lookup(target)?;
@@ -772,10 +776,14 @@ pub mod pallet {
<Registrars<T>>::get()
.get(reg_index as usize)
.and_then(Option::as_ref)
.and_then(|r| if r.account == sender { Some(r) } else { None })
.filter(|r| r.account == sender)
.ok_or(Error::<T>::InvalidIndex)?;
let mut id = <IdentityOf<T>>::get(&target).ok_or(Error::<T>::InvalidTarget)?;
if T::Hashing::hash_of(&id.info) != identity {
return Err(Error::<T>::JudgementForDifferentIdentity.into())
}
let item = (reg_index, judgement);
match id.judgements.binary_search_by_key(&reg_index, |x| x.0) {
Ok(position) => {