Skip to content

Commit

Permalink
feat(ibc-union): implement QueryResponses and cw-orch function genera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
adairrr committed Feb 20, 2025
1 parent 2b7e377 commit 512114d
Show file tree
Hide file tree
Showing 17 changed files with 3,260 additions and 1,986 deletions.
4,641 changes: 2,945 additions & 1,696 deletions Cargo.lock

Large diffs are not rendered by default.

64 changes: 45 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ members = [

"lib/beacon-api",
"lib/cometbft-rpc",
"lib/cosmos-client",
"lib/cometbft-types",

"lib/chain-utils",
Expand Down Expand Up @@ -53,6 +54,7 @@ members = [
"lib/voyager-core",
"lib/galois-rpc",
"lib/cosmos-sdk-event",
"lib/unionlabs-cosmwasm-upgradable",

# "lib/near/near-ibc",
# "lib/near/near-light-client",
Expand All @@ -68,36 +70,41 @@ members = [
"lib/scroll-verifier",
"lib/tendermint-verifier",

"lib/ethereum-light-client-types",
"lib/arbitrum-light-client-types",
"lib/berachain-light-client-types",
"lib/cometbls-light-client-types",
"lib/scroll-light-client-types",
"lib/tendermint-light-client-types",
"lib/linea-light-client-types",
"lib/ethereum-light-client-types",
"lib/ethermint-light-client-types",
"lib/movement-light-client-types",
"lib/linea-light-client-types",
"lib/scroll-light-client-types",
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-mpt-light-client-types",
"lib/state-lens-ics23-ics23-light-client-types",
"lib/state-lens-ics23-smt-light-client-types",

# these will all be re enabled and updated once ethereum-light-client is updated
"cosmwasm/deployer",

"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/state-lens-ics23-mpt",
# "cosmwasm/ibc-union/light-clients/scroll",
"cosmwasm/ibc-union/light-clients/tendermint",
# "cosmwasm/ibc-union/light-clients/linea",
"cosmwasm/ibc-union/lightclient/arbitrum",
"cosmwasm/ibc-union/lightclient/berachain",
"cosmwasm/ibc-union/lightclient/cometbls",
"cosmwasm/ibc-union/lightclient/ethereum",
"cosmwasm/ibc-union/lightclient/ethermint",
"cosmwasm/ibc-union/lightclient/tendermint",
"cosmwasm/ibc-union/lightclient/movement",
"cosmwasm/ibc-union/lightclient/state-lens-ics23-mpt",
"cosmwasm/ibc-union/lightclient/state-lens-ics23-smt",

"cosmwasm/ibc-union/light-clients/movement",
# these will all be re enabled and updated once ethereum-light-client is updated
# "cosmwasm/ibc-union/lightclient/scroll",
# "cosmwasm/ibc-union/lightclient/linea",

"tools/devnet-utils",
"tools/parse-wasm-client-type",
"tools/tidy",
"tools/move-bindgen",

"lib/move-bindgen-derive",

"unionvisor",
Expand All @@ -111,13 +118,15 @@ members = [

"voyager/modules/proof/cosmos-sdk",
"voyager/modules/proof/cosmos-sdk-union",
"voyager/modules/proof/ethermint",
"voyager/modules/proof/ethereum",
"voyager/modules/proof/movement",

"voyager/modules/client/cometbls",
"voyager/modules/client/ethereum",
"voyager/modules/client/movement",
"voyager/modules/client/tendermint",
"voyager/modules/client/ethermint",
"voyager/modules/client/state-lens/ics23-mpt",
"voyager/modules/client/state-lens/ics23-ics23",
"voyager/modules/client/state-lens/ics23-smt",
Expand All @@ -126,6 +135,7 @@ members = [
"voyager/modules/client-bootstrap/ethereum",
"voyager/modules/client-bootstrap/movement",
"voyager/modules/client-bootstrap/tendermint",
"voyager/modules/client-bootstrap/ethermint",
"voyager/modules/client-bootstrap/state-lens/ics23-mpt",
"voyager/modules/client-bootstrap/state-lens/ics23-smt",
"voyager/modules/client-bootstrap/state-lens/ics23-ics23",
Expand All @@ -141,6 +151,7 @@ members = [
"voyager/plugins/client-update/ethereum",
"voyager/plugins/client-update/movement",
"voyager/plugins/client-update/tendermint",
"voyager/plugins/client-update/ethermint",
"voyager/plugins/client-update/state-lens",

"voyager/plugins/periodic-client-update",
Expand Down Expand Up @@ -176,11 +187,17 @@ members = [
"lib/state-lens-light-client-types",
"lib/create3",
"lib/linea-types",
# "cosmwasm/native-token-minter",
"cosmwasm/cw20-token-minter",
"cosmwasm/ucs03-zkgm-token-minter-api",
"cosmwasm/cw20-base",
]

[workspace.package]
authors = ["Union Labs"]
edition = "2021"
license-file = "LICENSE"
publish = false
repository = "https://github.com/unionlabs/union"

[workspace.lints.clippy]
Expand All @@ -203,19 +220,20 @@ beacon-api-types = { path = "lib/beacon-api-types", default-features = false }
chain-utils = { path = "lib/chain-utils", default-features = false }
cometbft-rpc = { path = "lib/cometbft-rpc", default-features = false }
cometbft-types = { path = "lib/cometbft-types", default-features = false }
cosmos-client = { path = "lib/cosmos-client", default-features = false }

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

arbitrum-light-client-types = { path = "lib/arbitrum-light-client-types", default-features = false }
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 = { path = "cosmwasm/ibc-union/lightclient/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 }

ethereum-light-client = { path = "cosmwasm/ibc-union/light-clients/ethereum", default-features = false }
ethereum-light-client = { path = "cosmwasm/ibc-union/lightclient/ethereum", default-features = false }
ethereum-light-client-types = { path = "lib/ethereum-light-client-types", default-features = false }
ethereum-sync-protocol = { path = "lib/ethereum-sync-protocol", default-features = false }
evm-storage-verifier = { path = "lib/evm-storage-verifier", default-features = false }
Expand All @@ -229,7 +247,8 @@ state-lens-ics23-ics23-light-client-types = { path = "lib/state-lens-ics23-ics23
state-lens-ics23-mpt-light-client-types = { path = "lib/state-lens-ics23-mpt-light-client-types", default-features = false }
state-lens-ics23-smt-light-client-types = { path = "lib/state-lens-ics23-smt-light-client-types", default-features = false }

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

Expand All @@ -242,6 +261,11 @@ ibc-union = { path = "cosmwasm/ibc-union/core", default-features =
ibc-union-light-client = { path = "cosmwasm/ibc-union/core/light-client-interface", default-features = false }
ibc-union-msg = { path = "cosmwasm/ibc-union/core/msg", default-features = false }

unionlabs-cosmwasm-upgradable = { path = "lib/unionlabs-cosmwasm-upgradable", default-features = false }

ucs03-zkgm = { path = "cosmwasm/ibc-union/app/ucs03-zkgm", default-features = false }
ucs03-zkgm-token-minter-api = { path = "cosmwasm/ucs03-zkgm-token-minter-api", default-features = false }

gnark-key-parser = { path = "lib/gnark-key-parser", default-features = false }
gnark-mimc = { path = "lib/gnark-mimc", default-features = false }
ics23 = { path = "lib/ics23", default-features = false }
Expand Down Expand Up @@ -282,9 +306,9 @@ voyager-vm = { path = "lib/voyager-vm", default-features = false }
milagro_bls = { git = "https://github.com/Snowfork/milagro_bls", rev = "bc2b5b5e8d48b7e2e1bfaa56dc2d93e13cb32095", default-features = false }
tendermint-rpc = { git = "https://github.com/unionlabs/tendermint-rs", branch = "v0.39.1-bn254", default-features = false }

alloy = { version = "0.6", default-features = false }
alloy-primitives = { version = "0.8.16", default-features = false }
alloy-sol-types = { version = "0.8.12", default-features = true }
alloy = { version = "0.11.1", default-features = false }
alloy-primitives = { version = "0.8.21", default-features = false }
alloy-sol-types = { version = "0.8.21", default-features = true }

# https://github.com/aptos-labs/aptos-core/pull/12636
aptos-crypto = { git = "https://github.com/unionlabs/aptos-core" }
Expand Down Expand Up @@ -342,6 +366,8 @@ tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "ansi"] }
typenum = { version = "1.17.0", default-features = false }

cw-orch = "0.27.0"

[patch."crates-io"]
arbitrary = { git = "https://github.com/unionlabs/arbitrary" }
# parity-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" }
Expand Down
41 changes: 23 additions & 18 deletions cosmwasm/ibc-union/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[package]
authors = ["Hussein Ait Lahcen <[email protected]>"]
name = "ibc-union"
version = "0.0.0"

authors = { workspace = true }
edition = { workspace = true }
license-file = { workspace = true }
name = "ibc-union"
repository = "https://github.com/unionlabs/union"
version = "1.0.0"
publish = { workspace = true }
repository = { workspace = true }

[lints]
workspace = true
Expand All @@ -13,19 +15,22 @@ workspace = true
crate-type = ["cdylib", "rlib"]

[features]
library = []
cw-orch-interface = ["dep:cw-orch", "ibc-union-msg/cw-orch-interface"]
library = []

[dependencies]
alloy = { workspace = true, features = ["sol-types"] }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort"] }
cw-storage-plus = { workspace = true }
ethabi = { workspace = true }
hex = { workspace = true }
ibc-union-msg = { workspace = true }
ibc-union-spec = { workspace = true, features = ["ethabi", "serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi"] }
alloy = { workspace = true, features = ["sol-types"] }
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true, features = ["abort"] }
cw-storage-plus = { workspace = true }
ethabi = { workspace = true }
hex = { workspace = true }
ibc-union-msg = { workspace = true }
ibc-union-spec = { workspace = true, features = ["ethabi", "serde"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = { workspace = true }
unionlabs = { workspace = true, features = ["ethabi"] }
unionlabs-cosmwasm-upgradable = { workspace = true }
cw-orch = { workspace = true, optional = true }
41 changes: 25 additions & 16 deletions cosmwasm/ibc-union/core/light-client-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
[package]
edition.workspace = true
license-file.workspace = true
name = "ibc-union-light-client"
repository.workspace = true
version = "0.1.0"
name = "ibc-union-light-client"
version = "0.0.0"

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
ibc-union-msg = { workspace = true }
macros.workspace = true
schemars = { workspace = true }
serde = { workspace = true }
serde-utils.workspace = true
thiserror.workspace = true
unionlabs.workspace = true
authors = { workspace = true }
edition = { workspace = true }
license-file = { workspace = true }
publish = { workspace = true }
repository = { workspace = true }

[lints]
workspace = true

[dependencies]
cosmwasm-schema = { workspace = true }
cosmwasm-std = { workspace = true }
cw-storage-plus = { workspace = true }
ibc-union-msg = { workspace = true }
macros = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true }
serde-utils = { workspace = true }
thiserror = { workspace = true }
unionlabs = { workspace = true }
unionlabs-cosmwasm-upgradable = { workspace = true }

[features]
default = ["dummy-instantiate"]

dummy-instantiate = [] # exports a panicking instantiate entrypoint
24 changes: 13 additions & 11 deletions cosmwasm/ibc-union/core/light-client-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
use core::fmt::Debug;

use cosmwasm_std::{
from_json, to_json_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, QuerierWrapper,
Response, StdError,
from_json, to_json_binary, Addr, Binary, Deps, DepsMut, Env, QuerierWrapper, Response, StdError,
};
use cw_storage_plus::{Item, Map};
use ibc_union_msg::lightclient::{
MisbehaviourResponse, QueryMsg, Status, VerifyClientMessageUpdate, VerifyCreationResponse,
VerifyCreationResponseEvent,
};
use msg::InstantiateMsg;
use msg::InitMsg;
use state::IBC_HOST;
use unionlabs::{
encoding::{Decode, DecodeAs, DecodeErrorOf, Encode, EncodeAs, Encoding, EthAbi},
primitives::{encoding::Base64, Bytes},
ErrorReporter,
};
use unionlabs_cosmwasm_upgradable::UpgradeError;

pub mod msg;
pub mod state;
Expand Down Expand Up @@ -46,10 +47,12 @@ pub enum DecodeError<T: IbcClient> {
#[derive(macros::Debug, thiserror::Error)]
#[debug(bound())]
pub enum IbcClientError<T: IbcClient> {
#[error("decode error ({0:?})")]
Decode(#[from] DecodeError<T>),
#[error("std error ({0:?})")]
Std(#[from] StdError),
#[error("migration error")]
Migrate(#[from] UpgradeError),
#[error("decode error ({0:?})")]
Decode(#[from] DecodeError<T>),
#[error("unexpected call from the host module ({0})")]
UnexpectedCallDataFromHostModule(String),
#[error("client state not found")]
Expand Down Expand Up @@ -217,7 +220,7 @@ pub trait IbcClient: Sized {
fn verify_creation(
client_state: &Self::ClientState,
consensus_state: &Self::ConsensusState,
) -> Result<(), IbcClientError<Self>>;
) -> Result<Option<Vec<VerifyCreationResponseEvent>>, IbcClientError<Self>>;

/// Verify `header` against the trusted state (`client_state` and `consensus_state`)
/// and return `(updated height, updated client state, updated consensus state)`
Expand All @@ -233,11 +236,9 @@ pub trait IbcClient: Sized {
) -> Result<Self::ClientState, IbcClientError<Self>>;
}

pub fn instantiate<T: IbcClient>(
pub fn init<T: IbcClient>(
deps: DepsMut<T::CustomQuery>,
_env: Env,
_info: MessageInfo,
msg: InstantiateMsg,
msg: InitMsg,
) -> Result<Response, IbcClientError<T>> {
IBC_HOST.save(deps.storage, &msg.ibc_host)?;
Ok(Response::default())
Expand Down Expand Up @@ -281,11 +282,12 @@ pub fn query<T: IbcClient>(
let consensus_state = T::ConsensusState::decode(&consensus_state)
.map_err(|e| IbcClientError::Decode(DecodeError::ConsensusState(e)))?;

T::verify_creation(&client_state, &consensus_state)?;
let events = T::verify_creation(&client_state, &consensus_state)?;

let response = VerifyCreationResponse {
latest_height: T::get_latest_height(&client_state),
counterparty_chain_id: T::get_counterparty_chain_id(&client_state),
events,
};

to_json_binary(&response).map_err(Into::into)
Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/ibc-union/core/light-client-interface/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cosmwasm_std::Addr;
std::cmp::PartialEq,
cosmwasm_schema::schemars::JsonSchema,
)]
pub struct InstantiateMsg {
pub struct InitMsg {
pub ibc_host: Addr,
}

Expand Down
Loading

0 comments on commit 512114d

Please sign in to comment.