diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 7134492e4..998629fc8 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -6,6 +6,7 @@ use ibc_eureka_core_channel_types::events::AcknowledgePacket; use ibc_eureka_core_channel_types::msgs::MsgAcknowledgement; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, }; @@ -134,9 +135,20 @@ where { // TODO(rano): avoid a vs b confusion let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); let client_val_ctx_a = ctx_a.get_client_validation_context(); + let (stored_id_source_client_on_target, target_prefix) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } + let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; target_client_on_source diff --git a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs index 525924523..9774f8750 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -6,6 +6,7 @@ use ibc_eureka_core_channel_types::events::{ReceivePacket, WriteAcknowledgement} use ibc_eureka_core_channel_types::msgs::MsgRecvPacket; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ AckPathV2 as AckPath, ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, ReceiptPathV2 as ReceiptPath, SeqRecvPathV2 as SeqRecvPath, @@ -140,7 +141,20 @@ where // Verify proofs { let id_source_client_on_target = channel_source_client_on_target.as_ref(); + let id_target_client_on_source: &ClientId = channel_target_client_on_source.as_ref(); + let client_val_ctx_b = ctx_b.get_client_validation_context(); + + let (stored_id_target_client_on_source, source_prefix) = + client_val_ctx_b.counterparty_client(id_source_client_on_target)?; + + if &stored_id_target_client_on_source != id_target_client_on_source { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_target_client_on_source.clone(), + actual: id_target_client_on_source.clone(), + }); + } + let source_client_on_target = client_val_ctx_b.client_state(id_source_client_on_target)?; source_client_on_target diff --git a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs index e9e793195..463699357 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -4,6 +4,7 @@ use ibc_eureka_core_channel_types::events::SendPacket; use ibc_eureka_core_channel_types::packet::Packet; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, SeqSendPathV2 as SeqSendPath, }; @@ -36,9 +37,20 @@ pub fn send_packet_validate( let channel_source_client_on_target = &packet.header.source_client_on_target; let seq_on_a = &packet.header.seq_on_a; + let client_val_ctx_a = ctx_a.get_client_validation_context(); + let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); - let client_val_ctx_a = ctx_a.get_client_validation_context(); + let (stored_id_source_client_on_target, _) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index ca415ce70..fa474f85b 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -4,6 +4,7 @@ use ibc_eureka_core_channel_types::events::TimeoutPacket; use ibc_eureka_core_channel_types::msgs::MsgTimeout; use ibc_eureka_core_client::context::prelude::*; use ibc_eureka_core_handler_types::events::{IbcEvent, MessageEvent}; +use ibc_eureka_core_host::types::identifiers::ClientId; use ibc_eureka_core_host::types::path::{ ClientConsensusStatePath, CommitmentPathV2 as CommitmentPath, Path, ReceiptPathV2 as ReceiptPath, @@ -125,7 +126,20 @@ where // Verify proofs { let id_target_client_on_source = channel_target_client_on_source.as_ref(); + let id_source_client_on_target: &ClientId = channel_source_client_on_target.as_ref(); + let client_val_ctx_a = ctx_a.get_client_validation_context(); + + let (stored_id_source_client_on_target, target_prefix) = + client_val_ctx_a.counterparty_client(id_target_client_on_source)?; + + if &stored_id_source_client_on_target != id_source_client_on_target { + return Err(ChannelError::MismatchCounterparty { + expected: stored_id_source_client_on_target.clone(), + actual: id_source_client_on_target.clone(), + }); + } + let target_client_on_source = client_val_ctx_a.client_state(id_target_client_on_source)?; target_client_on_source