From 45c8ed88fbbd0d0bae251b7fb2f8ab9ae33a492d Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Thu, 22 Sep 2022 19:54:53 +0700 Subject: [PATCH] Fix secret message parsing when message is plaintext in IBC --- .../ibc-test-contract/src/contract.rs | 2 +- .../shared/contract-engine/src/message.rs | 15 +++++++++++++-- x/compute/internal/keeper/ibc_test.go | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cosmwasm/contracts/v1/compute-tests/ibc-test-contract/src/contract.rs b/cosmwasm/contracts/v1/compute-tests/ibc-test-contract/src/contract.rs index 3bf55f262..ad291d8f8 100644 --- a/cosmwasm/contracts/v1/compute-tests/ibc-test-contract/src/contract.rs +++ b/cosmwasm/contracts/v1/compute-tests/ibc-test-contract/src/contract.rs @@ -118,7 +118,7 @@ pub fn get_resp_based_on_num(env: Env, num: u64) -> StdResult msg: CosmosMsg::Wasm(WasmMsg::Execute { code_hash: env.contract.code_hash, contract_addr: env.contract.address.into_string(), - msg: Binary::from("{\"increment\":{\"addition\":5}}".as_bytes().to_vec()), + msg: Binary::from("{\"increment\":{ \"addition\":5}}".as_bytes().to_vec()), funds: vec![], }) .into(), diff --git a/cosmwasm/enclaves/shared/contract-engine/src/message.rs b/cosmwasm/enclaves/shared/contract-engine/src/message.rs index e1c1c996d..292d6a1f3 100644 --- a/cosmwasm/enclaves/shared/contract-engine/src/message.rs +++ b/cosmwasm/enclaves/shared/contract-engine/src/message.rs @@ -120,7 +120,12 @@ pub fn parse_message( base64::encode(&message) ); - let secret_msg = get_secret_msg(message); + let secret_msg = SecretMessage { + nonce: [0; 32], + user_public_key: [0; 32], + msg: message.into(), + }; + let decrypted_msg = secret_msg.msg.clone(); Ok(ParsedMessage { @@ -484,7 +489,7 @@ pub fn parse_message( let tmp_secret_data = get_secret_msg(parsed_encrypted_ibc_packet.packet.data.as_slice()); let mut was_msg_encrypted = false; - let orig_secret_msg = tmp_secret_data; + let mut orig_secret_msg = tmp_secret_data; match orig_secret_msg.decrypt() { Ok(decrypted_msg) => { @@ -505,6 +510,12 @@ pub fn parse_message( "ibc_packet_receive data was plaintext: {:?}", base64::encode(&message) ); + + orig_secret_msg = SecretMessage { + nonce: [0; 32], + user_public_key: [0; 32], + msg: message.into(), + }; } } Ok(ParsedMessage { diff --git a/x/compute/internal/keeper/ibc_test.go b/x/compute/internal/keeper/ibc_test.go index 0c8b69d6f..e53ba79b8 100644 --- a/x/compute/internal/keeper/ibc_test.go +++ b/x/compute/internal/keeper/ibc_test.go @@ -733,8 +733,8 @@ func TestIBCPacketReceive(t *testing.T) { }, } { t.Run(fmt.Sprintf("%s-Encryption:%t", test.description, isEncrypted), func(t *testing.T) { - ibcPacket := createIBCPacket(createIBCEndpoint(PortIDForContract(contractAddress), "channel.1"), - createIBCEndpoint(PortIDForContract(contractAddress), "channel.0"), + ibcPacket := createIBCPacket(createIBCEndpoint(PortIDForContract(contractAddress), "channel.11231231231231232112312321321321331232132131232132131232"), + createIBCEndpoint(PortIDForContract(contractAddress), "channel.0123123213213123123213123123123123123312321321321312321313213"), test.sequence, createIBCTimeout(math.MaxUint64), []byte{},