From b67de43efc7c4ee8651f23791841cb3f36293306 Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Thu, 6 Feb 2025 20:18:41 -0800 Subject: [PATCH 1/6] chore: remove ssz_rs dependency --- Cargo.lock | 58 ++++--------------- crates/light-client/Cargo.toml | 4 +- .../src/consensus/consensus_client.rs | 9 ++- crates/light-client/src/consensus/utils.rs | 52 ++++++++++------- crates/light-client/src/types.rs | 4 +- crates/light-client/src/utils.rs | 9 +-- portal-spec-tests | 2 +- 7 files changed, 57 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e332fa71..bf6922195 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -320,7 +320,7 @@ dependencies = [ "derive_more 1.0.0", "once_cell", "serde", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -2162,7 +2162,7 @@ dependencies = [ "ed25519", "rand_core", "serde", - "sha2 0.10.8", + "sha2", "subtle", "zeroize", ] @@ -2340,7 +2340,7 @@ checksum = "c853bd72c9e5787f8aafc3df2907c2ed03cff3150c3acd94e2e53a98ab70a8ab" dependencies = [ "cpufeatures", "ring", - "sha2 0.10.8", + "sha2", ] [[package]] @@ -2413,7 +2413,7 @@ dependencies = [ "serde-this-or-that", "serde_json", "serde_yaml", - "sha2 0.10.8", + "sha2", "sha3 0.9.1", "snap", "ssz_types", @@ -3659,7 +3659,7 @@ dependencies = [ "ecdsa", "elliptic-curve", "once_cell", - "sha2 0.10.8", + "sha2", "signature", ] @@ -3791,6 +3791,7 @@ dependencies = [ "anyhow", "async-trait", "chrono", + "ethereum_ssz", "ethportal-api", "figment", "futures", @@ -3804,7 +3805,6 @@ dependencies = [ "serde_json", "serde_yaml", "snowbridge-milagro-bls", - "ssz-rs", "ssz_types", "strum", "thiserror 1.0.69", @@ -3812,6 +3812,8 @@ dependencies = [ "tracing", "tracing-subscriber 0.3.19", "tree_hash", + "tree_hash_derive", + "trin-validation", ] [[package]] @@ -5157,7 +5159,7 @@ dependencies = [ "revm-primitives", "ripemd", "secp256k1", - "sha2 0.10.8", + "sha2", "substrate-bn", ] @@ -5272,7 +5274,7 @@ version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b241d2e59b74ef9e98d94c78c47623d04c8392abaf82014dfd372a16041128f" dependencies = [ - "sha2 0.10.8", + "sha2", ] [[package]] @@ -5380,7 +5382,7 @@ version = "7.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d38ff6bf570dc3bb7100fce9f7b60c33fa71d80e88da3f2580df4ff2bdded74" dependencies = [ - "sha2 0.10.8", + "sha2", "walkdir", ] @@ -5851,19 +5853,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha2" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" -dependencies = [ - "block-buffer 0.9.0", - "cfg-if", - "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "sha2" version = "0.10.8" @@ -6043,31 +6032,6 @@ dependencies = [ "der", ] -[[package]] -name = "ssz-rs" -version = "0.8.0" -source = "git+https://github.com/ralexstokes/ssz-rs?rev=d09f55b4f8554491e3431e01af1c32347a8781cd#d09f55b4f8554491e3431e01af1c32347a8781cd" -dependencies = [ - "bitvec", - "hex", - "lazy_static", - "num-bigint", - "serde", - "sha2 0.9.9", - "ssz-rs-derive", - "thiserror 1.0.69", -] - -[[package]] -name = "ssz-rs-derive" -version = "0.8.0" -source = "git+https://github.com/ralexstokes/ssz-rs?rev=d09f55b4f8554491e3431e01af1c32347a8781cd#d09f55b4f8554491e3431e01af1c32347a8781cd" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "ssz_types" version = "0.8.0" diff --git a/crates/light-client/Cargo.toml b/crates/light-client/Cargo.toml index daf790665..67bff107e 100644 --- a/crates/light-client/Cargo.toml +++ b/crates/light-client/Cargo.toml @@ -17,6 +17,8 @@ anyhow.workspace = true async-trait.workspace = true chrono.workspace = true ethportal-api.workspace = true +trin-validation.workspace = true +ethereum_ssz.workspace = true figment = { version = "0.10.7", features = ["toml", "env"] } futures.workspace = true hex.workspace = true @@ -29,7 +31,6 @@ serde.workspace = true serde-this-or-that.workspace = true serde_json.workspace = true serde_yaml.workspace = true -ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs", rev = "d09f55b4f8554491e3431e01af1c32347a8781cd" } ssz_types.workspace = true strum.workspace = true thiserror.workspace = true @@ -37,6 +38,7 @@ tokio.workspace = true tracing.workspace = true tracing-subscriber.workspace = true tree_hash.workspace = true +tree_hash_derive.workspace = true [lib] name = "light_client" diff --git a/crates/light-client/src/consensus/consensus_client.rs b/crates/light-client/src/consensus/consensus_client.rs index 8fcb8cf29..a74871ae8 100644 --- a/crates/light-client/src/consensus/consensus_client.rs +++ b/crates/light-client/src/consensus/consensus_client.rs @@ -19,7 +19,6 @@ use ethportal_api::{ utils::bytes::hex_encode, }; use milagro_bls::PublicKey; -use ssz_rs::prelude::*; use ssz_types::{typenum, BitVector, FixedVector}; use tracing::{debug, info, warn}; use tree_hash::TreeHash; @@ -583,12 +582,12 @@ fn compute_committee_sign_root( genesis_root: &[u8], header: Bytes32, fork_version: &[u8], -) -> Result { +) -> Result { let genesis_root = genesis_root.to_vec().try_into()?; let domain_type = &hex::decode("07000000")?[..]; - let fork_version = Vector::from_iter(fork_version.to_vec()); + let fork_version = FixedVector::from(fork_version.to_vec()); let domain = compute_domain(domain_type, fork_version, genesis_root)?; - compute_signing_root(header, domain) + Ok(compute_signing_root(header, domain)) } fn get_participating_keys( @@ -632,7 +631,7 @@ fn verify_sync_committee_signature( Ok(is_aggregate_valid( signature, - signing_root.r#as_bytes(), + signing_root.as_slice(), &public_keys, )) })(); diff --git a/crates/light-client/src/consensus/utils.rs b/crates/light-client/src/consensus/utils.rs index 4726d98ac..2e69ba9fc 100644 --- a/crates/light-client/src/consensus/utils.rs +++ b/crates/light-client/src/consensus/utils.rs @@ -1,8 +1,12 @@ +use alloy::primitives::B256; use anyhow::Result; use ethportal_api::consensus::{header::BeaconBlockHeader, signature::BlsSignature}; use milagro_bls::{AggregateSignature, PublicKey}; -use ssz_rs::prelude::*; +use ssz::Encode; +use ssz_types::{typenum::U4, FixedVector}; use tree_hash::TreeHash; +use tree_hash_derive::TreeHash; +use trin_validation::merkle::proof::merkle_root_from_branch; use crate::{types::Bytes32, utils::bytes32_to_node}; @@ -21,72 +25,78 @@ pub fn is_aggregate_valid(sig_bytes: &BlsSignature, msg: &[u8], pks: &[&PublicKe pub fn is_proof_valid( attested_header: &BeaconBlockHeader, - leaf_object: &mut L, + leaf_object: &L, branch: &[Bytes32], depth: usize, index: usize, ) -> bool { let res: Result = (move || { - let leaf_hash = Node::from_bytes(<[u8; 32]>::from(leaf_object.tree_hash_root())); + let leaf_hash = leaf_object.tree_hash_root(); let state_root = bytes32_to_node( &Bytes32::try_from(attested_header.state_root.0.to_vec()) .expect("Unable to convert state root to bytes"), )?; - let branch = branch_to_nodes(branch.to_vec())?; + let branches = branch_to_nodes(branch.to_vec())?; - let is_valid = is_valid_merkle_branch(&leaf_hash, branch.iter(), depth, index, &state_root); - Ok(is_valid) + leaf_hash.ssz_append(&mut branches.as_ssz_bytes()); + + let root = merkle_root_from_branch(leaf_hash, &branches, depth, index); + + println!("state root >>> {:?}", state_root); + println!("calculated root >>> {:?}", root); + + Ok(root == state_root) })(); res.unwrap_or_default() } -#[derive(SimpleSerialize, Default, Debug)] +#[derive(Default, Debug, TreeHash)] struct SigningData { object_root: Bytes32, domain: Bytes32, } -#[derive(SimpleSerialize, Default, Debug)] +#[derive(Default, Debug, TreeHash)] struct ForkData { - current_version: Vector, + current_version: FixedVector, genesis_validator_root: Bytes32, } -pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> Result { - let mut data = SigningData { +pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> B256 { + let data = SigningData { object_root, domain, }; - Ok(data.hash_tree_root()?) + data.tree_hash_root() } pub fn compute_domain( domain_type: &[u8], - fork_version: Vector, + fork_version: FixedVector, genesis_root: Bytes32, ) -> Result { - let fork_data_root = compute_fork_data_root(fork_version, genesis_root)?; + let fork_data_root = compute_fork_data_root(fork_version, genesis_root); let start = domain_type; - let end = &fork_data_root.as_bytes()[..28]; + let end = &fork_data_root.as_slice()[..28]; let d = [start, end].concat(); Ok(d.to_vec().try_into()?) } fn compute_fork_data_root( - current_version: Vector, + current_version: FixedVector, genesis_validator_root: Bytes32, -) -> Result { - let mut fork_data = ForkData { +) -> B256 { + let fork_data = ForkData { current_version, genesis_validator_root, }; - Ok(fork_data.hash_tree_root()?) + fork_data.tree_hash_root() } -pub fn branch_to_nodes(branch: Vec) -> Result> { +pub fn branch_to_nodes(branch: Vec) -> Result> { branch .iter() .map(bytes32_to_node) - .collect::>>() + .collect::>>() } diff --git a/crates/light-client/src/types.rs b/crates/light-client/src/types.rs index cf51f1922..ad932bad0 100644 --- a/crates/light-client/src/types.rs +++ b/crates/light-client/src/types.rs @@ -1,3 +1,3 @@ -use ssz_rs::Vector; +use ssz_types::{typenum::U32, FixedVector}; -pub type Bytes32 = Vector; +pub type Bytes32 = FixedVector; diff --git a/crates/light-client/src/utils.rs b/crates/light-client/src/utils.rs index 5ea42fbcd..86551feed 100644 --- a/crates/light-client/src/utils.rs +++ b/crates/light-client/src/utils.rs @@ -1,14 +1,15 @@ +use alloy::primitives::B256; use anyhow::Result; -use ssz_rs::{Node, Vector}; +use ssz_types::FixedVector; use crate::types::Bytes32; pub fn bytes_to_bytes32(bytes: &[u8]) -> Bytes32 { - Vector::from_iter(bytes.to_vec()) + FixedVector::from(bytes.to_vec()) } -pub fn bytes32_to_node(bytes: &Bytes32) -> Result { - Ok(Node::from_bytes(bytes.as_slice().try_into()?)) +pub fn bytes32_to_node(bytes: &Bytes32) -> Result { + Ok(B256::from_slice(bytes.iter().as_slice().try_into()?)) } pub fn u64_to_hex_string(val: u64) -> String { diff --git a/portal-spec-tests b/portal-spec-tests index 83b3a3e08..9942d0c36 160000 --- a/portal-spec-tests +++ b/portal-spec-tests @@ -1 +1 @@ -Subproject commit 83b3a3e08a789aa8005429331ef82eea9c59dd20 +Subproject commit 9942d0c367a542f6952e8aca5ed2c886c5786b0c From 427c8c1b142696e9d493427e8b4ae18d1e4c4a28 Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Thu, 6 Feb 2025 21:19:34 -0800 Subject: [PATCH 2/6] chore: fix clippy errors --- crates/light-client/src/consensus/consensus_client.rs | 2 +- crates/light-client/src/consensus/utils.rs | 10 ++-------- crates/light-client/src/utils.rs | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/light-client/src/consensus/consensus_client.rs b/crates/light-client/src/consensus/consensus_client.rs index a74871ae8..3cf6aaa7b 100644 --- a/crates/light-client/src/consensus/consensus_client.rs +++ b/crates/light-client/src/consensus/consensus_client.rs @@ -583,7 +583,7 @@ fn compute_committee_sign_root( header: Bytes32, fork_version: &[u8], ) -> Result { - let genesis_root = genesis_root.to_vec().try_into()?; + let genesis_root = genesis_root.to_vec().into(); let domain_type = &hex::decode("07000000")?[..]; let fork_version = FixedVector::from(fork_version.to_vec()); let domain = compute_domain(domain_type, fork_version, genesis_root)?; diff --git a/crates/light-client/src/consensus/utils.rs b/crates/light-client/src/consensus/utils.rs index 2e69ba9fc..5726d165c 100644 --- a/crates/light-client/src/consensus/utils.rs +++ b/crates/light-client/src/consensus/utils.rs @@ -32,19 +32,13 @@ pub fn is_proof_valid( ) -> bool { let res: Result = (move || { let leaf_hash = leaf_object.tree_hash_root(); - let state_root = bytes32_to_node( - &Bytes32::try_from(attested_header.state_root.0.to_vec()) - .expect("Unable to convert state root to bytes"), - )?; + let state_root = bytes32_to_node(&Bytes32::from(attested_header.state_root.0.to_vec()))?; let branches = branch_to_nodes(branch.to_vec())?; leaf_hash.ssz_append(&mut branches.as_ssz_bytes()); let root = merkle_root_from_branch(leaf_hash, &branches, depth, index); - println!("state root >>> {:?}", state_root); - println!("calculated root >>> {:?}", root); - Ok(root == state_root) })(); @@ -80,7 +74,7 @@ pub fn compute_domain( let start = domain_type; let end = &fork_data_root.as_slice()[..28]; let d = [start, end].concat(); - Ok(d.to_vec().try_into()?) + Ok(d.to_vec().into()) } fn compute_fork_data_root( diff --git a/crates/light-client/src/utils.rs b/crates/light-client/src/utils.rs index 86551feed..babd4d870 100644 --- a/crates/light-client/src/utils.rs +++ b/crates/light-client/src/utils.rs @@ -9,7 +9,7 @@ pub fn bytes_to_bytes32(bytes: &[u8]) -> Bytes32 { } pub fn bytes32_to_node(bytes: &Bytes32) -> Result { - Ok(B256::from_slice(bytes.iter().as_slice().try_into()?)) + Ok(B256::from_slice(bytes.iter().as_slice())) } pub fn u64_to_hex_string(val: u64) -> String { From c23f46d6fd063cbcbe6b01516f84e953e1934415 Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Thu, 6 Feb 2025 22:53:27 -0800 Subject: [PATCH 3/6] fix: remove ssz append to branches --- crates/light-client/src/consensus/utils.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/crates/light-client/src/consensus/utils.rs b/crates/light-client/src/consensus/utils.rs index 5726d165c..17d354e1f 100644 --- a/crates/light-client/src/consensus/utils.rs +++ b/crates/light-client/src/consensus/utils.rs @@ -2,7 +2,6 @@ use alloy::primitives::B256; use anyhow::Result; use ethportal_api::consensus::{header::BeaconBlockHeader, signature::BlsSignature}; use milagro_bls::{AggregateSignature, PublicKey}; -use ssz::Encode; use ssz_types::{typenum::U4, FixedVector}; use tree_hash::TreeHash; use tree_hash_derive::TreeHash; @@ -33,11 +32,9 @@ pub fn is_proof_valid( let res: Result = (move || { let leaf_hash = leaf_object.tree_hash_root(); let state_root = bytes32_to_node(&Bytes32::from(attested_header.state_root.0.to_vec()))?; - let branches = branch_to_nodes(branch.to_vec())?; + let branch = branch_to_nodes(branch.to_vec())?; - leaf_hash.ssz_append(&mut branches.as_ssz_bytes()); - - let root = merkle_root_from_branch(leaf_hash, &branches, depth, index); + let root = merkle_root_from_branch(leaf_hash, &branch, depth, index); Ok(root == state_root) })(); From 09f976e3e4949b015f63d43c99582cc95d3285ed Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Sat, 8 Feb 2025 23:58:40 -0800 Subject: [PATCH 4/6] fix: remove light_client Bytes32 type and replace with B256 --- crates/light-client/Cargo.toml | 2 +- .../src/consensus/consensus_client.rs | 20 ++----------- crates/light-client/src/consensus/utils.rs | 30 +++++++------------ crates/light-client/src/lib.rs | 1 - crates/light-client/src/types.rs | 3 -- crates/light-client/src/utils.rs | 18 ++++------- 6 files changed, 20 insertions(+), 54 deletions(-) delete mode 100644 crates/light-client/src/types.rs diff --git a/crates/light-client/Cargo.toml b/crates/light-client/Cargo.toml index 67bff107e..8812730af 100644 --- a/crates/light-client/Cargo.toml +++ b/crates/light-client/Cargo.toml @@ -17,7 +17,6 @@ anyhow.workspace = true async-trait.workspace = true chrono.workspace = true ethportal-api.workspace = true -trin-validation.workspace = true ethereum_ssz.workspace = true figment = { version = "0.10.7", features = ["toml", "env"] } futures.workspace = true @@ -39,6 +38,7 @@ tracing.workspace = true tracing-subscriber.workspace = true tree_hash.workspace = true tree_hash_derive.workspace = true +trin-validation.workspace = true [lib] name = "light_client" diff --git a/crates/light-client/src/consensus/consensus_client.rs b/crates/light-client/src/consensus/consensus_client.rs index 3cf6aaa7b..655c08d02 100644 --- a/crates/light-client/src/consensus/consensus_client.rs +++ b/crates/light-client/src/consensus/consensus_client.rs @@ -29,8 +29,6 @@ use crate::{ consensus::{ constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES, rpc::portal_rpc::expected_current_slot, }, - types::Bytes32, - utils::bytes_to_bytes32, }; // https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md @@ -580,10 +578,10 @@ pub fn verify_generic_update( fn compute_committee_sign_root( genesis_root: &[u8], - header: Bytes32, + header: B256, fork_version: &[u8], ) -> Result { - let genesis_root = genesis_root.to_vec().into(); + let genesis_root = B256::from_slice(genesis_root); let domain_type = &hex::decode("07000000")?[..]; let fork_version = FixedVector::from(fork_version.to_vec()); let domain = compute_domain(domain_type, fork_version, genesis_root)?; @@ -626,7 +624,7 @@ fn verify_sync_committee_signature( ) -> bool { let res: Result = (move || { let public_keys: Vec<&PublicKey> = pks.iter().collect(); - let header_root = bytes_to_bytes32(attested_header.tree_hash_root().as_slice()); + let header_root = attested_header.tree_hash_root(); let signing_root = compute_committee_sign_root(genesis_root, header_root, fork_version)?; Ok(is_aggregate_valid( @@ -644,10 +642,6 @@ fn is_finality_proof_valid( finality_header: &mut BeaconBlockHeader, finality_branch: &FixedVector, ) -> bool { - let finality_branch = finality_branch - .iter() - .map(|h| bytes_to_bytes32(h.as_slice())) - .collect::>(); is_proof_valid(attested_header, finality_header, &finality_branch, 6, 41) } @@ -656,10 +650,6 @@ fn is_next_committee_proof_valid( next_committee: &mut SyncCommittee, next_committee_branch: &FixedVector, ) -> bool { - let next_committee_branch = next_committee_branch - .iter() - .map(|h| bytes_to_bytes32(h.as_slice())) - .collect::>(); is_proof_valid( attested_header, next_committee, @@ -674,10 +664,6 @@ fn is_current_committee_proof_valid( current_committee: &mut SyncCommittee, current_committee_branch: &FixedVector, ) -> bool { - let current_committee_branch = current_committee_branch - .iter() - .map(|h| bytes_to_bytes32(h.as_slice())) - .collect::>(); is_proof_valid( attested_header, current_committee, diff --git a/crates/light-client/src/consensus/utils.rs b/crates/light-client/src/consensus/utils.rs index 17d354e1f..aa2df158c 100644 --- a/crates/light-client/src/consensus/utils.rs +++ b/crates/light-client/src/consensus/utils.rs @@ -7,8 +7,6 @@ use tree_hash::TreeHash; use tree_hash_derive::TreeHash; use trin_validation::merkle::proof::merkle_root_from_branch; -use crate::{types::Bytes32, utils::bytes32_to_node}; - pub fn calc_sync_period(slot: u64) -> u64 { let epoch = slot / 32; // 32 slots per epoch epoch / 256 // 256 epochs per sync committee @@ -25,14 +23,13 @@ pub fn is_aggregate_valid(sig_bytes: &BlsSignature, msg: &[u8], pks: &[&PublicKe pub fn is_proof_valid( attested_header: &BeaconBlockHeader, leaf_object: &L, - branch: &[Bytes32], + branch: &[B256], depth: usize, index: usize, ) -> bool { let res: Result = (move || { let leaf_hash = leaf_object.tree_hash_root(); - let state_root = bytes32_to_node(&Bytes32::from(attested_header.state_root.0.to_vec()))?; - let branch = branch_to_nodes(branch.to_vec())?; + let state_root = attested_header.state_root; let root = merkle_root_from_branch(leaf_hash, &branch, depth, index); @@ -44,17 +41,17 @@ pub fn is_proof_valid( #[derive(Default, Debug, TreeHash)] struct SigningData { - object_root: Bytes32, - domain: Bytes32, + object_root: B256, + domain: B256, } #[derive(Default, Debug, TreeHash)] struct ForkData { current_version: FixedVector, - genesis_validator_root: Bytes32, + genesis_validator_root: B256, } -pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> B256 { +pub fn compute_signing_root(object_root: B256, domain: B256) -> B256 { let data = SigningData { object_root, domain, @@ -65,18 +62,18 @@ pub fn compute_signing_root(object_root: Bytes32, domain: Bytes32) -> B256 { pub fn compute_domain( domain_type: &[u8], fork_version: FixedVector, - genesis_root: Bytes32, -) -> Result { + genesis_root: B256, +) -> Result { let fork_data_root = compute_fork_data_root(fork_version, genesis_root); let start = domain_type; let end = &fork_data_root.as_slice()[..28]; let d = [start, end].concat(); - Ok(d.to_vec().into()) + Ok(B256::from_slice(&d)) } fn compute_fork_data_root( current_version: FixedVector, - genesis_validator_root: Bytes32, + genesis_validator_root: B256, ) -> B256 { let fork_data = ForkData { current_version, @@ -84,10 +81,3 @@ fn compute_fork_data_root( }; fork_data.tree_hash_root() } - -pub fn branch_to_nodes(branch: Vec) -> Result> { - branch - .iter() - .map(bytes32_to_node) - .collect::>>() -} diff --git a/crates/light-client/src/lib.rs b/crates/light-client/src/lib.rs index a7f9f8e6e..024f55186 100644 --- a/crates/light-client/src/lib.rs +++ b/crates/light-client/src/lib.rs @@ -9,5 +9,4 @@ pub mod database; pub mod errors; pub mod node; pub mod rpc; -pub mod types; pub mod utils; diff --git a/crates/light-client/src/types.rs b/crates/light-client/src/types.rs deleted file mode 100644 index ad932bad0..000000000 --- a/crates/light-client/src/types.rs +++ /dev/null @@ -1,3 +0,0 @@ -use ssz_types::{typenum::U32, FixedVector}; - -pub type Bytes32 = FixedVector; diff --git a/crates/light-client/src/utils.rs b/crates/light-client/src/utils.rs index babd4d870..a599c6fdf 100644 --- a/crates/light-client/src/utils.rs +++ b/crates/light-client/src/utils.rs @@ -1,16 +1,10 @@ -use alloy::primitives::B256; -use anyhow::Result; -use ssz_types::FixedVector; +// pub fn bytes_to_bytes32(bytes: &[u8]) -> Bytes32 { +// FixedVector::from(bytes.to_vec()) +// } -use crate::types::Bytes32; - -pub fn bytes_to_bytes32(bytes: &[u8]) -> Bytes32 { - FixedVector::from(bytes.to_vec()) -} - -pub fn bytes32_to_node(bytes: &Bytes32) -> Result { - Ok(B256::from_slice(bytes.iter().as_slice())) -} +// pub fn bytes32_to_node(bytes: &Bytes32) -> Result { +// Ok(B256::from_slice(bytes.iter().as_slice())) +// } pub fn u64_to_hex_string(val: u64) -> String { format!("0x{val:x}") From c6dd4accc0261f3d98cf7b84d6f8b1da95090dca Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Sun, 9 Feb 2025 00:13:40 -0800 Subject: [PATCH 5/6] fix: fix clippy lint errors --- .../light-client/src/consensus/consensus_client.rs | 6 +++--- crates/light-client/src/consensus/utils.rs | 12 ++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/crates/light-client/src/consensus/consensus_client.rs b/crates/light-client/src/consensus/consensus_client.rs index 655c08d02..b77c97baf 100644 --- a/crates/light-client/src/consensus/consensus_client.rs +++ b/crates/light-client/src/consensus/consensus_client.rs @@ -642,7 +642,7 @@ fn is_finality_proof_valid( finality_header: &mut BeaconBlockHeader, finality_branch: &FixedVector, ) -> bool { - is_proof_valid(attested_header, finality_header, &finality_branch, 6, 41) + is_proof_valid(attested_header, finality_header, finality_branch, 6, 41) } fn is_next_committee_proof_valid( @@ -653,7 +653,7 @@ fn is_next_committee_proof_valid( is_proof_valid( attested_header, next_committee, - &next_committee_branch, + next_committee_branch, 5, 23, ) @@ -667,7 +667,7 @@ fn is_current_committee_proof_valid( is_proof_valid( attested_header, current_committee, - ¤t_committee_branch, + current_committee_branch, 5, 22, ) diff --git a/crates/light-client/src/consensus/utils.rs b/crates/light-client/src/consensus/utils.rs index aa2df158c..24d5702f3 100644 --- a/crates/light-client/src/consensus/utils.rs +++ b/crates/light-client/src/consensus/utils.rs @@ -27,16 +27,12 @@ pub fn is_proof_valid( depth: usize, index: usize, ) -> bool { - let res: Result = (move || { - let leaf_hash = leaf_object.tree_hash_root(); - let state_root = attested_header.state_root; + let leaf_hash = leaf_object.tree_hash_root(); + let state_root = attested_header.state_root; - let root = merkle_root_from_branch(leaf_hash, &branch, depth, index); + let root = merkle_root_from_branch(leaf_hash, branch, depth, index); - Ok(root == state_root) - })(); - - res.unwrap_or_default() + root == state_root } #[derive(Default, Debug, TreeHash)] From 172135a92cfb9ade20a3d55de01d551fdefc64d3 Mon Sep 17 00:00:00 2001 From: Omar Carey Date: Thu, 13 Feb 2025 10:36:33 -0800 Subject: [PATCH 6/6] fix: remove unused code and alphebatize light client cargo toml --- Cargo.lock | 2 +- crates/light-client/Cargo.toml | 2 +- crates/light-client/src/utils.rs | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf6922195..de9b7e76f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -300,7 +300,7 @@ dependencies = [ "derive_more 1.0.0", "once_cell", "serde", - "sha2 0.10.8", + "sha2", ] [[package]] diff --git a/crates/light-client/Cargo.toml b/crates/light-client/Cargo.toml index 8812730af..4286dec99 100644 --- a/crates/light-client/Cargo.toml +++ b/crates/light-client/Cargo.toml @@ -16,8 +16,8 @@ alloy.workspace = true anyhow.workspace = true async-trait.workspace = true chrono.workspace = true -ethportal-api.workspace = true ethereum_ssz.workspace = true +ethportal-api.workspace = true figment = { version = "0.10.7", features = ["toml", "env"] } futures.workspace = true hex.workspace = true diff --git a/crates/light-client/src/utils.rs b/crates/light-client/src/utils.rs index a599c6fdf..9b3754a5d 100644 --- a/crates/light-client/src/utils.rs +++ b/crates/light-client/src/utils.rs @@ -1,11 +1,3 @@ -// pub fn bytes_to_bytes32(bytes: &[u8]) -> Bytes32 { -// FixedVector::from(bytes.to_vec()) -// } - -// pub fn bytes32_to_node(bytes: &Bytes32) -> Result { -// Ok(B256::from_slice(bytes.iter().as_slice())) -// } - pub fn u64_to_hex_string(val: u64) -> String { format!("0x{val:x}") }