From 8e4ee37b9e3ee6ad870a93000c5fba5f6ac7cc8e Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sat, 13 Jan 2024 00:57:09 +0900 Subject: [PATCH] add light client update types of deneb Signed-off-by: Jun Kimura --- crates/light-client-verifier/src/updates.rs | 1 + .../src/updates/deneb.rs | 123 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 crates/light-client-verifier/src/updates/deneb.rs diff --git a/crates/light-client-verifier/src/updates.rs b/crates/light-client-verifier/src/updates.rs index d563fc2..d1431ec 100644 --- a/crates/light-client-verifier/src/updates.rs +++ b/crates/light-client-verifier/src/updates.rs @@ -11,6 +11,7 @@ use ethereum_consensus::{ }; pub mod bellatrix; pub mod capella; +pub mod deneb; pub trait LightClientBootstrap: core::fmt::Debug + Clone + PartialEq + Eq diff --git a/crates/light-client-verifier/src/updates/deneb.rs b/crates/light-client-verifier/src/updates/deneb.rs new file mode 100644 index 0000000..b7ae598 --- /dev/null +++ b/crates/light-client-verifier/src/updates/deneb.rs @@ -0,0 +1,123 @@ +pub use super::bellatrix::ExecutionUpdateInfo; +use super::{ConsensusUpdate, LightClientBootstrap}; +use core::ops::Deref; +use ethereum_consensus::{ + beacon::{BeaconBlockHeader, Slot}, + compute::hash_tree_root, + deneb::LightClientUpdate, + sync_protocol::{ + SyncAggregate, SyncCommittee, CURRENT_SYNC_COMMITTEE_DEPTH, EXECUTION_PAYLOAD_DEPTH, + FINALIZED_ROOT_DEPTH, NEXT_SYNC_COMMITTEE_DEPTH, + }, + types::H256, +}; + +#[derive(Clone, Debug, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)] +#[serde(transparent)] +pub struct LightClientBootstrapInfo< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, +>( + pub ethereum_consensus::deneb::LightClientBootstrap< + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + >, +); + +impl< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > Deref + for LightClientBootstrapInfo +{ + type Target = ethereum_consensus::deneb::LightClientBootstrap< + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + >; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > LightClientBootstrap + for LightClientBootstrapInfo +{ + fn beacon_header(&self) -> &BeaconBlockHeader { + &self.0.header.beacon + } + fn current_sync_committee(&self) -> &SyncCommittee { + &self.0.current_sync_committee + } + fn current_sync_committee_branch(&self) -> [H256; CURRENT_SYNC_COMMITTEE_DEPTH] { + self.0.current_sync_committee_branch.clone() + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Default, serde::Serialize, serde::Deserialize)] +pub struct ConsensusUpdateInfo< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, +>(pub LightClientUpdate); + +impl< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > Deref + for ConsensusUpdateInfo +{ + type Target = + LightClientUpdate; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > ConsensusUpdate + for ConsensusUpdateInfo +{ + fn attested_beacon_header(&self) -> &BeaconBlockHeader { + &self.attested_header.beacon + } + fn next_sync_committee(&self) -> Option<&SyncCommittee> { + self.next_sync_committee.as_ref().map(|c| &c.0) + } + fn next_sync_committee_branch(&self) -> Option<[H256; NEXT_SYNC_COMMITTEE_DEPTH]> { + self.next_sync_committee.as_ref().map(|c| c.1.clone()) + } + fn finalized_beacon_header(&self) -> &BeaconBlockHeader { + &self.finalized_header.beacon + } + fn finalized_beacon_header_branch(&self) -> [H256; FINALIZED_ROOT_DEPTH] { + self.finality_branch.clone() + } + fn finalized_execution_root(&self) -> H256 { + hash_tree_root(self.finalized_header.execution.clone()) + .unwrap() + .0 + .into() + } + fn finalized_execution_branch(&self) -> [H256; EXECUTION_PAYLOAD_DEPTH] { + self.finalized_header.execution_branch.clone() + } + fn sync_aggregate(&self) -> &SyncAggregate { + &self.sync_aggregate + } + fn signature_slot(&self) -> Slot { + self.signature_slot + } +}