From 55d36878dc6511bbef7253b9c44dbc53b41ca690 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sun, 14 Jan 2024 17:20:16 +0900 Subject: [PATCH 1/4] update verifier Signed-off-by: Jun Kimura --- crates/ibc/Cargo.toml | 4 +- crates/ibc/src/client_state.rs | 98 ++++++++++++++++++++++------------ crates/ibc/src/update.rs | 16 ++++-- 3 files changed, 79 insertions(+), 39 deletions(-) diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index 385eb67..f95bf54 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -15,8 +15,8 @@ tiny-keccak = { version = "2.0.2", default-features = false } ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", default-features = false, features = ["serde"] } ethereum-ibc-proto = { path = "../../proto", default-features = false } -ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "aac304f27372e8a0fb950522ee9cd6f41e43f56f", default-features = false } -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "aac304f27372e8a0fb950522ee9cd6f41e43f56f", default-features = false } +ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "f9efeb24a722db91d387eaa198b4cdc652ee4c93", default-features = false } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "f9efeb24a722db91d387eaa198b4cdc652ee4c93", default-features = false } [dev-dependencies] time = { version = "0.3", default-features = false, features = ["macros", "parsing"] } diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index 25e937b..348949a 100644 --- a/crates/ibc/src/client_state.rs +++ b/crates/ibc/src/client_state.rs @@ -9,7 +9,6 @@ use core::time::Duration; use ethereum_consensus::beacon::{Epoch, Root, Slot, Version}; use ethereum_consensus::context::ChainContext; use ethereum_consensus::fork::{ForkParameter, ForkParameters}; -use ethereum_consensus::preset; use ethereum_consensus::types::{Address, H256, U64}; use ethereum_ibc_proto::ibc::lightclients::ethereum::v1::{ClientState as RawClientState, Fork}; use ethereum_light_client_verifier::consensus::{ @@ -36,11 +35,9 @@ use serde::{Deserialize, Serialize}; pub const ETHEREUM_CLIENT_STATE_TYPE_URL: &str = "/ibc.lightclients.ethereum.v1.ClientState"; -pub type MainnetClientState = ClientState<{ preset::mainnet::PRESET.SYNC_COMMITTEE_SIZE }>; -pub type MinimalClientState = ClientState<{ preset::minimal::PRESET.SYNC_COMMITTEE_SIZE }>; - #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -pub struct ClientState { +pub struct ClientState +{ /// Chain parameters pub genesis_validators_root: Root, pub min_sync_committee_participants: U64, @@ -66,13 +63,18 @@ pub struct ClientState { /// Verifier #[serde(skip)] - pub consensus_verifier: - CurrentNextSyncProtocolVerifier>, + pub consensus_verifier: CurrentNextSyncProtocolVerifier< + SYNC_COMMITTEE_SIZE, + EXECUTION_PAYLOAD_TREE_DEPTH, + TrustedConsensusState, + >, #[serde(skip)] pub execution_verifier: ExecutionVerifier, } -impl ClientState { +impl + ClientState +{ pub fn with_frozen_height(self, h: Height) -> Self { Self { frozen_height: Some(h), @@ -215,7 +217,9 @@ impl ClientState { } } -impl Ics2ClientState for ClientState { +impl Ics2ClientState + for ClientState +{ fn chain_id(&self) -> ChainId { todo!() } @@ -390,7 +394,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(proof_height)?; let value = expected_consensus_state @@ -414,7 +419,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(proof_height)?; let value = expected_counterparty_connection_end @@ -438,7 +444,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(proof_height)?; let value = expected_counterparty_channel_end @@ -463,7 +470,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(proof_height)?; let value = expected_client_state.encode_to_vec(); @@ -487,7 +495,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(height)?; self.verify_membership( @@ -509,7 +518,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(height)?; self.verify_membership( @@ -531,7 +541,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(height)?; let mut seq_bytes = Vec::new(); @@ -557,7 +568,8 @@ impl Ics2ClientState for ClientState Result<(), ClientError> { - let client_state = downcast_eth_client_state::(self)?; + let client_state = + downcast_eth_client_state::(self)?; client_state.verify_height(height)?; self.verify_non_membership( @@ -595,13 +607,13 @@ fn validate_within_trusting_period( Ok(()) } -impl Protobuf - for ClientState +impl + Protobuf for ClientState { } -impl TryFrom - for ClientState +impl + TryFrom for ClientState { type Error = Error; @@ -655,8 +667,10 @@ impl TryFrom } } -impl From> for RawClientState { - fn from(value: ClientState) -> Self { +impl + From> for RawClientState +{ + fn from(value: ClientState) -> Self { use ethereum_ibc_proto::ibc::core::client::v1::Height as ProtoHeight; use ethereum_ibc_proto::ibc::lightclients::ethereum::v1::{ ForkParameters as ProtoForkParameters, Fraction as ProtoFraction, @@ -708,18 +722,27 @@ impl From> fo } } -impl Protobuf for ClientState {} +impl Protobuf + for ClientState +{ +} -impl TryFrom for ClientState { +impl TryFrom + for ClientState +{ type Error = ClientError; fn try_from(raw: Any) -> Result { use bytes::Buf; use core::ops::Deref; - fn decode_client_state( + fn decode_client_state< + const SYNC_COMMITTEE_SIZE: usize, + const EXECUTION_PAYLOAD_TREE_DEPTH: usize, + B: Buf, + >( buf: B, - ) -> Result, Error> { + ) -> Result, Error> { RawClientState::decode(buf) .map_err(Error::Decode)? .try_into() @@ -727,8 +750,10 @@ impl TryFrom for ClientState { - decode_client_state::(raw.value.deref()) - .map_err(Into::into) + decode_client_state::( + raw.value.deref(), + ) + .map_err(Into::into) } _ => Err(ClientError::UnknownClientStateType { client_state_type: raw.type_url, @@ -737,8 +762,10 @@ impl TryFrom for ClientState From> for Any { - fn from(value: ClientState) -> Self { +impl + From> for Any +{ + fn from(value: ClientState) -> Self { Self { type_url: ETHEREUM_CLIENT_STATE_TYPE_URL.to_string(), value: Protobuf::::encode_vec(&value) @@ -747,11 +774,14 @@ impl From> fo } } -fn downcast_eth_client_state( +fn downcast_eth_client_state< + const SYNC_COMMITTEE_SIZE: usize, + const EXECUTION_PAYLOAD_TREE_DEPTH: usize, +>( cs: &dyn Ics2ClientState, -) -> Result<&ClientState, ClientError> { +) -> Result<&ClientState, ClientError> { cs.as_any() - .downcast_ref::>() + .downcast_ref::>() .ok_or_else(|| ClientError::ClientArgsTypeMismatch { client_type: eth_client_type(), }) diff --git a/crates/ibc/src/update.rs b/crates/ibc/src/update.rs index 13207de..04d0e5c 100644 --- a/crates/ibc/src/update.rs +++ b/crates/ibc/src/update.rs @@ -36,15 +36,25 @@ pub fn new_consensus_update( } } -pub fn apply_updates( +pub fn apply_updates< + const SYNC_COMMITTEE_SIZE: usize, + const EXECUTION_PAYLOAD_TREE_DEPTH: usize, + C: ChainContext, +>( ctx: &C, - client_state: &ClientState, + client_state: &ClientState, trusted_consensus_state: &TrustedConsensusState, consensus_update: ConsensusUpdateInfo, execution_update: ExecutionUpdateInfo, account_update: AccountUpdateInfo, timestamp: Timestamp, -) -> Result<(ClientState, ConsensusState), Error> { +) -> Result< + ( + ClientState, + ConsensusState, + ), + Error, +> { let mut new_client_state = client_state.clone(); let store_period = From 953e0973d3ec897548d3c41361bce8d96f1bc714 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sun, 14 Jan 2024 19:51:29 +0900 Subject: [PATCH 2/4] reexport light client crate Signed-off-by: Jun Kimura --- crates/ibc/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index 963f73c..1867790 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -10,6 +10,8 @@ pub mod header; pub mod misbehaviour; pub mod types; pub mod update; +pub use ethereum_consensus as consensus; +pub use ethereum_light_client_verifier as light_client_verifier; mod internal_prelude { pub use alloc::boxed::Box; From e9f027490d98a6fea9709832f2e390d0cc7cf298 Mon Sep 17 00:00:00 2001 From: Jun Kimura Date: Sun, 14 Jan 2024 19:58:34 +0900 Subject: [PATCH 3/4] fix lint warning Signed-off-by: Jun Kimura --- crates/ibc/src/client_state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ibc/src/client_state.rs b/crates/ibc/src/client_state.rs index 348949a..75d80eb 100644 --- a/crates/ibc/src/client_state.rs +++ b/crates/ibc/src/client_state.rs @@ -101,7 +101,7 @@ impl Date: Sun, 14 Jan 2024 22:54:11 +0900 Subject: [PATCH 4/4] update verifier Signed-off-by: Jun Kimura --- crates/ibc/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ibc/Cargo.toml b/crates/ibc/Cargo.toml index f95bf54..2c12a11 100644 --- a/crates/ibc/Cargo.toml +++ b/crates/ibc/Cargo.toml @@ -15,8 +15,8 @@ tiny-keccak = { version = "2.0.2", default-features = false } ssz-rs = { git = "https://github.com/bluele/ssz_rs", branch = "serde-no-std", default-features = false, features = ["serde"] } ethereum-ibc-proto = { path = "../../proto", default-features = false } -ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "f9efeb24a722db91d387eaa198b4cdc652ee4c93", default-features = false } -ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "f9efeb24a722db91d387eaa198b4cdc652ee4c93", default-features = false } +ethereum-consensus = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "d0caaa0d9e25d481dd25bdb8eb4a8b8ad27aca55", default-features = false } +ethereum-light-client-verifier = { git = "https://github.com/datachainlab/ethereum-light-client-rs", rev = "d0caaa0d9e25d481dd25bdb8eb4a8b8ad27aca55", default-features = false } [dev-dependencies] time = { version = "0.3", default-features = false, features = ["macros", "parsing"] }