From 0f0207dbcd8f591d64cf47e492786051fee4b1e7 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Wed, 17 Jul 2024 09:54:59 -0700 Subject: [PATCH] fix: use Binary as checksum type for InstantiateMsg --- ibc-clients/cw-context/src/handlers.rs | 2 +- ibc-clients/cw-context/src/types/msgs.rs | 13 +++++++++++-- tests-integration/tests/cosmwasm/helper.rs | 11 +++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/ibc-clients/cw-context/src/handlers.rs b/ibc-clients/cw-context/src/handlers.rs index eb92e0928..8f8d6e4f4 100644 --- a/ibc-clients/cw-context/src/handlers.rs +++ b/ibc-clients/cw-context/src/handlers.rs @@ -27,7 +27,7 @@ where let any_consensus_state = Any::decode(&mut msg.consensus_state.as_slice())?; - self.set_checksum(msg.checksum); + self.set_checksum(msg.checksum.to_array()?.into()); client_state.initialise(self, &self.client_id(), any_consensus_state)?; diff --git a/ibc-clients/cw-context/src/types/msgs.rs b/ibc-clients/cw-context/src/types/msgs.rs index 1a7da1a4c..9e92c6ee9 100644 --- a/ibc-clients/cw-context/src/types/msgs.rs +++ b/ibc-clients/cw-context/src/types/msgs.rs @@ -1,7 +1,7 @@ //! Defines the messages sent to the CosmWasm contract by the 08-wasm proxy //! light client. use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Binary, Checksum}; +use cosmwasm_std::Binary; use ibc_core::client::types::proto::v1::Height as RawHeight; use ibc_core::client::types::Height; use ibc_core::commitment_types::commitment::{CommitmentPrefix, CommitmentProofBytes}; @@ -20,7 +20,16 @@ use super::error::ContractError; pub struct InstantiateMsg { pub client_state: Binary, pub consensus_state: Binary, - pub checksum: Checksum, + /// The checksum of the contract. + /// + /// NOTE: The checksum included in any type of 08-wasm messages, such as + /// [`WasmClientState`](ibc_client_wasm_types::client_state::ClientState), + /// is hex-encoded bytes. The ibc-go 08-wasm light client initially + /// hex-decodes this to a valid checksum. In a subsequent step, the entire + /// payload, including the checksum, is base64-encoded by the VM before + /// being passed to a CosmWasm contract entry point. Therefore, we use the + /// `Binary` type here to properly deserialize a base64-encoded checksum. + pub checksum: Binary, } // ------------------------------------------------------------ diff --git a/tests-integration/tests/cosmwasm/helper.rs b/tests-integration/tests/cosmwasm/helper.rs index e32e4d3e4..b0ba53b0c 100644 --- a/tests-integration/tests/cosmwasm/helper.rs +++ b/tests-integration/tests/cosmwasm/helper.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env}; -use cosmwasm_std::{coins, Checksum, Env, MessageInfo, Timestamp as CwTimestamp}; +use cosmwasm_std::{coins, Binary, Checksum, Env, MessageInfo, Timestamp as CwTimestamp}; use ibc::clients::tendermint::types::ConsensusState; use ibc::core::primitives::Timestamp as IbcTimestamp; use tendermint::Hash; @@ -13,9 +13,12 @@ pub fn dummy_msg_info() -> MessageInfo { message_info(&creator, &coins(1000, "ibc")) } -pub fn dummy_checksum() -> Checksum { - Checksum::from_hex("2469f43c3ca20d476442bd3d98cbd97a180776ab37332aa7b02cae5a620acfc6") - .expect("Never fails") +pub fn dummy_checksum() -> Binary { + let hex_bytes = + Checksum::from_hex("2469f43c3ca20d476442bd3d98cbd97a180776ab37332aa7b02cae5a620acfc6") + .expect("Never fails"); + + hex_bytes.as_slice().into() } pub fn dummy_sov_consensus_state(timestamp: IbcTimestamp) -> ConsensusState {