From ea662dcd675afde0d0ddd655418afa89c68b00e2 Mon Sep 17 00:00:00 2001 From: Rano | Ranadeep Date: Wed, 5 Jun 2024 15:48:07 +0200 Subject: [PATCH] unwrap ICS008 wasm client at ConnOpenTry and ConnOpenAck (#1246) * add GAT for ClientStateWrapperAtAnyCounterParty * add trait bounds * unwrap expecting a client state wrapper * fix test * rm trait bound * rm Into::into * validate_self_client takes wrapped client_state * nit on trait method types * revert logic * unpack wasm client on wasm client id * add tests for is_wasm_client_id * add trait bounds * add prost dep * successful compilation * impl fn to unpack host client state * update cargo lockfiles for ci * fix no_std import * fix is_wasm_client_id * fix comment * add changelog entry * doc-comment for unpack_host_client_state * use constant for wasm client-id prefix --- .../features/1237-unpack-wasm-client-state.md | 2 + ci/cw-check/Cargo.lock | 18 +- ci/no-std-check/Cargo.lock | 276 +++++++++--------- ibc-core/ics03-connection/Cargo.toml | 8 + .../src/handler/conn_open_ack.rs | 8 +- .../src/handler/conn_open_try.rs | 8 +- ibc-core/ics03-connection/src/handler/mod.rs | 51 ++++ .../types/src/identifiers/client_id.rs | 35 +++ 8 files changed, 263 insertions(+), 143 deletions(-) create mode 100644 .changelog/unreleased/features/1237-unpack-wasm-client-state.md diff --git a/.changelog/unreleased/features/1237-unpack-wasm-client-state.md b/.changelog/unreleased/features/1237-unpack-wasm-client-state.md new file mode 100644 index 000000000..68c1d29f2 --- /dev/null +++ b/.changelog/unreleased/features/1237-unpack-wasm-client-state.md @@ -0,0 +1,2 @@ +- Unpack Wasm client state at `ConnectionOpenTry` and `ConnectionOpenAck` for + host client state. ([#1237](https://github.com/cosmos/ibc-rs/issues/1237)). diff --git a/ci/cw-check/Cargo.lock b/ci/cw-check/Cargo.lock index a97424c34..a4fa71c13 100644 --- a/ci/cw-check/Cargo.lock +++ b/ci/cw-check/Cargo.lock @@ -627,6 +627,18 @@ dependencies = [ "ibc-app-transfer", ] +[[package]] +name = "ibc-client-wasm-types" +version = "0.53.0" +dependencies = [ + "base64 0.21.7", + "displaydoc", + "ibc-core-client", + "ibc-core-host-types", + "ibc-primitives", + "ibc-proto", +] + [[package]] name = "ibc-core" version = "0.53.0" @@ -742,11 +754,13 @@ dependencies = [ name = "ibc-core-connection" version = "0.53.0" dependencies = [ + "ibc-client-wasm-types", "ibc-core-client", "ibc-core-connection-types", "ibc-core-handler-types", "ibc-core-host", "ibc-primitives", + "prost", ] [[package]] @@ -1125,9 +1139,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.84" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] diff --git a/ci/no-std-check/Cargo.lock b/ci/no-std-check/Cargo.lock index f16deb620..74d87e54e 100644 --- a/ci/no-std-check/Cargo.lock +++ b/ci/no-std-check/Cargo.lock @@ -14,9 +14,9 @@ dependencies = [ [[package]] name = "addr2line" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -96,9 +96,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.83" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "ark-bls12-377" @@ -231,9 +231,9 @@ dependencies = [ [[package]] name = "array-bytes" -version = "6.2.2" +version = "6.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f840fb7195bcfc5e17ea40c26e5ce6d5b9ce5d584466e17703209657e459ae0" +checksum = "5d5dde061bd34119e902bbb2d9b90c5692635cf59fb91d582c2b68043f1b8293" [[package]] name = "arrayref" @@ -255,9 +255,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.71" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" dependencies = [ "addr2line", "cc", @@ -391,47 +391,26 @@ dependencies = [ [[package]] name = "borsh" -version = "0.10.3" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" dependencies = [ "borsh-derive", - "hashbrown 0.13.2", + "cfg_aliases", ] [[package]] name = "borsh-derive" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" -dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn 1.0.109", -] - -[[package]] -name = "borsh-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "borsh-schema-derive-internal" -version = "0.10.3" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" dependencies = [ + "once_cell", + "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", + "syn_derive", ] [[package]] @@ -484,9 +463,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.97" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" [[package]] name = "cfg-if" @@ -494,6 +473,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.38" @@ -622,7 +607,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -676,7 +661,7 @@ checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -719,7 +704,7 @@ checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -743,9 +728,9 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.63", + "syn 2.0.66", "termcolor", - "toml 0.8.12", + "toml", "walkdir", ] @@ -844,9 +829,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elliptic-curve" @@ -891,7 +876,7 @@ dependencies = [ "prettier-please", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -1003,7 +988,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -1070,9 +1055,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.28.1" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "group" @@ -1138,9 +1123,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-conservative" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" [[package]] name = "hmac" @@ -1533,7 +1518,7 @@ version = "0.7.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -1551,9 +1536,9 @@ dependencies = [ [[package]] name = "ibc-proto" -version = "0.44.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66080040d5a4800d52966d55b055400f86b79c34b854b935bef03c87aacda62a" +checksum = "7002e679ad26dc29bd27dfa490bb689d121d03c1512bed9f646f75028165644d" dependencies = [ "base64 0.22.1", "borsh", @@ -1710,9 +1695,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.154" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libsecp256k1" @@ -1816,9 +1801,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] @@ -1833,7 +1818,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "syn 2.0.63", + "syn 2.0.66", "tendermint", "tendermint-light-client-verifier", "tendermint-proto", @@ -1901,9 +1886,9 @@ dependencies = [ [[package]] name = "object" -version = "0.32.2" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" dependencies = [ "memchr", ] @@ -1954,7 +1939,7 @@ version = "3.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -1962,9 +1947,9 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -2062,7 +2047,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2072,7 +2057,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ba81f7b5faac81e528eb6158a6f3c9e0bb1008e0ffa19653bc8dea925ecb429" dependencies = [ "polkavm-derive-impl", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2094,7 +2079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22020dfcf177fcc7bf5deaf7440af371400c67c0de14c399938d8ed4fb4645d3" dependencies = [ "proc-macro2", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2112,36 +2097,50 @@ dependencies = [ [[package]] name = "proc-macro-crate" -version = "0.1.5" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" dependencies = [ - "toml 0.5.11", + "toml_edit 0.21.1", ] [[package]] -name = "proc-macro-crate" -version = "3.1.0" +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ - "toml_edit 0.21.1", + "proc-macro-error-attr", + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", ] [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", "prost-derive", @@ -2149,22 +2148,22 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.5" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", "itertools 0.12.1", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] name = "prost-types" -version = "0.12.4" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3235c33eb02c1f1e212abdbe34c78b264b038fb58ca612664343271e36e55ffe" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ "prost", ] @@ -2246,7 +2245,7 @@ checksum = "bcc303e793d3734489387d205e9b186fac9c6cfacedd98cbb2e8a5943595f3e6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2335,9 +2334,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "092474d1a01ea8278f69e6a358998405fae5b8b963ddaeb2b0b04a128bf1dfb0" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" @@ -2374,7 +2373,7 @@ version = "2.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2d35494501194174bda522a32605929eefc9ecf7e0a326c26db1fdd85881eb62" dependencies = [ - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -2382,9 +2381,9 @@ dependencies = [ [[package]] name = "schnellru" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b0cf7da6fc4477944d5529807234f66802fcb618fc62b9c05bedca7f9be6c43" +checksum = "c9a8ef13a93c54d20580de1e5c413e624e53121d42fc7e2c11d10ef7f8b02367" dependencies = [ "ahash 0.8.11", "cfg-if", @@ -2466,9 +2465,9 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "780f1cebed1629e4753a1a38a3c72d30b97ec044f0aef68cb26650a3c5cf363c" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -2493,13 +2492,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.201" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5e405930b9796f1c00bee880d03fc7e0bb4b9a11afc776885ffe84320da2865" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2521,14 +2520,14 @@ checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -2716,7 +2715,7 @@ checksum = "48d09fa0a5f7299fb81ee25ae3853d26200f7a348148aed6de76be905c007dbe" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -2833,10 +2832,10 @@ checksum = "0195f32c628fee3ce1dfbbf2e7e52a30ea85f3589da9fe62a8b816d70fc06294" dependencies = [ "Inflector", "expander", - "proc-macro-crate 3.1.0", + "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -3019,15 +3018,27 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.66", +] + [[package]] name = "tap" version = "1.0.1" @@ -3103,22 +3114,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -3177,30 +3188,21 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "toml" -version = "0.8.12" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.12", + "toml_edit 0.22.14", ] [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] @@ -3218,15 +3220,15 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.12" +version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.8", + "winnow 0.6.11", ] [[package]] @@ -3248,7 +3250,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] @@ -3391,9 +3393,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "w3f-bls" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7335e4c132c28cc43caef6adb339789e599e39adbe78da0c4d547fad48cbc331" +checksum = "9c5da5fa2c6afa2c9158eaa7cd9aee249765eb32b5fb0c63ad8b9e79336a47ec" dependencies = [ "ark-bls12-377", "ark-bls12-381", @@ -3450,7 +3452,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -3472,7 +3474,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3607,9 +3609,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.8" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" +checksum = "56c52728401e1dc672a56e81e593e912aa54c78f40246869f78359a2bf24d29d" dependencies = [ "memchr", ] @@ -3640,14 +3642,14 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] [[package]] name = "zeroize" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] @@ -3660,5 +3662,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.66", ] diff --git a/ibc-core/ics03-connection/Cargo.toml b/ibc-core/ics03-connection/Cargo.toml index 7cea316c2..199fba177 100644 --- a/ibc-core/ics03-connection/Cargo.toml +++ b/ibc-core/ics03-connection/Cargo.toml @@ -23,6 +23,9 @@ ibc-core-connection-types = { workspace = true } ibc-core-host = { workspace = true } ibc-core-handler-types = { workspace = true } ibc-primitives = { workspace = true } +ibc-client-wasm-types = { workspace = true, optional = true } + +prost = { workspace = true, optional = true } [features] default = [ "std" ] @@ -32,6 +35,7 @@ std = [ "ibc-core-host/std", "ibc-core-handler-types/std", "ibc-primitives/std", + "wasm-wrapped-client-state", ] serde = [ "ibc-core-client/serde", @@ -63,3 +67,7 @@ parity-scale-codec = [ "ibc-core-handler-types/parity-scale-codec", "ibc-primitives/parity-scale-codec", ] +wasm-wrapped-client-state = [ + "dep:ibc-client-wasm-types", + "dep:prost", +] diff --git a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs index a0630ef33..590fc260d 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_ack.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_ack.rs @@ -15,6 +15,8 @@ use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; use ibc_primitives::ToVec; +use crate::handler::unpack_host_client_state; + pub fn validate(ctx_a: &Ctx, msg: MsgConnectionOpenAck) -> Result<(), ContextError> where Ctx: ValidationContext, @@ -48,8 +50,10 @@ where let client_val_ctx_a = ctx_a.get_client_validation_context(); - let client_state_of_a_on_b = - Ctx::HostClientState::try_from(msg.client_state_of_a_on_b.clone()).map_err(Into::into)?; + let client_state_of_a_on_b = unpack_host_client_state::( + msg.client_state_of_a_on_b.clone(), + vars.client_id_on_b(), + )?; ctx_a.validate_self_client(client_state_of_a_on_b)?; diff --git a/ibc-core/ics03-connection/src/handler/conn_open_try.rs b/ibc-core/ics03-connection/src/handler/conn_open_try.rs index e85828e7e..a866c56c6 100644 --- a/ibc-core/ics03-connection/src/handler/conn_open_try.rs +++ b/ibc-core/ics03-connection/src/handler/conn_open_try.rs @@ -16,6 +16,8 @@ use ibc_primitives::prelude::*; use ibc_primitives::proto::{Any, Protobuf}; use ibc_primitives::ToVec; +use crate::handler::unpack_host_client_state; + pub fn validate(ctx_b: &Ctx, msg: MsgConnectionOpenTry) -> Result<(), ContextError> where Ctx: ValidationContext, @@ -38,8 +40,10 @@ where let client_val_ctx_b = ctx_b.get_client_validation_context(); - let client_state_of_b_on_a = - Ctx::HostClientState::try_from(msg.client_state_of_b_on_a.clone()).map_err(Into::into)?; + let client_state_of_b_on_a = unpack_host_client_state::( + msg.client_state_of_b_on_a.clone(), + &vars.client_id_on_a, + )?; ctx_b.validate_self_client(client_state_of_b_on_a)?; diff --git a/ibc-core/ics03-connection/src/handler/mod.rs b/ibc-core/ics03-connection/src/handler/mod.rs index c504edc00..a0c0378ca 100644 --- a/ibc-core/ics03-connection/src/handler/mod.rs +++ b/ibc-core/ics03-connection/src/handler/mod.rs @@ -1,4 +1,55 @@ +use ibc_core_client::types::error::ClientError; +use ibc_core_handler_types::error::ContextError; +use ibc_core_host::types::identifiers::ClientId; +use ibc_primitives::proto::Any; + pub mod conn_open_ack; pub mod conn_open_confirm; pub mod conn_open_init; pub mod conn_open_try; + +/// Unpacks the client state from the provided [`Any`] type. +/// +/// Currently, the IBC-go enabled chains stores Wasm LightClient states in a +/// WasmClientState wrapper. This function unpacks the client state from +/// the WasmClientState wrapper if the client identifier is of Wasm client type. +pub(crate) fn unpack_host_client_state( + value: Any, + host_client_id_at_counterparty: &ClientId, +) -> Result +where + CS: TryFrom, + >::Error: Into, +{ + #[cfg(feature = "wasm-wrapped-client-state")] + if host_client_id_at_counterparty.is_wasm_client_id() { + use ibc_client_wasm_types::client_state::ClientState as WasmClientState; + use ibc_core_connection_types::error::ConnectionError; + use ibc_primitives::prelude::ToString; + use prost::Message; + + let wasm_client_state = WasmClientState::try_from(value).map_err(|e| { + ContextError::ConnectionError(ConnectionError::InvalidClientState { + reason: e.to_string(), + }) + })?; + + let any_client_state = ::decode(wasm_client_state.data.as_slice()) + .map_err(|e| { + ContextError::ConnectionError(ConnectionError::InvalidClientState { + reason: e.to_string(), + }) + })?; + + Ok(CS::try_from(any_client_state).map_err(Into::::into)?) + } else { + Ok(CS::try_from(value).map_err(Into::::into)?) + } + + #[cfg(not(feature = "wasm-wrapped-client-state"))] + { + // this avoids lint warning for unused variable. + let _ = host_client_id_at_counterparty; + Ok(CS::try_from(value).map_err(Into::::into)?) + } +} diff --git a/ibc-core/ics24-host/types/src/identifiers/client_id.rs b/ibc-core/ics24-host/types/src/identifiers/client_id.rs index ecbfe1cca..d0128336b 100644 --- a/ibc-core/ics24-host/types/src/identifiers/client_id.rs +++ b/ibc-core/ics24-host/types/src/identifiers/client_id.rs @@ -66,6 +66,18 @@ impl ClientId { pub fn as_bytes(&self) -> &[u8] { self.0.as_bytes() } + + /// Check if the client identifier is for 08-wasm light client. + pub fn is_wasm_client_id(&self) -> bool { + const WASM_CLIENT_PREFIX: &str = "08-wasm-"; + + // prefixed with wasm client type identifier. + self.0.starts_with(WASM_CLIENT_PREFIX) + // followed by non-empty string. + && self.0.len() > WASM_CLIENT_PREFIX.len() + // and the rest of the string is numeric. + && self.0.chars().skip(WASM_CLIENT_PREFIX.len()).all(char::is_numeric) + } } impl FromStr for ClientId { @@ -89,3 +101,26 @@ impl PartialEq for ClientId { self.as_str().eq(other) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[rstest::rstest] + #[case("08-wasm-1", true)] + #[case("08-wasm-", false)] + #[case("08-wasm-abc", false)] + #[case("08-wasm-1-2", false)] + #[case("08-wasm", false)] + #[case("wasm", false)] + #[case("08-", false)] + fn test_is_wasm_client_id(#[case] client_id: &str, #[case] expected: bool) { + assert_eq!( + matches!( + client_id.parse().map(|id: ClientId| id.is_wasm_client_id()), + Ok(true) + ), + expected + ); + } +}