diff --git a/crates/consensus/src/config/goerli.rs b/crates/consensus/src/config/goerli.rs index 8359df1..77a2d5c 100644 --- a/crates/consensus/src/config/goerli.rs +++ b/crates/consensus/src/config/goerli.rs @@ -13,7 +13,8 @@ pub fn get_config() -> Config { fork_parameters: ForkParameters::new( Version([0, 0, 16, 32]), vec![ - ForkParameter::new(Version([4, 0, 16, 32]), U64(u64::MAX)), + ForkParameter::new(Version([5, 0, 16, 32]), U64(u64::MAX)), + ForkParameter::new(Version([4, 0, 16, 32]), U64(231680)), ForkParameter::new(Version([3, 0, 16, 32]), U64(162304)), ForkParameter::new(Version([2, 0, 16, 32]), U64(112260)), ForkParameter::new(Version([1, 0, 16, 32]), U64(36660)), diff --git a/crates/consensus/src/config/mainnet.rs b/crates/consensus/src/config/mainnet.rs index d1a4040..fc56c84 100644 --- a/crates/consensus/src/config/mainnet.rs +++ b/crates/consensus/src/config/mainnet.rs @@ -13,7 +13,8 @@ pub fn get_config() -> Config { fork_parameters: ForkParameters::new( Version([0, 0, 0, 0]), vec![ - ForkParameter::new(Version([4, 0, 0, 0]), U64(u64::MAX)), + ForkParameter::new(Version([5, 0, 0, 0]), U64(u64::MAX)), + ForkParameter::new(Version([4, 0, 0, 0]), U64(269568)), ForkParameter::new(Version([3, 0, 0, 0]), U64(194048)), ForkParameter::new(Version([2, 0, 0, 0]), U64(144896)), ForkParameter::new(Version([1, 0, 0, 0]), U64(74240)), diff --git a/crates/consensus/src/config/sepolia.rs b/crates/consensus/src/config/sepolia.rs index a19356a..24e3fb0 100644 --- a/crates/consensus/src/config/sepolia.rs +++ b/crates/consensus/src/config/sepolia.rs @@ -13,7 +13,8 @@ pub fn get_config() -> Config { fork_parameters: ForkParameters::new( Version([144, 0, 0, 105]), vec![ - ForkParameter::new(Version([144, 0, 0, 0]), U64(u64::MAX)), + ForkParameter::new(Version([144, 0, 0, 116]), U64(u64::MAX)), + ForkParameter::new(Version([144, 0, 0, 115]), U64(132608)), ForkParameter::new(Version([144, 0, 0, 114]), U64(56832)), ForkParameter::new(Version([144, 0, 0, 113]), U64(100)), ForkParameter::new(Version([144, 0, 0, 112]), U64(50)), diff --git a/crates/consensus/src/deneb.rs b/crates/consensus/src/deneb.rs index 17c0d4e..6ce8bcf 100644 --- a/crates/consensus/src/deneb.rs +++ b/crates/consensus/src/deneb.rs @@ -383,13 +383,13 @@ pub fn gen_execution_payload_proof< )) } -pub fn gen_execution_payload_fields_proof< +pub fn gen_execution_payload_field_proof< const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize, >( payload: &ExecutionPayloadHeader, - leaf_indices: &[usize], -) -> Result<(Root, Vec), Error> { + leaf_index: usize, +) -> Result<(Root, [H256; EXECUTION_PAYLOAD_TREE_DEPTH]), Error> { let tree = MerkleTree::from_leaves( ([ payload.parent_hash.0, @@ -427,12 +427,14 @@ pub fn gen_execution_payload_fields_proof< ] as [_; 32]) .as_ref(), ); - Ok(( - H256(tree.root().unwrap()), - tree.proof(leaf_indices) + let mut branch = [Default::default(); EXECUTION_PAYLOAD_TREE_DEPTH]; + branch.copy_from_slice( + tree.proof(&[leaf_index]) .proof_hashes() .into_iter() .map(|h| H256::from_slice(h)) - .collect(), - )) + .collect::>() + .as_slice(), + ); + Ok((H256(tree.root().unwrap()), branch)) } diff --git a/crates/consensus/src/lib.rs b/crates/consensus/src/lib.rs index 8c4a49b..cdbf1c3 100644 --- a/crates/consensus/src/lib.rs +++ b/crates/consensus/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(all(not(test), not(feature = "std")), no_std)] extern crate alloc; +#[allow(unused_imports)] mod internal_prelude { pub use alloc::string::{String, ToString}; pub use alloc::vec; diff --git a/crates/light-client-cli/src/chain.rs b/crates/light-client-cli/src/chain.rs index 21ddc33..94bcf0f 100644 --- a/crates/light-client-cli/src/chain.rs +++ b/crates/light-client-cli/src/chain.rs @@ -3,7 +3,7 @@ use ethereum_consensus::{ config::{self, Config}, types::H256, }; -use ethereum_light_client_verifier::updates::capella::LightClientBootstrapInfo; +use ethereum_light_client_verifier::updates::deneb::LightClientBootstrapInfo; use lodestar_rpc::client::RPCClient; type Result = core::result::Result; diff --git a/crates/light-client-cli/src/client.rs b/crates/light-client-cli/src/client.rs index 066da87..a2e8983 100644 --- a/crates/light-client-cli/src/client.rs +++ b/crates/light-client-cli/src/client.rs @@ -7,10 +7,9 @@ use crate::{ use core::time::Duration; use ethereum_consensus::{ beacon::{Root, Slot}, - bellatrix::EXECUTION_PAYLOAD_TREE_DEPTH, - capella::{self, LightClientUpdate}, compute::compute_sync_committee_period_at_slot, context::ChainContext, + deneb::{self, LightClientUpdate, EXECUTION_PAYLOAD_TREE_DEPTH}, execution::{ BlockNumber, EXECUTION_PAYLOAD_BLOCK_NUMBER_LEAF_INDEX, EXECUTION_PAYLOAD_STATE_ROOT_LEAF_INDEX, @@ -19,10 +18,10 @@ use ethereum_consensus::{ types::{H256, U64}, }; use ethereum_light_client_verifier::{ - consensus::{CurrentNextSyncProtocolVerifier, SyncProtocolVerifier}, + consensus::SyncProtocolVerifier, context::{ConsensusVerificationContext, Fraction, LightClientContext}, state::apply_sync_committee_update, - updates::capella::ConsensusUpdateInfo, + updates::deneb::ConsensusUpdateInfo, }; use log::*; type Result = core::result::Result; @@ -43,7 +42,7 @@ pub struct LightClient< > { ctx: Context, chain: Chain, - verifier: CurrentNextSyncProtocolVerifier< + verifier: SyncProtocolVerifier< SYNC_COMMITTEE_SIZE, EXECUTION_PAYLOAD_TREE_DEPTH, LightClientStore, @@ -225,11 +224,11 @@ impl< let execution_update = { let execution_payload_header = update.finalized_header.execution.clone(); - let (_, state_root_branch) = capella::gen_execution_payload_field_proof( + let (_, state_root_branch) = deneb::gen_execution_payload_field_proof( &execution_payload_header, EXECUTION_PAYLOAD_STATE_ROOT_LEAF_INDEX, )?; - let (_, block_number_branch) = capella::gen_execution_payload_field_proof( + let (_, block_number_branch) = deneb::gen_execution_payload_field_proof( &execution_payload_header, EXECUTION_PAYLOAD_BLOCK_NUMBER_LEAF_INDEX, )?; diff --git a/crates/light-client-cli/src/context.rs b/crates/light-client-cli/src/context.rs index 5aff588..7736e62 100644 --- a/crates/light-client-cli/src/context.rs +++ b/crates/light-client-cli/src/context.rs @@ -2,9 +2,9 @@ use crate::chain::Network; use crate::cli::Opts; use crate::db::{FileDB, DB}; use crate::{errors::Error, state::LightClientStore}; -use ethereum_consensus::capella::LightClientBootstrap; use ethereum_consensus::config::Config; use ethereum_consensus::context::ChainContext; +use ethereum_consensus::deneb::LightClientBootstrap; use log::*; #[derive(Debug)] diff --git a/crates/light-client-cli/src/state.rs b/crates/light-client-cli/src/state.rs index e5f26a8..37d462a 100644 --- a/crates/light-client-cli/src/state.rs +++ b/crates/light-client-cli/src/state.rs @@ -1,6 +1,6 @@ use ethereum_consensus::{ beacon::{BeaconBlockHeader, Slot}, - capella::{ExecutionPayloadHeader, LightClientBootstrap}, + deneb::{ExecutionPayloadHeader, LightClientBootstrap}, sync_protocol::SyncCommittee, types::{H256, U64}, }; diff --git a/crates/light-client-verifier/src/consensus.rs b/crates/light-client-verifier/src/consensus.rs index 8f94506..40a87e5 100644 --- a/crates/light-client-verifier/src/consensus.rs +++ b/crates/light-client-verifier/src/consensus.rs @@ -2,7 +2,7 @@ use crate::context::ConsensusVerificationContext; use crate::errors::{Error, MisbehaviourError}; use crate::internal_prelude::*; use crate::misbehaviour::Misbehaviour; -use crate::state::{NextSyncCommitteeView, SyncCommitteeView}; +use crate::state::SyncCommitteeView; use crate::updates::{ConsensusUpdate, ExecutionUpdate, LightClientBootstrap}; use core::marker::PhantomData; use ethereum_consensus::beacon::{ @@ -26,14 +26,21 @@ use ethereum_consensus::sync_protocol::{ use ethereum_consensus::types::H256; /// SyncProtocolVerifier is a verifier of [light client sync protocol](https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md) -pub trait SyncProtocolVerifier< +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct SyncProtocolVerifier< const SYNC_COMMITTEE_SIZE: usize, const EXECUTION_PAYLOAD_TREE_DEPTH: usize, - ST, -> + ST: SyncCommitteeView, +>(PhantomData); + +impl< + const SYNC_COMMITTEE_SIZE: usize, + const EXECUTION_PAYLOAD_TREE_DEPTH: usize, + ST: SyncCommitteeView, + > SyncProtocolVerifier { /// validates a LightClientBootstrap - fn validate_boostrap>( + pub fn validate_boostrap>( &self, bootstrap: &LB, trusted_block_root: Option, @@ -56,7 +63,7 @@ pub trait SyncProtocolVerifier< } /// validates consensus update and execution update - fn validate_updates< + pub fn validate_updates< CC: ChainContext + ConsensusVerificationContext, CU: ConsensusUpdate, EU: ExecutionUpdate, @@ -80,7 +87,7 @@ pub trait SyncProtocolVerifier< /// validate a consensus update with a committee from the trusted store /// follow the light client protocol in the consensus spec - fn validate_consensus_update< + pub fn validate_consensus_update< CC: ChainContext + ConsensusVerificationContext, CU: ConsensusUpdate, >( @@ -104,7 +111,7 @@ pub trait SyncProtocolVerifier< } /// validate an execution update with trusted/verified beacon block body - fn validate_execution_update( + pub fn validate_execution_update( &self, trusted_execution_root: Root, update: &EU, @@ -132,7 +139,7 @@ pub trait SyncProtocolVerifier< /// validates a misbehaviour with the store. /// it returns `Ok` if the misbehaviour is valid - fn validate_misbehaviour< + pub fn validate_misbehaviour< CC: ChainContext + ConsensusVerificationContext, CU: ConsensusUpdate, >( @@ -149,37 +156,7 @@ pub trait SyncProtocolVerifier< } /// ensure that the consensus update is relevant - fn ensure_relevant_update>( - &self, - ctx: &CC, - store: &ST, - update: &CU, - ) -> Result<(), Error>; - - /// returns a committee that needs to verify the update - fn get_attestation_verifier>( - &self, - ctx: &CC, - store: &ST, - update: &CU, - ) -> Result, Error>; -} - -#[derive(Debug, Clone, Default, PartialEq, Eq)] -pub struct CurrentNextSyncProtocolVerifier< - const SYNC_COMMITTEE_SIZE: usize, - const EXECUTION_PAYLOAD_TREE_DEPTH: usize, - ST: SyncCommitteeView, ->(PhantomData); - -impl< - const SYNC_COMMITTEE_SIZE: usize, - const EXECUTION_PAYLOAD_TREE_DEPTH: usize, - ST: SyncCommitteeView, - > SyncProtocolVerifier - for CurrentNextSyncProtocolVerifier -{ - fn ensure_relevant_update>( + pub fn ensure_relevant_update>( &self, ctx: &CC, store: &ST, @@ -236,7 +213,8 @@ impl< Ok(()) } - fn get_attestation_verifier>( + /// returns a committee that needs to verify the update + pub fn get_attestation_verifier>( &self, ctx: &CC, store: &ST, @@ -264,67 +242,6 @@ impl< } } -#[derive(Debug, Clone, Default, PartialEq, Eq)] -pub struct NextSyncProtocolVerifier< - const SYNC_COMMITTEE_SIZE: usize, - const EXECUTION_PAYLOAD_TREE_DEPTH: usize, ->; - -impl - SyncProtocolVerifier< - SYNC_COMMITTEE_SIZE, - EXECUTION_PAYLOAD_TREE_DEPTH, - NextSyncCommitteeView, - > for NextSyncProtocolVerifier -{ - fn ensure_relevant_update>( - &self, - _: &CC, - _: &NextSyncCommitteeView, - _: &CU, - ) -> Result<(), Error> { - Ok(()) - } - - fn get_attestation_verifier>( - &self, - ctx: &CC, - store: &NextSyncCommitteeView, - update: &CU, - ) -> Result, Error> { - let store_period = compute_sync_committee_period_at_slot(ctx, store.current_slot); - let update_signature_period = - compute_sync_committee_period_at_slot(ctx, update.signature_slot()); - let update_finalized_period = - compute_sync_committee_period_at_slot(ctx, update.finalized_beacon_header().slot); - let update_attested_period = - compute_sync_committee_period_at_slot(ctx, update.attested_beacon_header().slot); - - if update_signature_period != store_period + 1 { - return Err(Error::InvalidSingaturePeriod( - store_period, - update_signature_period, - "signature period must be equal to store_period+1".into(), - )); - } - if update_finalized_period != store_period + 1 { - return Err(Error::InvalidFinalizedPeriod( - store_period, - update_finalized_period, - "finalized period must be equal to store_period+1".into(), - )); - } - if update_finalized_period != update_attested_period { - return Err(Error::NotFinalizedUpdate( - update_finalized_period, - update_attested_period, - )); - } - - Ok(store.next_sync_committee.clone()) - } -} - /// verify a sync committee attestation pub fn verify_sync_committee_attestation< const SYNC_COMMITTEE_SIZE: usize, @@ -450,7 +367,7 @@ mod tests_bellatrix { #[test] fn test_bootstrap() { - let verifier = CurrentNextSyncProtocolVerifier::< + let verifier = SyncProtocolVerifier::< { preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }, EXECUTION_PAYLOAD_TREE_DEPTH, MockStore<{ preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }>, @@ -489,7 +406,7 @@ mod tests_bellatrix { #[test] fn test_verification() { - let verifier = CurrentNextSyncProtocolVerifier::< + let verifier = SyncProtocolVerifier::< { preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }, EXECUTION_PAYLOAD_TREE_DEPTH, MockStore<{ preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }>, @@ -536,66 +453,6 @@ mod tests_bellatrix { } } - #[test] - fn test_verification_with_next_committee() { - let verifier = NextSyncProtocolVerifier::< - { preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }, - EXECUTION_PAYLOAD_TREE_DEPTH, - >::default(); - let (_, _, genesis_validators_root) = - get_init_state(format!("{}/initial_state.json", TEST_DATA_DIR)); - - let state = { - let (consensus_update, _) = get_updates(format!( - "{}/light_client_update_period_5.json", - TEST_DATA_DIR - )); - NextSyncCommitteeView { - current_slot: consensus_update.light_client_update.finalized_header.0.slot, - next_sync_committee: consensus_update - .light_client_update - .next_sync_committee - .clone() - .unwrap() - .0, - } - }; - let config = get_minimal_bellatrix_config(); - // NOTE: this is workaround. we must get the correct timestamp from beacon state. - let genesis_time = config.min_genesis_time; - let ctx = LightClientContext::new_with_config( - config, - genesis_validators_root, - genesis_time, - Fraction::new(2, 3), - || U64(100000000000000u64.into()), - ); - - let valid_cases = [ - "light_client_update_period_6.json", - "finality_update_period_6.json", - ]; - let invalid_cases = [ - "light_client_update_period_5.json", - "light_client_update_period_7.json", - "finality_update_period_7.json", - "finality_update_period_8.json", - ]; - - for c in valid_cases.iter() { - let (consensus_update, execution_update) = - get_updates(format!("{}/{}", TEST_DATA_DIR, c)); - let res = verifier.validate_updates(&ctx, &state, &consensus_update, &execution_update); - assert!(res.is_ok()); - } - - for c in invalid_cases.iter() { - let (update, _) = get_updates(format!("{}/{}", TEST_DATA_DIR, c)); - let res = verifier.validate_consensus_update(&ctx, &state, &update); - assert!(res.is_err()); - } - } - // returns boostrap, execution_state_root, genesis_validators_root fn get_init_state( path: impl Into, diff --git a/crates/light-client-verifier/src/lib.rs b/crates/light-client-verifier/src/lib.rs index d819554..4fe4139 100644 --- a/crates/light-client-verifier/src/lib.rs +++ b/crates/light-client-verifier/src/lib.rs @@ -1,6 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] extern crate alloc; +#[allow(unused_imports)] mod internal_prelude { pub use alloc::boxed::Box; pub use alloc::format; diff --git a/crates/light-client-verifier/src/state.rs b/crates/light-client-verifier/src/state.rs index f163a9a..e675ea8 100644 --- a/crates/light-client-verifier/src/state.rs +++ b/crates/light-client-verifier/src/state.rs @@ -6,15 +6,6 @@ use ethereum_consensus::{ sync_protocol::SyncCommittee, }; -/// NextSyncCommitteeView is a view corresponds to a specific light client update -#[derive(Debug, Default, Clone, PartialEq, Eq)] -pub struct NextSyncCommitteeView { - /// finalized header's slot from light client update - pub current_slot: Slot, - /// next sync committee from light client update - pub next_sync_committee: SyncCommittee, -} - pub trait SyncCommitteeView { fn current_slot(&self) -> Slot; fn current_sync_committee(&self) -> &SyncCommittee; diff --git a/crates/light-client-verifier/src/updates/capella.rs b/crates/light-client-verifier/src/updates/capella.rs index 6da2405..4b68cc6 100644 --- a/crates/light-client-verifier/src/updates/capella.rs +++ b/crates/light-client-verifier/src/updates/capella.rs @@ -1,5 +1,6 @@ pub use super::bellatrix::ExecutionUpdateInfo; use super::{ConsensusUpdate, LightClientBootstrap}; +#[allow(unused_imports)] use crate::internal_prelude::*; use core::ops::Deref; use ethereum_consensus::{ diff --git a/crates/lodestar-rpc/src/types.rs b/crates/lodestar-rpc/src/types.rs index a8e9f6e..b775f96 100644 --- a/crates/lodestar-rpc/src/types.rs +++ b/crates/lodestar-rpc/src/types.rs @@ -1,7 +1,7 @@ use ethereum_consensus::{ beacon::{BeaconBlockHeader, Checkpoint, Root, Slot}, bls::Signature, - capella::{LightClientBootstrap, LightClientHeader, LightClientUpdate}, + deneb::{LightClientBootstrap, LightClientHeader, LightClientUpdate}, sync_protocol::FINALIZED_ROOT_DEPTH, sync_protocol::{ SyncAggregate, SyncCommittee, CURRENT_SYNC_COMMITTEE_DEPTH, NEXT_SYNC_COMMITTEE_DEPTH,