From 27004bcdcb1779b66bbe00f1f769b3d1642763b6 Mon Sep 17 00:00:00 2001 From: Yuanchao Sun Date: Mon, 18 Dec 2023 00:07:03 +0800 Subject: [PATCH] Backport bug fixes from upstream. Wrong seq encoding https://github.com/cosmos/ibc-rs/pull/1004 --- ibc-core/ics04-channel/src/handler/timeout.rs | 10 +--------- ibc-core/ics04-channel/src/handler/timeout_on_close.rs | 10 +--------- ibc-core/ics24-host/types/src/identifiers/sequence.rs | 5 +++++ 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/ibc-core/ics04-channel/src/handler/timeout.rs b/ibc-core/ics04-channel/src/handler/timeout.rs index 28cfd6587..0cfed7c03 100644 --- a/ibc-core/ics04-channel/src/handler/timeout.rs +++ b/ibc-core/ics04-channel/src/handler/timeout.rs @@ -15,7 +15,6 @@ use ibc_core_host::types::path::{ use ibc_core_host::{ExecutionContext, ValidationContext}; use ibc_core_router::module::Module; use ibc_primitives::prelude::*; -use prost::Message; use super::timeout_on_close; @@ -231,19 +230,12 @@ where let seq_recv_path_on_b = SeqRecvPath::new(&msg.packet.port_id_on_b, &msg.packet.chan_id_on_b); - let mut value = Vec::new(); - u64::from(msg.packet.seq_on_a) - .encode(&mut value) - .map_err(|_| PacketError::CannotEncodeSequence { - sequence: msg.packet.seq_on_a, - })?; - 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), - value, + msg.packet.seq_on_a.to_vec(), ) } else { let receipt_path_on_b = ReceiptPath::new( diff --git a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs index 641f0483c..c08c0e8d3 100644 --- a/ibc-core/ics04-channel/src/handler/timeout_on_close.rs +++ b/ibc-core/ics04-channel/src/handler/timeout_on_close.rs @@ -13,7 +13,6 @@ use ibc_core_host::types::path::{ use ibc_core_host::ValidationContext; use ibc_primitives::prelude::*; use ibc_primitives::proto::Protobuf; -use prost::Message; pub fn validate(ctx_a: &Ctx, msg: &MsgTimeoutOnClose) -> Result<(), ContextError> where @@ -135,19 +134,12 @@ where } let seq_recv_path_on_b = SeqRecvPath::new(&packet.port_id_on_b, &packet.chan_id_on_b); - let mut value = Vec::new(); - u64::from(packet.seq_on_a).encode(&mut value).map_err(|_| { - PacketError::CannotEncodeSequence { - sequence: packet.seq_on_a, - } - })?; - 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), - value, + packet.seq_on_a.to_vec(), ) } else { let receipt_path_on_b = ReceiptPath::new( diff --git a/ibc-core/ics24-host/types/src/identifiers/sequence.rs b/ibc-core/ics24-host/types/src/identifiers/sequence.rs index db6d9c560..86a17ddfa 100644 --- a/ibc-core/ics24-host/types/src/identifiers/sequence.rs +++ b/ibc-core/ics24-host/types/src/identifiers/sequence.rs @@ -44,6 +44,11 @@ impl Sequence { pub fn increment(&self) -> Sequence { Sequence(self.0 + 1) } + + /// Encodes the sequence number into a byte array in big endian. + pub fn to_vec(&self) -> Vec { + self.0.to_be_bytes().to_vec() + } } impl From for Sequence {