diff --git a/utils/cw-prover/query.proof b/utils/cw-prover/query.proof deleted file mode 100644 index 9053ddd..0000000 --- a/utils/cw-prover/query.proof +++ /dev/null @@ -1 +0,0 @@ -{"key":"03ade4a5f5803a439835c636395a8d648dee57b2fc90d98dc17fa887159b69638b7367787374617465","value":"7b22636f6d707574655f6d72656e636c617665223a2264633433663863343264386535663532633862626436386634323632343231353366306265313036333066663863636132353531323961336361303364323733222c226b65795f6d616e616765725f6d72656e636c617665223a2231636632653532393131343130666266336631393930353661393864353837393561353539613265383030393333663766636431336430343834363232373163222c227463625f696e666f223a2233313233383736227d","proof":{"ops":[{"field_type":"ics23:iavl","key":"A63kpfWAOkOYNcY2OVqNZI3uV7L8kNmNwX+ohxWbaWOLc2d4c3RhdGU=","data":"CrgDCikDreSl9YA6Q5g1xjY5Wo1kje5XsvyQ2Y3Bf6iHFZtpY4tzZ3hzdGF0ZRLIAXsiY29tcHV0ZV9tcmVuY2xhdmUiOiJkYzQzZjhjNDJkOGU1ZjUyYzhiYmQ2OGY0MjYyNDIxNTNmMGJlMTA2MzBmZjhjY2EyNTUxMjlhM2NhMDNkMjczIiwia2V5X21hbmFnZXJfbXJlbmNsYXZlIjoiMWNmMmU1MjkxMTQxMGZiZjNmMTk5MDU2YTk4ZDU4Nzk1YTU1OWEyZTgwMDkzM2Y3ZmNkMTNkMDQ4NDYyMjcxYyIsInRjYl9pbmZvIjoiMzEyMzg3NiJ9GgwIARgBIAEqBAACmAEiKggBEiYCBJgBIFclzyzP2y2LTcBhP0IxBhvnlMJiEFCsDEMUQ9dM5dvYICIsCAESBQQGmAEgGiEgfUSWe0VMFTsxkzDuMQNE05aSzdRTTvkWzZXkfplWUbEiKggBEiYGDJBnIEkK+nmGmXpOfREXvfonLrK4mEZx1XF4DgJp86QIVF1EICIsCAESBQgakGcgGiEgBl/NSR16eG1vDenJA6GEEJ9xcQv9Bwxv8wyhAL5JLwE="},{"field_type":"ics23:simple","key":"d2FzbQ==","data":"CqgBCgR3YXNtEiDYWxn2B9M/eGP18Gwl3zgWZkT7Yn/iFlcS0THfmfcfDBoJCAEYASABKgEAIiUIARIhAWLU8PgnJ/EMp4BYvtTN9MX/rS70dNQ3ZAzrJLssrLjRIiUIARIhAeZ4u8MKaaJoanRG1ZtncskBGpLgN5tPEXihifKcMflrIiUIARIhASJkYRU83gOvlkSLVW5EV87q/xnJXY2+Iipku/9Sjq/x"}]}} \ No newline at end of file diff --git a/utils/cw-prover/src/main.rs b/utils/cw-prover/src/main.rs index 8c0b654..ece964e 100644 --- a/utils/cw-prover/src/main.rs +++ b/utils/cw-prover/src/main.rs @@ -24,14 +24,13 @@ use std::{ use clap::{Parser, Subcommand}; use cosmrs::AccountId; +use cw_proof::proof::cw::RawCwProof; +use cw_proof::proof::{cw::CwProof, key::CwAbciKey, Proof}; use tendermint::{block::Height, AppHash}; use tendermint_rpc::{ client::HttpClient as TmRpcClient, endpoint::status::Response, Client, HttpClientUrl, }; -use cw_proof::proof::cw::RawCwProof; -use cw_proof::proof::{cw::CwProof, key::CwAbciKey, Proof}; - #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] struct Cli { diff --git a/utils/tm-prover/Cargo.lock b/utils/tm-prover/Cargo.lock index 8a78218..7c8952b 100644 --- a/utils/tm-prover/Cargo.lock +++ b/utils/tm-prover/Cargo.lock @@ -112,6 +112,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.21.5" @@ -124,6 +130,22 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bip32" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e141fb0f8be1c7b45887af94c88b182472b57c96b56773250ae00cd6a14a164" +dependencies = [ + "bs58", + "hmac", + "k256", + "rand_core", + "ripemd", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -148,6 +170,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bs58" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +dependencies = [ + "sha2 0.10.8", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -190,6 +221,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "num-traits", + "serde", +] + [[package]] name = "clap" version = "4.4.7" @@ -296,6 +337,37 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +[[package]] +name = "cosmos-sdk-proto" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32560304ab4c365791fd307282f76637213d8083c1a98490c35159cd67852237" +dependencies = [ + "prost", + "prost-types", + "tendermint-proto", +] + +[[package]] +name = "cosmrs" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47126f5364df9387b9d8559dcef62e99010e1d4098f39eb3f7ee4b5c254e40ea" +dependencies = [ + "bip32", + "cosmos-sdk-proto", + "ecdsa", + "eyre", + "k256", + "rand_core", + "serde", + "serde_json", + "signature", + "subtle-encoding", + "tendermint", + "thiserror", +] + [[package]] name = "cpufeatures" version = "0.2.11" @@ -326,6 +398,18 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -349,6 +433,56 @@ dependencies = [ "zeroize", ] +[[package]] +name = "cw-proof" +version = "0.1.0" +dependencies = [ + "clap", + "cosmrs", + "displaydoc", + "ics23", + "prost", + "serde", + "serde_with", + "tendermint", + "tendermint-rpc", +] + +[[package]] +name = "darling" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.39", +] + +[[package]] +name = "darling_macro" +version = "0.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.39", +] + [[package]] name = "der" version = "0.7.8" @@ -395,7 +529,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ "block-buffer 0.10.4", + "const-oid", "crypto-common", + "subtle", +] + +[[package]] +name = "displaydoc" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] @@ -427,6 +588,25 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "encoding_rs" version = "0.8.33" @@ -446,6 +626,16 @@ dependencies = [ "once_cell", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + [[package]] name = "flex-error" version = "0.4.4" @@ -568,6 +758,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -589,6 +780,17 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "h2" version = "0.3.21" @@ -638,6 +840,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "http" version = "0.2.9" @@ -710,6 +921,27 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "ics23" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "661e2d6f79952a65bc92b1c81f639ebd37228dae6ff412a5aba7d474bdc4b957" +dependencies = [ + "anyhow", + "bytes", + "hex", + "prost", + "ripemd", + "sha2 0.10.8", + "sha3", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.4.0" @@ -766,6 +998,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "k256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" +dependencies = [ + "cfg-if 1.0.0", + "ecdsa", + "elliptic-curve", + "sha2 0.10.8", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1041,9 +1294,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4fdd22f3b9c31b53c060df4a0613a1c7f062d4115a2b984dd15b1858f7e340d" +checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" dependencies = [ "bytes", "prost-derive", @@ -1051,9 +1304,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265baba7fabd416cf5078179f7d2cbeca4ce7a9041111900675ea7c4cb8a4c32" +checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", "itertools", @@ -1085,6 +1338,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "redox_syscall" @@ -1179,6 +1435,16 @@ dependencies = [ "winreg", ] +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + [[package]] name = "ring" version = "0.17.5" @@ -1193,6 +1459,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -1282,6 +1557,20 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + [[package]] name = "security-framework" version = "2.9.2" @@ -1384,6 +1673,33 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_with" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64cd236ccc1b7a29e7e2739f27c0b2dd199804abc4290e32f59f3b68d6405c23" +dependencies = [ + "base64", + "chrono", + "hex", + "serde", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93634eb5f75a2323b16de4748022ac4297f9e76b6dced2be287a099f41b5e788" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.39", +] + [[package]] name = "sha2" version = "0.9.9" @@ -1408,6 +1724,16 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -1431,6 +1757,10 @@ name = "signature" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest 0.10.7", + "rand_core", +] [[package]] name = "slab" @@ -1571,10 +1901,12 @@ dependencies = [ "ed25519-consensus", "flex-error", "futures", + "k256", "num-traits", "once_cell", "prost", "prost-types", + "ripemd", "serde", "serde_bytes", "serde_json", @@ -1793,8 +2125,12 @@ version = "0.1.0" dependencies = [ "clap", "color-eyre", + "cosmrs", + "cw-proof", "futures", + "serde", "serde_json", + "serde_with", "tendermint", "tendermint-light-client", "tendermint-light-client-detector", @@ -2228,9 +2564,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" dependencies = [ "zeroize_derive", ] diff --git a/utils/tm-prover/Cargo.toml b/utils/tm-prover/Cargo.toml index 1b5addb..47d43ad 100644 --- a/utils/tm-prover/Cargo.toml +++ b/utils/tm-prover/Cargo.toml @@ -6,15 +6,17 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.1.8", features = ["derive"] } +color-eyre = "0.6.2" +cosmrs = "0.15.0" +cw-proof = { path = "../cw-proof" } +futures = "0.3.27" +serde = { version = "1.0.189", features = ["derive"] } +serde_json = "1.0.94" tendermint = "0.34.0" tendermint-rpc = { version = "0.34.0", features = ["http-client"] } tendermint-light-client = "0.34.0" tendermint-light-client-detector = "0.34.0" - -clap = { version = "4.1.8", features = ["derive"] } -color-eyre = "0.6.2" -futures = "0.3.27" -serde_json = "1.0.94" tokio = { version = "1.26.0", features = ["full"] } tracing = "0.1.37" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } diff --git a/utils/tm-prover/README.md b/utils/tm-prover/README.md index 340e6df..c100f56 100644 --- a/utils/tm-prover/README.md +++ b/utils/tm-prover/README.md @@ -7,10 +7,11 @@ block height and trusted height/hash. ```bash cargo run -- --chain-id osmosis-1 \ - --primary https://rpc.osmosis.zone \ - --witnesses https://rpc.osmosis.zone \ - --trusted-height 12230413 \ - --trusted-hash D3742DD1573436AF972472135A24B31D5ACE9A2C04791A76196F875955B90F1D \ - --height 12230423 \ + --primary "http://127.0.0.1:26657" \ + --witnesses "http://127.0.0.1:26657" \ + --trusted-height 400 \ + --trusted-hash "DEA1738C2AEE72E935E39CE6EB8765B8782B791038789AC2FEA446526FDE8638" \ + --contract-address "wasm17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgsm0v070" \ + --storage-key "requests" \ --trace-file light-client-proof.json ``` diff --git a/utils/tm-prover/light-client-proof.json b/utils/tm-prover/light-client-proof.json new file mode 100644 index 0000000..3357033 --- /dev/null +++ b/utils/tm-prover/light-client-proof.json @@ -0,0 +1 @@ +{"light_client_proof":[{"signed_header":{"header":{"version":{"block":"11","app":"0"},"chain_id":"testing","height":"400","time":"2024-01-01T20:46:13.510205743Z","last_block_id":{"hash":"BC189DEF6C65323A84F2263F863CDB6C80C82B849F04BBBCE5063B671E4C5BD9","parts":{"total":1,"hash":"D08D088512C7BFB8A88EBCA38CB83D5FCDE13BCD3F3A53AE0EBFDABBDABD3C83"}},"last_commit_hash":"181CE355925014B46F83A4F7F3E09AF4F830B5380E1779CEB1BADC014BA973D9","data_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","validators_hash":"DCD72DC52B0AAFAE51BCCEA578A9238943216458531D7A2604D6E057705FA647","next_validators_hash":"DCD72DC52B0AAFAE51BCCEA578A9238943216458531D7A2604D6E057705FA647","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"172BD4336D4D11C8CE8DF5D4802881ACD8510F62B327E345226CDCB93D756E33","last_results_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","evidence_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","proposer_address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67"},"commit":{"height":"400","round":0,"block_id":{"hash":"DEA1738C2AEE72E935E39CE6EB8765B8782B791038789AC2FEA446526FDE8638","parts":{"total":1,"hash":"8DF6BE61FB106775B8087515F9E966A8D5C3DB82414464177C3D866DBD2C259F"}},"signatures":[{"block_id_flag":2,"validator_address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","timestamp":"2024-01-01T20:46:18.803728572Z","signature":"pgZz9qoQjP2c6IpfQ3NA521iU8PBcr+3dWxToUeLBtiFKmMIZuKmJMcrrq8v/4I1DE2oKOM0CC+lZOPgdqufDw=="}]}},"validator_set":{"validators":[{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null}],"proposer":{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null},"total_voting_power":"250"},"next_validator_set":{"validators":[{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null}],"proposer":null,"total_voting_power":"250"},"provider":"2601e427670cfa018366dbb360522d5a622ba734"},{"signed_header":{"header":{"version":{"block":"11","app":"0"},"chain_id":"testing","height":"780","time":"2024-01-02T13:13:21.589832659Z","last_block_id":{"hash":"342AFEB4F2B9886D25DCA0F89B7990AEA1F4756EB2658EF8E1F25995D04E0CC1","parts":{"total":1,"hash":"881759DC5288476E2D2C191507C78592F931B3FF8AB095981342866DBEF00ED9"}},"last_commit_hash":"F9C4200DAF86ADC846E2B4815469B9AB5B26229DC19C980F4F25C831A8E6E8B5","data_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","validators_hash":"DCD72DC52B0AAFAE51BCCEA578A9238943216458531D7A2604D6E057705FA647","next_validators_hash":"DCD72DC52B0AAFAE51BCCEA578A9238943216458531D7A2604D6E057705FA647","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"31D7AD77E00D1643A1C08EB304778CA344EB2F2B001F5AABC0DB0CAE093B4268","last_results_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","evidence_hash":"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855","proposer_address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67"},"commit":{"height":"780","round":0,"block_id":{"hash":"FB97BF6CE7D2BC81F6C56C5A5D230CE9EA13223E2A9768C8DDAF673E85FA2B9A","parts":{"total":1,"hash":"151B2C323D4F1E278A8E97D3FE2901BC4578B4DBD3E2EA73AAC16741EA9E38B9"}},"signatures":[{"block_id_flag":2,"validator_address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","timestamp":"2024-01-02T13:13:26.661200506Z","signature":"o17sNhO4FWp4ZF+4rbej8L7Qzq4XkXxsfRryKLACn+wCdYdyd2tE9Lwtafata90jINIqD1xW7eUH1Dxc33fVDw=="}]}},"validator_set":{"validators":[{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null}],"proposer":{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null},"total_voting_power":"250"},"next_validator_set":{"validators":[{"address":"EEFD30D2B8A1B5DBB53F0BF125A8513F35EBFA67","pub_key":{"type":"tendermint/PubKeyEd25519","value":"bBrxVo7fybcsc76shxtDH/bnBoG16Y//CdLo3nRuut8="},"power":"250","name":null}],"proposer":null,"total_voting_power":"250"},"provider":"2601e427670cfa018366dbb360522d5a622ba734"}],"merkle_proof":{"key":"03f04a313a7349b120c55c99788f12f712176bb3e5926d012d0ea72fa2bbb850517265717565737473","value":"5b5b2234323564383766383632306531646564656565373035393063633535623136346238663031343830656535396530623164613335343336613266376332373737222c7b226a6f696e5f636f6d707574655f6e6f6465223a5b22303345363745463039323133363333303734464234464246333338363433463446304335373445443630454631314430333432324545423036464133384338463346222c227761736d31306e3464736c6a79796670326b3268793665387675633972793332707832656777743565306d225d7d5d2c5b2234323564383766383632306531646564656565373035393063633535623136346238663031343830656535396530623164613335343336613266376332373737222c7b226a6f696e5f636f6d707574655f6e6f6465223a5b22303345363745463039323133363333303734464234464246333338363433463446304335373445443630454631314430333432324545423036464133384338463346222c227761736d31306e3464736c6a79796670326b3268793665387675633972793332707832656777743565306d225d7d5d5d","proof":{"ops":[{"field_type":"ics23:iavl","key":"A/BKMTpzSbEgxVyZeI8S9xIXa7Plkm0BLQ6nL6K7uFBRcmVxdWVzdHM=","data":"Cr0FCikD8EoxOnNJsSDFXJl4jxL3Ehdrs+WSbQEtDqcvoru4UFFyZXF1ZXN0cxKhA1tbIjQyNWQ4N2Y4NjIwZTFkZWRlZWU3MDU5MGNjNTViMTY0YjhmMDE0ODBlZTU5ZTBiMWRhMzU0MzZhMmY3YzI3NzciLHsiam9pbl9jb21wdXRlX25vZGUiOlsiMDNFNjdFRjA5MjEzNjMzMDc0RkI0RkJGMzM4NjQzRjRGMEM1NzRFRDYwRUYxMUQwMzQyMkVFQjA2RkEzOEM4RjNGIiwid2FzbTEwbjRkc2xqeXlmcDJrMmh5NmU4dnVjOXJ5MzJweDJlZ3d0NWUwbSJdfV0sWyI0MjVkODdmODYyMGUxZGVkZWVlNzA1OTBjYzU1YjE2NGI4ZjAxNDgwZWU1OWUwYjFkYTM1NDM2YTJmN2MyNzc3Iix7ImpvaW5fY29tcHV0ZV9ub2RlIjpbIjAzRTY3RUYwOTIxMzYzMzA3NEZCNEZCRjMzODY0M0Y0RjBDNTc0RUQ2MEVGMTFEMDM0MjJFRUIwNkZBMzhDOEYzRiIsIndhc20xMG40ZHNsanl5ZnAyazJoeTZlOHZ1YzlyeTMycHgyZWd3dDVlMG0iXX1dXRoMCAEYASABKgQAArAGIioIARImAgSwBiBOpzP2s/6SIunMBbaHCRLEgoaVNga+vmEiNh7vhehyDCAiLAgBEgUEBrAGIBohIAsZ7FCkq3DffcNWIOBhCJtBX0VkI6fPIq4WG9A5kvAHIioIARImBg6wBiCzKKOIkxaoGXjgKaw6rKaTMwh9QavhVQfxZaaBPL/TUCAiKggBEiYIHrAGIE3sONaqyo/izFlcX87VN1MrH9LInKh9UPkoc37KwAJnICIsCAESBQw4sAYgGiEgR+BP64lBpTiwqraA1NTDDm22GVQrUBvDgnGZSK8cwnA="},{"field_type":"ics23:simple","key":"d2FzbQ==","data":"CqgBCgR3YXNtEiCc/abm+sGXQuxUS/in3jZ8QRv4EkrL8XvsdhpOyhBHkBoJCAEYASABKgEAIiUIARIhAWLU8PgnJ/EMp4BYvtTN9MX/rS70dNQ3ZAzrJLssrLjRIiUIARIhAeyOzGvgMZqvNLX4HSeqxpRsX5wvzkCXwuSZQx2+D+VFIiUIARIhATN4tA396yO15lqAYWrGYBOs2UWy32MxkhTHVoMbn1bz"}]}}} \ No newline at end of file diff --git a/utils/tm-prover/src/main.rs b/utils/tm-prover/src/main.rs index 0131886..957ba8d 100644 --- a/utils/tm-prover/src/main.rs +++ b/utils/tm-prover/src/main.rs @@ -20,7 +20,12 @@ use color_eyre::{ eyre::{eyre, Result}, Report, }; +use cosmrs::AccountId; +use cw_proof::error::ProofError; +use cw_proof::proof::cw::RawCwProof; +use cw_proof::proof::{cw::CwProof, key::CwAbciKey, Proof}; use futures::future::join_all; +use serde::{Deserialize, Serialize}; use tendermint::{crypto::default::Sha256, evidence::Evidence}; use tendermint_light_client::{ builder::LightClientBuilder, @@ -29,10 +34,12 @@ use tendermint_light_client::{ types::{Hash, Height, LightBlock, TrustThreshold}, }; use tendermint_light_client_detector::{detect_divergence, Error, Provider, Trace}; -use tendermint_rpc::{Client, HttpClient, HttpClientUrl}; +use tendermint_rpc::{client::HttpClient, Client, HttpClientUrl}; use tracing::{error, info, metadata::LevelFilter}; use tracing_subscriber::{util::SubscriberInitExt, EnvFilter}; +const WASM_STORE_KEY: &str = "/store/wasm/key"; + fn parse_trust_threshold(s: &str) -> Result { if let Some((l, r)) = s.split_once('/') { TrustThreshold::new(l.parse()?, r.parse()?).map_err(Into::into) @@ -74,6 +81,12 @@ impl Verbosity { } } +#[derive(Clone, Debug, Serialize, Deserialize)] +struct ProofOutput { + light_client_proof: Vec, + merkle_proof: RawCwProof, +} + #[derive(Debug, Parser)] #[command(author, version, about, long_about = None)] struct Cli { @@ -82,7 +95,7 @@ struct Cli { chain_id: String, /// Primary RPC address - #[clap(long)] + #[clap(long, default_value = "http://127.0.0.1:26657")] primary: HttpClientUrl, /// Comma-separated list of witnesses RPC addresses @@ -97,10 +110,6 @@ struct Cli { #[clap(long)] trusted_hash: Hash, - /// Height of the header to verify - #[clap(long)] - height: Option, - /// Trust threshold #[clap(long, value_parser = parse_trust_threshold, default_value_t = TrustThreshold::TWO_THIRDS)] trust_threshold: TrustThreshold, @@ -124,6 +133,14 @@ struct Cli { /// Increase verbosity #[clap(flatten)] verbose: Verbosity, + + /// Address of the CosmWasm contract + #[clap(long)] + contract_address: AccountId, + + /// Storage key of the state item for which proofs must be retrieved + #[clap(long)] + storage_key: String, } #[tokio::main] @@ -150,23 +167,31 @@ async fn main() -> Result<()> { let mut primary = make_provider( &args.chain_id, - args.primary, + args.primary.clone(), args.trusted_height, args.trusted_hash, options, ) .await?; + let client = HttpClient::builder(args.primary.clone()).build()?; + let trusted_block = primary .latest_trusted() .ok_or_else(|| eyre!("No trusted state found for primary"))?; - let primary_block = if let Some(target_height) = args.height { - info!("Verifying to height {} on primary...", target_height); - primary.verify_to_height(target_height) - } else { + let primary_block = { info!("Verifying to latest height on primary..."); - primary.verify_to_highest() + + let status = client.status().await?; + let proof_height = { + let latest_height = status.sync_info.latest_block_height; + (latest_height.value() - 1) + .try_into() + .expect("infallible conversion") + }; + + primary.verify_to_height(proof_height) }?; info!("Verified to height {} on primary", primary_block.height()); @@ -197,14 +222,36 @@ async fn main() -> Result<()> { ) .await?; + let status = client.status().await?; + let (proof_height, latest_app_hash) = + (primary_block.height(), status.sync_info.latest_app_hash); + + let path = WASM_STORE_KEY.to_owned(); + let data = CwAbciKey::new(args.contract_address, args.storage_key, None); + let result = client + .abci_query(Some(path), data, Some(proof_height), true) + .await?; + + let proof: CwProof = result + .clone() + .try_into() + .expect("result should contain proof"); + proof + .verify(latest_app_hash.clone().into()) + .map_err(|e: ProofError| eyre!(e))?; + if let Some(trace_file) = args.trace_file { - write_trace_to_file(trace_file, primary_trace).await?; + let output = ProofOutput { + light_client_proof: primary_trace, + merkle_proof: proof.into(), + }; + write_proof_to_file(trace_file, output).await?; }; Ok(()) } -async fn write_trace_to_file(trace_file: PathBuf, output: Vec) -> Result<()> { +async fn write_proof_to_file(trace_file: PathBuf, output: ProofOutput) -> Result<()> { info!("Writing proof to output file ({})", trace_file.display()); let file = File::create(trace_file)?;