mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +00:00
Reject storage proofs with unused nodes: begin (#1878)
* reject storage proofs with unused nodes: begin * fix ignores_parachain_head_if_it_is_missing_from_storage_proof * message_proof_is_rejected_if_it_has_duplicate_trie_nodes && message_proof_is_rejected_if_it_has_unused_trie_nodes * proof_with_duplicate_items_is_rejected and proof_with_unused_items_is_rejected * clippy * fix benchmarks compilation * impl From<Error> for &'static str * fix review comments * added comment
This commit is contained in:
committed by
Bastian Köcher
parent
9e30130054
commit
25c17feb23
@@ -19,35 +19,36 @@
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use bp_runtime::{BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, StorageProofChecker};
|
||||
use bp_runtime::{
|
||||
BasicOperatingMode, Chain, HashOf, HasherOf, HeaderOf, RawStorageProof, StorageProofChecker,
|
||||
StorageProofError,
|
||||
};
|
||||
use codec::{Codec, Decode, Encode, EncodeLike, MaxEncodedLen};
|
||||
use core::{clone::Clone, cmp::Eq, default::Default, fmt::Debug};
|
||||
use frame_support::PalletError;
|
||||
use scale_info::TypeInfo;
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sp_finality_grandpa::{AuthorityList, ConsensusLog, SetId, GRANDPA_ENGINE_ID};
|
||||
use sp_runtime::{traits::Header as HeaderT, Digest, RuntimeDebug};
|
||||
use sp_std::boxed::Box;
|
||||
use sp_trie::StorageProof;
|
||||
|
||||
pub mod justification;
|
||||
pub mod storage_keys;
|
||||
|
||||
/// Header chain error.
|
||||
#[derive(Clone, Copy, Decode, Encode, Eq, PalletError, PartialEq, RuntimeDebug, TypeInfo)]
|
||||
#[derive(Clone, Eq, PartialEq, RuntimeDebug)]
|
||||
pub enum HeaderChainError {
|
||||
/// Header with given hash is missing from the chain.
|
||||
UnknownHeader,
|
||||
/// The storage proof doesn't contains storage root.
|
||||
StorageRootMismatch,
|
||||
/// Storage proof related error.
|
||||
StorageProof(StorageProofError),
|
||||
}
|
||||
|
||||
impl From<HeaderChainError> for &'static str {
|
||||
fn from(err: HeaderChainError) -> &'static str {
|
||||
match err {
|
||||
HeaderChainError::UnknownHeader => "UnknownHeader",
|
||||
HeaderChainError::StorageRootMismatch => "StorageRootMismatch",
|
||||
HeaderChainError::StorageProof(e) => e.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,13 +84,13 @@ pub trait HeaderChain<C: Chain> {
|
||||
/// Parse storage proof using finalized header.
|
||||
fn parse_finalized_storage_proof<R>(
|
||||
header_hash: HashOf<C>,
|
||||
storage_proof: StorageProof,
|
||||
storage_proof: RawStorageProof,
|
||||
parse: impl FnOnce(StorageProofChecker<HasherOf<C>>) -> R,
|
||||
) -> Result<R, HeaderChainError> {
|
||||
let state_root = Self::finalized_header_state_root(header_hash)
|
||||
.ok_or(HeaderChainError::UnknownHeader)?;
|
||||
let storage_proof_checker = bp_runtime::StorageProofChecker::new(state_root, storage_proof)
|
||||
.map_err(|_| HeaderChainError::StorageRootMismatch)?;
|
||||
.map_err(HeaderChainError::StorageProof)?;
|
||||
|
||||
Ok(parse(storage_proof_checker))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user