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

Cosmos <> EVM state lens #3456

Merged
merged 24 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
10cde95
chore: introduce `evm-in-cosmos-light-client-types`
aeryz Jan 2, 2025
bfc9a0c
chore(evm-in-cosmos-cw): migrate to ibc-union
aeryz Jan 2, 2025
d087e7d
chore(evm-in-cosmos-cw): client compiles
aeryz Jan 2, 2025
8a5aba4
chore: mimic sol implementation for evm-in-cosmos
aeryz Jan 6, 2025
34912a2
chore(cometbls-lc): fix membership verification
aeryz Jan 6, 2025
dccf0c8
chore: add cosmos state lens types
aeryz Jan 6, 2025
3840a60
chore(cometbls-lc): add contract address to client proto
aeryz Jan 6, 2025
df7e93c
feat(voyager): add cosmos state lens client module
aeryz Jan 6, 2025
5028de2
feat(voyager): add cosmos state lens bootstrap module
aeryz Jan 6, 2025
5ef442b
feat(voyager): add cosmos state lens client update module
aeryz Jan 6, 2025
4c695a5
chore(voyager): proper encoding for state lenses
aeryz Jan 6, 2025
fdaf873
chore(evm-in-cosmos): don't depend on ethereum lc
aeryz Jan 7, 2025
8745103
chore(evm): add `CosmosInCosmos` to the deploy list
aeryz Jan 7, 2025
ebe1586
chore(evm): add `contractAddress` to `CosmosInCosmos`
aeryz Jan 7, 2025
f91c436
chore: fix voyager state lens encodings
aeryz Jan 7, 2025
9b3aaee
chore(tm-lc): proper membership verification
aeryz Jan 7, 2025
e110695
chore: bunch of fixes after rebase
aeryz Jan 7, 2025
fc7ba54
chore: bunch of more fixes
aeryz Jan 8, 2025
d786831
chore: state lens client commitment fixes
aeryz Jan 8, 2025
18f7805
chore: bunch more fixes
aeryz Jan 8, 2025
f288c62
chore(evm): add cosmos in cosmos to deployer
aeryz Jan 8, 2025
6307e52
chore(evm): save client state on update for cosmos in cosmos
aeryz Jan 8, 2025
d8b1693
chore: fmt
aeryz Jan 8, 2025
588e8bf
chore: review fixes
aeryz Jan 8, 2025
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
103 changes: 103 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ members = [
"lib/linea-light-client-types",
"lib/movement-light-client-types",
"lib/state-lens/evm-light-client-types",
"lib/state-lens/cosmos-light-client-types",

# these will all be re enabled and updated once ethereum-light-client is updated

"cosmwasm/ibc-union/light-clients/ethereum",
"cosmwasm/ibc-union/light-clients/arbitrum",
"cosmwasm/ibc-union/light-clients/berachain",
"cosmwasm/ibc-union/light-clients/cometbls",
# "cosmwasm/ibc-union/light-clients/evm-in-cosmos",
"cosmwasm/ibc-union/light-clients/evm-in-cosmos",
# "cosmwasm/ibc-union/light-clients/scroll",
"cosmwasm/ibc-union/light-clients/tendermint",
# "cosmwasm/ibc-union/light-clients/linea",
Expand Down Expand Up @@ -117,12 +118,14 @@ members = [
"voyager/modules/client/movement",
"voyager/modules/client/tendermint",
"voyager/modules/client/state-lens/evm",
"voyager/modules/client/state-lens/ics23-ics23",

"voyager/modules/client-bootstrap/cometbls",
"voyager/modules/client-bootstrap/ethereum",
"voyager/modules/client-bootstrap/movement",
"voyager/modules/client-bootstrap/tendermint",
"voyager/modules/client-bootstrap/state-lens/evm",
"voyager/modules/client-bootstrap/state-lens/ics23-ics23",

"voyager/modules/consensus/berachain",
"voyager/modules/consensus/cometbls",
Expand All @@ -136,6 +139,7 @@ members = [
"voyager/plugins/client-update/movement",
"voyager/plugins/client-update/tendermint",
"voyager/plugins/client-update/state-lens/evm",
"voyager/plugins/client-update/state-lens/ics23-ics23",

"voyager/plugins/periodic-client-update",

Expand Down Expand Up @@ -199,6 +203,7 @@ arbitrum-light-client-types = { path = "lib/arbitrum-light-client-types", defaul
arbitrum-verifier = { path = "lib/arbitrum-verifier", default-features = false }

cometbls-groth16-verifier = { path = "lib/cometbls-groth16-verifier", default-features = false }
cometbls-light-client = { path = "cosmwasm/ibc-union/light-clients/cometbls", default-features = false }
cometbls-light-client-types = { path = "lib/cometbls-light-client-types", default-features = false }

scroll-light-client-types = { path = "lib/scroll-light-client-types", default-features = false }
Expand All @@ -213,7 +218,8 @@ scroll-api = { path = "lib/scroll-api", default-features = fal
scroll-codec = { path = "lib/scroll-codec", default-features = false }
scroll-rpc = { path = "lib/scroll-rpc", default-features = false }

evm-state-lens-light-client-types = { path = "lib/state-lens/evm-light-client-types", default-features = false }
cosmos-state-lens-light-client-types = { path = "lib/state-lens/cosmos-light-client-types", default-features = false }
evm-state-lens-light-client-types = { path = "lib/state-lens/evm-light-client-types", default-features = false }

tendermint-light-client = { path = "cosmwasm/ibc-union/light-clients/tendermint", default-features = false }
tendermint-light-client-types = { path = "lib/tendermint-light-client-types", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions cosmwasm/ibc-union/core/light-client-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ repository.workspace = true
version = "0.1.0"

[dependencies]
cosmwasm-schema = { workspace = true, package = "cosmwasm-schema" }
cosmwasm-std = { workspace = true, package = "cosmwasm-std" }
cw-storage-plus = { workspace = true, package = "cw-storage-plus" }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
ibc-union-msg = { workspace = true }
macros.workspace = true
schemars = { workspace = true }
Expand Down
47 changes: 46 additions & 1 deletion cosmwasm/ibc-union/core/light-client-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod state;
// These are only used for `key` calculation. We don't want this crate to depend on `ibc-union`.
pub const CLIENT_STATES: Map<u32, Binary> = Map::new("client_states");
pub const CLIENT_CONSENSUS_STATES: Map<(u32, u64), Binary> = Map::new("client_consensus_states");
const CLIENT_IMPLS: Map<u32, Addr> = Map::new("client_impls");
const QUERY_STORE: Item<Binary> = Item::new("query_store");

// TODO: Add #[source] to all variants
Expand Down Expand Up @@ -121,6 +122,47 @@ impl<'a, T: IbcClient> IbcClientCtx<'a, T> {
height,
)
}

pub fn verify_membership<Client: IbcClient>(
&self,
client_id: u32,
height: u64,
path: Bytes,
storage_proof: Client::StorageProof,
value: Bytes,
) -> Result<(), IbcClientError<Client>> {
let client_impl = client_impl(self.deps.querier.into_empty(), &self.ibc_host, client_id)?;
self.deps.querier.query_wasm_smart::<()>(
&client_impl,
&QueryMsg::VerifyMembership {
client_id,
height,
proof: storage_proof.encode_as::<Client::Encoding>().into(),
path,
value,
},
)?;

Ok(())
}
}

fn client_impl<T: IbcClient>(
querier: QuerierWrapper,
ibc_host: &Addr,
client_id: u32,
) -> Result<Addr, IbcClientError<T>> {
let addr = from_json::<Addr>(
querier
.query_wasm_raw(ibc_host.to_string(), CLIENT_IMPLS.key(client_id).to_vec())?
.ok_or_else(|| {
IbcClientError::Std(StdError::generic_err(format!(
"unable to read client state of client {client_id}"
)))
})?,
)?;

Ok(addr)
}

pub trait IbcClient: Sized {
Expand All @@ -136,7 +178,10 @@ pub trait IbcClient: Sized {
/// a common encoding scheme for state lenses. When doing state lenses, client X will read the
/// consensus state of client Y by assuming it's state is ethabi-encoded.
type ConsensusState: Decode<EthAbi, Error: Debug> + Encode<EthAbi> + Debug + 'static;
type StorageProof: Decode<Self::Encoding, Error: Debug> + Debug + 'static;
type StorageProof: Encode<Self::Encoding>
+ Decode<Self::Encoding, Error: Debug>
+ Debug
+ 'static;
type Encoding: Encoding;

fn verify_membership(
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ibc-union/light-clients/cometbls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
cometbls-groth16-verifier = { workspace = true }
cometbls-light-client-types = { workspace = true, features = ["serde", "ethabi", "proto"] }
cometbls-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
cosmwasm-std = { workspace = true, features = ["abort", "iterator"] }
ibc-union-light-client = { workspace = true }
ibc-union-msg = { workspace = true }
Expand Down
43 changes: 25 additions & 18 deletions cosmwasm/ibc-union/light-clients/cometbls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ibc_union_light_client::IbcClientCtx;
use ibc_union_msg::lightclient::Status;
use ics23::ibc_api::SDK_SPECS;
use unionlabs::{
encoding::Proto,
encoding::Bincode,
ibc::core::{
client::height::Height,
commitment::{merkle_proof::MerkleProof, merkle_root::MerkleRoot},
Expand Down Expand Up @@ -38,26 +38,33 @@ impl<T: ZkpVerifier> ibc_union_light_client::IbcClient for CometblsLightClient<T

type StorageProof = MerkleProof;

type Encoding = Proto;
type Encoding = Bincode;

fn verify_membership(
_ctx: ibc_union_light_client::IbcClientCtx<Self>,
_height: u64,
_key: Vec<u8>,
_storage_proof: Self::StorageProof,
_value: Vec<u8>,
ctx: ibc_union_light_client::IbcClientCtx<Self>,
height: u64,
key: Vec<u8>,
storage_proof: Self::StorageProof,
value: Vec<u8>,
) -> Result<(), ibc_union_light_client::IbcClientError<Self>> {
// let consensus_state = ctx.read_self_consensus_state(height)?;
// Ok(ics23::ibc_api::verify_membership(
// &storage_proof,
// &SDK_SPECS,
// &consensus_state.app_hash,
// // FIXME: concat(contract, key) right?
// &[b"wasm".to_vec(), key],
// value,
// )
// .map_err(Into::<Error>::into)?)
Ok(())
let client_state = ctx.read_self_client_state()?;
let consensus_state = ctx.read_self_consensus_state(height)?;
Ok(ics23::ibc_api::verify_membership(
&storage_proof,
&SDK_SPECS,
&consensus_state.app_hash,
&[
b"wasm".to_vec(),
0x3u8
.to_le_bytes()
.into_iter()
.chain(client_state.contract_address)
.chain(key)
.collect::<Vec<_>>(),
],
value,
)
.map_err(Into::<Error>::into)?)
}

fn verify_non_membership(
Expand Down
5 changes: 2 additions & 3 deletions cosmwasm/ibc-union/light-clients/ethereum/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ use cosmwasm_std::{
from_json, to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response,
StdResult, SubMsg,
};
use ethereum_light_client_types::{ClientState, ConsensusState};
use ethereum_light_client_types::ClientState;
use ibc_union_light_client::{
msg::{InstantiateMsg, QueryMsg},
read_consensus_state,
state::IBC_HOST,
IbcClientError, CLIENT_CONSENSUS_STATES, CLIENT_STATES,
IbcClientError, CLIENT_STATES,
};
use ibc_union_msg::module::IbcUnionMsg;
use serde::{Deserialize, Serialize};
use unionlabs::{
encoding::{Bincode, EncodeAs, EthAbi},
Expand Down
21 changes: 13 additions & 8 deletions cosmwasm/ibc-union/light-clients/evm-in-cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ workspace = true
crate-type = ["cdylib", "rlib"]

[dependencies]
cometbls-light-client-types = { workspace = true, features = ["proto"] }
cosmwasm-std = { workspace = true, features = ["abort"] }
# ethereum-light-client = { workspace = true, features = ["mainnet", "library"] }
ics008-wasm-client = { workspace = true }
ics23 = { workspace = true }
protos = { workspace = true }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi", "stargate"] }
cometbls-light-client = { workspace = true, features = ["library"] }
cosmwasm-std = { workspace = true, features = ["abort"] }
ethereum-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
evm-state-lens-light-client-types = { workspace = true, features = ["serde", "ethabi", "bincode"] }
evm-storage-verifier = { workspace = true }
ibc-union-light-client = { workspace = true }
ibc-union-msg = { workspace = true }
ibc-union-spec = { workspace = true }
ics23 = { workspace = true }
rlp = { workspace = true }
serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi", "stargate", "bincode"] }

[features]
default = []
Expand Down
Loading
Loading