Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: deneb support #8

Merged
merged 3 commits into from
Oct 25, 2024
Merged
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
3 changes: 2 additions & 1 deletion crates/consensus/src/config/goerli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
3 changes: 2 additions & 1 deletion crates/consensus/src/config/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
3 changes: 2 additions & 1 deletion crates/consensus/src/config/sepolia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
18 changes: 10 additions & 8 deletions crates/consensus/src/deneb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES>,
leaf_indices: &[usize],
) -> Result<(Root, Vec<H256>), Error> {
leaf_index: usize,
) -> Result<(Root, [H256; EXECUTION_PAYLOAD_TREE_DEPTH]), Error> {
let tree = MerkleTree::from_leaves(
([
payload.parent_hash.0,
Expand Down Expand Up @@ -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::<Vec<H256>>()
.as_slice(),
);
Ok((H256(tree.root().unwrap()), branch))
}
1 change: 1 addition & 0 deletions crates/consensus/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/light-client-cli/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = core::result::Result<T, Error>;
Expand Down
13 changes: 6 additions & 7 deletions crates/light-client-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<T> = core::result::Result<T, Error>;
Expand All @@ -43,7 +42,7 @@ pub struct LightClient<
> {
ctx: Context<BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES, SYNC_COMMITTEE_SIZE>,
chain: Chain,
verifier: CurrentNextSyncProtocolVerifier<
verifier: SyncProtocolVerifier<
SYNC_COMMITTEE_SIZE,
EXECUTION_PAYLOAD_TREE_DEPTH,
LightClientStore<SYNC_COMMITTEE_SIZE, BYTES_PER_LOGS_BLOOM, MAX_EXTRA_DATA_BYTES>,
Expand Down Expand Up @@ -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,
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/light-client-cli/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion crates/light-client-cli/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ethereum_consensus::{
beacon::{BeaconBlockHeader, Slot},
capella::{ExecutionPayloadHeader, LightClientBootstrap},
deneb::{ExecutionPayloadHeader, LightClientBootstrap},
sync_protocol::SyncCommittee,
types::{H256, U64},
};
Expand Down
Loading
Loading