From 46588f5ba06a5e8256946533268c847ceffa66d4 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz Date: Mon, 11 Mar 2024 14:40:49 +0100 Subject: [PATCH] cf-guest-cw: add light client implementation for the guest blockchain (#478) --------- Signed-off-by: Michal Nazarewicz Co-authored-by: Dhruv D Jain --- Cargo.lock | 1143 ++++++++++++++--- Cargo.toml | 3 +- light-clients/cf-guest-cw/Cargo.toml | 57 + light-clients/cf-guest-cw/src/bin/schema.rs | 25 + light-clients/cf-guest-cw/src/context.rs | 182 +++ light-clients/cf-guest-cw/src/contract.rs | 149 +++ light-clients/cf-guest-cw/src/crypto.rs | 107 ++ light-clients/cf-guest-cw/src/error.rs | 56 + light-clients/cf-guest-cw/src/ibc.rs | 16 + light-clients/cf-guest-cw/src/lib.rs | 30 + light-clients/cf-guest-cw/src/msg.rs | 150 +++ .../cf-guest-cw/src/serialisation.rs | 268 ++++ light-clients/cf-guest-cw/src/state.rs | 250 ++++ 13 files changed, 2241 insertions(+), 195 deletions(-) create mode 100644 light-clients/cf-guest-cw/Cargo.toml create mode 100644 light-clients/cf-guest-cw/src/bin/schema.rs create mode 100644 light-clients/cf-guest-cw/src/context.rs create mode 100644 light-clients/cf-guest-cw/src/contract.rs create mode 100644 light-clients/cf-guest-cw/src/crypto.rs create mode 100644 light-clients/cf-guest-cw/src/error.rs create mode 100644 light-clients/cf-guest-cw/src/ibc.rs create mode 100644 light-clients/cf-guest-cw/src/lib.rs create mode 100644 light-clients/cf-guest-cw/src/msg.rs create mode 100644 light-clients/cf-guest-cw/src/serialisation.rs create mode 100644 light-clients/cf-guest-cw/src/state.rs diff --git a/Cargo.lock b/Cargo.lock index 467622f79..67eb577f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,6 +179,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + [[package]] name = "always-assert" version = "0.1.2" @@ -339,6 +348,12 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "ascii" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" + [[package]] name = "asn1-rs" version = "0.3.1" @@ -559,7 +574,7 @@ dependencies = [ "bitflags 1.3.2", "bytes", "futures-util", - "http", + "http 0.2.9", "http-body", "hyper", "itoa", @@ -586,7 +601,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", + "http 0.2.9", "http-body", "mime", "rustversion", @@ -641,9 +656,15 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.0" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" [[package]] name = "base64ct" @@ -799,7 +820,7 @@ dependencies = [ "pbkdf2 0.11.0", "rand_core 0.6.4", "ripemd", - "sha2 0.10.6", + "sha2 0.10.8", "subtle", "zeroize", ] @@ -849,7 +870,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -895,7 +916,7 @@ dependencies = [ "cc", "cfg-if 1.0.0", "constant_time_eq 0.2.4", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -953,6 +974,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" +[[package]] +name = "bnum" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" + [[package]] name = "borsh" version = "0.10.3" @@ -1067,9 +1094,23 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" [[package]] name = "bytemuck" -version = "1.13.1" +version = "1.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" +checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] [[package]] name = "byteorder" @@ -1158,6 +1199,47 @@ dependencies = [ "nom", ] +[[package]] +name = "cf-guest" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "borsh", + "bytemuck", + "derive_more", + "guestchain", + "ibc-core-client-context", + "ibc-core-commitment-types", + "ibc-core-host", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "lib", + "prost 0.12.3", + "prost-build 0.12.3", + "sealable-trie", + "stdx", + "trie-ids", +] + +[[package]] +name = "cf-guest-cw" +version = "0.0.0" +dependencies = [ + "base64 0.22.0", + "borsh", + "cf-guest", + "cosmwasm-schema", + "cosmwasm-std", + "derive_more", + "ed25519-dalek 2.1.1", + "guestchain", + "ibc 0.50.0", + "prost 0.12.3", + "schemars", + "serde", + "sha2 0.10.8", +] + [[package]] name = "cfg-expr" version = "0.15.5" @@ -1403,7 +1485,7 @@ dependencies = [ "clap 3.2.23", "frame-metadata 15.1.0", "hex", - "http", + "http 0.2.9", "jsonrpsee", "parity-scale-codec", "serde_json", @@ -1436,8 +1518,8 @@ version = "6.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e7b787b0dc42e8111badfdbe4c3059158ccb2db8780352fa1b01e8ccf45cc4d" dependencies = [ - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "unicode-width", ] @@ -1540,31 +1622,32 @@ dependencies = [ [[package]] name = "cosmwasm-crypto" -version = "1.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f22add0f9b2a5416df98c1d0248a8d8eedb882c38fbf0c5052b64eebe865df6d" +checksum = "9934c79e58d9676edfd592557dee765d2a6ef54c09d5aa2edb06156b00148966" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", + "ecdsa 0.16.7", "ed25519-zebra", - "k256 0.11.6", + "k256 0.13.1", "rand_core 0.6.4", "thiserror", ] [[package]] name = "cosmwasm-derive" -version = "1.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e64f710a18ef90d0a632cf27842e98ffc2d005a38a6f76c12fd0bc03bc1a2d" +checksum = "bc5e72e330bd3bdab11c52b5ecbdeb6a8697a004c57964caeb5d876f0b088b3c" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe5ad2e23a971b9e4cd57b20cee3e2e79c33799bed4b128e473aca3702bfe5dd" +checksum = "ac3e3a2136e2a60e8b6582f5dffca5d1a683ed77bf38537d330bc1dfccd69010" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -1575,9 +1658,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2926d159a9bb1a716a592b40280f1663f2491a9de3b6da77c0933cee2a2655b8" +checksum = "f5d803bea6bd9ed61bd1ee0b4a2eb09ee20dbb539cc6e0b8795614d20952ebb1" dependencies = [ "proc-macro2", "quote", @@ -1586,11 +1669,13 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.2.3" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76fee88ff5bf7bef55bd37ac0619974701b99bf6bd4b16cf56ee8810718abd71" +checksum = "ef8666e572a3a2519010dde88c04d16e9339ae751b56b2bb35081fe3f7d6be74" dependencies = [ - "base64 0.13.1", + "base64 0.21.7", + "bech32", + "bnum", "cosmwasm-crypto", "cosmwasm-derive", "derivative", @@ -1598,10 +1683,10 @@ dependencies = [ "hex", "schemars", "serde", - "serde-json-wasm", - "sha2 0.10.6", + "serde-json-wasm 0.5.2", + "sha2 0.10.8", + "static_assertions", "thiserror", - "uint", ] [[package]] @@ -2479,7 +2564,7 @@ dependencies = [ "cfg-if 1.0.0", "cpufeatures", "curve25519-dalek-derive", - "digest 0.10.6", + "digest 0.10.7", "fiat-crypto", "platforms 3.0.2", "rustc_version", @@ -2850,9 +2935,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.3", "const-oid", @@ -2976,7 +3061,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" dependencies = [ "der 0.7.8", - "digest 0.10.6", + "digest 0.10.7", "elliptic-curve 0.13.6", "rfc6979 0.4.0", "signature 2.1.0", @@ -2994,9 +3079,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8 0.10.2", "signature 2.1.0", @@ -3030,15 +3115,16 @@ dependencies = [ [[package]] name = "ed25519-dalek" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7277392b266383ef8396db7fdeb1e77b6c52fed775f5df15bb24f35b72156980" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek 4.1.1", - "ed25519 2.2.2", + "ed25519 2.2.3", "rand_core 0.6.4", "serde", - "sha2 0.10.6", + "sha2 0.10.8", + "subtle", "zeroize", ] @@ -3072,7 +3158,7 @@ dependencies = [ "base16ct 0.1.1", "crypto-bigint 0.4.9", "der 0.6.1", - "digest 0.10.6", + "digest 0.10.7", "ff 0.12.1", "generic-array 0.14.6", "group 0.12.1", @@ -3093,7 +3179,7 @@ checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" dependencies = [ "base16ct 0.2.0", "crypto-bigint 0.5.3", - "digest 0.10.6", + "digest 0.10.7", "ff 0.13.0", "generic-array 0.14.6", "group 0.13.0", @@ -4081,7 +4167,7 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc" dependencies = [ - "aho-corasick", + "aho-corasick 0.7.20", "bstr", "fnv", "log", @@ -4192,6 +4278,28 @@ dependencies = [ "subtle", ] +[[package]] +name = "guestchain" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "borsh", + "bytemuck", + "derive_more", + "ibc-core-client-context", + "ibc-core-commitment-types", + "ibc-core-host", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "lib", + "prost 0.12.3", + "prost-build 0.12.3", + "sealable-trie", + "stdx", + "strum 0.25.0", + "trie-ids", +] + [[package]] name = "gumdrop" version = "0.8.1" @@ -4223,7 +4331,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.9", "indexmap 1.9.2", "slab", "tokio", @@ -4300,7 +4408,7 @@ dependencies = [ "bitflags 1.3.2", "bytes", "headers-core", - "http", + "http 0.2.9", "httpdate", "mime", "sha1", @@ -4312,7 +4420,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" dependencies = [ - "http", + "http 0.2.9", ] [[package]] @@ -4398,7 +4506,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -4434,6 +4542,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.5" @@ -4441,7 +4560,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", - "http", + "http 0.2.9", "pin-project-lite 0.2.13", ] @@ -4480,7 +4599,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.9", "http-body", "httparse", "httpdate", @@ -4502,7 +4621,7 @@ dependencies = [ "bytes", "futures", "headers", - "http", + "http 0.2.9", "hyper", "hyper-rustls 0.22.1", "rustls-native-certs 0.5.0", @@ -4536,7 +4655,7 @@ version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1788965e61b367cd03a62950836d5cd41560c3577d90e40e0819373194d1661c" dependencies = [ - "http", + "http 0.2.9", "hyper", "log", "rustls 0.20.8", @@ -4552,7 +4671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d78e1e73ec14cf7375674f74d7dde185c8206fd9dea6fb6295e8a98098aaa97" dependencies = [ "futures-util", - "http", + "http 0.2.9", "hyper", "log", "rustls 0.21.7", @@ -4603,7 +4722,7 @@ dependencies = [ "hyperspace-metrics", "hyperspace-parachain", "hyperspace-primitives", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "ibc-rpc", "ics08-wasm", @@ -4646,12 +4765,12 @@ dependencies = [ "bech32", "bip32", "derive_more", - "digest 0.10.6", + "digest 0.10.7", "ed25519-zebra", "futures", "hex", "hyperspace-primitives", - "ibc", + "ibc 0.15.0", "ibc-primitives 0.1.0", "ibc-proto 0.18.0", "ibc-rpc", @@ -4669,10 +4788,10 @@ dependencies = [ "rs_merkle", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "tendermint 0.28.0", "tendermint-light-client", - "tendermint-light-client-verifier", + "tendermint-light-client-verifier 0.28.0", "tendermint-proto 0.28.0", "tendermint-rpc", "thiserror", @@ -4690,7 +4809,7 @@ dependencies = [ "anyhow", "futures-util", "hyper", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "log", "prometheus", @@ -4719,7 +4838,7 @@ dependencies = [ "hex", "hex-literal 0.3.4", "hyperspace-primitives", - "ibc", + "ibc 0.15.0", "ibc-primitives 0.1.0", "ibc-proto 0.18.0", "ibc-rpc", @@ -4774,7 +4893,7 @@ dependencies = [ "async-trait", "futures", "hex", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "ibc-rpc", "ics08-wasm", @@ -4803,7 +4922,7 @@ dependencies = [ "hyperspace-cosmos", "hyperspace-parachain", "hyperspace-primitives", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "ics10-grandpa", "light-client-common", @@ -4860,8 +4979,8 @@ dependencies = [ "env_logger 0.9.3", "flex-error", "hex", - "ibc-core-host-types", - "ibc-derive", + "ibc-core-host-types 0.48.1", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "ics23 0.10.0", "log", @@ -4875,7 +4994,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "sp-core 7.0.0", "sp-std 5.0.0", @@ -4890,6 +5009,376 @@ dependencies = [ "uint", ] +[[package]] +name = "ibc" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-apps", + "ibc-clients", + "ibc-core", + "ibc-core-host-cosmos", + "ibc-derive 0.6.0", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-app-nft-transfer" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-app-nft-transfer-types", + "ibc-core", + "serde-json-wasm 1.0.1", +] + +[[package]] +name = "ibc-app-nft-transfer-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "base64 0.21.7", + "borsh", + "derive_more", + "displaydoc", + "http 1.0.0", + "ibc-core", + "ibc-proto 0.41.0", + "mime", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "serde-json-wasm 1.0.1", +] + +[[package]] +name = "ibc-app-transfer" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-app-transfer-types", + "ibc-core", + "serde-json-wasm 1.0.1", +] + +[[package]] +name = "ibc-app-transfer-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core", + "ibc-proto 0.41.0", + "primitive-types", + "serde", + "uint", +] + +[[package]] +name = "ibc-apps" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-app-nft-transfer", + "ibc-app-transfer", +] + +[[package]] +name = "ibc-client-tendermint" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "derive_more", + "ibc-client-tendermint-types", + "ibc-core-client", + "ibc-core-commitment-types", + "ibc-core-handler-types", + "ibc-core-host", + "ibc-primitives 0.50.0", + "serde", + "tendermint 0.34.0", + "tendermint-light-client-verifier 0.34.0", +] + +[[package]] +name = "ibc-client-tendermint-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "displaydoc", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "serde", + "tendermint 0.34.0", + "tendermint-light-client-verifier 0.34.0", + "tendermint-proto 0.34.0", +] + +[[package]] +name = "ibc-client-wasm-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "base64 0.21.7", + "displaydoc", + "ibc-core-client", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "serde", +] + +[[package]] +name = "ibc-clients" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-client-tendermint", + "ibc-client-wasm-types", +] + +[[package]] +name = "ibc-core" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-core-channel", + "ibc-core-client", + "ibc-core-commitment-types", + "ibc-core-connection", + "ibc-core-handler", + "ibc-core-host", + "ibc-core-router", + "ibc-derive 0.6.0", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-core-channel" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-core-channel-types", + "ibc-core-client", + "ibc-core-commitment-types", + "ibc-core-connection", + "ibc-core-handler-types", + "ibc-core-host", + "ibc-core-router", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-core-channel-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-connection-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "sha2 0.10.8", + "subtle-encoding", + "tendermint 0.34.0", +] + +[[package]] +name = "ibc-core-client" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-core-client-context", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-handler-types", + "ibc-core-host", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-core-client-context" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "derive_more", + "displaydoc", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-handler-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "subtle-encoding", + "tendermint 0.34.0", +] + +[[package]] +name = "ibc-core-client-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core-commitment-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "subtle-encoding", + "tendermint 0.34.0", +] + +[[package]] +name = "ibc-core-commitment-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "ics23 0.11.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "subtle-encoding", +] + +[[package]] +name = "ibc-core-connection" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-core-client", + "ibc-core-connection-types", + "ibc-core-handler-types", + "ibc-core-host", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-core-connection-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "subtle-encoding", + "tendermint 0.34.0", +] + +[[package]] +name = "ibc-core-handler" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "ibc-core-channel", + "ibc-core-client", + "ibc-core-commitment-types", + "ibc-core-connection", + "ibc-core-handler-types", + "ibc-core-host", + "ibc-core-router", + "ibc-primitives 0.50.0", +] + +[[package]] +name = "ibc-core-handler-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core-channel-types", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-connection-types", + "ibc-core-host-types 0.50.0", + "ibc-core-router-types", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "subtle-encoding", + "tendermint 0.34.0", +] + +[[package]] +name = "ibc-core-host" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "derive_more", + "displaydoc", + "ibc-core-channel-types", + "ibc-core-client-context", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-connection-types", + "ibc-core-handler-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "subtle-encoding", +] + +[[package]] +name = "ibc-core-host-cosmos" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-app-transfer-types", + "ibc-client-tendermint", + "ibc-core-client-context", + "ibc-core-client-types", + "ibc-core-commitment-types", + "ibc-core-connection-types", + "ibc-core-handler-types", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "serde", + "sha2 0.10.8", + "subtle-encoding", + "tendermint 0.34.0", +] + [[package]] name = "ibc-core-host-types" version = "0.48.1" @@ -4901,6 +5390,54 @@ dependencies = [ "ibc-primitives 0.48.1", ] +[[package]] +name = "ibc-core-host-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-primitives 0.50.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", +] + +[[package]] +name = "ibc-core-router" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "derive_more", + "displaydoc", + "ibc-core-channel-types", + "ibc-core-host-types 0.50.0", + "ibc-core-router-types", + "ibc-primitives 0.50.0", + "subtle-encoding", +] + +[[package]] +name = "ibc-core-router-types" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-core-host-types 0.50.0", + "ibc-primitives 0.50.0", + "ibc-proto 0.41.0", + "parity-scale-codec", + "scale-info", + "schemars", + "serde", + "subtle-encoding", + "tendermint 0.34.0", +] + [[package]] name = "ibc-derive" version = "0.1.0" @@ -4912,6 +5449,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ibc-derive" +version = "0.6.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.32", +] + [[package]] name = "ibc-primitives" version = "0.1.0" @@ -4920,12 +5467,12 @@ dependencies = [ "blake2", "frame-support", "hex", - "ibc", + "ibc 0.15.0", "parity-scale-codec", "ripemd", "scale-info", "serde", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "sp-core 7.0.0", "sp-io 7.0.0", @@ -4949,6 +5496,24 @@ dependencies = [ "time 0.3.17", ] +[[package]] +name = "ibc-primitives" +version = "0.50.0" +source = "git+https://github.com/cosmos/ibc-rs?rev=6dd3c6465e594d4c177f21724dd896a15e8f3634#6dd3c6465e594d4c177f21724dd896a15e8f3634" +dependencies = [ + "borsh", + "derive_more", + "displaydoc", + "ibc-proto 0.41.0", + "parity-scale-codec", + "prost 0.12.3", + "scale-info", + "schemars", + "serde", + "tendermint 0.34.0", + "time 0.3.17", +] + [[package]] name = "ibc-proto" version = "0.18.0" @@ -4968,7 +5533,7 @@ version = "0.38.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93cbf4cbe9e5113cc7c70f3208a7029b2205c629502cbb2ae7ea0a09a97d3005" dependencies = [ - "base64 0.21.0", + "base64 0.21.7", "bytes", "flex-error", "ics23 0.11.0", @@ -4977,13 +5542,34 @@ dependencies = [ "tendermint-proto 0.34.0", ] +[[package]] +name = "ibc-proto" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd4ee32b22d3b06f31529b956f4928e5c9a068d71e46cf6abfa19c31ca550553" +dependencies = [ + "base64 0.21.7", + "borsh", + "bytes", + "flex-error", + "ics23 0.11.0", + "informalsystems-pbjson 0.7.0", + "parity-scale-codec", + "prost 0.12.3", + "scale-info", + "schemars", + "serde", + "subtle-encoding", + "tendermint-proto 0.34.0", +] + [[package]] name = "ibc-proto-compiler" version = "0.2.0" dependencies = [ "argh", "git2", - "prost-build", + "prost-build 0.11.6", "tempdir", "tonic-build", "walkdir", @@ -4994,8 +5580,8 @@ name = "ibc-rpc" version = "0.1.0" dependencies = [ "frame-system", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-primitives 0.1.0", "ibc-proto 0.18.0", "ibc-runtime-api", @@ -5033,8 +5619,8 @@ dependencies = [ "env_logger 0.9.3", "flex-error", "hex", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "ics23 0.10.0", "log", @@ -5042,10 +5628,10 @@ dependencies = [ "prost 0.11.6", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "subtle-encoding", "tendermint 0.28.0", - "tendermint-light-client-verifier", + "tendermint-light-client-verifier 0.28.0", "tendermint-proto 0.28.0", "tendermint-rpc", "tendermint-testgen", @@ -5064,14 +5650,14 @@ dependencies = [ "cosmwasm-std", "cw-multi-test", "derive_more", - "digest 0.10.6", + "digest 0.10.7", "ed25519 1.5.3", "ed25519-consensus", "ed25519-zebra", "hex", "hyperspace-primitives", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "ics07-tendermint", "ics08-wasm", @@ -5080,12 +5666,12 @@ dependencies = [ "prost 0.11.6", "schemars", "serde", - "serde-json-wasm", + "serde-json-wasm 0.5.2", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "tendermint 0.28.0", - "tendermint-light-client-verifier", + "tendermint-light-client-verifier 0.28.0", "tendermint-proto 0.28.0", "thiserror", ] @@ -5096,7 +5682,7 @@ version = "0.1.0" dependencies = [ "cosmwasm-schema", "hex", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "prost 0.11.6", "serde", @@ -5119,15 +5705,15 @@ dependencies = [ "grandpa-prover", "hex", "hyperspace-core", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "jsonrpsee-ws-client", "light-client-common", "log", "parity-scale-codec", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "prost-types 0.11.6", "sc-consensus-grandpa-rpc", "serde", @@ -5154,14 +5740,14 @@ dependencies = [ "cw-multi-test", "cw-storage-plus", "derive_more", - "digest 0.10.6", + "digest 0.10.7", "ed25519-zebra", "finality-grandpa", "grandpa-light-client-primitives", "hex", "hyperspace-primitives", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "ics08-wasm", "ics10-grandpa", @@ -5171,9 +5757,9 @@ dependencies = [ "prost 0.11.6", "schemars", "serde", - "serde-json-wasm", + "serde-json-wasm 0.5.2", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "sp-core 7.0.0", "sp-io 7.0.0", @@ -5199,13 +5785,13 @@ dependencies = [ "frame-support", "futures", "hyperspace-core", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "light-client-common", "parity-scale-codec", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "prost-types 0.11.6", "serde", "serde_json", @@ -5231,8 +5817,8 @@ dependencies = [ "derive_more", "env_logger 0.9.3", "flex-error", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-proto 0.18.0", "ics23 0.10.0", "modelator", @@ -5244,7 +5830,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "sp-core 7.0.0", "subtle-encoding", @@ -5270,7 +5856,7 @@ dependencies = [ "hex", "prost 0.11.6", "ripemd", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", ] @@ -5283,7 +5869,12 @@ dependencies = [ "anyhow", "bytes", "hex", + "informalsystems-pbjson 0.6.0", "prost 0.12.3", + "ripemd", + "serde", + "sha2 0.10.8", + "sha3", ] [[package]] @@ -5420,6 +6011,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "informalsystems-pbjson" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4eecd90f87bea412eac91c6ef94f6b1e390128290898cbe14f2b926787ae1fb" +dependencies = [ + "base64 0.13.1", + "serde", +] + +[[package]] +name = "informalsystems-pbjson" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aa4a0980c8379295100d70854354e78df2ee1c6ca0f96ffe89afeb3140e3a3d" +dependencies = [ + "base64 0.21.7", + "serde", +] + [[package]] name = "inout" version = "0.1.3" @@ -5574,7 +6185,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8b3815d9f5d5de348e5f162b316dc9cdf4548305ebb15b4eb9328e66cf27d7a" dependencies = [ "futures-util", - "http", + "http 0.2.9", "jsonrpsee-core", "jsonrpsee-types", "pin-project", @@ -5656,7 +6267,7 @@ checksum = "cf4d945a6008c9b03db3354fb3c83ee02d2faa9f2e755ec1dfb69c3551b8f4ba" dependencies = [ "futures-channel", "futures-util", - "http", + "http 0.2.9", "hyper", "jsonrpsee-core", "jsonrpsee-types", @@ -5690,7 +6301,7 @@ version = "0.16.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e1b3975ed5d73f456478681a417128597acd6a2487855fdb7b4a3d4d195bf5e" dependencies = [ - "http", + "http 0.2.9", "jsonrpsee-client-transport", "jsonrpsee-core", "jsonrpsee-types", @@ -5705,7 +6316,7 @@ dependencies = [ "cfg-if 1.0.0", "ecdsa 0.14.8", "elliptic-curve 0.12.3", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", ] @@ -5719,7 +6330,8 @@ dependencies = [ "ecdsa 0.16.7", "elliptic-curve 0.13.6", "once_cell", - "sha2 0.10.6", + "sha2 0.10.8", + "signature 2.1.0", ] [[package]] @@ -5889,6 +6501,19 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "lib" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "base64 0.21.7", + "borsh", + "bytemuck", + "derive_more", + "sha2 0.10.8", + "stdx", +] + [[package]] name = "libc" version = "0.2.148" @@ -6054,13 +6679,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "276bb57e7af15d8f100d3c11cbdd32c6752b7eef4ba7a18ecf464972c07abcce" dependencies = [ "bs58", - "ed25519-dalek 2.0.0", + "ed25519-dalek 2.1.1", "log", "multiaddr", "multihash 0.17.0", "quick-protobuf", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.8", "thiserror", "zeroize", ] @@ -6085,7 +6710,7 @@ dependencies = [ "log", "quick-protobuf", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.8", "smallvec", "thiserror", "uint", @@ -6143,7 +6768,7 @@ dependencies = [ "once_cell", "quick-protobuf", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.8", "snow", "static_assertions", "thiserror", @@ -6447,7 +7072,7 @@ dependencies = [ "async-trait", "derive_more", "hash-db", - "ibc", + "ibc 0.15.0", "ibc-proto 0.18.0", "parity-scale-codec", "serde", @@ -6606,7 +7231,7 @@ version = "0.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -6615,7 +7240,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -6651,7 +7276,7 @@ version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -6705,6 +7330,14 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memory" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "derive_more", +] + [[package]] name = "memory-db" version = "0.32.0" @@ -6751,9 +7384,9 @@ checksum = "39617bc909d64b068dcffd0e3e31679195b5576d0c83fadc52690268cc2b2b55" [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minimal-lexical" @@ -6860,7 +7493,7 @@ dependencies = [ "regex", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "tempfile", "thiserror", "tracing", @@ -6908,9 +7541,9 @@ dependencies = [ "blake2s_simd", "blake3", "core2", - "digest 0.10.6", + "digest 0.10.7", "multihash-derive", - "sha2 0.10.6", + "sha2 0.10.8", "sha3", "unsigned-varint", ] @@ -6922,9 +7555,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835d6ff01d610179fbce3de1694d007e500bf33a7f29689838941d6bf783ae40" dependencies = [ "core2", - "digest 0.10.6", + "digest 0.10.7", "multihash-derive", - "sha2 0.10.6", + "sha2 0.10.8", "unsigned-varint", ] @@ -7415,7 +8048,7 @@ checksum = "51f44edd08f51e2ade572f141051021c5af22677e42b7dd28a88155151c33594" dependencies = [ "ecdsa 0.14.8", "elliptic-curve 0.12.3", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -7426,7 +8059,7 @@ checksum = "dfc8c5bf642dde52bb9e87c0ecd8ca5a76faac2eeed98dedb7c717997e1080aa" dependencies = [ "ecdsa 0.14.8", "elliptic-curve 0.12.3", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -7720,7 +8353,7 @@ dependencies = [ "sp-npos-elections", "sp-runtime 7.0.0", "sp-std 5.0.0", - "strum", + "strum 0.24.1", ] [[package]] @@ -7811,8 +8444,8 @@ dependencies = [ "grandpa-light-client-primitives", "hex", "hex-literal 0.3.4", - "ibc", - "ibc-derive", + "ibc 0.15.0", + "ibc-derive 0.1.0", "ibc-primitives 0.1.0", "ibc-proto 0.18.0", "ics07-tendermint", @@ -7836,7 +8469,7 @@ dependencies = [ "scale-info", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "simple-iavl", "sp-consensus-aura", "sp-consensus-grandpa", @@ -7849,7 +8482,7 @@ dependencies = [ "sp-std 5.0.0", "sp-trie 7.0.0", "tendermint 0.28.0", - "tendermint-light-client-verifier", + "tendermint-light-client-verifier 0.28.0", "tendermint-proto 0.28.0", ] @@ -7859,7 +8492,7 @@ version = "0.0.1" dependencies = [ "frame-support", "frame-system", - "ibc", + "ibc 0.15.0", "ibc-primitives 0.1.0", "log", "parity-scale-codec", @@ -8622,7 +9255,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal 0.3.4", - "ibc", + "ibc 0.15.0", "ibc-primitives 0.1.0", "ibc-runtime-api", "log", @@ -8808,7 +9441,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -8909,7 +9542,7 @@ checksum = "9f02b677c1859756359fc9983c2e56a0237f18624a3789528804406b7e915e5d" dependencies = [ "once_cell", "pest", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -9609,7 +10242,7 @@ dependencies = [ "rand 0.8.5", "sc-authority-discovery", "sc-network", - "strum", + "strum 0.24.1", "thiserror", "tracing-gum", ] @@ -10283,9 +10916,9 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", @@ -10425,7 +11058,7 @@ dependencies = [ "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax", + "regex-syntax 0.6.28", "rusty-fork", "tempfile", "unarray", @@ -10483,6 +11116,26 @@ dependencies = [ "which", ] +[[package]] +name = "prost-build" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2" +dependencies = [ + "bytes", + "heck", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prost 0.12.3", + "prost-types 0.12.3", + "regex", + "tempfile", + "which", +] + [[package]] name = "prost-derive" version = "0.9.0" @@ -10885,13 +11538,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ - "aho-corasick", + "aho-corasick 1.1.2", "memchr", - "regex-syntax", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", ] [[package]] @@ -10900,7 +11554,18 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" dependencies = [ - "regex-syntax", + "regex-syntax 0.6.28", +] + +[[package]] +name = "regex-automata" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +dependencies = [ + "aho-corasick 1.1.2", + "memchr", + "regex-syntax 0.7.5", ] [[package]] @@ -10909,6 +11574,12 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -10970,7 +11641,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -11102,7 +11773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a632a43487c1332be8e183588079f89b6820fab24e04db49521eacd536837372" dependencies = [ "micromath", - "sha2 0.10.6", + "sha2 0.10.8", ] [[package]] @@ -11285,7 +11956,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" dependencies = [ - "base64 0.21.0", + "base64 0.21.7", ] [[package]] @@ -11433,7 +12104,7 @@ dependencies = [ "multihash 0.17.0", "parity-scale-codec", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "rand 0.8.5", "sc-client-api", "sc-network", @@ -12010,7 +12681,7 @@ dependencies = [ "libp2p-identity", "log", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "sc-client-api", "sc-network", "sc-network-common", @@ -12033,7 +12704,7 @@ dependencies = [ "futures-timer", "libp2p-identity", "parity-scale-codec", - "prost-build", + "prost-build 0.11.6", "sc-consensus", "sc-peerset", "sc-utils", @@ -12079,7 +12750,7 @@ dependencies = [ "log", "parity-scale-codec", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "sc-client-api", "sc-network", "sc-network-common", @@ -12107,7 +12778,7 @@ dependencies = [ "mockall", "parity-scale-codec", "prost 0.11.6", - "prost-build", + "prost-build 0.11.6", "sc-client-api", "sc-consensus", "sc-network", @@ -12256,7 +12927,7 @@ name = "sc-rpc-server" version = "4.0.0-dev" source = "git+https://github.com/paritytech//substrate.git?branch=polkadot-v0.9.43#5e49f6e44820affccaf517fd22af564f4b495d40" dependencies = [ - "http", + "http 0.2.9", "jsonrpsee", "log", "serde_json", @@ -12636,9 +13307,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -12650,9 +13321,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -12691,9 +13362,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.11" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" dependencies = [ "dyn-clone", "schemars_derive", @@ -12703,9 +13374,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.11" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" dependencies = [ "proc-macro2", "quote", @@ -12786,6 +13457,23 @@ dependencies = [ "url", ] +[[package]] +name = "sealable-trie" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "ascii", + "base64 0.21.7", + "borsh", + "bytemuck", + "derive_more", + "lib", + "memory", + "sha2 0.10.8", + "stdx", + "strum 0.25.0", +] + [[package]] name = "sec1" version = "0.3.0" @@ -12899,9 +13587,18 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" +dependencies = [ + "serde", +] + +[[package]] +name = "serde-json-wasm" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f05da0d153dd4595bdffd5099dc0e9ce425b205ee648eb93437ff7302af8c9a5" dependencies = [ "serde", ] @@ -12999,7 +13696,7 @@ checksum = "f5058ada175748e33390e40e872bd0fe59a19f265d0158daa551c5a88a76009c" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -13010,7 +13707,7 @@ checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -13040,13 +13737,13 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] @@ -13055,7 +13752,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "keccak", ] @@ -13089,7 +13786,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "rand_core 0.6.4", ] @@ -13099,7 +13796,7 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "rand_core 0.6.4", ] @@ -13140,7 +13837,7 @@ dependencies = [ "ics23 0.10.0", "proptest", "rand 0.8.5", - "sha2 0.10.6", + "sha2 0.10.8", "tendermint 0.28.0", ] @@ -13211,7 +13908,7 @@ dependencies = [ "rand_core 0.6.4", "ring", "rustc_version", - "sha2 0.10.6", + "sha2 0.10.8", "subtle", ] @@ -13245,7 +13942,7 @@ dependencies = [ "bytes", "flate2", "futures", - "http", + "http 0.2.9", "httparse", "log", "rand 0.8.5", @@ -13455,7 +14152,7 @@ dependencies = [ "sp-mmr-primitives", "sp-runtime 7.0.0", "sp-std 5.0.0", - "strum", + "strum 0.24.1", ] [[package]] @@ -13584,8 +14281,8 @@ source = "git+https://github.com/paritytech//substrate.git?branch=polkadot-v0.9. dependencies = [ "blake2b_simd", "byteorder", - "digest 0.10.6", - "sha2 0.10.6", + "digest 0.10.7", + "sha2 0.10.8", "sha3", "sp-std 5.0.0", "twox-hash", @@ -13599,8 +14296,8 @@ checksum = "2ee599a8399448e65197f9a6cee338ad192e9023e35e31f22382964c3c174c68" dependencies = [ "blake2b_simd", "byteorder", - "digest 0.10.6", - "sha2 0.10.6", + "digest 0.10.7", + "sha2 0.10.8", "sha3", "sp-std 8.0.0", "twox-hash", @@ -13757,7 +14454,7 @@ dependencies = [ "lazy_static", "sp-core 7.0.0", "sp-runtime 7.0.0", - "strum", + "strum 0.24.1", ] [[package]] @@ -14345,7 +15042,7 @@ checksum = "08615eea740067d9899969bc2891c68a19c315cb1f66640af9a9ecb91b13bcab" dependencies = [ "lazy_static", "maplit", - "strum", + "strum 0.24.1", ] [[package]] @@ -14448,6 +15145,11 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "stdx" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" + [[package]] name = "strsim" version = "0.10.0" @@ -14460,7 +15162,16 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" dependencies = [ - "strum_macros", + "strum_macros 0.24.3", +] + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros 0.25.3", ] [[package]] @@ -14476,6 +15187,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.32", +] + [[package]] name = "stun" version = "0.4.4" @@ -14616,7 +15340,7 @@ dependencies = [ "cargo_metadata", "filetime", "sp-maybe-compressed-blob", - "strum", + "strum 0.24.1", "tempfile", "toml 0.7.6", "walkdir", @@ -14839,7 +15563,7 @@ version = "0.28.0" source = "git+https://github.com/informalsystems/tendermint-rs?rev=e81f7bf23d63ffbcd242381d1ce5e35da3515ff1#e81f7bf23d63ffbcd242381d1ce5e35da3515ff1" dependencies = [ "bytes", - "digest 0.10.6", + "digest 0.10.7", "ed25519 1.5.3", "ed25519-consensus", "flex-error", @@ -14854,7 +15578,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.6", + "sha2 0.10.8", "signature 1.6.4", "subtle", "subtle-encoding", @@ -14870,8 +15594,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc2294fa667c8b548ee27a9ba59115472d0a09c2ba255771092a7f1dcf03a789" dependencies = [ "bytes", - "digest 0.10.6", - "ed25519 2.2.2", + "digest 0.10.7", + "ed25519 2.2.3", + "ed25519-consensus", "flex-error", "futures", "num-traits", @@ -14882,6 +15607,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", + "sha2 0.10.8", "signature 2.1.0", "subtle", "subtle-encoding", @@ -14918,7 +15644,7 @@ dependencies = [ "serde_derive", "static_assertions", "tendermint 0.28.0", - "tendermint-light-client-verifier", + "tendermint-light-client-verifier 0.28.0", "tendermint-rpc", "time 0.3.17", "tokio", @@ -14936,6 +15662,19 @@ dependencies = [ "time 0.3.17", ] +[[package]] +name = "tendermint-light-client-verifier" +version = "0.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74994da9de4b1144837a367ca2c60c650f5526a7c1a54760a3020959b522e474" +dependencies = [ + "derive_more", + "flex-error", + "serde", + "tendermint 0.34.0", + "time 0.3.17", +] + [[package]] name = "tendermint-proto" version = "0.28.0" @@ -14982,7 +15721,7 @@ dependencies = [ "flex-error", "futures", "getrandom 0.2.8", - "http", + "http 0.2.9", "hyper", "hyper-proxy", "hyper-rustls 0.22.1", @@ -15179,7 +15918,7 @@ dependencies = [ "pbkdf2 0.11.0", "rand 0.8.5", "rustc-hash", - "sha2 0.10.6", + "sha2 0.10.8", "thiserror", "unicode-normalization", "wasm-bindgen", @@ -15378,7 +16117,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.9", "http-body", "hyper", "hyper-timeout", @@ -15407,7 +16146,7 @@ checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4" dependencies = [ "prettyplease 0.1.23", "proc-macro2", - "prost-build", + "prost-build 0.11.6", "quote", "syn 1.0.109", ] @@ -15442,7 +16181,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", + "http 0.2.9", "http-body", "http-range-header", "pin-project-lite 0.2.13", @@ -15461,7 +16200,7 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", + "http 0.2.9", "http-body", "http-range-header", "pin-project-lite 0.2.13", @@ -15626,6 +16365,22 @@ dependencies = [ "smallvec", ] +[[package]] +name = "trie-ids" +version = "0.0.0" +source = "git+https://github.com/ComposableFi/emulated-light-client/#bad65fcb9e20f7716d79d70476fef991d60fda52" +dependencies = [ + "ascii", + "base64 0.21.7", + "bytemuck", + "derive_more", + "ibc-core-channel-types", + "ibc-core-client-types", + "ibc-core-connection-types", + "ibc-core-host-types 0.50.0", + "strum 0.25.0", +] + [[package]] name = "trie-root" version = "0.18.0" @@ -15738,7 +16493,7 @@ dependencies = [ "base64 0.13.1", "byteorder", "bytes", - "http", + "http 0.2.9", "httparse", "log", "rand 0.8.5", @@ -15759,7 +16514,7 @@ dependencies = [ "byteorder", "bytes", "data-encoding", - "http", + "http 0.2.9", "httparse", "log", "rand 0.8.5", @@ -15796,8 +16551,8 @@ version = "1.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ - "cfg-if 1.0.0", - "digest 0.10.6", + "cfg-if 0.1.10", + "digest 0.10.7", "rand 0.8.5", "static_assertions", ] @@ -16154,8 +16909,8 @@ checksum = "87fef6d0d508f08334e0ab0e6877feb4c0ecb3956bcf2cb950699b22fedf3e9c" dependencies = [ "anyhow", "libc", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "tempfile", "thiserror", "wasm-opt-cxx-sys", @@ -16311,14 +17066,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c86437fa68626fe896e5afc69234bb2b5894949083586535f200385adfd71213" dependencies = [ "anyhow", - "base64 0.21.0", + "base64 0.21.7", "bincode", "directories-next", "file-per-thread-logger", "log", "rustix 0.36.8", "serde", - "sha2 0.10.6", + "sha2 0.10.8", "toml 0.5.11", "windows-sys 0.45.0", "zstd 0.11.2+zstd.1.5.2", @@ -16548,7 +17303,7 @@ dependencies = [ "sdp", "serde", "serde_json", - "sha2 0.10.6", + "sha2 0.10.8", "stun", "thiserror", "time 0.3.17", @@ -16611,7 +17366,7 @@ dependencies = [ "sec1 0.3.0", "serde", "sha1", - "sha2 0.10.6", + "sha2 0.10.8", "signature 1.6.4", "subtle", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index e11faa40c..d2892ca32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ # ibc light clients "light-clients/common", + "light-clients/cf-guest-cw", "light-clients/ics07-tendermint", "light-clients/ics07-tendermint-cw", "light-clients/ics08-wasm", @@ -228,4 +229,4 @@ substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech//sub substrate-wasm-builder = { git = "https://github.com/paritytech//substrate.git", branch = "polkadot-v0.9.43" } [profile.release] -overflow-checks = true \ No newline at end of file +overflow-checks = true diff --git a/light-clients/cf-guest-cw/Cargo.toml b/light-clients/cf-guest-cw/Cargo.toml new file mode 100644 index 000000000..17cf12c2e --- /dev/null +++ b/light-clients/cf-guest-cw/Cargo.toml @@ -0,0 +1,57 @@ +[package] +name = "cf-guest-cw" +version = "0.0.0" +authors = ["Michal Nazarewicz "] +edition = "2021" + +exclude = [ + # Those files are rust-optimizer artifacts. You might want to + # commit them for convenience but they should not be part of the + # source code publication. + "contract.wasm", + "hash.txt", +] + +[lib] +crate-type = ["cdylib", "rlib"] + +[package.metadata.scripts] +optimize = """docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/rust-optimizer:0.12.6 +""" + +[dependencies] +cf-guest = { git = "https://github.com/ComposableFi/emulated-light-client/", default-features = false } +guestchain = { git = "https://github.com/ComposableFi/emulated-light-client/", default-features = false } + +base64 = { version = "0.22", default-features = false, features = ["alloc"] } +borsh = { version = "0.10.3", default-features = false } +cosmwasm-schema = "1.5.3" +cosmwasm-std = "1.5.3" +derive_more = "0.99.17" +ed25519-dalek = { version = "2.1.1", default-features = false, features = ["pkcs8"] } + +# Same version emulated-light-client uses +ibc = { git = "https://github.com/cosmos/ibc-rs", rev = "6dd3c6465e594d4c177f21724dd896a15e8f3634", default-features = false, features = ["borsh", "serde"] } + +prost = { version = "0.12.3", default-features = false } +schemars = "0.8.10" +serde = { version = "1.0.145", default-features = false, features = ["derive"] } +sha2 = "0.10" + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] +default = [] +std = [ + "base64/std", + "ed25519-dalek/std", + "ibc/std", + "prost/std", + "serde/std", + "sha2/std", +] diff --git a/light-clients/cf-guest-cw/src/bin/schema.rs b/light-clients/cf-guest-cw/src/bin/schema.rs new file mode 100644 index 000000000..fa9bda8c3 --- /dev/null +++ b/light-clients/cf-guest-cw/src/bin/schema.rs @@ -0,0 +1,25 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cf_guest_cw::msg; +use cosmwasm_schema::write_api; + +fn main() { + write_api! { + instantiate: msg::InstantiateMsg, + sudo: msg::SudoMsg, + query: msg::QueryMsg, + } +} diff --git a/light-clients/cf-guest-cw/src/context.rs b/light-clients/cf-guest-cw/src/context.rs new file mode 100644 index 000000000..c979eafc6 --- /dev/null +++ b/light-clients/cf-guest-cw/src/context.rs @@ -0,0 +1,182 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use core::str::FromStr; + +use cosmwasm_std::{Api, Deps, DepsMut, Env, Storage}; + +use crate::{ibc, state}; + +type Result = core::result::Result; + +/// Base context for handling CosmWasm operations. +/// +/// It wraps together access to CosmWasm API and information about the request +/// such as block height, current time and IBC client id corresponding to this +/// contract. +/// +/// The object dereferences into [`state::Metadata`] such that metadata fields +/// are directly accessible through this object. +#[derive(derive_more::Deref)] +pub(crate) struct ContextBase<'a> { + #[deref] + pub metadata: state::Metadata, + pub client_id: ibc::ClientId, + pub api: &'a dyn Api, +} + +/// Mutable execution context for handling CosmWasm operations. +/// +/// It wraps together access to CosmWasm APIs, storage and information about the +/// request. To construct a new context object use [`new`] function. +#[derive(derive_more::Deref)] +pub(crate) struct ContextMut<'a> { + #[deref] + base: ContextBase<'a>, + storage: &'a mut dyn Storage, +} + +/// Constructs a new mutable execution context. +pub(crate) fn new<'a>(deps: DepsMut<'a>, env: Env) -> ContextMut<'a> { + ContextMut { base: ContextBase::new(env, deps.api), storage: deps.storage } +} + +/// Read-only execution context for handling CosmWasm operations. +/// +/// It wraps together access to CosmWasm APIs, storage and information about the +/// request. To construct a new context object use [`new_ro`] function. +/// +/// The object dereferences into [`ContextBase`] which holds data common between +/// read-only and mutable execution contexts. +#[derive(derive_more::Deref)] +pub(crate) struct Context<'a> { + #[deref] + base: ContextBase<'a>, + storage: &'a dyn Storage, +} + +/// Constructs a new read-only execution context. +pub(crate) fn new_ro<'a>(deps: Deps<'a>, env: Env) -> Context<'a> { + Context { base: ContextBase::new(env, deps.api), storage: deps.storage } +} + +impl<'a> ContextBase<'a> { + fn new(env: Env, api: &'a dyn Api) -> Self { + let metadata = state::Metadata { + host_timestamp_ns: env.block.time.nanos(), + host_height: env.block.height, + }; + let address = env.contract.address.as_str(); + let client_id = ibc::ClientId::from_str(address).unwrap(); + Self { client_id, metadata, api } + } + + pub fn log(&self, msg: impl alloc::string::ToString) { + self.api.debug(&msg.to_string()) + } +} + +/// Logs formatted text using CosmWasm API. +/// +/// To log string literals prefer [`ContextBase::log`] method. +macro_rules! log { + ($self:expr, $($tt:tt)*) => { + $self.log(format_args!($($tt)*)) + }; +} + +pub(crate) use log; + +impl<'a> Context<'a> { + /// Reads this light client’s client state from storage. + pub fn client_state(&self) -> Result { + req_client_state(&self.client_id, self.client_states().get()) + } + + /// Returns object providing access to read client state from the + /// storage. + pub fn client_states(&self) -> &'a state::ClientStates { + state::ClientStates::new_ro(self.storage) + } + + /// Reads this light client’s consensus state at given height from + /// storage. + pub fn consensus_state(&self, height: ibc::Height) -> Result { + req_consensus_state(&self.client_id, height, self.consensus_states().get(height)) + } + + /// Returns object providing access to read consensus states from the + /// storage. + pub fn consensus_states(&self) -> &'a state::ConsensusStates { + state::ConsensusStates::new_ro(self.storage) + } +} + +impl<'a> ContextMut<'a> { + /// Reads this light client’s client state from storage. + pub fn client_state(&self) -> Result { + req_client_state(&self.client_id, self.client_states().get()) + } + + /// Returns object providing access to read client state from the + /// storage. + pub fn client_states(&self) -> &state::ClientStates { + state::ClientStates::new_ro(self.storage) + } + + /// Returns object providing access to read or write client state + /// from/to the storage. + pub fn client_states_mut(&mut self) -> &mut state::ClientStates { + state::ClientStates::new(self.storage) + } + + /// Reads this light client’s consensus state at given height from + /// storage. + pub fn consensus_state(&self, height: ibc::Height) -> Result { + req_consensus_state(&self.client_id, height, self.consensus_states().get(height)) + } + + /// Returns object providing access to read consensus states from the + /// storage. + pub fn consensus_states(&self) -> &state::ConsensusStates { + state::ConsensusStates::new_ro(self.storage) + } + + /// Returns object providing access to read or write consensus states + /// from/to the storage. + pub fn consensus_states_mut(&mut self) -> &mut state::ConsensusStates { + state::ConsensusStates::new(self.storage) + } +} + +/// Returns an error if client state is not present. +fn req_client_state( + client_id: &ibc::ClientId, + state: Result>, +) -> Result { + let make_err = || ibc::ClientError::ClientStateNotFound { client_id: client_id.clone() }.into(); + state.and_then(|state| state.ok_or_else(make_err)) +} + +/// Returns an error if consensus state is not present. +fn req_consensus_state( + client_id: &ibc::ClientId, + height: ibc::Height, + state: Result>, +) -> Result { + let make_err = + || ibc::ClientError::ConsensusStateNotFound { client_id: client_id.clone(), height }.into(); + state.and_then(|state| state.map(|(state, _metadata)| state).ok_or_else(make_err)) +} diff --git a/light-clients/cf-guest-cw/src/contract.rs b/light-clients/cf-guest-cw/src/contract.rs new file mode 100644 index 000000000..d68a1c57f --- /dev/null +++ b/light-clients/cf-guest-cw/src/contract.rs @@ -0,0 +1,149 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cosmwasm_std::{ + to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint64, +}; +use prost::Message; + +use crate::{context, context::log, crypto::Verifier, ibc, msg, state}; + +type Result = core::result::Result; + +#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] +fn instantiate( + deps: DepsMut, + env: Env, + _info: MessageInfo, + msg: msg::InstantiateMsg, +) -> Result { + let mut ctx = context::new(deps, env); + log!(ctx, "instantiate: {msg:?}"); + + ctx.client_states_mut().set(&msg.client_state); + + let height = ibc::Height::new(0, msg.client_state.latest_height.into()).unwrap(); + let metadata = ctx.metadata; + ctx.consensus_states_mut().set(height, &msg.consensus_state, metadata); + + Ok(Response::default()) +} + +#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] +fn sudo(deps: DepsMut, env: Env, msg: msg::SudoMsg) -> Result { + let mut ctx = context::new(deps, env); + log!(ctx, "sudo({msg:?})"); + match msg { + msg::SudoMsg::UpdateStateOnMisbehaviour(_msg) => { + let client_state = ctx.client_state()?.frozen(); + ctx.client_states_mut().set(client_state); + }, + msg::SudoMsg::UpdateState(msg) => process_update_state_msg(ctx, msg)?, + } + Ok(Response::default()) +} + +fn process_update_state_msg(mut ctx: context::ContextMut, msg: msg::UpdateStateMsg) -> Result { + let client_state = ctx.client_state()?; + let now_ns = ctx.host_timestamp_ns; + + ctx.consensus_states_mut().prune_oldest_consensus_state(&client_state, now_ns)?; + + let new_consensus_state = state::ConsensusState::from(&msg.header); + let new_client_state = client_state.with_header(&msg.header); + + let metadata = ctx.metadata; + let height = ibc::Height::new(0, msg.header.block_header.block_height.into())?; + ctx.client_states_mut().set(&new_client_state); + ctx.consensus_states_mut().set(height, &new_consensus_state, metadata); + Ok(()) +} + +#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] +fn query(deps: Deps, env: Env, msg: msg::QueryMsg) -> StdResult { + let ctx = context::new_ro(deps, env); + match msg { + msg::QueryMsg::VerifyClientMessage(msg) => { + query_verify_client_msg(ctx, msg)?; + to_json_binary(&()) + }, + msg::QueryMsg::CheckForMisbehaviour(msg) => { + let res = query_check_for_misbehaviour_msg(ctx, msg)?; + to_json_binary(&res) + }, + msg::QueryMsg::VerifyStateProof(msg) => { + query_verify_state_proof(ctx, msg)?; + to_json_binary(&()) + }, + msg::QueryMsg::Status(msg::StatusMsg {}) => to_json_binary(&query_status(ctx)?), + msg::QueryMsg::TimestampAtHeight(msg) => { + let state = ctx.consensus_state(msg.height)?; + to_json_binary(&Uint64::from(state.timestamp_ns.get())) + }, + msg::QueryMsg::ExportMetadata(msg::ExportMetadataMsg {}) => { + let meta = ctx.consensus_states().get_all_metadata()?; + to_json_binary(&meta) + }, + } +} + +fn query_verify_state_proof(ctx: context::Context, msg: msg::VerifyStateProofMsg) -> StdResult<()> { + let consensus_state = ctx.consensus_state(msg.height)?; + cf_guest::proof::verify( + &ibc::CommitmentPrefix::default(), + &msg.proof, + &consensus_state.block_hash, + msg.path, + msg.value.as_deref(), + ) + .map_err(|err| StdError::GenericErr { msg: err.to_string() }) +} + +fn query_verify_client_msg(ctx: context::Context, msg: msg::VerifyClientMessageMsg) -> Result { + let client_message = + ibc::proto::Any::decode(msg.client_message.as_slice()).map_err(crate::Error::from)?; + ctx.client_state()? + .verify_client_message(&Verifier, &ctx.client_id, client_message) + .map_err(crate::Error::from) +} + +fn query_check_for_misbehaviour_msg( + ctx: context::Context, + msg: msg::CheckForMisbehaviourMsg, +) -> Result { + let client_message = + ibc::proto::Any::decode(msg.client_message.as_slice()).map_err(crate::Error::from)?; + ctx.client_state()? + .check_for_misbehaviour(&Verifier, &ctx.client_id, client_message) + .map_err(crate::Error::from) +} + +fn query_status(ctx: context::Context) -> StdResult { + let client_state = ctx.client_state()?; + if client_state.is_frozen { + return Ok(msg::StatusResponse::Frozen) + } + + let height = client_state.latest_height; + let height = ibc::Height::new(0, height.into()).unwrap(); + let consensus_state = ctx.consensus_state(height)?; + + let age = ctx.host_timestamp_ns.saturating_sub(consensus_state.timestamp_ns.get()); + Ok(if age >= client_state.trusting_period_ns { + msg::StatusResponse::Expired + } else { + msg::StatusResponse::Active + }) +} diff --git a/light-clients/cf-guest-cw/src/crypto.rs b/light-clients/cf-guest-cw/src/crypto.rs new file mode 100644 index 000000000..c4ff05a2e --- /dev/null +++ b/light-clients/cf-guest-cw/src/crypto.rs @@ -0,0 +1,107 @@ +use borsh::maybestd::io; + +/// Ed25519 public key (a.k.a. verifying key). +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[repr(transparent)] +pub struct PubKey(ed25519_dalek::VerifyingKey); + +impl guestchain::PubKey for PubKey { + type Signature = Signature; + + fn to_vec(&self) -> Vec { + self.0.as_bytes().to_vec() + } + fn from_bytes(bytes: &[u8]) -> Result { + bytes.try_into().map(Self).map_err(|_| guestchain::BadFormat) + } +} + +impl borsh::BorshSerialize for PubKey { + fn serialize(&self, wr: &mut W) -> io::Result<()> { + wr.write_all(self.0.as_bytes()) + } +} + +impl borsh::BorshDeserialize for PubKey { + fn deserialize_reader(rd: &mut R) -> io::Result { + let mut bytes = ed25519_dalek::pkcs8::PublicKeyBytes([0; 32]); + rd.read_exact(&mut bytes.0[..])?; + ed25519_dalek::VerifyingKey::try_from(bytes) + .map(Self) + .map_err(|_| io::Error::new(io::ErrorKind::Other, "malformed Ed25519 public key")) + } +} + +impl PartialOrd for PubKey { + fn partial_cmp(&self, rhs: &Self) -> Option { + Some(self.cmp(rhs)) + } +} + +impl Ord for PubKey { + fn cmp(&self, rhs: &Self) -> core::cmp::Ordering { + self.0.as_bytes().cmp(rhs.0.as_bytes()) + } +} + +/// Ed25519 signature. +#[derive(Clone, PartialEq, Eq, Debug)] +#[repr(transparent)] +pub struct Signature(ed25519_dalek::Signature); + +impl guestchain::Signature for Signature { + fn to_vec(&self) -> Vec { + self.0.to_vec() + } + fn from_bytes(bytes: &[u8]) -> Result { + ed25519_dalek::Signature::from_slice(bytes) + .map(Self) + .map_err(|_| guestchain::BadFormat) + } +} + +impl borsh::BorshSerialize for Signature { + fn serialize(&self, wr: &mut W) -> io::Result<()> { + wr.write_all(self.0.r_bytes())?; + wr.write_all(self.0.s_bytes())?; + Ok(()) + } +} + +impl borsh::BorshDeserialize for Signature { + fn deserialize_reader(rd: &mut R) -> io::Result { + let mut buf = [0; 64]; + rd.read_exact(&mut buf[..])?; + Ok(Self(ed25519_dalek::Signature::from_bytes(&buf))) + } +} + +impl core::hash::Hash for Signature { + fn hash(&self, hasher: &mut H) { + hasher.write(self.0.r_bytes()); + hasher.write(self.0.s_bytes()); + } +} + +impl PartialOrd for Signature { + fn partial_cmp(&self, rhs: &Self) -> Option { + Some(self.cmp(rhs)) + } +} + +impl Ord for Signature { + fn cmp(&self, rhs: &Self) -> core::cmp::Ordering { + let lhs = (self.0.r_bytes(), self.0.s_bytes()); + let rhs = (rhs.0.r_bytes(), rhs.0.s_bytes()); + lhs.cmp(&rhs) + } +} + +/// Verifier for Ed25519 signatures using ed25519-dalek implementation. +pub(crate) struct Verifier; + +impl guestchain::Verifier for Verifier { + fn verify(&self, message: &[u8], pubkey: &PubKey, signature: &Signature) -> bool { + pubkey.0.verify_strict(message, &signature.0).is_ok() + } +} diff --git a/light-clients/cf-guest-cw/src/error.rs b/light-clients/cf-guest-cw/src/error.rs new file mode 100644 index 000000000..a5e812f76 --- /dev/null +++ b/light-clients/cf-guest-cw/src/error.rs @@ -0,0 +1,56 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cosmwasm_std::StdError; + +#[derive(Debug, derive_more::From, derive_more::Display)] +pub enum Error { + Std(StdError), + Client(crate::ibc::ClientError), + Wasm(crate::ibc::wasm::Error), + BadProto(prost::DecodeError), + #[from(ignore)] + BadMessage, + #[from(ignore)] + BadType, +} + +#[cfg(feature = "std")] +impl std::error::Error for Error {} + +impl From for Error { + fn from(err: alloc::string::FromUtf8Error) -> Self { + Self::Std(StdError::InvalidUtf8 { msg: err.to_string() }) + } +} + +impl From for Error { + fn from(err: cf_guest::DecodeError) -> Self { + match err { + cf_guest::DecodeError::BadMessage => Self::BadMessage, + cf_guest::DecodeError::BadType => Self::BadType, + cf_guest::DecodeError::BadProto(err) => err.into(), + } + } +} + +impl From for StdError { + fn from(err: Error) -> Self { + match err { + Error::Std(err) => err, + _ => StdError::GenericErr { msg: err.to_string() }, + } + } +} diff --git a/light-clients/cf-guest-cw/src/ibc.rs b/light-clients/cf-guest-cw/src/ibc.rs new file mode 100644 index 000000000..3a7170bf5 --- /dev/null +++ b/light-clients/cf-guest-cw/src/ibc.rs @@ -0,0 +1,16 @@ +//! A helper module which collects IBC types we’re using in a flatter namespace. + +pub mod wasm { + pub use ibc::clients::wasm_types::{ + client_state::ClientState, consensus_state::ConsensusState, error::Error, + }; +} + +pub use ibc::{ + core::{ + client::{context::types::error::ClientError, types::Height}, + commitment_types::commitment::{CommitmentPrefix, CommitmentProofBytes}, + host::types::{identifiers::ClientId, path}, + }, + primitives::{proto, Timestamp}, +}; diff --git a/light-clients/cf-guest-cw/src/lib.rs b/light-clients/cf-guest-cw/src/lib.rs new file mode 100644 index 000000000..61a97abcf --- /dev/null +++ b/light-clients/cf-guest-cw/src/lib.rs @@ -0,0 +1,30 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#![allow(dead_code)] + +extern crate alloc; +extern crate core; + +mod context; +mod contract; +mod crypto; +mod error; +mod ibc; +pub mod msg; +mod serialisation; +pub mod state; + +use crate::{crypto::PubKey, error::Error}; diff --git a/light-clients/cf-guest-cw/src/msg.rs b/light-clients/cf-guest-cw/src/msg.rs new file mode 100644 index 000000000..ce84d4ba6 --- /dev/null +++ b/light-clients/cf-guest-cw/src/msg.rs @@ -0,0 +1,150 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cosmwasm_schema::{cw_serde, QueryResponses}; +use cosmwasm_std::Uint64; + +use crate::{ibc, serialisation, state}; + +#[cw_serde] +pub struct InstantiateMsg { + #[serde(with = "serialisation::Base64")] + pub client_state: state::ClientState, + #[serde(with = "serialisation::Base64")] + pub consensus_state: state::ConsensusState, +} + +#[cw_serde] +pub enum SudoMsg { + //MigrateClientStore(MigrateClientStoreMsg), + UpdateState(UpdateStateMsg), + UpdateStateOnMisbehaviour(UpdateStateOnMisbehaviourMsg), + // VerifyUpgradeAndUpdateState(VerifyUpgradeAndUpdateStateMsg), +} + +// #[cw_serde] +// pub struct MigrateClientStoreMsg {} + +#[cw_serde] +pub struct UpdateStateMsg { + #[serde(with = "serialisation::Base64")] + pub header: state::Header, +} + +#[cw_serde] +pub struct UpdateStateOnMisbehaviourMsg { + #[serde(with = "serialisation::Base64")] + pub misbehaviour_message: state::Misbehaviour, +} + +// #[cw_serde] +// pub struct VerifyUpgradeAndUpdateStateMsg { +// #[serde(with = "serialisation::Base64")] +// pub upgrade_client_state: state::ClientState, +// #[serde(with = "serialisation::Base64")] +// pub upgrade_consensus_state: state::ConsensusState, +// #[serde(with = "serialisation::Base64")] +// pub proof_upgrade_client: ibc::CommitmentProofBytes, +// #[serde(with = "serialisation::Base64")] +// pub proof_upgrade_consensus_state: ibc::CommitmentProofBytes, +// } + +#[cw_serde] +#[derive(QueryResponses)] +pub enum QueryMsg { + /// Verifies client message. + #[returns(())] + VerifyClientMessage(VerifyClientMessageMsg), + + /// Checks client message for misbehaviour. + #[returns(bool)] + CheckForMisbehaviour(CheckForMisbehaviourMsg), + + /// Checks whether provided membership or non-membership proof is valid. + /// + /// The proof is a membership proof is `self.0.value` field is `Some`. + /// Otherwise, if `self.0.value` is `None`, the proof is non-membership + /// proof. + #[returns(())] + VerifyStateProof(VerifyStateProofMsg), + + /// Checks status of the client. + #[returns(StatusResponse)] + Status(StatusMsg), + + /// Returns timestamp for consensus at given height. + /// + /// The timestamp is represented as nanoseconds since Unix epoch. + #[returns(Uint64)] + TimestampAtHeight(TimestampAtHeightMsg), + + /// Gets metadata of all consensus states. + #[returns(Vec)] + ExportMetadata(ExportMetadataMsg), +} + +#[cw_serde] +pub struct VerifyClientMessageMsg { + #[serde(with = "serialisation::Base64")] + pub client_message: Vec, +} + +#[cw_serde] +pub struct CheckForMisbehaviourMsg { + #[serde(with = "serialisation::Base64")] + pub client_message: Vec, +} + +#[cw_serde] +pub struct VerifyStateProofMsg { + #[serde(with = "serialisation::Base64")] + pub proof: ibc::CommitmentProofBytes, + #[serde(with = "serialisation::AsStr")] + pub path: ibc::path::Path, + #[serde(with = "serialisation::OptBase64", default, skip_serializing_if = "Option::is_none")] + pub value: Option>, + #[serde(with = "serialisation::Height")] + pub height: ibc::Height, +} + +#[cw_serde] +pub struct StatusMsg {} + +#[cw_serde] +pub enum StatusResponse { + Active, + Expired, + Frozen, +} + +#[cw_serde] +pub struct GetLatestHeightsMsg {} + +#[cw_serde] +pub struct TimestampAtHeightMsg { + #[serde(with = "serialisation::Height")] + pub height: ibc::Height, +} + +#[cw_serde] +pub struct ExportMetadataMsg {} + +#[cw_serde] +pub struct ConsensusStateMetadata { + #[serde(with = "serialisation::Height")] + pub height: ibc::Height, + pub host_timestamp_ns: Uint64, + pub host_height: Uint64, +} diff --git a/light-clients/cf-guest-cw/src/serialisation.rs b/light-clients/cf-guest-cw/src/serialisation.rs new file mode 100644 index 000000000..881b7acd1 --- /dev/null +++ b/light-clients/cf-guest-cw/src/serialisation.rs @@ -0,0 +1,268 @@ +use core::{fmt, marker::PhantomData, str::FromStr}; + +use cosmwasm_std::Binary; +use prost::Message; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +use crate::{ibc, state}; + +/// A Serde serialisation implementation which encodes binary data as +/// base64-string (when serialising to human-readable form). +pub struct Base64; + +/// A Serde serialisation implementation handling `Option` values where `T` +/// can be serialised using [`Base64`]. +pub struct OptBase64; + +/// A Serde serialisation implementation which encodes object using +/// `Display` and deserialises using `FromStr`. +pub struct AsStr; + +/// A Serde serialisation implementation for [`ibc::Height`]. +/// +/// We need it because we need this to implement `JsonSchema`. ibc-rs does +/// support schema with a `schema` feature however that brings in `std` and we +/// don’t want that. As a result, we need to define our own serialisation for +/// IBC height. +pub struct Height; + +// ==================== Base64 ================================================= + +impl Base64 { + pub fn serialize(obj: &T, ser: S) -> Result { + Base64Bytes(obj.to_bytes()?.as_ref()).serialize(ser) + } + + pub fn deserialize<'de, T: BytesConv, D: Deserializer<'de>>(de: D) -> Result { + T::from_bytes(Binary::deserialize(de)?.into()) + } +} + +impl OptBase64 { + pub fn serialize( + obj: &Option, + ser: S, + ) -> Result { + if let Some(ref obj) = obj { + let bytes = obj.to_bytes()?; + ser.serialize_some(&Base64Bytes(bytes.as_ref())) + } else { + ser.serialize_none() + } + } + + pub fn deserialize<'de, T: BytesConv, D: Deserializer<'de>>( + de: D, + ) -> Result, D::Error> { + match Option::::deserialize(de)? { + None => Ok(None), + Some(bin) => T::from_bytes(bin.into()).map(Some), + } + } +} + +/// Wrapper which serialised bytes slice using base64 encoding. +struct Base64Bytes<'a>(&'a [u8]); + +impl Serialize for Base64Bytes<'_> { + fn serialize(&self, ser: S) -> Result { + use base64::engine::{general_purpose::STANDARD, Engine}; + ser.serialize_str(&STANDARD.encode(self.0)) + } +} + +/// Trait implementing conversion to and from bytes used by [`Base64`] and +/// [`OptBase64`]. +pub trait BytesConv: Sized { + type Bytes<'a>: AsRef<[u8]> + where + Self: 'a; + + fn to_bytes<'a, E: serde::ser::Error>(&'a self) -> Result, E>; + fn from_bytes(bytes: Vec) -> Result; +} + +impl BytesConv for Vec { + type Bytes<'a> = &'a [u8]; + fn to_bytes<'a, E: serde::ser::Error>(&'a self) -> Result<&'a [u8], E> { + Ok(self.as_slice()) + } + + fn from_bytes(bytes: Vec) -> Result { + Ok(bytes) + } +} + +impl BytesConv for ibc::CommitmentProofBytes { + type Bytes<'a> = &'a [u8]; + fn to_bytes<'a, E: serde::ser::Error>(&'a self) -> Result<&'a [u8], E> { + Ok(self.as_ref()) + } + + fn from_bytes(bytes: Vec) -> Result { + Self::try_from(bytes).map_err(E::custom) + } +} + +macro_rules! conv_via_any { + ($msg:ty) => { + impl BytesConv for $msg { + type Bytes<'a> = Vec; + + fn to_bytes<'a, E: serde::ser::Error>(&'a self) -> Result, E> { + Ok(ibc::proto::Any::from(self).encode_to_vec()) + } + + fn from_bytes(bytes: Vec) -> Result { + let any = ibc::proto::Any::decode(bytes.as_slice()).map_err(E::custom)?; + <$msg>::try_from(any).map_err(E::custom) + } + } + }; +} + +conv_via_any!(state::ClientState); +conv_via_any!(state::ConsensusState); +conv_via_any!(state::Header); +conv_via_any!(state::Misbehaviour); + +impl schemars::JsonSchema for Base64 { + fn schema_name() -> alloc::string::String { + "Base64".into() + } + fn schema_id() -> alloc::borrow::Cow<'static, str> { + alloc::borrow::Cow::Borrowed("cf_guest::Base64") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + String::json_schema(gen) + } +} + +impl schemars::JsonSchema for OptBase64 { + fn schema_name() -> alloc::string::String { + "Nullable_Base64".into() + } + fn schema_id() -> alloc::borrow::Cow<'static, str> { + alloc::borrow::Cow::Borrowed("Option") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + >::json_schema(gen) + } +} + +// ==================== As String ============================================== + +impl AsStr { + pub fn serialize(obj: &T, ser: S) -> Result { + ser.serialize_str(&obj.to_string()) + } + + pub fn deserialize<'de, T, E, D>(de: D) -> Result + where + T: FromStr, + E: fmt::Display, + D: Deserializer<'de>, + { + de.deserialize_str(AsStrVisitor::::default()) + } +} + +struct AsStrVisitor(PhantomData); + +impl Default for AsStrVisitor { + fn default() -> Self { + Self(PhantomData) + } +} + +impl<'de, T, Err> serde::de::Visitor<'de> for AsStrVisitor +where + T: FromStr, + Err: fmt::Display, +{ + type Value = T; + + fn expecting(&self, fmtr: &mut fmt::Formatter) -> fmt::Result { + write!(fmtr, "object formatted to string") + } + + fn visit_str(self, value: &str) -> Result { + T::from_str(value).map_err(E::custom) + } +} + +impl schemars::JsonSchema for AsStr { + fn schema_name() -> alloc::string::String { + String::schema_name() + } + fn schema_id() -> alloc::borrow::Cow<'static, str> { + String::schema_id() + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + String::json_schema(gen) + } +} + +// ==================== IBC Height ============================================= + +impl Height { + pub fn serialize(height: &ibc::Height, ser: S) -> Result { + RawHeight::from(*height).serialize(ser) + } + + pub fn deserialize<'de, D: Deserializer<'de>>(de: D) -> Result { + use serde::de::Error; + let height = ::deserialize(de)?; + ibc::Height::try_from(height).map_err(|_| { + D::Error::invalid_value( + serde::de::Unexpected::Unsigned(0), + &"height with non-zero revision_height", + ) + }) + } +} + +/// The core IBC height type, which represents the height of a chain, which +/// typically is the number of blocks since genesis (or more generally, since +/// the last revision/hard upgrade). +#[derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)] +pub struct RawHeight { + /// Previously known as "epoch" + #[serde(default, skip_serializing_if = "is_zero")] + pub revision_number: cosmwasm_std::Uint64, + + /// The height of a block + pub revision_height: cosmwasm_std::Uint64, +} + +impl TryFrom for ibc::Height { + type Error = ibc::ClientError; + fn try_from(height: RawHeight) -> Result { + Self::new(height.revision_number.into(), height.revision_height.into()) + } +} + +impl From for RawHeight { + fn from(height: ibc::Height) -> Self { + Self { + revision_number: height.revision_number().into(), + revision_height: height.revision_height().into(), + } + } +} + +impl schemars::JsonSchema for Height { + fn schema_name() -> alloc::string::String { + "Height".into() + } + fn schema_id() -> alloc::borrow::Cow<'static, str> { + alloc::borrow::Cow::Borrowed("cf_guest::IbcHeight") + } + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + ::json_schema(gen) + } +} + +fn is_zero(num: &cosmwasm_std::Uint64) -> bool { + num.u64() == 0 +} diff --git a/light-clients/cf-guest-cw/src/state.rs b/light-clients/cf-guest-cw/src/state.rs new file mode 100644 index 000000000..4dcf0a0f5 --- /dev/null +++ b/light-clients/cf-guest-cw/src/state.rs @@ -0,0 +1,250 @@ +// Copyright (C) 2022 ComposableFi. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use cosmwasm_std::Storage; +use prost::Message; + +use crate::{ibc, ibc::proto::Any}; + +type Result = core::result::Result; + +pub type ClientMessage = cf_guest::ClientMessage; +pub type ClientState = cf_guest::ClientState; +pub type ConsensusState = cf_guest::ConsensusState; +pub type Header = cf_guest::Header; +pub type Misbehaviour = cf_guest::Misbehaviour; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(crate) struct Metadata { + pub host_timestamp_ns: u64, + pub host_height: u64, +} + +/// Wrapper for accessing client state saved in the storage. +#[repr(transparent)] +pub(crate) struct ClientStates(dyn Storage); + +impl ClientStates { + pub fn new<'a>(storage: &'a mut dyn Storage) -> &'a mut Self { + // SAFETY: Self is repr(transparent) over dyn Storage so the + // transmutation is sound. + unsafe { wrap_mut(storage) } + } + + pub fn new_ro<'a>(storage: &'a dyn Storage) -> &'a Self { + // SAFETY: Self is repr(transparent) over dyn Storage so the + // transmutation is sound. + unsafe { wrap_ref(storage) } + } + + pub fn get(&self) -> Result, E> + where + T: TryFrom, + E: From + From, + { + self.get_impl(Self::KEY) + } + + pub fn set(&mut self, state: impl Into) { + self.set_impl(Self::KEY, state) + } + + const KEY: &'static [u8] = b"clientState/"; + + fn get_impl(&self, key: &[u8]) -> Result, E> + where + T: TryFrom, + E: From + From, + { + self.0 + .get(&key) + .map(|value| { + let any = Any::decode(value.as_slice())?; + T::try_from(any).map_err(|err| err.into()) + }) + .transpose() + } + + fn set_impl(&mut self, key: &[u8], state: impl Into) { + self.0.set(&key, state.into().encode_to_vec().as_slice()) + } +} + +/// Wrapper for accessing consensus state saved in the storage. +#[repr(transparent)] +pub(crate) struct ConsensusStates(dyn Storage); + +impl ConsensusStates { + pub fn new<'a>(storage: &'a mut dyn Storage) -> &'a mut Self { + // SAFETY: Self is repr(transparent) over dyn Storage so the + // transmutation is sound. + unsafe { wrap_mut(storage) } + } + + pub fn new_ro<'a>(storage: &'a dyn Storage) -> &'a Self { + // SAFETY: Self is repr(transparent) over dyn Storage so the + // transmutation is sound. + unsafe { wrap_ref(storage) } + } + + pub fn get(&self, height: ibc::Height) -> Result, E> + where + T: TryFrom, + E: From + From, + { + self.get_impl(&Self::key(height)) + } + + pub fn set(&mut self, height: ibc::Height, state: impl Into, metadata: Metadata) { + self.set_impl(Self::key(height), state, metadata) + } + + fn all<'a>( + &'a self, + ) -> impl Iterator, Any, Metadata), prost::DecodeError>> + 'a { + self.0 + .range( + Some(Self::key_impl(0, 0).as_slice()), + Some(Self::key_impl(u64::MAX, u64::MAX).as_slice()), + cosmwasm_std::Order::Ascending, + ) + .map(|(key, value)| { + let (any, metadata) = ConsensusWithMetadata::decode(value.as_slice())?.into_parts(); + Ok((key, any, metadata)) + }) + } + + pub fn prune_oldest_consensus_state( + &mut self, + client_state: &ClientState, + now_ns: u64, + ) -> Result<()> { + let (key, any) = match self.all().next() { + None => return Ok(()), + Some(Err(err)) => return Err(err.into()), + Some(Ok((key, any, _metadata))) => (key, any), + }; + let state = ConsensusState::try_from(any)?; + let elapsed = now_ns.saturating_sub(state.timestamp_ns.get()); + if elapsed >= client_state.trusting_period_ns { + self.0.remove(key.as_slice()); + } + Ok(()) + } + + pub fn get_all_metadata(&self) -> Result> { + let mut records = Vec::new(); + for record in self.all() { + let (key, _state, metadata) = record?; + let key = &key[key.len() - 16..]; + let revision_number = u64::from_be_bytes(key[..8].try_into().unwrap()); + let revision_height = u64::from_be_bytes(key[8..].try_into().unwrap()); + records.push(crate::msg::ConsensusStateMetadata { + height: ibc::Height::new(revision_number, revision_height).unwrap(), + host_timestamp_ns: metadata.host_timestamp_ns.into(), + host_height: metadata.host_height.into(), + }) + } + Ok(records) + } + + pub fn del(&mut self, height: ibc::Height) { + self.0.remove(&Self::key(height)) + } + + fn key(height: ibc::Height) -> Vec { + Self::key_impl(height.revision_number(), height.revision_height()) + } + + fn key_impl(rev_number: u64, rev_height: u64) -> Vec { + let rev_number = rev_number.to_be_bytes(); + let rev_height = rev_height.to_be_bytes(); + [b"consensusState/", &rev_number[..], &rev_height[..]].concat() + } + + fn get_impl(&self, key: &[u8]) -> Result, E> + where + T: TryFrom, + E: From + From, + { + let value = match self.0.get(&key) { + None => return Ok(None), + Some(value) => value, + }; + let (any, metadata) = ConsensusWithMetadata::decode(value.as_slice())?.into_parts(); + Ok(Some((T::try_from(any)?, metadata))) + } + + fn set_impl(&mut self, key: Vec, state: impl Into, metadata: Metadata) { + let state = ConsensusWithMetadata::new(state, metadata); + self.0.set(&key, state.encode_to_vec().as_slice()) + } +} + +/// Extension of protobuf’s Any type to include host height and host timestamp. +#[derive(Clone, PartialEq, prost::Message)] +struct ConsensusWithMetadata { + #[prost(string, tag = "1")] + pub type_url: ::prost::alloc::string::String, + #[prost(bytes = "vec", tag = "2")] + pub value: ::prost::alloc::vec::Vec, + #[prost(uint64, tag = "3")] + pub host_timestamp_ns: u64, + #[prost(uint64, tag = "4")] + pub host_height: u64, +} + +impl ConsensusWithMetadata { + fn new(state: impl Into, metadata: Metadata) -> Self { + let Any { type_url, value } = state.into(); + let Metadata { host_timestamp_ns, host_height } = metadata; + Self { type_url, value, host_timestamp_ns, host_height } + } + + fn into_parts(self) -> (Any, Metadata) { + ( + Any { type_url: self.type_url, value: self.value }, + Metadata { host_timestamp_ns: self.host_timestamp_ns, host_height: self.host_height }, + ) + } +} + +unsafe fn wrap_ref(from: &F) -> &T { + assert!(core::mem::size_of::<*const F>() == core::mem::size_of::<*const T>()); + let inner_ptr = core::mem::ManuallyDrop::new(from as *const F); + // SAFETY: Caller guarantees soundness. + unsafe { + // A pointer cast doesn't work here because rustc can't tell + // that the vtables match (because of the `?Sized` restriction + // relaxation). A `transmute` doesn't work because the sizes + // are unspecified. + let outer_ptr: *const T = core::mem::transmute_copy(&inner_ptr); + &*outer_ptr + } +} + +unsafe fn wrap_mut(from: &mut F) -> &mut T { + assert!(core::mem::size_of::<*mut F>() == core::mem::size_of::<*mut T>()); + let inner_ptr = core::mem::ManuallyDrop::new(from as *mut F); + // SAFETY: Caller guarantees soundness. + unsafe { + // A pointer cast doesn't work here because rustc can't tell + // that the vtables match (because of the `?Sized` restriction + // relaxation). A `transmute` doesn't work because the sizes + // are unspecified. + let outer_ptr: *mut T = core::mem::transmute_copy(&inner_ptr); + &mut *outer_ptr + } +}