snowbridge_verification_primitives/
lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
5use codec::{Decode, DecodeWithMemTracking, Encode};
6use frame_support::PalletError;
7use scale_info::TypeInfo;
8use snowbridge_beacon_primitives::{BeaconHeader, ExecutionProof};
9use sp_core::{RuntimeDebug, H160, H256};
10use sp_std::prelude::*;
11
12pub trait Verifier {
14 fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>;
15}
16
17#[derive(Clone, Encode, Decode, DecodeWithMemTracking, RuntimeDebug, PalletError, TypeInfo)]
18#[cfg_attr(feature = "std", derive(PartialEq))]
19pub enum VerificationError {
20 HeaderNotFound,
22 LogNotFound,
24 InvalidLog,
26 InvalidProof,
28 InvalidExecutionProof(#[codec(skip)] &'static str),
30}
31
32#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
34pub struct EventProof {
35 pub event_log: Log,
37 pub proof: Proof,
39}
40
41const MAX_TOPICS: usize = 4;
42
43#[derive(Clone, RuntimeDebug)]
44pub enum LogValidationError {
45 TooManyTopics,
46}
47
48#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
50pub struct Log {
51 pub address: H160,
52 pub topics: Vec<H256>,
53 pub data: Vec<u8>,
54}
55
56impl Log {
57 pub fn validate(&self) -> Result<(), LogValidationError> {
58 if self.topics.len() > MAX_TOPICS {
59 return Err(LogValidationError::TooManyTopics)
60 }
61 Ok(())
62 }
63}
64
65#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
67pub struct Proof {
68 pub receipt_proof: (Vec<Vec<u8>>, Vec<Vec<u8>>),
70 pub execution_proof: ExecutionProof,
72}
73
74#[derive(Clone, RuntimeDebug)]
75pub struct EventFixture {
76 pub event: EventProof,
77 pub finalized_header: BeaconHeader,
78 pub block_roots_root: H256,
79}