Skip to content

Commit

Permalink
fix: use Binary as checksum type for InstantiateMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Jul 17, 2024
1 parent 00aa061 commit 0f0207d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ibc-clients/cw-context/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
13 changes: 11 additions & 2 deletions ibc-clients/cw-context/src/types/msgs.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
}

// ------------------------------------------------------------
Expand Down
11 changes: 7 additions & 4 deletions tests-integration/tests/cosmwasm/helper.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 0f0207d

Please sign in to comment.