snowbridge_verification_primitives/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3//! Types for representing inbound messages
4#![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
12/// A trait for verifying inbound messages from Ethereum.
13pub 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	/// Execution header is missing
21	HeaderNotFound,
22	/// Event log was not found in the verified transaction receipt
23	LogNotFound,
24	/// Event log has an invalid format
25	InvalidLog,
26	/// Unable to verify the transaction receipt with the provided proof
27	InvalidProof,
28	/// Unable to verify the execution header with ancestry proof
29	InvalidExecutionProof(#[codec(skip)] &'static str),
30}
31
32/// A bridge message from the Gateway contract on Ethereum
33#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
34pub struct EventProof {
35	/// Event log emitted by Gateway contract
36	pub event_log: Log,
37	/// Inclusion proof for a transaction receipt containing the event log
38	pub proof: Proof,
39}
40
41/// Event log
42#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
43pub struct Log {
44	pub address: H160,
45	pub topics: Vec<H256>,
46	pub data: Vec<u8>,
47}
48
49/// Inclusion proof for a transaction receipt
50#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, RuntimeDebug, TypeInfo)]
51pub struct Proof {
52	// Proof keys and values (receipts tree)
53	pub receipt_proof: (Vec<Vec<u8>>, Vec<Vec<u8>>),
54	// Proof that an execution header was finalized by the beacon chain
55	pub execution_proof: ExecutionProof,
56}
57
58#[derive(Clone, RuntimeDebug)]
59pub struct EventFixture {
60	pub event: EventProof,
61	pub finalized_header: BeaconHeader,
62	pub block_roots_root: H256,
63}