Skip to content

Commit

Permalink
Backport bug fixes from upstream. Wrong seq encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
en committed Dec 17, 2023
1 parent e53b98e commit 27004bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
10 changes: 1 addition & 9 deletions ibc-core/ics04-channel/src/handler/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
10 changes: 1 addition & 9 deletions ibc-core/ics04-channel/src/handler/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(ctx_a: &Ctx, msg: &MsgTimeoutOnClose) -> Result<(), ContextError>
where
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions ibc-core/ics24-host/types/src/identifiers/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
self.0.to_be_bytes().to_vec()
}
}

impl From<u64> for Sequence {
Expand Down

0 comments on commit 27004bc

Please sign in to comment.