snowbridge_verification_primitives/
lib.rs#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Decode, DecodeWithMemTracking, Encode};
use frame_support::PalletError;
use scale_info::TypeInfo;
use snowbridge_beacon_primitives::ExecutionProof;
use sp_core::{RuntimeDebug, H160, H256};
use sp_std::prelude::*;
pub trait Verifier {
fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>;
}
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PalletError, TypeInfo)]
#[cfg_attr(feature = "std", derive(PartialEq))]
pub enum VerificationError {
HeaderNotFound,
LogNotFound,
InvalidLog,
InvalidProof,
InvalidExecutionProof(#[codec(skip)] &'static str),
}
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
pub struct EventProof {
pub event_log: Log,
pub proof: Proof,
}
const MAX_TOPICS: usize = 4;
#[derive(Clone, RuntimeDebug)]
pub enum LogValidationError {
TooManyTopics,
}
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Log {
pub address: H160,
pub topics: Vec<H256>,
pub data: Vec<u8>,
}
impl Log {
pub fn validate(&self) -> Result<(), LogValidationError> {
if self.topics.len() > MAX_TOPICS {
return Err(LogValidationError::TooManyTopics)
}
Ok(())
}
}
#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
pub struct Proof {
pub receipt_proof: (Vec<Vec<u8>>, Vec<Vec<u8>>),
pub execution_proof: ExecutionProof,
}