diff --git a/ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs index 72fba2140..da8a1318a 100644 --- a/ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-eureka-core/ics03-connection/src/handler/conn_open_ack.rs @@ -8,7 +8,9 @@ use ibc_eureka_core_connection_types::msgs::MsgConnectionOpenAck; use ibc_eureka_core_connection_types::{ConnectionEnd, Counterparty, State}; 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, ClientStatePath, ConnectionPath, Path}; +use ibc_eureka_core_host::types::path::{ + ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path, +}; use ibc_eureka_core_host::{ExecutionContext, ValidationContext}; use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; diff --git a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs index 0fca79e62..e14618cb3 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/acknowledgement.rs @@ -37,8 +37,13 @@ pub fn acknowledgement_packet_execute( where ExecCtx: ExecutionContext, { - let chan_end_path_on_a = - ChannelEndPath::new(&msg.packet.port_id_on_a, &msg.packet.chan_id_on_a); + let payload = &msg.packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &msg.packet.header.source_client; + let seq_on_a = &msg.packet.header.seq_on_a; + + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; let conn_id_on_a = &chan_end_on_a.connection_hops()[0]; @@ -51,11 +56,8 @@ where ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?; ctx_a.emit_ibc_event(event)?; - let commitment_path_on_a = CommitmentPath::new( - &msg.packet.port_id_on_a, - &msg.packet.chan_id_on_a, - msg.packet.seq_on_a, - ); + let commitment_path_on_a = + CommitmentPath::new(port_id_on_a, channel_id_on_a, msg.packet.header.seq_on_a); // check if we're in the NO-OP case if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() { @@ -78,9 +80,8 @@ where if let Order::Ordered = chan_end_on_a.ordering { // Note: in validation, we verified that `msg.packet.sequence == nextSeqRecv` // (where `nextSeqRecv` is the value in the store) - let seq_ack_path_on_a = - SeqAckPath::new(&msg.packet.port_id_on_a, &msg.packet.chan_id_on_a); - ctx_a.store_next_sequence_ack(&seq_ack_path_on_a, msg.packet.seq_on_a.increment())?; + let seq_ack_path_on_a = SeqAckPath::new(port_id_on_a, channel_id_on_a); + ctx_a.store_next_sequence_ack(&seq_ack_path_on_a, (*seq_on_a).increment())?; } } @@ -109,15 +110,21 @@ where ctx_a.validate_message_signer(&msg.signer)?; let packet = &msg.packet; - let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + let data = &payload.data; + + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; chan_end_on_a.verify_state_matches(&ChannelState::Open)?; - let counterparty = Counterparty::new( - packet.port_id_on_b.clone(), - Some(packet.chan_id_on_b.clone()), - ); + let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone())); chan_end_on_a.verify_counterparty_matches(&counterparty)?; @@ -126,8 +133,7 @@ where conn_end_on_a.verify_state_matches(&ConnectionState::Open)?; - let commitment_path_on_a = - CommitmentPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); + let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); // Verify packet commitment let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { @@ -139,9 +145,9 @@ where }; let expected_commitment_on_a = compute_packet_commitment( - &packet.data, - &packet.timeout_height_on_b, - &packet.timeout_timestamp_on_b, + data, + &packet.header.timeout_height_on_b, + &packet.header.timeout_timestamp_on_b, ); if commitment_on_a != expected_commitment_on_a { @@ -152,11 +158,11 @@ where } if let Order::Ordered = chan_end_on_a.ordering { - let seq_ack_path_on_a = SeqAckPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let seq_ack_path_on_a = SeqAckPath::new(port_id_on_a, channel_id_on_a); let next_seq_ack = ctx_a.get_next_sequence_ack(&seq_ack_path_on_a)?; - if packet.seq_on_a != next_seq_ack { + if seq_on_a != &next_seq_ack { return Err(ChannelError::MismatchedPacketSequence { - actual: packet.seq_on_a, + actual: *seq_on_a, expected: next_seq_ack, }); } @@ -184,8 +190,7 @@ where let consensus_state_of_b_on_a = client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?; let ack_commitment = compute_ack_commitment(&msg.acknowledgement); - let ack_path_on_b = - AckPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a); + let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); verify_conn_delay_passed(ctx_a, msg.proof_height_on_b, &conn_end_on_a)?; diff --git a/ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs b/ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs index 9aef575db..729cd27d7 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/chan_open_ack.rs @@ -1,5 +1,7 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenAck`. -use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; +use ibc_eureka_core_channel_types::channel::{ + ChannelEnd, Counterparty, State, State as ChannelState, +}; use ibc_eureka_core_channel_types::error::ChannelError; use ibc_eureka_core_channel_types::events::OpenAck; use ibc_eureka_core_channel_types::msgs::MsgChannelOpenAck; diff --git a/ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs b/ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs index 8a19350e5..4347c3bb0 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/chan_open_confirm.rs @@ -1,6 +1,8 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenConfirm`. -use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State, State as ChannelState}; +use ibc_eureka_core_channel_types::channel::{ + ChannelEnd, Counterparty, State, State as ChannelState, +}; use ibc_eureka_core_channel_types::error::ChannelError; use ibc_eureka_core_channel_types::events::OpenConfirm; use ibc_eureka_core_channel_types::msgs::MsgChannelOpenConfirm; diff --git a/ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs b/ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs index ac10bc846..f6ba84811 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/chan_open_init.rs @@ -1,5 +1,7 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenInit`. +use core::str::FromStr; + use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State}; use ibc_eureka_core_channel_types::error::ChannelError; use ibc_eureka_core_channel_types::events::OpenInit; @@ -21,7 +23,8 @@ where ValCtx: ValidationContext, { validate(ctx_a, &msg)?; - let chan_id_on_a = ChannelId::new(ctx_a.channel_counter()?); + // todo(rano): hack + let chan_id_on_a = ChannelId::from_str("00-dummy-0")?; module.on_chan_open_init_validate( msg.ordering, @@ -43,7 +46,8 @@ pub fn chan_open_init_execute( where ExecCtx: ExecutionContext, { - let chan_id_on_a = ChannelId::new(ctx_a.channel_counter()?); + // todo(rano): hack + let chan_id_on_a = ChannelId::from_str("00-dummy-0")?; let (extras, version) = module.on_chan_open_init_execute( msg.ordering, &msg.connection_hops_on_a, diff --git a/ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs b/ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs index adeeed2ef..b6c2dec68 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/chan_open_try.rs @@ -1,5 +1,7 @@ //! Protocol logic specific to ICS4 messages of type `MsgChannelOpenTry`. +use core::str::FromStr; + use ibc_eureka_core_channel_types::channel::{ChannelEnd, Counterparty, State as ChannelState}; use ibc_eureka_core_channel_types::error::ChannelError; use ibc_eureka_core_channel_types::events::OpenTry; @@ -27,7 +29,8 @@ where { validate(ctx_b, &msg)?; - let chan_id_on_b = ChannelId::new(ctx_b.channel_counter()?); + // todo(rano): hack + let chan_id_on_b = ChannelId::from_str("00-dummy-0")?; module.on_chan_open_try_validate( msg.ordering, @@ -49,7 +52,8 @@ pub fn chan_open_try_execute( where ExecCtx: ExecutionContext, { - let chan_id_on_b = ChannelId::new(ctx_b.channel_counter()?); + // todo(rano): hack + let chan_id_on_b = ChannelId::from_str("00-dummy-0")?; let (extras, version) = module.on_chan_open_try_execute( msg.ordering, &msg.connection_hops_on_b, 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 0056c5473..4cf70bf11 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/recv_packet.rs @@ -37,8 +37,14 @@ pub fn recv_packet_execute( where ExecCtx: ExecutionContext, { - let chan_end_path_on_b = - ChannelEndPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let packet = &msg.packet; + let payload = &packet.payloads[0]; + + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + + let chan_end_path_on_b = ChannelEndPath::new(port_id_on_b, channel_id_on_b); let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?; // Check if another relayer already relayed the packet. @@ -48,19 +54,16 @@ where // Note: ibc-go doesn't make the check for `Order::None` channels Order::None => false, Order::Unordered => { - let packet = &msg.packet; - let receipt_path_on_b = - ReceiptPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a); + let receipt_path_on_b = ReceiptPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); ctx_b.get_packet_receipt(&receipt_path_on_b)?.is_ok() } Order::Ordered => { - let seq_recv_path_on_b = - SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b); let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?; // the sequence number has already been incremented, so // another relayer already relayed the packet - msg.packet.seq_on_a < next_seq_recv + seq_on_a < &next_seq_recv } }; @@ -77,26 +80,21 @@ where match chan_end_on_b.ordering { Order::Unordered => { let receipt_path_on_b = ReceiptPath { - port_id: msg.packet.port_id_on_b.clone(), - channel_id: msg.packet.chan_id_on_b.clone(), - sequence: msg.packet.seq_on_a, + port_id: port_id_on_b.clone(), + channel_id: channel_id_on_b.clone(), + sequence: *seq_on_a, }; ctx_b.store_packet_receipt(&receipt_path_on_b, Receipt::Ok)?; } Order::Ordered => { - let seq_recv_path_on_b = - SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b); let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?; ctx_b.store_next_sequence_recv(&seq_recv_path_on_b, next_seq_recv.increment())?; } _ => {} } - let ack_path_on_b = AckPath::new( - &msg.packet.port_id_on_b, - &msg.packet.chan_id_on_b, - msg.packet.seq_on_a, - ); + let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); // `writeAcknowledgement` handler state changes ctx_b.store_packet_acknowledgement( &ack_path_on_b, @@ -143,16 +141,22 @@ where { ctx_b.validate_message_signer(&msg.signer)?; - let chan_end_path_on_b = - ChannelEndPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let packet = &msg.packet; + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + let data = &payload.data; + + let chan_end_path_on_b = ChannelEndPath::new(port_id_on_b, channel_id_on_b); let chan_end_on_b = ctx_b.channel_end(&chan_end_path_on_b)?; chan_end_on_b.verify_state_matches(&ChannelState::Open)?; - let counterparty = Counterparty::new( - msg.packet.port_id_on_a.clone(), - Some(msg.packet.chan_id_on_a.clone()), - ); + let counterparty = Counterparty::new(port_id_on_a.clone(), Some(channel_id_on_a.clone())); chan_end_on_b.verify_counterparty_matches(&counterparty)?; @@ -162,16 +166,16 @@ where conn_end_on_b.verify_state_matches(&ConnectionState::Open)?; let latest_height = ctx_b.host_height()?; - if msg.packet.timeout_height_on_b.has_expired(latest_height) { + if packet.header.timeout_height_on_b.has_expired(latest_height) { return Err(ChannelError::InsufficientPacketHeight { chain_height: latest_height, - timeout_height: msg.packet.timeout_height_on_b, + timeout_height: packet.header.timeout_height_on_b, }); } let latest_timestamp = ctx_b.host_timestamp()?; - if msg - .packet + if packet + .header .timeout_timestamp_on_b .has_expired(&latest_timestamp) { @@ -200,15 +204,11 @@ where client_val_ctx_b.consensus_state(&client_cons_state_path_on_b)?; let expected_commitment_on_a = compute_packet_commitment( - &msg.packet.data, - &msg.packet.timeout_height_on_b, - &msg.packet.timeout_timestamp_on_b, - ); - let commitment_path_on_a = CommitmentPath::new( - &msg.packet.port_id_on_a, - &msg.packet.chan_id_on_a, - msg.packet.seq_on_a, + data, + &packet.header.timeout_height_on_b, + &packet.header.timeout_timestamp_on_b, ); + let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); verify_conn_delay_passed(ctx_b, msg.proof_height_on_a, &conn_end_on_b)?; @@ -224,17 +224,16 @@ where match chan_end_on_b.ordering { Order::Ordered => { - let seq_recv_path_on_b = - SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b); let next_seq_recv = ctx_b.get_next_sequence_recv(&seq_recv_path_on_b)?; - if msg.packet.seq_on_a > next_seq_recv { + if seq_on_a > &next_seq_recv { return Err(ChannelError::MismatchedPacketSequence { - actual: msg.packet.seq_on_a, + actual: *seq_on_a, expected: next_seq_recv, }); } - if msg.packet.seq_on_a == next_seq_recv { + if seq_on_a == &next_seq_recv { // Case where the recvPacket is successful and an // acknowledgement will be written (not a no-op) validate_write_acknowledgement(ctx_b, msg)?; @@ -265,10 +264,16 @@ fn validate_write_acknowledgement(ctx_b: &Ctx, msg: &MsgRecvPacket) -> Resu where Ctx: ValidationContext, { - let packet = msg.packet.clone(); - let ack_path_on_b = AckPath::new(&packet.port_id_on_b, &packet.chan_id_on_b, packet.seq_on_a); + let packet = &msg.packet; + let payload = &packet.payloads[0]; + + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + + let ack_path_on_b = AckPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); if ctx_b.get_packet_acknowledgement(&ack_path_on_b).is_ok() { - return Err(ChannelError::DuplicateAcknowledgment(msg.packet.seq_on_a)); + return Err(ChannelError::DuplicateAcknowledgment(*seq_on_a)); } Ok(()) 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 f4960a490..1415ca2b1 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/send_packet.rs @@ -28,21 +28,27 @@ pub fn send_packet_validate( ctx_a: &impl SendPacketValidationContext, packet: &Packet, ) -> Result<(), ChannelError> { - if !packet.timeout_height_on_b.is_set() && !packet.timeout_timestamp_on_b.is_set() { + if !packet.header.timeout_height_on_b.is_set() && !packet.header.timeout_timestamp_on_b.is_set() + { return Err(ChannelError::MissingTimeout); } - let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; // Checks the channel end not be `Closed`. // This allows for optimistic packet processing before a channel opens chan_end_on_a.verify_not_closed()?; - let counterparty = Counterparty::new( - packet.port_id_on_b.clone(), - Some(packet.chan_id_on_b.clone()), - ); + let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone())); chan_end_on_a.verify_counterparty_matches(&counterparty)?; @@ -62,10 +68,14 @@ pub fn send_packet_validate( let latest_height_on_a = client_state_of_b_on_a.latest_height(); - if packet.timeout_height_on_b.has_expired(latest_height_on_a) { + if packet + .header + .timeout_height_on_b + .has_expired(latest_height_on_a) + { return Err(ChannelError::InsufficientPacketHeight { chain_height: latest_height_on_a, - timeout_height: packet.timeout_height_on_b, + timeout_height: packet.header.timeout_height_on_b, }); } @@ -77,17 +87,17 @@ pub fn send_packet_validate( let consensus_state_of_b_on_a = client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?; let latest_timestamp = consensus_state_of_b_on_a.timestamp()?; - let packet_timestamp = packet.timeout_timestamp_on_b; + let packet_timestamp = packet.header.timeout_timestamp_on_b; if packet_timestamp.has_expired(&latest_timestamp) { return Err(ChannelError::ExpiredPacketTimestamp); } - let seq_send_path_on_a = SeqSendPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let seq_send_path_on_a = SeqSendPath::new(port_id_on_a, channel_id_on_a); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; - if packet.seq_on_a != next_seq_send_on_a { + if seq_on_a != &next_seq_send_on_a { return Err(ChannelError::MismatchedPacketSequence { - actual: packet.seq_on_a, + actual: *seq_on_a, expected: next_seq_send_on_a, }); } @@ -102,25 +112,32 @@ pub fn send_packet_execute( ctx_a: &mut impl SendPacketExecutionContext, packet: Packet, ) -> Result<(), ChannelError> { + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let seq_on_a = &packet.header.seq_on_a; + let data = &payload.data; + { - let seq_send_path_on_a = SeqSendPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let seq_send_path_on_a = SeqSendPath::new(port_id_on_a, channel_id_on_a); let next_seq_send_on_a = ctx_a.get_next_sequence_send(&seq_send_path_on_a)?; ctx_a.store_next_sequence_send(&seq_send_path_on_a, next_seq_send_on_a.increment())?; } ctx_a.store_packet_commitment( - &CommitmentPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a), + &CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a), compute_packet_commitment( - &packet.data, - &packet.timeout_height_on_b, - &packet.timeout_timestamp_on_b, + data, + &packet.header.timeout_height_on_b, + &packet.header.timeout_timestamp_on_b, ), )?; // emit events and logs { - let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; let conn_id_on_a = &chan_end_on_a.connection_hops()[0]; diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs index bcb945f98..3ac0190e8 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout.rs @@ -53,7 +53,14 @@ where TimeoutMsgType::Timeout(msg) => (msg.packet, msg.signer), TimeoutMsgType::TimeoutOnClose(msg) => (msg.packet, msg.signer), }; - let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let seq_on_a = &packet.header.seq_on_a; + + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; // In all cases, this event is emitted @@ -61,8 +68,7 @@ where ctx_a.emit_ibc_event(IbcEvent::Message(MessageEvent::Channel))?; ctx_a.emit_ibc_event(event)?; - let commitment_path_on_a = - CommitmentPath::new(&packet.port_id_on_a, &packet.chan_id_on_a, packet.seq_on_a); + let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); // check if we're in the NO-OP case if ctx_a.get_packet_commitment(&commitment_path_on_a).is_err() { @@ -100,8 +106,8 @@ where let conn_id_on_a = chan_end_on_a.connection_hops()[0].clone(); let event = IbcEvent::ChannelClosed(ChannelClosed::new( - packet.port_id_on_a.clone(), - packet.chan_id_on_a.clone(), + port_id_on_a.clone(), + channel_id_on_a.clone(), chan_end_on_a.counterparty().port_id.clone(), chan_end_on_a.counterparty().channel_id.clone(), conn_id_on_a, @@ -129,17 +135,21 @@ where { ctx_a.validate_message_signer(&msg.signer)?; - let chan_end_on_a = ctx_a.channel_end(&ChannelEndPath::new( - &msg.packet.port_id_on_a, - &msg.packet.chan_id_on_a, - ))?; + let packet = &msg.packet; + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + let data = &payload.data; + + let chan_end_on_a = ctx_a.channel_end(&ChannelEndPath::new(port_id_on_a, channel_id_on_a))?; chan_end_on_a.verify_state_matches(&State::Open)?; - let counterparty = Counterparty::new( - msg.packet.port_id_on_b.clone(), - Some(msg.packet.chan_id_on_b.clone()), - ); + let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone())); chan_end_on_a.verify_counterparty_matches(&counterparty)?; @@ -147,11 +157,7 @@ where let conn_end_on_a = ctx_a.connection_end(&conn_id_on_a)?; //verify packet commitment - let commitment_path_on_a = CommitmentPath::new( - &msg.packet.port_id_on_a, - &msg.packet.chan_id_on_a, - msg.packet.seq_on_a, - ); + let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { // This error indicates that the timeout has already been relayed // or there is a misconfigured relayer attempting to prove a timeout @@ -161,9 +167,9 @@ where }; let expected_commitment_on_a = compute_packet_commitment( - &msg.packet.data, - &msg.packet.timeout_height_on_b, - &msg.packet.timeout_timestamp_on_b, + data, + &packet.header.timeout_height_on_b, + &packet.header.timeout_timestamp_on_b, ); if commitment_on_a != expected_commitment_on_a { @@ -197,9 +203,9 @@ where if !msg.packet.timed_out(×tamp_of_b, msg.proof_height_on_b) { return Err(ChannelError::InsufficientPacketTimeout { - timeout_height: msg.packet.timeout_height_on_b, + timeout_height: packet.header.timeout_height_on_b, chain_height: msg.proof_height_on_b, - timeout_timestamp: msg.packet.timeout_timestamp_on_b, + timeout_timestamp: packet.header.timeout_timestamp_on_b, chain_timestamp: timestamp_of_b, }); } @@ -208,29 +214,24 @@ where let next_seq_recv_verification_result = match chan_end_on_a.ordering { Order::Ordered => { - if msg.packet.seq_on_a < msg.next_seq_recv_on_b { + if seq_on_a < &msg.next_seq_recv_on_b { return Err(ChannelError::MismatchedPacketSequence { - actual: msg.packet.seq_on_a, + actual: *seq_on_a, expected: msg.next_seq_recv_on_b, }); } - let seq_recv_path_on_b = - SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); + let seq_recv_path_on_b = SeqRecvPath::new(port_id_on_b, channel_id_on_b); client_state_of_b_on_a.verify_membership( conn_end_on_a.counterparty().prefix(), &msg.proof_unreceived_on_b, consensus_state_of_b_on_a.root(), Path::SeqRecv(seq_recv_path_on_b), - msg.packet.seq_on_a.to_vec(), + seq_on_a.to_vec(), ) } Order::Unordered => { - let receipt_path_on_b = ReceiptPath::new( - &msg.packet.port_id_on_b, - &msg.packet.chan_id_on_b, - msg.packet.seq_on_a, - ); + let receipt_path_on_b = ReceiptPath::new(port_id_on_b, channel_id_on_b, *seq_on_a); client_state_of_b_on_a.verify_non_membership( conn_end_on_a.counterparty().prefix(), diff --git a/ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs b/ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs index d85f76067..353e2b44b 100644 --- a/ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs +++ b/ibc-eureka-core/ics04-channel/src/handler/timeout_on_close.rs @@ -19,21 +19,23 @@ where ctx_a.validate_message_signer(&msg.signer)?; let packet = &msg.packet; - let chan_end_path_on_a = ChannelEndPath::new(&packet.port_id_on_a, &packet.chan_id_on_a); + let payload = &packet.payloads[0]; + + let port_id_on_a = &payload.header.source_port.1; + let channel_id_on_a = &packet.header.source_client; + let port_id_on_b = &payload.header.target_port.1; + let channel_id_on_b = &packet.header.target_client; + let seq_on_a = &packet.header.seq_on_a; + let data = &payload.data; + + let chan_end_path_on_a = ChannelEndPath::new(port_id_on_a, channel_id_on_a); let chan_end_on_a = ctx_a.channel_end(&chan_end_path_on_a)?; - let counterparty = Counterparty::new( - packet.port_id_on_b.clone(), - Some(packet.chan_id_on_b.clone()), - ); + let counterparty = Counterparty::new(port_id_on_b.clone(), Some(channel_id_on_b.clone())); chan_end_on_a.verify_counterparty_matches(&counterparty)?; - let commitment_path_on_a = CommitmentPath::new( - &msg.packet.port_id_on_a, - &msg.packet.chan_id_on_a, - msg.packet.seq_on_a, - ); + let commitment_path_on_a = CommitmentPath::new(port_id_on_a, channel_id_on_a, *seq_on_a); //verify the packet was sent, check the store let Ok(commitment_on_a) = ctx_a.get_packet_commitment(&commitment_path_on_a) else { @@ -45,9 +47,9 @@ where }; let expected_commitment_on_a = compute_packet_commitment( - &packet.data, - &packet.timeout_height_on_b, - &packet.timeout_timestamp_on_b, + data, + &packet.header.timeout_height_on_b, + &packet.header.timeout_timestamp_on_b, ); if commitment_on_a != expected_commitment_on_a { return Err(ChannelError::MismatchedPacketCommitment { @@ -80,7 +82,7 @@ where client_val_ctx_a.consensus_state(&client_cons_state_path_on_a)?; let prefix_on_b = conn_end_on_a.counterparty().prefix(); let port_id_on_b = chan_end_on_a.counterparty().port_id.clone(); - let chan_id_on_b = chan_end_on_a + let channel_id_on_b = chan_end_on_a .counterparty() .channel_id() .ok_or(ChannelError::MissingCounterparty)?; @@ -89,10 +91,8 @@ where .connection_id() .ok_or(ConnectionError::MissingCounterparty)?; let expected_conn_hops_on_b = vec![conn_id_on_b.clone()]; - let expected_counterparty = Counterparty::new( - packet.port_id_on_a.clone(), - Some(packet.chan_id_on_a.clone()), - ); + let expected_counterparty = + Counterparty::new(port_id_on_a.clone(), Some(channel_id_on_a.clone())); let expected_chan_end_on_b = ChannelEnd::new( State::Closed, *chan_end_on_a.ordering(), @@ -101,7 +101,7 @@ where chan_end_on_a.version().clone(), )?; - let chan_end_path_on_b = ChannelEndPath(port_id_on_b, chan_id_on_b.clone()); + let chan_end_path_on_b = ChannelEndPath(port_id_on_b.clone(), channel_id_on_b.clone()); // Verify the proof for the channel state against the expected channel end. // A counterparty channel id of None in not possible, and is checked by validate_basic in msg. @@ -117,29 +117,24 @@ where let next_seq_recv_verification_result = match chan_end_on_a.ordering { Order::Ordered => { - if packet.seq_on_a < msg.next_seq_recv_on_b { + if seq_on_a < &msg.next_seq_recv_on_b { return Err(ChannelError::MismatchedPacketSequence { - actual: packet.seq_on_a, + actual: *seq_on_a, expected: msg.next_seq_recv_on_b, }); } - let seq_recv_path_on_b = - SeqRecvPath::new(&packet.port_id_on_b, &packet.chan_id_on_b); + let seq_recv_path_on_b = SeqRecvPath::new(&port_id_on_b, channel_id_on_b); client_state_of_b_on_a.verify_membership( conn_end_on_a.counterparty().prefix(), &msg.proof_unreceived_on_b, consensus_state_of_b_on_a.root(), Path::SeqRecv(seq_recv_path_on_b), - packet.seq_on_a.to_vec(), + seq_on_a.to_vec(), ) } Order::Unordered => { - let receipt_path_on_b = ReceiptPath::new( - &msg.packet.port_id_on_b, - &msg.packet.chan_id_on_b, - msg.packet.seq_on_a, - ); + let receipt_path_on_b = ReceiptPath::new(&port_id_on_b, channel_id_on_b, *seq_on_a); client_state_of_b_on_a.verify_non_membership( conn_end_on_a.counterparty().prefix(), diff --git a/ibc-eureka-core/ics24-host/types/src/identifiers/channel_id.rs b/ibc-eureka-core/ics24-host/types/src/identifiers/channel_id.rs index f472d6df1..154977d09 100644 --- a/ibc-eureka-core/ics24-host/types/src/identifiers/channel_id.rs +++ b/ibc-eureka-core/ics24-host/types/src/identifiers/channel_id.rs @@ -5,7 +5,6 @@ use derive_more::Into; use ibc_primitives::prelude::*; use crate::error::IdentifierError; - use crate::identifiers::ClientId; const CHANNEL_ID_PREFIX: &str = "channel";