Skip to content

Commit

Permalink
check clientid and use prefix of counterparty
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Oct 28, 2024
1 parent d8c4acd commit 6bbe295
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion ibc-eureka-core/ics04-channel/src/handler/send_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)?;

Expand Down
14 changes: 14 additions & 0 deletions ibc-eureka-core/ics04-channel/src/handler/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6bbe295

Please sign in to comment.