Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 63 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ members = [
"modules/ismp/clients/polygon",
"modules/ismp/clients/tendermint",
"modules/pallets/collator-manager",
"modules/ismp/clients/beefy",

# cryptography
"modules/consensus/sync-committee/prover",
"modules/consensus/sync-committee/verifier",
"modules/consensus/sync-committee/primitives",
"modules/consensus/beefy/primitives",
"modules/consensus/beefy/prover",
"modules/consensus/beefy/verifier",
"modules/consensus/geth-primitives",
"modules/consensus/bsc/verifier",
"modules/consensus/bsc/prover",
Expand Down Expand Up @@ -225,6 +227,7 @@ reqwest-middleware = "0.2.4"
reqwest = { version="0.11.14", features=["json"]}
prost = { version = "0.13.0", default-features = false }
impl-trait-for-tuples = "0.2.3"
k256 = { version = "0.13.3", default-features = false, features = ["ecdsa"] }

# arkworks
ark-ec = { version = "0.4.2", default-features = false }
Expand Down Expand Up @@ -269,6 +272,7 @@ subxt-utils = { path = "modules/utils/subxt", default-features = false }
# consensus provers & verifiers
beefy-verifier-primitives = { path = "./modules/consensus/beefy/primitives", default-features = false }
beefy-prover = { path = "./modules/consensus/beefy/prover" }
beefy-verifier = { path = "./modules/consensus/beefy/verifier", default-features = false }
bsc-prover = { path = "./modules/consensus/bsc/prover" }
bsc-verifier = { path = "./modules/consensus/bsc/verifier", default-features = false }
geth-primitives = { path = "./modules/consensus/geth-primitives", default-features = false }
Expand Down Expand Up @@ -311,6 +315,7 @@ pallet-intents-coprocessor = { path = "modules/pallets/intents-coprocessor", def
pallet-intents-rpc = { path = "modules/pallets/intents-coprocessor/rpc" }
pallet-token-gateway-inspector = { path = "modules/pallets/token-gateway-inspector", default-features = false }
pallet-bridge-airdrop = { path = "modules/pallets/bridge-drop", default-features = false }
ismp-beefy = { path = "modules/ismp/clients/beefy", default-features = false}

# merkle trees
ethereum-triedb = { version = "0.1.1", path = "./modules/trees/ethereum", default-features = false }
Expand Down Expand Up @@ -390,4 +395,6 @@ features = ["derive"]
version = "0.5.0"
default-features = false

[patch.crates-io]
[workspace.dependencies.rs_merkle]
version = "1.2.0"
default-features = false
1 change: 0 additions & 1 deletion modules/consensus/beefy/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ features = [
"sp-core",
"sp-consensus-beefy",
"sp-mmr-primitives",
"sp-io",
]

[features]
Expand Down
92 changes: 88 additions & 4 deletions modules/consensus/beefy/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,27 @@ pub struct PartialMmrLeaf {
pub beefy_next_authority_set: BeefyAuthoritySet<H256>,
}

#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq)]
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
/// Parachain header and metadata needed for merkle inclusion proof
pub struct ParachainHeader {
/// scale encoded parachain header
pub header: Vec<u8>,
/// leaf index for parachain heads proof
pub index: usize,
pub index: u32,
/// ParaId for parachain
pub para_id: u32,
}

#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq)]
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
/// Parachain proofs definition
pub struct ParachainProof {
/// List of parachains we have a proof for
pub parachains: Vec<ParachainHeader>,

/// Proof for parachain header inclusion in the parachain headers root
pub proof: Vec<Vec<(usize, [u8; 32])>>,
pub proof: Vec<[u8; 32]>,
/// Total leaves count for the proof
pub total_leaves: u32,
}

#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq)]
Expand All @@ -119,6 +121,88 @@ pub struct ConsensusMessage {
pub mmr: MmrProof,
}

/// Represents a node in a Merkle proof, containing a hash and its index at a specific layer.
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct Node {
/// The positional index of the node in its layer of the Merkle tree.
pub index: u32,
/// The hash of the node.
pub hash: H256,
}

/// Represents a canonical BEEFY Merkle Mountain Range (MMR) leaf.
///
/// This struct contains the essential data about a finalized block that is committed to the MMR.
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BeefyMmrLeaf {
/// The version of the MMR leaf format.
pub version: MmrLeafVersion,
/// A tuple containing the block number and hash of the parent block.
pub parent_block_and_hash: (u32, H256),
/// The authority set that will be active in the next BEEFY session.
pub beefy_next_authority_set: BeefyAuthoritySet<H256>,
/// The k-index of the leaf, used in MMR calculations.
pub k_index: u32,
/// The sequential index of this leaf in the MMR.
pub leaf_index: u32,
/// An extra data field
pub extra: H256,
}

/// Represents the proof components for verifying the relay chain's consensus state
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct RelaychainProof {
/// Signed commitment
pub signed_commitment: SignedCommitment,
/// Latest leaf added to mmr
pub latest_mmr_leaf: BeefyMmrLeaf,
/// Proof for the latest mmr leaf
pub mmr_proof: Vec<H256>,
/// Proof for authorities in current/next session
pub proof: Vec<H256>,
}

/// Represents a complete BEEFY consensus proof.
///
/// This proof contains all the necessary data to verify a BEEFY finality proof from the relay chain
/// and to prove the inclusion of specific parachain headers within that finalized block.
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct BeefyConsensusProof {
/// The proof items for the relay chain consensus
pub relay: RelaychainProof,
/// The proof items for parachain headers
pub parachain: ParachainProof,
}

/// Proof type identifier for naive proofs
pub const PROOF_TYPE_NAIVE: u8 = 0x00;

/// Proof type identifier for SP1 ZK proofs
pub const PROOF_TYPE_SP1: u8 = 0x01;

/// SP1 BEEFY proof
/// The proof bytes are prefixed with PROOF_TYPE_SP1 (0x01) by the prover.
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct Sp1BeefyProof {
/// BEEFY commitment (block number + validator set ID)
pub commitment: Sp1MiniCommitment,
/// Latest MMR leaf data
pub mmr_leaf: BeefyMmrLeaf,
/// Parachain headers finalized by this proof
pub parachain: ParachainProof,
/// SP1 proof bytes
pub proof: Vec<u8>,
}

/// Minimal BEEFY commitment for SP1 proofs
#[derive(sp_std::fmt::Debug, Clone, PartialEq, Eq, Encode, Decode)]
pub struct Sp1MiniCommitment {
/// Relay chain block number
pub block_number: u32,
/// Validator set ID that signed the commitment
pub validator_set_id: u64,
}

#[cfg(feature = "std")]
#[derive(Clone, serde::Serialize, serde::Deserialize)]
/// finality proof
Expand Down
Loading