Skip to main content

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::{H160, H256};
10use sp_std::prelude::*;
11
12pub mod receipt;
13
14/// A trait for verifying inbound messages from Ethereum.
15pub trait Verifier {
16	fn verify(event: &Log, proof: &Proof) -> Result<(), VerificationError>;
17}
18
19#[derive(Clone, Encode, Decode, DecodeWithMemTracking, Debug, PalletError, TypeInfo)]
20#[cfg_attr(feature = "std", derive(PartialEq))]
21pub enum VerificationError {
22	/// Execution header is missing
23	HeaderNotFound,
24	/// Event log was not found in the verified transaction receipt
25	LogNotFound,
26	/// Event log has an invalid format
27	InvalidLog,
28	/// Unable to verify the transaction receipt with the provided proof
29	InvalidProof,
30	/// Unable to verify the execution header with ancestry proof
31	InvalidExecutionProof(#[codec(skip)] &'static str),
32	/// The verifier is halted. Proofs cannot be verified while the bridge is in an emergency
33	/// halted state (e.g. a compromised beacon light client).
34	Halted,
35}
36
37/// A bridge message from the Gateway contract on Ethereum
38#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Debug, TypeInfo)]
39pub struct EventProof {
40	/// Event log emitted by Gateway contract
41	pub event_log: Log,
42	/// Inclusion proof for a transaction receipt containing the event log
43	pub proof: Proof,
44}
45
46/// Event log
47#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Debug, TypeInfo)]
48pub struct Log {
49	pub address: H160,
50	pub topics: Vec<H256>,
51	pub data: Vec<u8>,
52	pub tx_index: u64,
53}
54
55/// Inclusion proof for a transaction receipt
56#[derive(Clone, Encode, Decode, DecodeWithMemTracking, PartialEq, Debug, TypeInfo)]
57pub struct Proof {
58	// Proof values from receipts tree
59	pub receipt_proof: Vec<Vec<u8>>,
60	// Proof that an execution header was finalized by the beacon chain
61	pub execution_proof: ExecutionProof,
62}
63
64#[derive(Clone, Debug)]
65pub struct EventFixture {
66	pub event: EventProof,
67	pub finalized_header: BeaconHeader,
68	pub block_roots_root: H256,
69}