Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use consensus state and client state from lightclient 232 #670

Merged
merged 51 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
ec9c0c2
fix: make reply on success
sabinchitrakar Aug 22, 2023
40a7f28
fix: clear callback data
sabinchitrakar Aug 22, 2023
f5c5015
fix: chan open init remove reply
sabinchitrakar Aug 22, 2023
091564d
fix: remove reply chan open try
sabinchitrakar Aug 22, 2023
757f734
fix: remove reply from open confirm
sabinchitrakar Aug 22, 2023
e47c97c
fix: remove close init reply
sabinchitrakar Aug 22, 2023
780744a
fix: fix tests
sabinchitrakar Aug 22, 2023
30e46ef
fix: add unit tests
sabinchitrakar Aug 22, 2023
3d5c6ed
fix: add unit tests
sabinchitrakar Aug 23, 2023
8cc2792
fix: unit tests
sabinchitrakar Aug 23, 2023
116c8df
fix: remove reply on ack
sabinchitrakar Aug 23, 2023
a17d440
fix: fix format
sabinchitrakar Aug 23, 2023
16d3afc
chore: pull main
sabinchitrakar Aug 23, 2023
5c76422
fix: remove receive packet callback
sabinchitrakar Aug 23, 2023
269812a
chore: pass buils
sabinchitrakar Aug 23, 2023
79ef045
fix: add tests
sabinchitrakar Aug 23, 2023
d67ec6b
fix: refactor test setup
sabinchitrakar Aug 23, 2023
ee0b200
fix: cleanup test
sabinchitrakar Aug 23, 2023
5679743
fix: receive test
sabinchitrakar Aug 23, 2023
c41e894
fix: refactor test
sabinchitrakar Aug 24, 2023
cc072b6
chore: pass build
sabinchitrakar Aug 24, 2023
cdde90a
chore: pull main
sabinchitrakar Aug 24, 2023
465f229
chore: merge main
sabinchitrakar Aug 24, 2023
de45317
fix: fix close init test
sabinchitrakar Aug 24, 2023
da9c75f
fix: add test for send packet
sabinchitrakar Aug 24, 2023
8069205
fix: test for close confirm
sabinchitrakar Aug 24, 2023
80da7ea
chore: pass build
sabinchitrakar Aug 24, 2023
33d7913
fix: fix conflicts
sabinchitrakar Aug 25, 2023
5bd5314
Merge branch 'main' of https://github.com/icon-project/IBC-Integratio…
sabinchitrakar Aug 28, 2023
d3b5cf4
fix: cargo fmt
sabinchitrakar Aug 28, 2023
40fcb2e
fix: unit tests
sabinchitrakar Aug 28, 2023
03efb6c
fix: tests
sabinchitrakar Aug 28, 2023
e7ac95e
chore: pull test fix
sabinchitrakar Aug 28, 2023
2623d84
fix: refactor test
sabinchitrakar Aug 28, 2023
1051e11
fix: timeout packet reply never
sabinchitrakar Aug 29, 2023
103f3c1
Merge branch 'fix/security-review-180-183-185' of https://github.com/…
sabinchitrakar Aug 29, 2023
752ab54
fix: fix test
sabinchitrakar Aug 29, 2023
906af82
fix: cleanup
sabinchitrakar Aug 29, 2023
80ae228
chore: pull main
sabinchitrakar Aug 29, 2023
3e991fe
fix: pull
sabinchitrakar Aug 30, 2023
0d66172
fix: refactor tests
sabinchitrakar Aug 30, 2023
6d4ed72
fix: remove client and consensus state
sabinchitrakar Aug 30, 2023
9370dd8
chore: pass build
sabinchitrakar Aug 30, 2023
ffeb07d
Merge branch 'main' of https://github.com/icon-project/IBC-Integratio…
sabinchitrakar Aug 30, 2023
6d455f2
chore: pull main
sabinchitrakar Aug 30, 2023
7f38cf1
fix: refactor test
sabinchitrakar Aug 30, 2023
c6bb349
fix: channel tests
sabinchitrakar Aug 30, 2023
268dafa
chore: pass build
sabinchitrakar Aug 30, 2023
221b2e9
fix: Missing IBC core checks against timestamp #191 (#636)
ibrizsabin Sep 5, 2023
d071aea
fix: Rust Light Client update reply #181 (#662)
ibrizsabin Sep 6, 2023
5662afb
Merge branch 'main' into fix/security-review-232
redlarva Sep 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions contracts/cosmwasm-vm/cw-common/src/client_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub enum QueryMsg {
#[returns(Vec<u8>)]
GetConsensusState { client_id: String, height: u64 },
#[returns(Vec<u8>)]
GetLatestConsensusState { client_id: String },
#[returns(Vec<u8>)]
GetClientState { client_id: String },
#[returns(bool)]
VerifyMembership {
Expand Down Expand Up @@ -79,6 +81,8 @@ pub enum QueryMsg {
VerifyConnectionOpenAck(VerifyConnectionPayload),
#[returns(Vec<u64>)]
GetPreviousConsensusState { client_id: String, height: u64 },
#[returns(u64)]
GetTimestampAtHeight { client_id: String, height: u64 },
}

#[cw_serde]
Expand Down Expand Up @@ -113,7 +117,6 @@ pub struct VerifyConnectionState {
pub proof_height: String,
pub counterparty_prefix: Vec<u8>,
pub proof: Vec<u8>,
pub root: Vec<u8>,
pub counterparty_conn_end_path: Vec<u8>,
pub expected_counterparty_connection_end: Vec<u8>,
}
Expand All @@ -122,15 +125,13 @@ impl VerifyConnectionState {
proof_height: String,
counterparty_prefix: Vec<u8>,
proof: Vec<u8>,
root: Vec<u8>,
counterparty_conn_end_path: Vec<u8>,
expected_counterparty_connection_end: Vec<u8>,
) -> Self {
Self {
proof_height,
counterparty_prefix,
proof,
root,
counterparty_conn_end_path,
expected_counterparty_connection_end,
}
Expand All @@ -142,7 +143,6 @@ pub struct VerifyClientFullState {
pub proof_height: String,
pub counterparty_prefix: Vec<u8>,
pub client_state_proof: Vec<u8>,
pub root: Vec<u8>,
pub client_state_path: Vec<u8>,
pub expected_client_state: Vec<u8>,
}
Expand All @@ -151,15 +151,13 @@ impl VerifyClientFullState {
proof_height: String,
counterparty_prefix: Vec<u8>,
client_state_proof: Vec<u8>,
root: Vec<u8>,
client_state_path: Vec<u8>,
expected_client_state: Vec<u8>,
) -> Self {
Self {
proof_height,
counterparty_prefix,
client_state_proof,
root,
client_state_path,
expected_client_state,
}
Expand All @@ -171,7 +169,6 @@ pub struct VerifyClientConsensusState {
pub proof_height: String,
pub counterparty_prefix: Vec<u8>,
pub consensus_state_proof: Vec<u8>,
pub root: Vec<u8>,
pub conesenus_state_path: Vec<u8>,
pub expected_conesenus_state: Vec<u8>,
}
Expand All @@ -181,15 +178,13 @@ impl VerifyClientConsensusState {
proof_height: String,
counterparty_prefix: Vec<u8>,
consensus_state_proof: Vec<u8>,
root: Vec<u8>,
conesenus_state_path: Vec<u8>,
expected_conesenus_state: Vec<u8>,
) -> Self {
Self {
proof_height,
counterparty_prefix,
consensus_state_proof,
root,
conesenus_state_path,
expected_conesenus_state,
}
Expand Down
63 changes: 8 additions & 55 deletions contracts/cosmwasm-vm/cw-ibc-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<'a> CwIbcCoreContext<'a> {
CoreExecuteMsg::CreateClient { msg } => {
cw_println!(deps, "[IBCCore] CreateClient Called");
let message: RawMsgCreateClient = Self::raw_from_hex(&msg)?;
self.create_client(deps, info, message)
self.create_client(deps, info, env, message)
}
CoreExecuteMsg::UpdateClient { msg } => {
cw_println!(deps, "[IBCCore] UpdateClient Called");
Expand Down Expand Up @@ -277,7 +277,7 @@ impl<'a> CwIbcCoreContext<'a> {
}
QueryMsg::GetConsensusState { client_id } => {
let res = self
.consensus_state_any(deps.storage, &IbcClientId::from_str(&client_id).unwrap())
.consensus_state_any(deps, &IbcClientId::from_str(&client_id).unwrap())
.map_err(|_e| {
cw_println!(deps, "{_e:?}");
ContractError::InvalidClientId { client_id }
Expand All @@ -288,15 +288,16 @@ impl<'a> CwIbcCoreContext<'a> {
}
QueryMsg::GetConsensusStateByHeight { client_id, height } => {
let client_val = IbcClientId::from_str(&client_id).unwrap();
let client = self.get_client(deps.storage, &client_val).unwrap();
let client = self.get_light_client(deps.storage, &client_val).unwrap();
let res = client
.get_consensus_state(deps, &client_val, height)
.unwrap();
to_binary(&hex::encode(res))
let state = res.as_bytes();
to_binary(&hex::encode(state))
}
QueryMsg::GetClientState { client_id } => {
let res = self
.client_state_any(deps.storage, &IbcClientId::from_str(&client_id).unwrap())
.client_state_any(deps, &IbcClientId::from_str(&client_id).unwrap())
.map_err(|_| ContractError::InvalidClientId { client_id })
.unwrap();

Expand Down Expand Up @@ -497,7 +498,7 @@ impl<'a> CwIbcCoreContext<'a> {
}
QueryMsg::GetPreviousConsensusStateHeight { client_id, height } => {
let client_val = IbcClientId::from_str(&client_id).unwrap();
let client = self.get_client(deps.storage, &client_val).unwrap();
let client = self.get_light_client(deps.storage, &client_val).unwrap();
let res = client
.get_previous_consensus_state(deps, &client_val, height)
.unwrap();
Expand Down Expand Up @@ -529,7 +530,6 @@ impl<'a> CwIbcCoreContext<'a> {
message: Reply,
) -> Result<Response, ContractError> {
match message.id {
EXECUTE_CREATE_CLIENT => self.execute_create_client_reply(deps, env, message),
EXECUTE_UPDATE_CLIENT => self.execute_update_client_reply(deps, env, message),
EXECUTE_UPGRADE_CLIENT => self.execute_upgrade_client_reply(deps, env, message),
MISBEHAVIOUR => self.execute_misbehaviour_reply(deps, env, message),
Expand Down Expand Up @@ -683,32 +683,22 @@ impl<'a> CwIbcCoreContext<'a> {

#[cfg(test)]
mod tests {
use std::str::FromStr;

use crate::context::CwIbcCoreContext;
use crate::contract::{CONTRACT_NAME, CONTRACT_VERSION};
use common::ibc::core::ics02_client::height::Height;
use common::{
constants::ICON_CONSENSUS_STATE_TYPE_URL,
icon::icon::lightclient::v1::ConsensusState as RawConsensusState, traits::AnyTypes,
};

use crate::msg::MigrateMsg;
use cw2::{get_contract_version, ContractVersion};
use cw_common::ibc_types::IbcClientType;

use cw_common::cw_println;
use prost::Message;

use super::{instantiate, query, InstantiateMsg, QueryMsg};

use cosmwasm_std::{
from_binary,
testing::{mock_dependencies, mock_env, mock_info, MockApi, MockQuerier, MockStorage},
Addr, OwnedDeps,
};
use cw_common::ibc_types::IbcClientId;
use cw_common::raw_types::{Any, RawHeight};

const SENDER: &str = "sender";

fn setup() -> OwnedDeps<MockStorage, MockApi, MockQuerier> {
Expand Down Expand Up @@ -757,43 +747,6 @@ mod tests {
assert_eq!(client, result_parsed.as_str());
}

#[test]
fn test_query_get_consensus_state() {
let contract = CwIbcCoreContext::default();
let client_id = "test_client_1".to_string();
let mut deps = setup();
let commitment_root =
"0x7702db70e830e07b4ff46313456fc86d677c7eeca0c011d7e7dcdd48d5aacfe2".to_string();
let consensus_state = RawConsensusState {
message_root: commitment_root.encode_to_vec(),
next_proof_context_hash: vec![1, 2, 3, 4],
};

let height = Height::new(123, 456).unwrap();
let _raw_height: RawHeight = RawHeight::from(height);
contract
.store_consensus_state(
deps.as_mut().storage,
&IbcClientId::from_str(&client_id).unwrap(),
height,
consensus_state.to_any().encode_to_vec(),
consensus_state.get_keccak_hash().to_vec(),
)
.unwrap();

let msg = QueryMsg::GetConsensusState { client_id };
let result = query(deps.as_ref(), mock_env(), msg).unwrap();
let result_parsed: String = from_binary(&result).unwrap();
let result_bytes = hex::decode(result_parsed).unwrap();

let result_decoded = Any::decode(result_bytes.as_ref()).unwrap();
cw_println!(deps, "{result_decoded:?}");
assert_eq!(
ICON_CONSENSUS_STATE_TYPE_URL.to_string(),
result_decoded.type_url
);
}

#[test]
fn test_migrate() {
let mut mock_deps = mock_dependencies();
Expand Down
2 changes: 2 additions & 0 deletions contracts/cosmwasm-vm/cw-ibc-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ pub enum ContractError {
#[error("InvalidHeight")]
InvalidHeight,

#[error("PacketNotExpired")]
PacketNotExpired,
#[error("CallAlreadyInProgress")]
CallAlreadyInProgress,
}
Expand Down
Loading