From 5ffc71afea8dc738732156a8096b0dfb1a149c5e Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Thu, 7 Sep 2023 21:16:22 +0900 Subject: [PATCH 1/7] update lcp version Signed-off-by: Naohiro Yoshida --- Cargo.lock | 646 +++++++++++++++------------- light-client/Cargo.toml | 19 +- light-client/src/client.rs | 74 ++-- light-client/src/client_state.rs | 5 +- light-client/src/consensus_state.rs | 8 +- light-client/src/errors.rs | 4 +- light-client/src/header/mod.rs | 2 +- light-client/src/lib.rs | 2 +- light-client/src/misbehaviour.rs | 2 +- light-client/src/misc.rs | 8 +- 10 files changed, 411 insertions(+), 359 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edfc02a..d8a421f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "ahash" version = "0.7.6" @@ -31,9 +46,9 @@ source = "git+https://github.com/datachainlab/milagro_bls?rev=bc2b5b5e8d48b7e2e1 [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "arrayref" @@ -43,9 +58,9 @@ checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "async-stream" @@ -66,18 +81,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.29", ] [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.29", ] [[package]] @@ -88,9 +103,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.6.15" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b32c5ea3aabaf4deb5f5ced2d688ec0844c881c9e6c696a8b769a05fc691e62" +checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", "axum-core", @@ -131,6 +146,21 @@ dependencies = [ "tower-service", ] +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base16ct" version = "0.2.0" @@ -145,9 +175,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.0" +version = "0.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "414dcefbc63d77c526a76b3afcf6fbb9b5e2791c19c3aa2297733208750c6e53" [[package]] name = "base64ct" @@ -268,9 +298,12 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -281,30 +314,29 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "commitments" version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" dependencies = [ "crypto", + "ethabi", "flex-error", "hex", "lcp-types", "prost", - "rlp", "serde", - "sha2 0.10.6", - "validation-context", + "sha2 0.10.7", ] [[package]] name = "const-oid" -version = "0.9.2" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" dependencies = [ "libc", ] @@ -318,21 +350,22 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto" version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" dependencies = [ "flex-error", "hex", "libsecp256k1", "serde", + "serde-big-array", "sgx_types", "tiny-keccak 1.5.0", ] [[package]] name = "crypto-bigint" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" +checksum = "740fe28e594155f10cfc383984cbefd529d7396050557148f79cb0f621204124" dependencies = [ "generic-array", "rand_core", @@ -375,9 +408,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" dependencies = [ "const-oid", "zeroize", @@ -405,9 +438,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.4", "const-oid", @@ -417,32 +450,32 @@ dependencies = [ [[package]] name = "displaydoc" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bf95dc3f046b9da4f2d51833c0d3547d8564ef6910f5c1ed130306a75b92886" +checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.29", ] [[package]] name = "dyn-clone" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" +checksum = "bbfc4744c1b8f2a09adc0e55242f60b1af195d88596bd8700be74418c056c555" [[package]] name = "ecdsa" -version = "0.16.7" +version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" dependencies = [ "der", - "digest 0.10.6", + "digest 0.10.7", "elliptic-curve", "rfc6979", - "signature 2.0.0", + "signature 2.1.0", "spki", ] @@ -470,9 +503,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "elliptic-curve" @@ -482,7 +515,7 @@ checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" dependencies = [ "base16ct", "crypto-bigint", - "digest 0.10.6", + "digest 0.10.7", "ff", "generic-array", "group", @@ -493,15 +526,53 @@ dependencies = [ "zeroize", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "erased-serde" -version = "0.3.25" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2b0c2380453a92ea8b6c8e5f64ecaafccddde8ceab55ff7a8ac1029f894569" +checksum = "837c0466252947ada828b975e12daf82e18bb5444e4df87be6038d4469e2a3d2" dependencies = [ "serde", ] +[[package]] +name = "ethabi" +version = "18.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7413c5f74cc903ea37386a8965a936cbeb334bd270862fdece542c1b2dcbc898" +dependencies = [ + "ethereum-types", + "hex", + "sha3", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "fixed-hash", + "primitive-types", + "uint", +] + +[[package]] +name = "eyre" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "ff" version = "0.13.0" @@ -530,6 +601,7 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" dependencies = [ + "eyre", "paste", ] @@ -619,15 +691,21 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" dependencies = [ "cfg-if", "libc", "wasi", ] +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + [[package]] name = "group" version = "0.13.0" @@ -641,9 +719,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.18" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f8a914c2987b688368b5138aa05321db91f4090cf26118185672ad588bce21" +checksum = "91fc23aa11be92976ef4729127f1a74adf36d8436f7816b185d18df956790833" dependencies = [ "bytes", "fnv", @@ -651,7 +729,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 1.9.3", "slab", "tokio", "tokio-util", @@ -692,9 +770,10 @@ dependencies = [ ] [[package]] -name = "hashbrown_tstd" -version = "0.12.0" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" +name = "hashbrown" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" [[package]] name = "hex" @@ -704,9 +783,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-literal" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" [[package]] name = "hmac" @@ -724,7 +803,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]] @@ -768,15 +847,15 @@ checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "hyper" -version = "0.14.26" +version = "0.14.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" dependencies = [ "bytes", "futures-channel", @@ -789,7 +868,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -828,7 +907,7 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "sha2 0.10.6", + "sha2 0.10.7", "subtle-encoding", "tendermint", "tendermint-light-client-verifier", @@ -867,7 +946,7 @@ dependencies = [ "hex", "prost", "ripemd", - "sha2 0.10.6", + "sha2 0.10.7", "sha3", ] @@ -900,6 +979,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -910,6 +995,16 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "indexmap" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +dependencies = [ + "equivalent", + "hashbrown 0.14.0", +] + [[package]] name = "itertools" version = "0.10.5" @@ -921,9 +1016,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "k256" @@ -934,38 +1029,49 @@ dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", - "sha2 0.10.6", + "sha2 0.10.7", ] [[package]] name = "keccak" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3afef3b6eff9ce9d8ff9b3601125eec7f0c8cbac7abd14f355d053fa56c98768" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" dependencies = [ "cpufeatures", ] +[[package]] +name = "lcp-proto" +version = "0.1.0" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" +dependencies = [ + "ibc-proto", + "prost", + "serde", +] + [[package]] name = "lcp-types" version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" dependencies = [ "flex-error", + "hex", "ibc", - "ibc-proto", - "prost-types", + "lcp-proto", + "prost", "serde", "serde_json", - "sgx_tstd", + "sgx_types", "tendermint", ] [[package]] name = "libc" -version = "0.2.141" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libsecp256k1" @@ -1018,41 +1124,29 @@ dependencies = [ [[package]] name = "light-client" version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" dependencies = [ "bincode", "commitments", "derive_more", "flex-error", + "ibc", "lcp-types", "serde", "store", ] -[[package]] -name = "light-client-registry" -version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" -dependencies = [ - "flex-error", - "light-client", - "sgx_tstd", -] - [[package]] name = "log" -version = "0.4.17" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "matchit" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40" +checksum = "ed1202b2a6f884ae56f04cff409ab315c5ce26b5e58d7412e484f01fd52f52ef" [[package]] name = "memchr" @@ -1087,14 +1181,22 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" -version = "0.8.6" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", - "log", "wasi", "windows-sys", ] @@ -1112,18 +1214,27 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" -version = "1.17.1" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "opaque-debug" @@ -1133,9 +1244,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "parity-scale-codec" -version = "3.4.0" +version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "637935964ff85a605d114591d4d2c13c5d1ba2806dae97cea6bf180238a749ac" +checksum = "dd8e946cc0cc711189c0b0249fb8b599cbeeab9784d83c415719368bb8d4ac64" dependencies = [ "arrayvec", "bitvec", @@ -1147,9 +1258,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.1.4" +version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b26a931f824dd4eca30b3e43bb4f31cd5f0d3a403c5f5ff27106b805bfde7b" +checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -1185,15 +1296,11 @@ dependencies = [ name = "parlia-ibc-lc" version = "0.1.0" dependencies = [ - "commitments", - "crypto", "elliptic-curve", "hex-literal", "ibc-proto", "k256", - "lcp-types", "light-client", - "light-client-registry", "milagro_bls", "parlia-ibc-proto", "patricia-merkle-trie", @@ -1205,14 +1312,13 @@ dependencies = [ "store", "tiny-keccak 2.0.2", "trie-db", - "validation-context", ] [[package]] name = "parlia-ibc-proto" version = "0.1.0" dependencies = [ - "base64 0.21.0", + "base64 0.21.3", "bytes", "ibc-proto", "prost", @@ -1223,9 +1329,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "patricia-merkle-trie" @@ -1244,35 +1350,35 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" [[package]] name = "pin-project" -version = "1.0.12" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.12" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.29", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "12cc1b0bf1727a77a54b6654e7b5f1af8604923edc8b81885f8ec92f9e3f0a05" [[package]] name = "pin-utils" @@ -1329,9 +1435,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" dependencies = [ "unicode-ident", ] @@ -1370,9 +1476,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -1429,7 +1535,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]] @@ -1442,6 +1548,12 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -1450,15 +1562,15 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "safe-proc-macro2" @@ -1509,9 +1621,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.5.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cfdffd972d76b22f3d7f81c8be34b2296afd3a25e0a547bd9abe340a4dbbe97" +checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" dependencies = [ "cfg-if", "derive_more", @@ -1521,9 +1633,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.5.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61fa974aea2d63dd18a4ec3a49d59af9f34178c73a4f56d2f18205628d00681e" +checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" dependencies = [ "proc-macro-crate 1.3.1", "proc-macro2", @@ -1533,9 +1645,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +checksum = "763f8cd0d4c71ed8389c90cb8100cba87e763bd01a8e614d4f0af97bcd50a161" dependencies = [ "dyn-clone", "schemars_derive", @@ -1545,9 +1657,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.12" +version = "0.8.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +checksum = "ec0f696e21e10fa546b7ffb1c9672c6de8fbc7a81acf59524386d8639bf12737" dependencies = [ "proc-macro2", "quote", @@ -1571,31 +1683,40 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.160" +version = "1.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "9f5db24220c009de9bd45e69fb2938f4b6d2df856aa9304ce377b3180f83b7c1" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "5ad697f7e0b65af4983a4ce8f56ed5b357e8d3c36651bf6a7e13639c17b8e670" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.29", ] [[package]] @@ -1611,9 +1732,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" dependencies = [ "itoa", "ryu", @@ -1622,80 +1743,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.12" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", -] - -[[package]] -name = "sgx_alloc" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" - -[[package]] -name = "sgx_backtrace_sys" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "cc", - "sgx_build_helper", - "sgx_libc", -] - -[[package]] -name = "sgx_build_helper" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" - -[[package]] -name = "sgx_demangle" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" - -[[package]] -name = "sgx_libc" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "sgx_types", -] - -[[package]] -name = "sgx_tprotected_fs" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "sgx_trts", - "sgx_types", -] - -[[package]] -name = "sgx_trts" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "sgx_libc", - "sgx_types", -] - -[[package]] -name = "sgx_tstd" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "hashbrown_tstd", - "sgx_alloc", - "sgx_backtrace_sys", - "sgx_demangle", - "sgx_libc", - "sgx_tprotected_fs", - "sgx_trts", - "sgx_types", - "sgx_unwind", + "syn 2.0.29", ] [[package]] @@ -1703,14 +1757,6 @@ name = "sgx_types" version = "1.1.6" source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -[[package]] -name = "sgx_unwind" -version = "1.1.6" -source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk?rev=v1.1.6#c3d82372dff81e5bafb07f71bc8ad532d06b504e" -dependencies = [ - "sgx_build_helper", -] - [[package]] name = "sha2" version = "0.9.9" @@ -1726,22 +1772,22 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.6", + "digest 0.10.7", ] [[package]] name = "sha3" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54c2bb1a323307527314a36bfb73f24febb08ce2b8a554bf4ffd6f51ad15198c" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "keccak", ] @@ -1753,28 +1799,28 @@ checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" [[package]] name = "signature" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fe458c98333f9c8152221191a77e2a44e8325d0193484af2e9421a53019e57d" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" dependencies = [ - "digest 0.10.6", + "digest 0.10.7", "rand_core", ] [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "socket2" @@ -1786,6 +1832,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b18701741680e0322a2302176d3253a35388e2e62f172f64f4f16605f877" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "spki" version = "0.7.2" @@ -1805,7 +1861,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "store" version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" +source = "git+https://github.com/datachainlab/lcp?rev=v0.2.2#c073f89517fcdc4f796c07ad420b0029bbc148db" dependencies = [ "flex-error", "log", @@ -1814,9 +1870,9 @@ dependencies = [ [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "subtle-encoding" @@ -1846,9 +1902,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.15" +version = "2.0.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" dependencies = [ "proc-macro2", "quote", @@ -1886,7 +1942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda53c85447577769cdfc94c10a56f34afef2c00e4108badb57fce6b1a0c75eb" dependencies = [ "bytes", - "digest 0.10.6", + "digest 0.10.7", "ed25519", "ed25519-consensus", "flex-error", @@ -1899,7 +1955,7 @@ dependencies = [ "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.6", + "sha2 0.10.7", "signature 1.6.4", "subtle", "subtle-encoding", @@ -1945,6 +2001,7 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" dependencies = [ + "serde", "time-core", "time-macros", ] @@ -1984,16 +2041,16 @@ dependencies = [ [[package]] name = "tokio" -version = "1.27.0" +version = "1.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "17ed6077ed6cd6c74735e21f37eb16dc3935f96878b1fe961074089cc80893f9" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", "mio", "pin-project-lite", - "socket2", + "socket2 0.5.3", "tokio-macros", "windows-sys", ] @@ -2010,20 +2067,20 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.29", ] [[package]] name = "tokio-stream" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" +checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" dependencies = [ "futures-core", "pin-project-lite", @@ -2032,9 +2089,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ "bytes", "futures-core", @@ -2055,17 +2112,17 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" [[package]] name = "toml_edit" -version = "0.19.8" +version = "0.19.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" +checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" dependencies = [ - "indexmap", + "indexmap 2.0.0", "toml_datetime", "winnow", ] @@ -2110,7 +2167,7 @@ checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", "futures-util", - "indexmap", + "indexmap 1.9.3", "pin-project", "pin-project-lite", "rand", @@ -2148,20 +2205,20 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.23" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.29", ] [[package]] name = "tracing-core" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", ] @@ -2215,9 +2272,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" [[package]] name = "unicode-xid" @@ -2225,16 +2282,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "validation-context" -version = "0.1.0" -source = "git+https://github.com/datachainlab/lcp.git?rev=v0.1.6#170ed46bf85de9f4f8951d81580409fc089ad00e" -dependencies = [ - "lcp-types", - "rlp", - "serde", -] - [[package]] name = "version_check" version = "0.9.4" @@ -2243,11 +2290,10 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] @@ -2281,18 +2327,18 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -2305,51 +2351,51 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.4.1" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "d09770118a7eb1ccaf4a594a221334119a44a814fcb0d31c5b85e83e97227a97" dependencies = [ "memchr", ] @@ -2380,5 +2426,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn 2.0.29", ] diff --git a/light-client/Cargo.toml b/light-client/Cargo.toml index 13fd91f..bf9b391 100644 --- a/light-client/Cargo.toml +++ b/light-client/Cargo.toml @@ -6,12 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -light-client = { git = "https://github.com/datachainlab/lcp.git",rev = "v0.1.6" } -light-client-registry = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.1.6", default-features = false } -lcp-types = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.1.6", default-features = false } -commitments = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.1.6" } -crypto = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.1.6", default-features = false } -validation-context = { git = "https://github.com/datachainlab/lcp.git",rev = "v0.1.6" } +light-client = { git = "https://github.com/datachainlab/lcp", rev = "v0.2.2", default-features = false, features=["ibc"] } rlp = { version = "0.5.2", default-features = false } prost = { version = "0.11", default-features = false } @@ -26,27 +21,21 @@ primitive-types = { version = "0.12.1", default-features = false } k256 = { version = "0.13.1", default-features = false, features = ["alloc", "ecdsa"] } elliptic-curve = { version = "0.13.5", default-features = false, features = ["hazmat", "sec1"] } -hex-literal = "0.3.1" serde = { version = "1.0", default-features = false, features = ["alloc"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } milagro_bls = { git = "https://github.com/datachainlab/milagro_bls", rev = "bc2b5b5e8d48b7e2e1bfaa56dc2d93e13cb32095", default-features = false } +hex-literal = "0.4.1" [dev-dependencies] -store = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.1.6", default-features = false } +store = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.2.2", default-features = false } ibc-proto = { version = "0.26.0", default-features = false } - [features] default = ["std"] std = [ - "light-client-registry/std", - "lcp-types/std", + "light-client/std", "trie-db/std", "patricia-merkle-trie/std" ] -sgx = [ - "light-client-registry/sgx", - "lcp-types/sgx" -] dev = [] diff --git a/light-client/src/client.rs b/light-client/src/client.rs index 3e17298..b9fd85c 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -1,16 +1,16 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; -use commitments::{ - gen_state_id_from_any, CommitmentPrefix, StateCommitment, StateID, UpdateClientCommitment, -}; -use lcp_types::{Any, ClientId, Height}; use light_client::{ + commitments::{ + gen_state_id_from_any, CommitmentContext, CommitmentPrefix, StateCommitment, StateID, + UpdateClientCommitment, + }, + types::{Any, ClientId, Height}, CreateClientResult, Error as LightClientError, HostClientReader, LightClient, StateVerificationResult, UpdateClientResult, }; use patricia_merkle_trie::keccak::keccak_256; -use validation_context::ValidationParams; use crate::client_state::ClientState; use crate::commitment::{ @@ -64,8 +64,9 @@ impl LightClient for ParliaLightClient { prev_height: None, new_height: height, timestamp, - validation_params: ValidationParams::Empty, - }, + context: CommitmentContext::Empty, + } + .into(), prove: false, }) } @@ -121,8 +122,9 @@ impl LightClient for ParliaLightClient { prev_height: Some(trusted_height), new_height: height, timestamp, - validation_params: ValidationParams::Empty, - }, + context: CommitmentContext::Empty, + } + .into(), prove: true, }) } @@ -155,7 +157,8 @@ impl LightClient for ParliaLightClient { Some(value), proof_height, state_id, - ), + ) + .into(), }) } @@ -171,7 +174,8 @@ impl LightClient for ParliaLightClient { let state_id = self.verify_commitment(ctx, client_id, &prefix, &path, None, &proof_height, proof)?; Ok(StateVerificationResult { - state_commitment: StateCommitment::new(prefix, path, None, proof_height, state_id), + state_commitment: StateCommitment::new(prefix, path, None, proof_height, state_id) + .into(), }) } } @@ -339,8 +343,9 @@ mod test { use std::collections::BTreeMap; use hex_literal::hex; - use lcp_types::{Any, ClientId, Height, Time}; + use light_client::types::{Any, ClientId, Height, Time}; + use light_client::commitments::Commitment; use light_client::{ClientReader, HostClientReader, HostContext, LightClient}; use patricia_merkle_trie::keccak::keccak_256; @@ -523,15 +528,20 @@ mod test { assert_eq!(new_consensus_state.timestamp, header.timestamp().unwrap()); assert_eq!(new_consensus_state.validators_hash, new_validators_hash); assert_eq!(new_consensus_state.validators_size, new_validators_size); - assert_eq!(data.commitment.new_height, header.height()); - assert_eq!(data.commitment.new_state, None); - assert!(!data.commitment.new_state_id.to_vec().is_empty()); - assert_eq!( - data.commitment.prev_height, - Some(new_height(0, header.trusted_height().revision_height())) - ); - assert!(data.commitment.prev_state_id.is_some()); - assert_eq!(data.commitment.timestamp, header.timestamp().unwrap()); + match &data.commitment { + Commitment::UpdateClient(data) => { + assert_eq!(data.new_height, header.height()); + assert_eq!(data.new_state, None); + assert!(!data.new_state_id.to_vec().is_empty()); + assert_eq!( + data.prev_height, + Some(new_height(0, header.trusted_height().revision_height())) + ); + assert!(data.prev_state_id.is_some()); + assert_eq!(data.timestamp, header.timestamp().unwrap()); + } + _ => unreachable!("invalid commitment {:?}", data.commitment), + } } Err(e) => unreachable!("error {:?}", e), }; @@ -567,7 +577,7 @@ mod test { }; let err = client.update_client(&ctx, client_id, any).unwrap_err(); assert!( - format!("{:?}", err).ends_with("UnexpectedCoinbase: 31501907"), + format!("{}", err).contains("UnexpectedCoinbase: 31501907"), "{}", err ); @@ -655,14 +665,14 @@ mod test { proof_height, storage_proof_rlp.to_vec(), ) { - Ok(data) => { - assert_eq!(data.state_commitment.path, path); - assert_eq!(data.state_commitment.height, proof_height); - assert_eq!( - data.state_commitment.value, - Some(keccak_256(expected_value.as_slice())) - ); - } + Ok(data) => match &data.state_commitment { + Commitment::State(data) => { + assert_eq!(data.path, path); + assert_eq!(data.height, proof_height); + assert_eq!(data.value, Some(keccak_256(expected_value.as_slice()))); + } + _ => unreachable!("invalid state commitment {:?}", data.state_commitment), + }, Err(e) => unreachable!("error {:?}", e), }; } @@ -717,7 +727,7 @@ mod test { .submit_misbehaviour(&ctx, client_id.clone(), any) .unwrap_err(); assert!( - format!("{:?}", err).ends_with("UnexpectedSameBlockHash : 0-31500440"), + format!("{:?}", err).contains("UnexpectedSameBlockHash : 0-31500440"), "{}", err ); @@ -748,7 +758,7 @@ mod test { .submit_misbehaviour(&ctx, client_id, any) .unwrap_err(); assert!( - format!("{:?}", err).ends_with("UnexpectedCoinbase: 31500568"), + format!("{:?}", err).contains("UnexpectedCoinbase: 31500568"), "{}", err ); diff --git a/light-client/src/client_state.rs b/light-client/src/client_state.rs index 93643ce..a998713 100644 --- a/light-client/src/client_state.rs +++ b/light-client/src/client_state.rs @@ -2,7 +2,7 @@ use alloc::borrow::ToOwned as _; use alloc::vec::Vec; use core::time::Duration; -use lcp_types::{Any, Height, Time}; +use light_client::types::{Any, Height, Time}; use prost::Message as _; use parlia_ibc_proto::google::protobuf::Any as IBCAny; @@ -216,11 +216,12 @@ mod test { use hex_literal::hex; use crate::client_state::ClientState; + use light_client::types::Any; #[test] fn test_try_from_any() { let relayer_client_state_protobuf = hex!("0a272f6962632e6c69676874636c69656e74732e7061726c69612e76312e436c69656e7453746174651248088f4e1214aa43d337145e8930d01cb4e60abf6595c692921e1a200000000000000000000000000000000000000000000000000000000000000000220310c8012a04080110033064").to_vec(); - let any: lcp_types::Any = relayer_client_state_protobuf.try_into().unwrap(); + let any: Any = relayer_client_state_protobuf.try_into().unwrap(); let cs: ClientState = any.try_into().unwrap(); // Check if the result are same as relayer's one diff --git a/light-client/src/consensus_state.rs b/light-client/src/consensus_state.rs index e4e762a..a44b4e3 100644 --- a/light-client/src/consensus_state.rs +++ b/light-client/src/consensus_state.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; use core::ops::Add; use core::time::Duration; -use lcp_types::{Any, Time}; +use light_client::types::{Any, Time}; use prost::Message as _; use parlia_ibc_proto::google::protobuf::Any as IBCAny; @@ -129,7 +129,7 @@ mod test { use std::ops::{Add, Sub}; use hex_literal::hex; - use lcp_types::Time; + use light_client::types::{Any, Time}; use crate::consensus_state::ConsensusState; use crate::errors::Error; @@ -138,7 +138,7 @@ mod test { fn test_assert_not_expired() { let consensus_state = ConsensusState { state_root: [0u8; 32], - timestamp: Time::from_unix_timestamp_secs(1560000000).unwrap(), + timestamp: Time::from_unix_timestamp_nanos(1_560_000_000_000_000_000).unwrap(), validators_hash: [0u8; 32], validators_size: 0, }; @@ -182,7 +182,7 @@ mod test { fn test_try_from_any() { // This is ibc-parlia-relay's unit test data let relayer_consensus_state_protobuf = hex!("0a2a2f6962632e6c69676874636c69656e74732e7061726c69612e76312e436f6e73656e737573537461746512440a20c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4701a2073b0a7eec725ec1c4016d9cba46fbdac22478f8eadb6690067b2aa943afa0a9c").to_vec(); - let any: lcp_types::Any = relayer_consensus_state_protobuf.try_into().unwrap(); + let any: Any = relayer_consensus_state_protobuf.try_into().unwrap(); let cs: ConsensusState = any.try_into().unwrap(); // Check if the result are same as relayer's one diff --git a/light-client/src/errors.rs b/light-client/src/errors.rs index 1095377..894a367 100644 --- a/light-client/src/errors.rs +++ b/light-client/src/errors.rs @@ -3,7 +3,7 @@ use alloc::vec::Vec; use core::fmt::Formatter; use k256::ecdsa::signature; -use lcp_types::{ClientId, Height, Time, TimeError}; +use light_client::types::{ClientId, Height, Time, TimeError}; use trie_db::TrieError; use crate::misc::{Address, BlockNumber, Hash}; @@ -15,6 +15,7 @@ pub enum Error { LCPError(light_client::Error), // data conversion error + TimestampOverflowError(u128), TimeError(TimeError), RLPDecodeError(rlp::DecoderError), ProtoDecodeError(prost::DecodeError), @@ -103,6 +104,7 @@ impl core::fmt::Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { match self { Error::LCPError(e) => write!(f, "LCPError: {}", e), + Error::TimestampOverflowError(e) => write!(f, "TimestampOverflowError: {}", e), Error::TimeError(e) => write!(f, "TimeError: {}", e), Error::RLPDecodeError(e) => write!(f, "RLPDecodeError : {}", e), Error::ProtoDecodeError(e) => write!(f, "ProtoDecodeError: {}", e), diff --git a/light-client/src/header/mod.rs b/light-client/src/header/mod.rs index 2d25ca7..7e4b031 100644 --- a/light-client/src/header/mod.rs +++ b/light-client/src/header/mod.rs @@ -1,7 +1,7 @@ use alloc::borrow::ToOwned as _; use alloc::vec::Vec; -use lcp_types::{Any, Height, Time}; +use light_client::types::{Any, Height, Time}; use prost::Message as _; use parlia_ibc_proto::google::protobuf::Any as IBCAny; diff --git a/light-client/src/lib.rs b/light-client/src/lib.rs index 5f549cf..518ab8e 100644 --- a/light-client/src/lib.rs +++ b/light-client/src/lib.rs @@ -15,7 +15,7 @@ pub mod header; pub mod misbehaviour; mod misc; -pub fn register_implementations(registry: &mut dyn light_client_registry::LightClientRegistry) { +pub fn register_implementations(registry: &mut dyn light_client::LightClientRegistry) { registry .put_light_client( alloc::string::String::from(client_state::PARLIA_CLIENT_STATE_TYPE_URL), diff --git a/light-client/src/misbehaviour.rs b/light-client/src/misbehaviour.rs index 0098fe6..3a52b8a 100644 --- a/light-client/src/misbehaviour.rs +++ b/light-client/src/misbehaviour.rs @@ -1,6 +1,6 @@ use core::str::FromStr; -use lcp_types::{Any, ClientId}; +use light_client::types::{Any, ClientId}; use prost::Message; use parlia_ibc_proto::google::protobuf::Any as IBCAny; diff --git a/light-client/src/misc.rs b/light-client/src/misc.rs index 62ccd79..9f13228 100644 --- a/light-client/src/misc.rs +++ b/light-client/src/misc.rs @@ -1,6 +1,6 @@ use alloc::vec::Vec; -use lcp_types::{Height, Time}; +use light_client::types::{Height, Time}; use patricia_merkle_trie::keccak::keccak_256; use rlp::{Decodable, Rlp}; @@ -91,7 +91,11 @@ pub fn new_height(revision_number: u64, height: BlockNumber) -> Height { } pub fn new_timestamp(second: u64) -> Result { - Time::from_unix_timestamp_secs(second).map_err(Error::TimeError) + let second = second as u128; + let nanos = second + .checked_mul(1_000_000_000) + .ok_or_else(|| Error::TimestampOverflowError(second))?; + Time::from_unix_timestamp_nanos(nanos).map_err(Error::TimeError) } pub fn keccak_256_vec(targets: &[Vec]) -> Hash { From 87b6d7fe22d363e01ef01d60df724dc604fe1936 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 8 Sep 2023 17:34:39 +0900 Subject: [PATCH 2/7] update Signed-off-by: Naohiro Yoshida --- light-client/src/client.rs | 1 + light-client/src/client_state.rs | 18 +- light-client/src/errors.rs | 2 + light-client/src/header/mod.rs | 36 +-- light-client/src/misbehaviour.rs | 2 +- proto-compiler/src/cmd/compile.rs | 243 +----------------- .../ibc/lightclients/parlia/v1/parlia.proto | 4 +- proto/src/google.rs | 236 +++++++++++++++++ proto/src/prost/google.protobuf.rs | 78 ++++++ proto/src/prost/ibc.lightclients.parlia.v1.rs | 15 +- 10 files changed, 360 insertions(+), 275 deletions(-) create mode 100644 proto/src/google.rs diff --git a/light-client/src/client.rs b/light-client/src/client.rs index b9fd85c..5bbb3ef 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -368,6 +368,7 @@ mod test { "0000000000000000000000000000000000000000000000000000000000000000" ), trusting_period: core::time::Duration::new(86400 * 365 * 100, 0), + max_clock_drift: core::time::Duration::new(1, 0), latest_height: Default::default(), frozen: false, } diff --git a/light-client/src/client_state.rs b/light-client/src/client_state.rs index a998713..8292301 100644 --- a/light-client/src/client_state.rs +++ b/light-client/src/client_state.rs @@ -28,6 +28,7 @@ pub struct ClientState { ///Light Client parameters pub trusting_period: Duration, + pub max_clock_drift: Duration, /// State pub latest_height: Height, @@ -140,7 +141,18 @@ impl TryFrom for ClientState { .try_into() .map_err(|_| Error::UnexpectedStoreAddress(value.ibc_commitments_slot))?; - let trusting_period = Duration::from_secs(value.trusting_period); + let trusting_period = value + .trusting_period + .ok_or(Error::MissingTrustingPeriod)? + .try_into() + .map_err(|_| Error::MissingTrustingPeriod)?; + + let max_clock_drift = value + .max_clock_drift + .ok_or(Error::NegativeMaxClockDrift)? + .try_into() + .map_err(|_| Error::NegativeMaxClockDrift)?; + let frozen = value.frozen; Ok(Self { @@ -149,6 +161,7 @@ impl TryFrom for ClientState { ibc_commitments_slot, latest_height, trusting_period, + max_clock_drift, frozen, }) } @@ -164,7 +177,8 @@ impl From for RawClientState { revision_number: value.latest_height.revision_number(), revision_height: value.latest_height.revision_height(), }), - trusting_period: value.trusting_period.as_secs(), + trusting_period: Some(value.trusting_period.into()), + max_clock_drift: Some(value.max_clock_drift.into()), frozen: value.frozen.to_owned(), } } diff --git a/light-client/src/errors.rs b/light-client/src/errors.rs index 894a367..5d2bbeb 100644 --- a/light-client/src/errors.rs +++ b/light-client/src/errors.rs @@ -51,6 +51,7 @@ pub enum Error { InvalidTrustThreshold(u64, u64), MissingTrustedHeight, MissingTrustingPeriod, + NegativeMaxClockDrift, UnexpectedTrustedHeight(BlockNumber, BlockNumber), EmptyHeader, InsufficientHeaderToVerify(BlockNumber, usize, usize), @@ -191,6 +192,7 @@ impl core::fmt::Display for Error { write!(f, "UnexpectedHeaderRelation: {} {}", e1, e2) } Error::MissingTrustingPeriod => write!(f, "MissingTrustingPeriod"), + Error::NegativeMaxClockDrift => write!(f, "NegativeMaxClockDrift"), Error::IllegalTimestamp(e1, e2) => write!(f, "IllegalTimestamp: {} {}", e1, e2), Error::UnexpectedHeader(e1, e3) => write!(f, "UnexpectedHeader: {} {:?}", e1, e3), Error::ProofRLPError(e) => write!(f, "ProofRLPError : {}", e), diff --git a/light-client/src/header/mod.rs b/light-client/src/header/mod.rs index 7e4b031..dc4b304 100644 --- a/light-client/src/header/mod.rs +++ b/light-client/src/header/mod.rs @@ -1,4 +1,3 @@ -use alloc::borrow::ToOwned as _; use alloc::vec::Vec; use light_client::types::{Any, Height, Time}; @@ -25,9 +24,8 @@ mod eth_header; pub(crate) mod validator_set; mod vote_attestation; -#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq)] pub struct Header { - inner: RawHeader, account_proof: Vec, target: ETHHeader, parent: ETHHeader, @@ -102,7 +100,6 @@ impl TryFrom for Header { type Error = Error; fn try_from(value: RawHeader) -> Result { - let inner = value.clone(); let trusted_height = value .trusted_height .as_ref() @@ -135,11 +132,8 @@ impl TryFrom for Header { return Err(Error::MissingTargetTrustedValidators(target.number)); } - let account_proof = inner.account_proof.clone(); - Ok(Self { - inner, - account_proof, + account_proof: value.account_proof, target, parent, trusted_height, @@ -149,12 +143,6 @@ impl TryFrom for Header { } } -impl From
for RawHeader { - fn from(value: Header) -> Self { - value.inner - } -} - impl TryFrom for Header { type Error = Error; @@ -167,12 +155,6 @@ impl TryFrom for Header { } } -impl From
for Any { - fn from(value: Header) -> Self { - IBCAny::from(value).into() - } -} - impl TryFrom for Header { type Error = Error; @@ -181,19 +163,5 @@ impl TryFrom for Header { } } -impl From
for IBCAny { - fn from(value: Header) -> Self { - let value: RawHeader = value.into(); - let mut v = Vec::new(); - value - .encode(&mut v) - .expect("encoding to `Any` from `ParliaHeader`"); - Self { - type_url: PARLIA_HEADER_TYPE_URL.to_owned(), - value: v, - } - } -} - #[cfg(test)] pub(crate) mod testdata; diff --git a/light-client/src/misbehaviour.rs b/light-client/src/misbehaviour.rs index 3a52b8a..a1be524 100644 --- a/light-client/src/misbehaviour.rs +++ b/light-client/src/misbehaviour.rs @@ -11,7 +11,7 @@ use crate::header::Header; pub const PARLIA_MISBEHAVIOUR_TYPE_URL: &str = "/ibc.lightclients.parlia.v1.Misbehaviour"; -#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq)] pub struct Misbehaviour { pub client_id: ClientId, pub header_1: Header, diff --git a/proto-compiler/src/cmd/compile.rs b/proto-compiler/src/cmd/compile.rs index 634a57c..c2a13c3 100644 --- a/proto-compiler/src/cmd/compile.rs +++ b/proto-compiler/src/cmd/compile.rs @@ -1,12 +1,8 @@ -use std::fs::remove_dir_all; -use std::fs::{copy, create_dir_all}; +use argh::FromArgs; +use std::fs::{create_dir_all, remove_dir_all}; use std::path::{Path, PathBuf}; use std::process; - -use tempdir::TempDir; use walkdir::WalkDir; - -use argh::FromArgs; #[derive(Debug, FromArgs)] #[argh(subcommand, name = "compile")] /// Compile @@ -22,94 +18,24 @@ pub struct CompileCmd { impl CompileCmd { pub fn run(&self) { - let tmp_ibc = TempDir::new("ibc-proto-ibc-go").unwrap(); - Self::compile_ibc_protos(&self.ibc, tmp_ibc.as_ref()); - - let tmp_lcp = TempDir::new("lcp").unwrap(); - Self::compile_lcp_protos(&self.ibc, tmp_lcp.as_ref()); - - Self::copy_generated_files(tmp_lcp.as_ref(), tmp_ibc.as_ref(), &self.out); + Self::compile_protos(&self.ibc, self.out.as_ref()); } - fn compile_lcp_protos(ibc_dir: &Path, out_dir: &Path) { + fn compile_protos(ibc_dir: &Path, out_dir: &Path) { + // Remove old compiled files + remove_dir_all(&out_dir).unwrap_or_default(); + create_dir_all(&out_dir).unwrap(); + println!( - "[info ] Compiling LCP .proto files to Rust into '{}'...", + "[info ] Compiling parlia-ibc .proto files to Rust into '{}'...", out_dir.display() ); let root = env!("CARGO_MANIFEST_DIR"); - // Paths - let proto_paths = [format!("{}/../proto/definitions", root)]; - - let proto_includes_paths = [ - format!("{}/../proto/definitions", root), - format!("{}/proto", ibc_dir.display()), - format!("{}/third_party/proto", ibc_dir.display()), - ]; - - // List available proto files - let mut protos: Vec = vec![]; - for proto_path in &proto_paths { - println!("Looking for proto files in {:?}", proto_path); - protos.append( - &mut WalkDir::new(proto_path) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| { - e.file_type().is_file() - && e.path().extension().is_some() - && e.path().extension().unwrap() == "proto" - }) - .map(|e| e.into_path()) - .collect(), - ); - } - - println!("Found the following protos:"); - // Show which protos will be compiled - for proto in &protos { - println!("\t-> {:?}", proto); - } - println!("[info ] Compiling.."); - - // List available paths for dependencies - let includes: Vec = proto_includes_paths.iter().map(PathBuf::from).collect(); - let attrs_serde = r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#; - let compilation = tonic_build::configure() - .build_client(true) - .compile_well_known_types(true) - .client_mod_attribute(".", r#"#[cfg(feature = "client")]"#) - .build_server(false) - .out_dir(out_dir) - .extern_path(".tendermint", "::tendermint_proto") - .type_attribute(".ibc.lightclients.parlia.v1", attrs_serde) - .type_attribute(".cosmos.upgrade.v1beta1", attrs_serde) - .type_attribute(".cosmos.base.v1beta1", attrs_serde) - .type_attribute(".cosmos.base.query.v1beta1", attrs_serde) - .type_attribute(".cosmos.bank.v1beta1", attrs_serde) - .compile(&protos, &includes); - - match compilation { - Ok(_) => { - println!("Successfully compiled proto files"); - } - Err(e) => { - println!("Failed to compile:{:?}", e.to_string()); - process::exit(1); - } - } - } - - fn compile_ibc_protos(ibc_dir: &Path, out_dir: &Path) { - println!( - "[info ] Compiling IBC .proto files to Rust into '{}'...", - out_dir.display() - ); - // Paths let proto_paths = [ - // ibc-go proto files + format!("{}/../proto/definitions", root), format!( "{}/proto/ibc/core/client/v1/client.proto", ibc_dir.display() @@ -117,6 +43,7 @@ impl CompileCmd { ]; let proto_includes_paths = [ + format!("{}/../proto/definitions", root), format!("{}/proto", ibc_dir.display()), format!("{}/third_party/proto", ibc_dir.display()), ]; @@ -148,25 +75,16 @@ impl CompileCmd { // List available paths for dependencies let includes: Vec = proto_includes_paths.iter().map(PathBuf::from).collect(); - let attrs_serde = r#"#[derive(::serde::Serialize, ::serde::Deserialize)]"#; let attrs_jsonschema = r#"#[cfg_attr(feature = "json-schema", derive(::schemars::JsonSchema))]"#; let attrs_ord = "#[derive(Eq, PartialOrd, Ord)]"; - let attrs_eq = "#[derive(Eq)]"; let attrs_serde_default = r#"#[serde(default)]"#; - let attrs_serde_base64 = r#"#[serde(with = "crate::base64")]"#; - let attrs_jsonschema_str = - r#"#[cfg_attr(feature = "json-schema", schemars(with = "String"))]"#; - let compilation = tonic_build::configure() .build_client(true) .compile_well_known_types(true) - .client_mod_attribute(".", r#"#[cfg(feature = "client")]"#) .build_server(false) .out_dir(out_dir) - .extern_path(".tendermint", "::tendermint_proto") - .type_attribute(".ibc.lightclients.parlia.v1", attrs_serde) .type_attribute(".google.protobuf.Any", attrs_serde) .type_attribute(".google.protobuf.Timestamp", attrs_serde) .type_attribute(".google.protobuf.Duration", attrs_serde) @@ -174,60 +92,7 @@ impl CompileCmd { .type_attribute(".ibc.core.client.v1.Height", attrs_ord) .type_attribute(".ibc.core.client.v1.Height", attrs_jsonschema) .field_attribute(".ibc.core.client.v1.Height", attrs_serde_default) - .type_attribute(".ibc.core.commitment.v1", attrs_serde) - .type_attribute(".ibc.core.commitment.v1.MerkleRoot", attrs_jsonschema) - .field_attribute( - ".ibc.core.commitment.v1.MerkleRoot.hash", - attrs_serde_base64, - ) - .field_attribute( - ".ibc.core.commitment.v1.MerkleRoot.hash", - attrs_jsonschema_str, - ) - .type_attribute(".ibc.core.commitment.v1.MerklePrefix", attrs_jsonschema) - .field_attribute( - ".ibc.core.commitment.v1.MerklePrefix.key_prefix", - attrs_serde_base64, - ) - .field_attribute( - ".ibc.core.commitment.v1.MerklePrefix.key_prefix", - attrs_jsonschema_str, - ) - .type_attribute(".ibc.core.channel.v1", attrs_serde) - .type_attribute(".ibc.core.channel.v1.Channel", attrs_jsonschema) - .type_attribute(".ibc.core.channel.v1.Counterparty", attrs_jsonschema) - .type_attribute(".ibc.core.connection.v1", attrs_serde) - .type_attribute(".ibc.core.connection.v1.ConnectionEnd", attrs_jsonschema) - .type_attribute(".ibc.core.connection.v1.Counterparty", attrs_jsonschema) - .type_attribute(".ibc.core.connection.v1.Version", attrs_jsonschema) - .type_attribute(".ibc.core.types.v1", attrs_serde) - .type_attribute(".ibc.applications.transfer.v1", attrs_serde) - .type_attribute(".ibc.applications.transfer.v2", attrs_serde) - .type_attribute( - ".ibc.applications.interchain_accounts.controller.v1", - attrs_serde, - ) - .type_attribute(".ics23", attrs_serde) - .type_attribute(".ics23.LeafOp", attrs_eq) - .type_attribute(".ics23.LeafOp", attrs_jsonschema) - .field_attribute(".ics23.LeafOp.prehash_key", attrs_serde_default) - .field_attribute(".ics23.LeafOp.prefix", attrs_serde_base64) - .field_attribute(".ics23.LeafOp.prefix", attrs_jsonschema_str) - .type_attribute(".ics23.InnerOp", attrs_jsonschema) - .field_attribute(".ics23.InnerOp.prefix", attrs_serde_base64) - .field_attribute(".ics23.InnerOp.prefix", attrs_jsonschema_str) - .field_attribute(".ics23.InnerOp.suffix", attrs_serde_base64) - .field_attribute(".ics23.InnerOp.suffix", attrs_jsonschema_str) - .type_attribute(".ics23.InnerOp", attrs_eq) - .type_attribute(".ics23.ProofSpec", attrs_eq) - .type_attribute(".ics23.ProofSpec", attrs_jsonschema) - .field_attribute(".ics23.ProofSpec.max_depth", attrs_serde_default) - .field_attribute(".ics23.ProofSpec.min_depth", attrs_serde_default) - .type_attribute(".ics23.InnerSpec", attrs_eq) - .type_attribute(".ics23.InnerSpec", attrs_jsonschema) - .field_attribute(".ics23.InnerSpec.empty_child", attrs_serde_default) - .field_attribute(".ics23.InnerSpec.empty_child", attrs_serde_base64) - .field_attribute(".ics23.InnerSpec.empty_child", attrs_jsonschema_str) + .type_attribute(".cosmos.upgrade.v1beta1", attrs_serde) .compile(&protos, &includes); match compilation { @@ -240,86 +105,4 @@ impl CompileCmd { } } } - - fn copy_generated_files(from_dir_lcp: &Path, from_dir_ibc: &Path, to_dir: &Path) { - println!( - "[info ] Copying generated files into '{}'...", - to_dir.display() - ); - - // Remove old compiled files - remove_dir_all(to_dir).unwrap_or_default(); - create_dir_all(to_dir).unwrap(); - - // Copy new compiled files (prost does not use folder structures) - // Copy the SDK files first - let errors_sdk = WalkDir::new(from_dir_lcp) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_file()) - .map(|e| { - copy( - e.path(), - format!( - "{}/{}", - to_dir.display(), - &e.file_name().to_os_string().to_str().unwrap() - ), - ) - }) - .filter_map(|e| e.err()) - .collect::>(); - - if !errors_sdk.is_empty() { - for e in errors_sdk { - println!("[error] Error while copying SDK-compiled file: {}", e); - } - - panic!("[error] Aborted."); - } - - // Copy the IBC-go files second, double-checking if anything is overwritten - let errors_ibc = WalkDir::new(from_dir_ibc) - .into_iter() - .filter_map(|e| e.ok()) - .filter(|e| e.file_type().is_file()) - .map(|e| { - let generated_fname = e.file_name().to_owned().into_string().unwrap(); - let prefix = &generated_fname[0..6]; - - let target_fname = format!( - "{}/{}", - to_dir.display(), - generated_fname, - ); - - // If it's a cosmos-relevant file and it exists, we should not overwrite it. - if Path::new(&target_fname).exists() && prefix.eq("cosmos") { - let original_cosmos_file = std::fs::read(target_fname.clone()).unwrap(); - let new_cosmos_file = std::fs::read(e.path()).unwrap(); - if original_cosmos_file != new_cosmos_file { - println!( - "[warn ] Cosmos-related file exists already {}! Ignoring the one generated from IBC-go {:?}", - target_fname, e.path() - ); - } - Ok(0) - } else { - copy( - e.path(), - target_fname, - ) - } - }) - .filter_map(|e| e.err()) - .collect::>(); - - if !errors_ibc.is_empty() { - for e in errors_ibc { - println!("[error] Error while copying IBC-go compiled file: {}", e); - } - - panic!("[error] Aborted."); - } - } -} \ No newline at end of file +} diff --git a/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto b/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto index 3774a80..952ebb1 100644 --- a/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto +++ b/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto @@ -5,6 +5,7 @@ option (gogoproto.goproto_getters_all) = false; import "gogoproto/gogo.proto"; import "ibc/core/client/v1/client.proto"; +import "google/protobuf/duration.proto"; message ClientState { uint64 chain_id = 1; @@ -14,7 +15,8 @@ message ClientState { ibc.core.client.v1.Height latest_height = 4; - uint64 trusting_period = 6; + google.protobuf.Duration trusting_period = 5; + google.protobuf.Duration max_clock_drift = 6; bool frozen = 7; } diff --git a/proto/src/google.rs b/proto/src/google.rs new file mode 100644 index 0000000..acc1b58 --- /dev/null +++ b/proto/src/google.rs @@ -0,0 +1,236 @@ +// This mod is a copy from https://github.com/informalsystems/ibc-rs/blob/e8c98d440949abf971ac45a68ed9dd9e6e9f48ed/proto/src/google.rs +pub mod protobuf { + use crate::include_proto; + include_proto!("google.protobuf.rs"); + + // source: https://github.com/tokio-rs/prost/blob/master/prost-types/src/lib.rs + #[allow(unused_imports)] + use core::convert::TryFrom; + use core::i32; + use core::i64; + #[allow(unused_imports)] + use core::time; + + // The Protobuf `Duration` and `Timestamp` types can't delegate to the standard library equivalents + // because the Protobuf versions are signed. To make them easier to work with, `From` conversions + // are defined in both directions. + + #[allow(dead_code)] + const NANOS_PER_SECOND: i32 = 1_000_000_000; + const NANOS_MAX: i32 = NANOS_PER_SECOND - 1; + + impl Duration { + /// Normalizes the duration to a canonical format. + pub fn normalize(&mut self) { + // Make sure nanos is in the range. + if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { + if let Some(seconds) = self + .seconds + .checked_add((self.nanos / NANOS_PER_SECOND) as i64) + { + self.seconds = seconds; + self.nanos %= NANOS_PER_SECOND; + } else if self.nanos < 0 { + // Negative overflow! Set to the least normal value. + self.seconds = i64::MIN; + self.nanos = -NANOS_MAX; + } else { + // Positive overflow! Set to the greatest normal value. + self.seconds = i64::MAX; + self.nanos = NANOS_MAX; + } + } + + // nanos should have the same sign as seconds. + if self.seconds < 0 && self.nanos > 0 { + if let Some(seconds) = self.seconds.checked_add(1) { + self.seconds = seconds; + self.nanos -= NANOS_PER_SECOND; + } else { + // Positive overflow! Set to the greatest normal value. + debug_assert_eq!(self.seconds, i64::MAX); + self.nanos = NANOS_MAX; + } + } else if self.seconds > 0 && self.nanos < 0 { + if let Some(seconds) = self.seconds.checked_sub(1) { + self.seconds = seconds; + self.nanos += NANOS_PER_SECOND; + } else { + // Negative overflow! Set to the least normal value. + debug_assert_eq!(self.seconds, i64::MIN); + self.nanos = -NANOS_MAX; + } + } + } + } + + /// Converts a `std::time::Duration` to a `Duration`. + impl From for Duration { + fn from(duration: time::Duration) -> Duration { + let seconds = duration.as_secs(); + let seconds = if seconds > i64::MAX as u64 { + i64::MAX + } else { + seconds as i64 + }; + let nanos = duration.subsec_nanos(); + let nanos = if nanos > i32::MAX as u32 { + i32::MAX + } else { + nanos as i32 + }; + let mut duration = Duration { seconds, nanos }; + duration.normalize(); + duration + } + } + + impl TryFrom for time::Duration { + type Error = time::Duration; + + /// Converts a `Duration` to a result containing a positive (`Ok`) or negative (`Err`) + /// `std::time::Duration`. + fn try_from(mut duration: Duration) -> Result { + duration.normalize(); + if duration.seconds >= 0 { + Ok(time::Duration::new( + duration.seconds as u64, + duration.nanos as u32, + )) + } else { + Err(time::Duration::new( + (-duration.seconds) as u64, + (-duration.nanos) as u32, + )) + } + } + } + + impl Timestamp { + /// Normalizes the timestamp to a canonical format. + #[cfg(feature = "std")] + pub fn normalize(&mut self) { + // Make sure nanos is in the range. + if self.nanos <= -NANOS_PER_SECOND || self.nanos >= NANOS_PER_SECOND { + if let Some(seconds) = self + .seconds + .checked_add((self.nanos / NANOS_PER_SECOND) as i64) + { + self.seconds = seconds; + self.nanos %= NANOS_PER_SECOND; + } else if self.nanos < 0 { + // Negative overflow! Set to the earliest normal value. + self.seconds = i64::MIN; + self.nanos = 0; + } else { + // Positive overflow! Set to the latest normal value. + self.seconds = i64::MAX; + self.nanos = 999_999_999; + } + } + + // For Timestamp nanos should be in the range [0, 999999999]. + if self.nanos < 0 { + if let Some(seconds) = self.seconds.checked_sub(1) { + self.seconds = seconds; + self.nanos += NANOS_PER_SECOND; + } else { + // Negative overflow! Set to the earliest normal value. + debug_assert_eq!(self.seconds, i64::MIN); + self.nanos = 0; + } + } + } + } + + /// Implements the unstable/naive version of `Eq`: a basic equality check on the internal fields of the `Timestamp`. + /// This implies that `normalized_ts != non_normalized_ts` even if `normalized_ts == non_normalized_ts.normalized()`. + #[cfg(feature = "std")] + impl Eq for Timestamp {} + + #[cfg(feature = "std")] + #[allow(clippy::derived_hash_with_manual_eq)] // Derived logic is correct: comparing the 2 fields for equality + impl std::hash::Hash for Timestamp { + fn hash(&self, state: &mut H) { + self.seconds.hash(state); + self.nanos.hash(state); + } + } + + #[cfg(feature = "std")] + impl From for Timestamp { + fn from(system_time: std::time::SystemTime) -> Timestamp { + let (seconds, nanos) = match system_time.duration_since(std::time::UNIX_EPOCH) { + Ok(duration) => { + let seconds = i64::try_from(duration.as_secs()).unwrap(); + (seconds, duration.subsec_nanos() as i32) + } + Err(error) => { + let duration = error.duration(); + let seconds = i64::try_from(duration.as_secs()).unwrap(); + let nanos = duration.subsec_nanos() as i32; + if nanos == 0 { + (-seconds, 0) + } else { + (-seconds - 1, 1_000_000_000 - nanos) + } + } + }; + Timestamp { seconds, nanos } + } + } + + /// Indicates that a [`Timestamp`] could not be converted to + /// [`SystemTime`][std::time::SystemTime] because it is out of range. + /// + /// The range of times that can be represented by `SystemTime` depends on the platform. + /// All `Timestamp`s are likely representable on 64-bit Unix-like platforms, but + /// other platforms, such as Windows and 32-bit Linux, may not be able to represent + /// the full range of `Timestamp`s. + #[cfg(feature = "std")] + #[derive(Debug)] + #[non_exhaustive] + pub struct TimestampOutOfSystemRangeError { + pub timestamp: Timestamp, + } + + #[cfg(feature = "std")] + impl core::fmt::Display for TimestampOutOfSystemRangeError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!( + f, + "{:?} is not representable as a `SystemTime` because it is out of range", + self + ) + } + } + + #[cfg(feature = "std")] + impl std::error::Error for TimestampOutOfSystemRangeError {} + + #[cfg(feature = "std")] + impl TryFrom for std::time::SystemTime { + type Error = TimestampOutOfSystemRangeError; + + fn try_from(mut timestamp: Timestamp) -> Result { + let orig_timestamp = timestamp.clone(); + timestamp.normalize(); + + let system_time = if timestamp.seconds >= 0 { + std::time::UNIX_EPOCH + .checked_add(time::Duration::from_secs(timestamp.seconds as u64)) + } else { + std::time::UNIX_EPOCH + .checked_sub(time::Duration::from_secs((-timestamp.seconds) as u64)) + }; + + let system_time = system_time.and_then(|system_time| { + system_time.checked_add(time::Duration::from_nanos(timestamp.nanos as u64)) + }); + + system_time.ok_or(TimestampOutOfSystemRangeError { + timestamp: orig_timestamp, + }) + } + } +} diff --git a/proto/src/prost/google.protobuf.rs b/proto/src/prost/google.protobuf.rs index bd81d8f..518a909 100644 --- a/proto/src/prost/google.protobuf.rs +++ b/proto/src/prost/google.protobuf.rs @@ -1378,3 +1378,81 @@ pub struct Timestamp { #[prost(int32, tag = "2")] pub nanos: i32, } +/// A Duration represents a signed, fixed-length span of time represented +/// as a count of seconds and fractions of seconds at nanosecond +/// resolution. It is independent of any calendar and concepts like "day" +/// or "month". It is related to Timestamp in that the difference between +/// two Timestamp values is a Duration and it can be added or subtracted +/// from a Timestamp. Range is approximately +-10,000 years. +/// +/// # Examples +/// +/// Example 1: Compute Duration from two Timestamps in pseudo code. +/// +/// Timestamp start = ...; +/// Timestamp end = ...; +/// Duration duration = ...; +/// +/// duration.seconds = end.seconds - start.seconds; +/// duration.nanos = end.nanos - start.nanos; +/// +/// if (duration.seconds < 0 && duration.nanos > 0) { +/// duration.seconds += 1; +/// duration.nanos -= 1000000000; +/// } else if (duration.seconds > 0 && duration.nanos < 0) { +/// duration.seconds -= 1; +/// duration.nanos += 1000000000; +/// } +/// +/// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. +/// +/// Timestamp start = ...; +/// Duration duration = ...; +/// Timestamp end = ...; +/// +/// end.seconds = start.seconds + duration.seconds; +/// end.nanos = start.nanos + duration.nanos; +/// +/// if (end.nanos < 0) { +/// end.seconds -= 1; +/// end.nanos += 1000000000; +/// } else if (end.nanos >= 1000000000) { +/// end.seconds += 1; +/// end.nanos -= 1000000000; +/// } +/// +/// Example 3: Compute Duration from datetime.timedelta in Python. +/// +/// td = datetime.timedelta(days=3, minutes=10) +/// duration = Duration() +/// duration.FromTimedelta(td) +/// +/// # JSON Mapping +/// +/// In JSON format, the Duration type is encoded as a string rather than an +/// object, where the string ends in the suffix "s" (indicating seconds) and +/// is preceded by the number of seconds, with nanoseconds expressed as +/// fractional seconds. For example, 3 seconds with 0 nanoseconds should be +/// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should +/// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 +/// microsecond should be expressed in JSON format as "3.000001s". +/// +/// +#[derive(::serde::Serialize, ::serde::Deserialize)] +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Duration { + /// Signed seconds of the span of time. Must be from -315,576,000,000 + /// to +315,576,000,000 inclusive. Note: these bounds are computed from: + /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + #[prost(int64, tag = "1")] + pub seconds: i64, + /// Signed fractions of a second at nanosecond resolution of the span + /// of time. Durations less than one second are represented with a 0 + /// `seconds` field and a positive or negative `nanos` field. For durations + /// of one second or more, a non-zero value for the `nanos` field must be + /// of the same sign as the `seconds` field. Must be from -999,999,999 + /// to +999,999,999 inclusive. + #[prost(int32, tag = "2")] + pub nanos: i32, +} diff --git a/proto/src/prost/ibc.lightclients.parlia.v1.rs b/proto/src/prost/ibc.lightclients.parlia.v1.rs index 653d11c..4c2bca6 100644 --- a/proto/src/prost/ibc.lightclients.parlia.v1.rs +++ b/proto/src/prost/ibc.lightclients.parlia.v1.rs @@ -1,4 +1,3 @@ -#[derive(::serde::Serialize, ::serde::Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ClientState { @@ -12,19 +11,23 @@ pub struct ClientState { pub latest_height: ::core::option::Option< super::super::super::core::client::v1::Height, >, - #[prost(uint64, tag = "6")] - pub trusting_period: u64, + #[prost(message, optional, tag = "5")] + pub trusting_period: ::core::option::Option< + super::super::super::super::google::protobuf::Duration, + >, + #[prost(message, optional, tag = "6")] + pub max_clock_drift: ::core::option::Option< + super::super::super::super::google::protobuf::Duration, + >, #[prost(bool, tag = "7")] pub frozen: bool, } -#[derive(::serde::Serialize, ::serde::Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct EthHeader { #[prost(bytes = "vec", tag = "1")] pub header: ::prost::alloc::vec::Vec, } -#[derive(::serde::Serialize, ::serde::Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Header { @@ -43,7 +46,6 @@ pub struct Header { #[prost(bytes = "vec", repeated, tag = "6")] pub target_validators: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, } -#[derive(::serde::Serialize, ::serde::Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct ConsensusState { @@ -56,7 +58,6 @@ pub struct ConsensusState { #[prost(uint64, tag = "4")] pub validator_size: u64, } -#[derive(::serde::Serialize, ::serde::Deserialize)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Misbehaviour { From 4aa1de3300830f0039a52d2f70416083f35a8dd4 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 8 Sep 2023 17:59:22 +0900 Subject: [PATCH 3/7] use TrustingPeriodContext on update_client Signed-off-by: Naohiro Yoshida --- light-client/src/client.rs | 43 +++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/light-client/src/client.rs b/light-client/src/client.rs index 5bbb3ef..84676d4 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -1,6 +1,7 @@ use alloc::string::{String, ToString}; use alloc::vec::Vec; +use light_client::commitments::TrustingPeriodContext; use light_client::{ commitments::{ gen_state_id_from_any, CommitmentContext, CommitmentPrefix, StateCommitment, StateID, @@ -108,6 +109,9 @@ impl LightClient for ParliaLightClient { header, )?; + let trusted_state_timestamp = latest_trusted_consensus_state.timestamp; + let trusting_period = client_state.trusting_period; + let max_clock_drift = client_state.max_clock_drift; let prev_state_id = gen_state_id(client_state, latest_trusted_consensus_state)?; let new_state_id = gen_state_id(new_client_state.clone(), new_consensus_state.clone())?; @@ -121,8 +125,13 @@ impl LightClient for ParliaLightClient { new_state: None, prev_height: Some(trusted_height), new_height: height, - timestamp, - context: CommitmentContext::Empty, + timestamp: timestamp.clone(), + context: CommitmentContext::TrustingPeriod(TrustingPeriodContext::new( + trusting_period, + max_clock_drift, + timestamp, + trusted_state_timestamp, + )), } .into(), prove: true, @@ -345,7 +354,7 @@ mod test { use hex_literal::hex; use light_client::types::{Any, ClientId, Height, Time}; - use light_client::commitments::Commitment; + use light_client::commitments::{Commitment, CommitmentContext, TrustingPeriodContext}; use light_client::{ClientReader, HostClientReader, HostContext, LightClient}; use patricia_merkle_trie::keccak::keccak_256; @@ -498,7 +507,8 @@ mod test { let client = ParliaLightClient::default(); let client_id = ClientId::new(&client.client_type(), 1).unwrap(); let mut mock_consensus_state = BTreeMap::new(); - mock_consensus_state.insert(Height::new(0, trusted_height), ConsensusState::default()); + let trusted_cs = ConsensusState::default(); + mock_consensus_state.insert(Height::new(0, trusted_height), trusted_cs.clone()); let epoch_cs = ConsensusState { validators_hash: target_validator_hash, validators_size: target_validator_size, @@ -506,13 +516,14 @@ mod test { }; mock_consensus_state.insert(Height::new(0, c_epoch_height), epoch_cs.clone()); mock_consensus_state.insert(Height::new(0, c_epoch_height - BLOCKS_PER_EPOCH), epoch_cs); + let cs = ClientState { + chain_id: ChainId::new(56), + ibc_store_address: hex!("151f3951FA218cac426edFe078fA9e5C6dceA500"), + latest_height: Height::new(0, height), + ..Default::default() + }; let ctx = MockClientReader { - client_state: Some(ClientState { - chain_id: ChainId::new(56), - ibc_store_address: hex!("151f3951FA218cac426edFe078fA9e5C6dceA500"), - latest_height: Height::new(0, height), - ..Default::default() - }), + client_state: Some(cs.clone()), consensus_state: mock_consensus_state, }; match client.update_client(&ctx, client_id, any) { @@ -540,6 +551,18 @@ mod test { ); assert!(data.prev_state_id.is_some()); assert_eq!(data.timestamp, header.timestamp().unwrap()); + match &data.context { + CommitmentContext::TrustingPeriod(actual) => { + let expected = TrustingPeriodContext::new( + cs.trusting_period, + cs.max_clock_drift, + header.timestamp().unwrap(), + trusted_cs.timestamp, + ); + assert_eq!(format!("{}", actual), format!("{}", expected)); + } + _ => unreachable!("invalid commitment context {:?}", data.context), + } } _ => unreachable!("invalid commitment {:?}", data.commitment), } From 655e7267ae0cb0db16484f37d7877d6289ecd087 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Fri, 8 Sep 2023 19:15:18 +0900 Subject: [PATCH 4/7] add option Signed-off-by: Naohiro Yoshida --- proto/definitions/ibc/lightclients/parlia/v1/parlia.proto | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto b/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto index 952ebb1..50a327d 100644 --- a/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto +++ b/proto/definitions/ibc/lightclients/parlia/v1/parlia.proto @@ -15,8 +15,8 @@ message ClientState { ibc.core.client.v1.Height latest_height = 4; - google.protobuf.Duration trusting_period = 5; - google.protobuf.Duration max_clock_drift = 6; + google.protobuf.Duration trusting_period = 5 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; + google.protobuf.Duration max_clock_drift = 6 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true]; bool frozen = 7; } From 5d2de72447ad68a5144605efcd015dfd8325c552 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Sun, 10 Sep 2023 14:55:02 +0900 Subject: [PATCH 5/7] fix clippy Signed-off-by: Naohiro Yoshida --- light-client/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/light-client/src/client.rs b/light-client/src/client.rs index 84676d4..ab9a290 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -125,7 +125,7 @@ impl LightClient for ParliaLightClient { new_state: None, prev_height: Some(trusted_height), new_height: height, - timestamp: timestamp.clone(), + timestamp, context: CommitmentContext::TrustingPeriod(TrustingPeriodContext::new( trusting_period, max_clock_drift, From 77403261262e8a0faae8d6065b29b34a9a202531 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Sun, 10 Sep 2023 16:22:15 +0900 Subject: [PATCH 6/7] add test Signed-off-by: Naohiro Yoshida --- light-client/src/client.rs | 33 ++++++++++++++++++++++++++++++++ light-client/src/client_state.rs | 3 ++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/light-client/src/client.rs b/light-client/src/client.rs index ab9a290..226393b 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -443,6 +443,39 @@ mod test { } } + #[test] + fn test_success_create_client() { + let client_state = hex!("0a272f6962632e6c69676874636c69656e74732e7061726c69612e76312e436c69656e745374617465124a088f4e1214aa43d337145e8930d01cb4e60abf6595c692921e1a200000000000000000000000000000000000000000000000000000000000000000220310c8012a020864320410c0843d").to_vec(); + let consensus_state = hex!("0a2a2f6962632e6c69676874636c69656e74732e7061726c69612e76312e436f6e73656e737573537461746512460a20c3608871098f21b59607ef3fb9412a091de9246ad1281a92f5b07dc2f465b7a01a2095ec85e33c9b37a199994464ea84512a8ebbb62dea3817dbe2f8eacd7c702ff12015").to_vec(); + let client = ParliaLightClient::default(); + let mock_consensus_state = BTreeMap::new(); + let ctx = MockClientReader { + client_state: None, + consensus_state: mock_consensus_state, + }; + let any_client_state: Any = client_state.try_into().unwrap(); + let any_consensus_state: Any = consensus_state.try_into().unwrap(); + let result = client + .create_client(&ctx, any_client_state.clone(), any_consensus_state.clone()) + .unwrap(); + assert_eq!(result.height.revision_height(), 200); + match result.commitment { + Commitment::UpdateClient(data) => { + assert_eq!(data.new_height.revision_height(), 200); + let cs = ConsensusState::try_from(any_consensus_state).unwrap(); + assert_eq!( + data.timestamp.as_unix_timestamp_secs(), + cs.timestamp.as_unix_timestamp_secs() + ); + assert_eq!(data.new_state.unwrap(), any_client_state); + assert!(!data.new_state_id.to_vec().is_empty()); + assert!(data.prev_height.is_none()); + assert!(data.prev_state_id.is_none()); + } + _ => unreachable!("invalid commitment"), + } + } + #[test] fn test_success_update_client_epoch() { let header = hex!("0a222f6962632e6c69676874636c69656e74732e7061726c69612e76312e48656164657212f14b0ab2110aaf11f908aca0f6ac769a0025c9f14f3b68a2c62512a923edda1f47a388d50f978d0d4a4570dea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347942d4c407bbe49438ed859fe965b140dcf1aab71a9a07e850baa1d540ac80cd46bd19d45d44a46b288bf223fc59168a98c941499ed8fa0dcfb0664efb647d1eabb456349d81c9d449120152f3ad534ef605a6e63be3751a0710b44dd29d5b630d62052c5529dd0a23693f830c249f0687668ebbe72bc56c0b901000db012f4a444755a0a5cb26c941000cad620f100a3885850af0bfd0b37f3311487241a2575af0205c268386c41be321780fa32d0104e76f0c70210da252436d8ce4d4529a95830a0075e588df323f43d69911de719c60412c48cdd6ce862e400df6c09668a469c312a47e390811c19290dc958f3190bf4ae4685fc55104805a2206ab144913438283a9c740555c0aabc16ae0489e9201648139820c0dcc054292b22289052879b717e4c2f3c62a76604ecaf80b36f9eb683db04602360586c8fab3ede063055d85332931023b5c2b024b751a2421c8804f60379f5bb9762e5613ad28b0588f748010bb7a4660943a30119748b200594c45c353d6cc2f820005e028401e0ab908408583b0083b4ce368464f8408bb906add88301020b846765746888676f312e31392e38856c696e7578000000b19df4a2150bac492386862ad3df4b666bc096b0505bb694dab0bec348681af766751cb839576e9c515a09c8bffa30a46296ccc56612490eb480d03bf948e10005bbcc0421f90b3d4e2465176c461afb316ebc773c61faee85a6515daa8a923564c6ffd37fb2fe9f118ef88092e8762c7addb526ab7eb1e772baef85181f892c731be0c1891a50e6b06262c816295e26495cef6f69dfa69911d9d8e4f3bbadb89b977cf58294f7239d515e15b24cfeb82494056cf691eaf729b165f32c9757c429dba5051155903067e56ebe3698678e912d4c407bbe49438ed859fe965b140dcf1aab71a993c1f7f6929d1fe2a17b4e14614ef9fc5bdc713d6631d675403fbeefac55611bf612700b1b65f4744861b80b0f7d6ab03f349bbafec1551819b8be1efea2fc46ca749aa184248a459464eec1a21e7fc7b71a053d9644e9bb8da4853b8f872cd7c1d6b324bf1922829830646ceadfb658d3de009a61dd481a114a2e761c554b641742c973867899d38a80967d39e406a0a9642d41e9007a27fc1150a267d143a9f786cd2b5eecbdcc4036273705225b956d5e2f8f5eb95d25685b1ded8013785d6623cc18d214320b6bb647598a60f82a7bcf74b4cb053b9bfe83d0ed02a84ebb10865dfdd8e26e7535c43a1cccd268e860f502216b379dfc9971d35870f657164e5b75689b64b7fd1fa275f334f28e1896a26afa1295da81418593bd12814463d9f6e45c36a0e47eb4cd3e5b6af29c41e2a3a5636430155a466e216585af3ba772b61c6014342d914470ec7ac2975be345796c2b81db0422a5fd08e40db1fc2368d2245e4b18b1d0b85c921aaaafd2e341760e29fc613edd39f71254614e2055c3287a517ae2f5b9e386cd1b50a4550696d957cb4900f03ab84f83ff2df44193496793b847f64e9d6db1b3953682bb95edd096eb1e69bbd357c200992ca78050d0cbe180cfaa018e8b6c8fd93d6f4cea42bbb345dbc6f0dfdb5bec73a8a257074e82b881cfa06ef3eb4efeca060c2531359abd0eab8af1e3edfa2025fca464ac9c3fd123f6c24a0d78869485a6f79b60359f141df90a0c745125b131caaffd12b772e180fbf38a051c97dabc8aaa0126a233a9e828cdafcc7422c4bb1f4030a56ba364c54103f26bad91508b5220b741b218c5d6af1f979ac42bc68d98a5a0d796c6ab01b659ad0fbd9f515893fdd740b29ba0772dbde9b4635921dd91bd2963a0fc855e31f6338f45b211c4e9dedb7f2eb09de7b4dd66d7c2c7e57f628210187192fb89d4b99dd4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000be807dddb074639cd9fa61b47676c064fc50d62cb1f2c71577def3144fabeb75a8a1c8cb5b51d1d1b4a05eec67988b8685008baa17459ec425dbaebc852f496dc92196cdcc8e6d00c17eb431350c6c50d8b8f05176b90b11b3a3d4feb825ae9702711566df5dbf38e82add4dd1b573b95d2466fa6501ccb81e9d26a352b96150ccbf7b697fd0a419d1d6bf74282782b0b3eb1413c901d6ecf02e8e28939e8fb41b682372335be8070199ad3e8621d1743bcac4cc9d8f0f6e10f41e56461385c8eb5daac804fe3f2bca6ce739e9ae3261a475a27bb1028f140bc2a7c843318afd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ea0a6e3c511bbd10f4519ece37dc24887e11b55db2d4c6283c44a1c7bd503aaba7666e9f0c830e0ff016c1c750a5e48757a713d0836b1cabfd5c281b1de3b77d1c192183ee226379db83cffc681495730c11fdde79ba4c0cae7bc6faa3f0cc3e6093b633fd7ee4f86970926958d0b7ec80437f936acf212b78f0cd095f4565fff144fd458d233a5bef0274e31810c9df02f98fafde0f841f4e66a1cd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f8b5830577ffb860ab6d818df2c2bd16619fa980d394da1ffbd28da874f0fc870ae32767f6ae404b75ff5e291c69275f4603ed9071a0fe1416ffdd01b440c682c5b34d0c78564a9ba712033fcdfbcb847995c9b16294ee198dd225f7f5f1ad96a03222ae5ef9b3c8f84c8401e0ab8ea07cfcbc85fd81638aacbf263d8482ffa2686d99f3bfe4579123f03c0b42f638068401e0ab8fa0f6ac769a0025c9f14f3b68a2c62512a923edda1f47a388d50f978d0d4a4570de8033b0debefa5bf4e7b9c865412beae551bb5a5c3f95464f0887bdd95c60a6a6b6539a36d150c6187b53712a19c7e3a673b8657a597f1d9f39fb8b21a7d6253c5b00a0000000000000000000000000000000000000000000000000000000000000000088000000000000000080129e060a9b06f90318a07cfcbc85fd81638aacbf263d8482ffa2686d99f3bfe4579123f03c0b42f63806a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794295e26495cef6f69dfa69911d9d8e4f3bbadb89ba0354a24783ddc9355e2982eccada0c2986832c57acf83e9d4e9ecd5d988a344b3a007fca39575f2d97362214b9e5151fa218102eaa759369a15cb89a0d1fc5ab1c9a03d03b92d4902c2d7930fc5c4fede5634d65356175ad26dcca41c9a795009130cb901007cfafaedd478541aaf5c3256969a5a76f75bfe229e9c137f6e8bdfeed093c9b296499ef675ace88957eb7c9d5fba2e30e63fe459310937ce7096aaee462dfefeccc87e701d549829c9feffee8bb598fd29dd4aef366eab4e36fcfca5fc6e3ed85a5cee778fce3c3d6b5357de47d61c9bcfbd40ef19c9ffbc26268e71dd724b3d4d9aa0942eabc7cf3f89b647fa42e9b8bfbefdcb6f3c77eb2f5219d889c4792c0e028691f6ced37faf7e8ed7efdce714fcb52e5dfbaf6f395f943abbfddec8f3b8b75f626c3b4ccf3df562b929eaba64eae5f4641d9cd555fb55557efa6df5fdddbf87c5b3cbfb264f6fcec7e1b579207f7cc6b1ef3f434eedf3851d1b75ddd6028401e0ab8f8408583b008401543eb08464f84088b90118d883010209846765746888676f312e32302e36856c696e7578000000b19df4a2f8b5830577ffb860894a04f0c835981bf5c08144180ffc024d07b3c21f01ccadb30f629f83b9239cc9d518d0a7e5e772e318d532dbbd641113613b93366b9b5855c398852f680d0b172ae56a8a3eee46018e2cbd0f9cc43ac33b659324438fa396ae20f81dff20cdf84c8401e0ab8da00ba1291c1d179a1bb21f9dc587a79655177780f1c5cc67d7b0e69588b9ce21108401e0ab8ea07cfcbc85fd81638aacbf263d8482ffa2686d99f3bfe4579123f03c0b42f638068073589c5e96971f030d75344cca1ed56a4825e0632d2ca6bb8531b08415ec23f949f7216aa6a8c6517bfdd502c2a3c67cbd099937f71fdcbee072c92826b8e66701a00000000000000000000000000000000000000000000000000000000000000000880000000000000000801a05108fd7820f22951df90e92f90211a00964e3155b81fe7c9327a9284f05f4296d6a04a4d6730ba1f634f2152277f6cda0957e41ffbf96a4e0f3f43060b8e4adbe4150e04ab2935b971fab4f227b167654a0528c1031fab6ff52277beb5aeae6ccc030a9d93c691ccd20c89ddb1a73734449a046d99bbaa3833bef5f9dbda789c9154d0f1e623b5d5e429645009d69f38ea0a9a0c2f8d760e6c456185e994aefbb2865f47e705fc60dd85038bf9cd05198b375cda09e9bc8ae5d61e19d8050fc16d792acbde61f7f08523c262272572316abd223a2a08d672502afb93970e159fe82f6eb85220fa1a0792c8c1b682ea25ea3563ca8dfa024bf8aa60ad87263ec488a48ddb000a742eea3b6e26686c1366ea8587a41be28a0b2fa2f805f410f8b1e6cb66b712e819823cff50ba917bcb182a33a49636e8bb0a09781513539ef27bf289c664bb9be7468cbf85725bd5861a039cabfba483c6ac0a0b25a1d7a76ae229e2d44041c46fbfef2ddba9868204e864377835a530b64fd88a062ca1a5ff0c05a14a06642caee0bca8fd9313dae192408e3ab1b244daa3efdd0a06d1061ddd8438e3110f7303e9bd0c6b9f74968b00d604ee33d4abe66a91812b3a016c17aa400ae30d87672284167c9b8e07dd7bb1e51008fb3d60b328a01150f89a0955750ed8af97233861684d3df1edb1231d4634255b0c2bec2a08134bd16b688a0cecb933aff647eb790f69f0339a2e9002d1c411a4f1453761665e96c43a80ccf80f90211a0c668792835d296132453b796d127fe4cfbcba68622b96e642452465254ce9676a0eab2edd59f6a24564f5382c5d152b2d6ed63f61e4be71722e1e2e395be0940a1a001fdea6466fb10d421a12e72959699a4292f47df4d2fcd020c95095cad36398ea06411c14c3957ef14d7f25e33a69202af63e6da360d1770e3b7fee487db46f57ca0662431334b01d1687f1c5e31219e8efd20adf7d03c19233dc1d8c0e33170ab04a0f19584ad036dc3597066d93a999009e40984458eaab4f900320c7475fc83fd0aa0b0b62cc119478d1736ea03d78a54a845b9f07802bc0b304023d9b8b8a242d6a5a0215e013cbcf3c7e164d7622a6bed8a8d31d5dc458ec303de2613fb9088fcb574a0d0c2e83e204fae24926c2b54af8f460cd608c2792d62bfa0817c062227f23aeaa0982481dc3324991e287a36ff98f62140ec350fb205ce73c40861d1b537ca567ba0973a0c050970303707cbf4518548753e6694ea7b39a102e43a2075d6a1dad584a07f337826faccc425946bc62304eed22557c8a2f0c0e9ce579d577f44b1ab5b24a088328aa6bfc4d16e10116bc0ee52b4bfe79be230ae08b0cdd425591c86019346a030262756bcdd2eaa6e004a332501939575fb51d1264c88a32b0df79c15a42ad7a057a30ecfff488bc881fdd972a678595ea60924773f4a9ff11e6a65d64f72e64da017f758d2044ddbea0f33de984985dfbb0d8664e454a53fe1ef2f85c09ff989cf80f90211a0c77ac60eb17a20b5c80b83036dbf6811cd0aef0a6bc1b2a2153a75642c147c33a093200ba226d6b0b33b7ce2446a96251575db6d801be8ffd61d61d4c9e18b1928a0b70ffe8303b0075b2fa611d67f064c7fec59bb9403b11ac0e8b821c7599ebedca03e4ff222417bec1f369a5bd1f451d72f56910c31dd052d16e31d38753a404c28a0d49c1ac57fc9c833e71844a858ba560ac599497d7b8d35fcf859513670dcba36a01fff647eca8a9627d525db8b18c6633f8e021e1123faf47cf629badceb529c55a0eb545ef6a47e949b786149d24e35cd4a60dc7165af9bdcf7933bab1c83f1a98da00514000c38197916cd26cb3949d68880cbcbce09f3e8646bc11ea53473639c0da083c06439a937b48ab457a654b2f24eed307d6db2d86de6bd481a0ae4fb055fa9a04bc0c2dd7f7fd9bdd0100db71520be8dd15520796f75023448c86efbb05110fba07f53ad5c27c83b8b868c1a8f2c2b54d720a32ec2206b15c2c44121fc1a495aa7a090d69477356d1c46d2f1b61847bf07a9098d3e45de19e5a88029177d551bdca2a0fa7c2949fb48cb97d04232ca0c14dbc5cd19f9a7e1e16e4f3f255430b6b04b42a01a6d05a474a53ba7cc9bb18eead8da7baf94e5782b51d9a2eeb2a98f68b76246a0c09ed689e6f3f3a6e1df9b9166091a1efcd9a47b0d72e5c12bf169738f92fdd0a004089d3d926ddd731f8c21457c5a8eff5cfa4b1bdb961908234701a4e7c8786280f90211a0dce33de62bf49fdbf1d19e0fdcdf7316b3e9e9ee28e936c944501325cde41245a0a6cef11baa7cdf85210135c2bc68973f8e949f861a7397bddddf55147f94e2dea08c29f96efc5cc63adaadad0e4b3744f3c0885dcdee2c02fd40583185f6e53b7fa042fed6400a66aef5f2e3c55636f49854f489881f089526a003ac78ecb42bafcaa0cbc367ca405a383f79dd4d3093ec402971c3247b1ccdae582f9a3367ce725d41a09b7bc1daf4e8e5e1cc66aae5eb99a35c4a0db889f9000d5458543da691d4da44a03031591e222c77f503c53473dd7196a6666c6bb04a1400829653fcfb49d119eda03930a8efca0e9cff8d775129523b348158b6be19c64e6201ed2e00812d752c2aa0f8ff11e818899b1c883c246af93b4c51071520f5426fe94ba74fd048626446afa0385401466420285419fdf931b147158e190d8dc09fae48acd09a77f81d51096da0dfac6948957e8c37e3ca9e4099ad01019ec7093bd76659b01f8457e83d6939aca03f75966fa80aa9b4cd0a24033937132d18f3dbc506fdd3c3d7a443a5c120becea03e063f9663a92a03f0420fb81c31f80948adf88992e49b9f7255efc4c65512d7a0de3920cd5b33f70046dbcc501aeb61c419d80d751aeee6179fc0a8dbc5fc8832a0420ed21a865ef6da26e12bd3cb40fd8bde2eaebea90c2ed94e1d32cebbeb80a1a00d2179d2e9ef7bce1325f27a3a0cd57e74addf198704e36c89c0065ace417b8f80f90211a09266cc171961bdbe99b5d3e81222891584360854ab3bd0ba637b0328045638cfa0701a701e14ff5249c51efc72d994fdb08774307c79c6de9cc6fa40d0ef822be2a0bfe5ac7b3ede31763437dbbabf98627676721edea9c9f536c75cd8a705905e48a0ed9b9413f89286332c3dd5e7047bcdfc571e14a5345e74b727befc02e612ad49a096ac70b809e1cc20c66b9777dbf64d6ab9761c8fbb8a9bc7ceb7b13ddc5700bda0d34c641dc1ef3491414764589b9ba400d1031fd5762401769b75381284b27aa9a02c8e199513447acad095bc3055d8ddde105b40e08816f48ab794f85dd6b8247fa0a908de3ec739b00b9d10c8dc00f628e890970f9aa9aef9a86cf9a1f6b22ff6f1a0f1b54ec574ab3ea2c76c90f1241ab0d74f4c8da90749f81d9f118366105bcf0ca04f3ae8e50f70c066723b2208e8330af99fa42a0fd764c88f40585c1948648a50a0899d9f7f4b3acc15580275d4444d4de5604a9a31bf10abf52c0729d30d2f9c4aa023649d744d41560614e1662a93059ad7cdd8e797dc02fecb0afef8d2f3433438a042f19b7930e9573b999b08fb6c0a1d5202463411a71260ab35111c0e4abaf214a049336eef38e9dc1a5e17a2355ab660d77597f3c28aece83dcaea1ebec84843c0a0dd5172ff0b4d923550639808205f38c327122ae295d3665d38bfa18c8353b926a0b749fecc509a19e4ba21e91be9cc2230945e28373c35addd3319a689e063735f80f90211a06505ca81e32b2f5fc16bb0e57d08b63cf94273063579ce1dba42c410fcb5241ea0c6c70650f6edd7057de9a8d7aeb5a52bc40dffb8a9cb71d55990a628f1596402a03d50a67e8ec93696c35865d9f03814e95406c8d04e5decc320b9a24e5beee1baa0a928e2ea8773ba69dde5344d69069b237667dbaaa69e86133d4e444e432799b1a0f9e0c0fad1c45acb28e2c52c22d8a34b91b0033d758ba237e7cce78321555219a0762aeb8161d2b1b8a5ee51d1ede36f51cc2dad7e0c4d0ff097b89c831aff8c35a0957a8eaaac924688482d21a95b7a7f01889ab39a7a50d58efaaffa9e486ae071a0fa59d52ce31992709b7380abb4db6a33327763297b3c94791f348d886c7125faa08a831384faa68f9caa047a6200464e11cfe5f9f700a5ed9435e5241d9d2a501ca020630d0f41d1f38c61fc8d3fc6170f6f11fc52ade454930a3b5e4f4491b47467a0e8ff4ce1d72375673ffacb49b9c6508ab72e13b22a2017b437d74381b977fd60a027260ee4cb30c6d9777f583271ce726c44b7a0d94a066a365833a101439c7f43a0c7035c196627d2e6754f2a2ee7f93b829aa13ed595898aa4c4e8fb5454ef9693a0ac0b668136cd535099f69475c16ca2bae9e920e6513c30d2d563d3db0991659da0c3fb71b77522f06c4a4e4cb7029e7faeb747b8e446460586ea0d5e9abae68cd9a0ce5c5a5d4657257f3e6a3abc403ef40e586bfb7319420b3dedf6c03c8396a60380f9013180a0c2cb770a3d18eb1214a782cc81b79a7fd772716c2d050ef66011095c3774e8f7a08fc7d7da06fba7ffa69b095aae41147e3a55b89644682057cedab705ba7aefd5a05975b434f69398107a4d1729f8f56e75247df09c65b1a750797818607bf118df80a026cea4c13260b2a1dd74bb6fcc7cc36162d2856ce691a36165c633ba68f7b783a0f7b0c667509a4ce937c487b45bc53c0700543daf4f8c127fbe475b4e1084d2328080a0454eca3fcc32afd4c4000ccbb47732bbce342b1a9d374fb5872162f2c873625fa0b3e6c44579a731cc730a5472e83c6098fa2943e5b2c72f4475f0afea76848a87a03b8c951788b8c93366aedbf88f6c1ca6085cd0249025ce542f19294b40bb92f180a02d17e5d80adfe7bb5ee6ad2c69f508f60d60182e0b724de4bcbfb0e6487bb378808080e482000ea07b2632b8b97e159d88f112a8dd9d44df2f3c4502e0c79a29297ea7f61f41f311f851a030590b16841225b9590cdc95b19176201d442ca0b931c6e4314d20a1c772ea9ba052e8f9f247cd159c65b304863d444087f6a60d7dbec3a0e4fa09f007b5a1c64f808080808080808080808080808080f86c9c20120c458c4c09a9448628f84e81161b308d5c4041a3d3a1ea329d0eb84df84b0487400e8b4f1c9c00a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a4702a440bac492386862ad3df4b666bc096b0505bb694dab0bec348681af766751cb839576e9c515a09c8bffa30a46296ccc56612490eb480d03bf948e10005bbcc0421f90b3d4e2a442465176c461afb316ebc773c61faee85a6515daa8a923564c6ffd37fb2fe9f118ef88092e8762c7addb526ab7eb1e772baef85181f892c731be0c1891a50e6b06262c8162a44295e26495cef6f69dfa69911d9d8e4f3bbadb89b977cf58294f7239d515e15b24cfeb82494056cf691eaf729b165f32c9757c429dba5051155903067e56ebe3698678e912a442d4c407bbe49438ed859fe965b140dcf1aab71a993c1f7f6929d1fe2a17b4e14614ef9fc5bdc713d6631d675403fbeefac55611bf612700b1b65f4744861b80b0f7d6ab02a4435ebb5849518aff370ca25e19e1072cc1a9fabcaa7f3e2c0b4b16ad183c473bafe30a36e39fa4a143657e229cd23c77f8fbc8e4e4e241695dd3d248d1e51521eee6619142a443f349bbafec1551819b8be1efea2fc46ca749aa184248a459464eec1a21e7fc7b71a053d9644e9bb8da4853b8f872cd7c1d6b324bf1922829830646ceadfb658d3de009a2a4461dd481a114a2e761c554b641742c973867899d38a80967d39e406a0a9642d41e9007a27fc1150a267d143a9f786cd2b5eecbdcc4036273705225b956d5e2f8f5eb95d252a447ae2f5b9e386cd1b50a4550696d957cb4900f03ab84f83ff2df44193496793b847f64e9d6db1b3953682bb95edd096eb1e69bbd357c200992ca78050d0cbe180cfaa018e2a448b6c8fd93d6f4cea42bbb345dbc6f0dfdb5bec73a8a257074e82b881cfa06ef3eb4efeca060c2531359abd0eab8af1e3edfa2025fca464ac9c3fd123f6c24a0d788694852a44a6f79b60359f141df90a0c745125b131caaffd12b772e180fbf38a051c97dabc8aaa0126a233a9e828cdafcc7422c4bb1f4030a56ba364c54103f26bad91508b5220b7412a44b218c5d6af1f979ac42bc68d98a5a0d796c6ab01b659ad0fbd9f515893fdd740b29ba0772dbde9b4635921dd91bd2963a0fc855e31f6338f45b211c4e9dedb7f2eb09de72a44b4dd66d7c2c7e57f628210187192fb89d4b99dd40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a44be807dddb074639cd9fa61b47676c064fc50d62cb1f2c71577def3144fabeb75a8a1c8cb5b51d1d1b4a05eec67988b8685008baa17459ec425dbaebc852f496dc92196cd2a44cc8e6d00c17eb431350c6c50d8b8f05176b90b11b3a3d4feb825ae9702711566df5dbf38e82add4dd1b573b95d2466fa6501ccb81e9d26a352b96150ccbf7b697fd0a4192a44d1d6bf74282782b0b3eb1413c901d6ecf02e8e28939e8fb41b682372335be8070199ad3e8621d1743bcac4cc9d8f0f6e10f41e56461385c8eb5daac804fe3f2bca6ce7392a44d93dbfb27e027f5e9e6da52b9e1c413ce35adc110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a44e2d3a739effcd3a99387d015e260eefac72ebea1956c470ddff48cb49300200b5f83497f3a3ccb3aeb83c5edd9818569038e61d197184f4aa6939ea5e9911e3e98ac6d212a44e9ae3261a475a27bb1028f140bc2a7c843318afd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a44ea0a6e3c511bbd10f4519ece37dc24887e11b55db2d4c6283c44a1c7bd503aaba7666e9f0c830e0ff016c1c750a5e48757a713d0836b1cabfd5c281b1de3b77d1c1921832a44ee226379db83cffc681495730c11fdde79ba4c0cae7bc6faa3f0cc3e6093b633fd7ee4f86970926958d0b7ec80437f936acf212b78f0cd095f4565fff144fd458d233a5b2a44ef0274e31810c9df02f98fafde0f841f4e66a1cd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032440bac492386862ad3df4b666bc096b0505bb694dab0bec348681af766751cb839576e9c515a09c8bffa30a46296ccc56612490eb480d03bf948e10005bbcc0421f90b3d4e32442465176c461afb316ebc773c61faee85a6515daa8a923564c6ffd37fb2fe9f118ef88092e8762c7addb526ab7eb1e772baef85181f892c731be0c1891a50e6b06262c8163244295e26495cef6f69dfa69911d9d8e4f3bbadb89b977cf58294f7239d515e15b24cfeb82494056cf691eaf729b165f32c9757c429dba5051155903067e56ebe3698678e9132442d4c407bbe49438ed859fe965b140dcf1aab71a993c1f7f6929d1fe2a17b4e14614ef9fc5bdc713d6631d675403fbeefac55611bf612700b1b65f4744861b80b0f7d6ab0324435ebb5849518aff370ca25e19e1072cc1a9fabcaa7f3e2c0b4b16ad183c473bafe30a36e39fa4a143657e229cd23c77f8fbc8e4e4e241695dd3d248d1e51521eee66191432443f349bbafec1551819b8be1efea2fc46ca749aa184248a459464eec1a21e7fc7b71a053d9644e9bb8da4853b8f872cd7c1d6b324bf1922829830646ceadfb658d3de009a324461dd481a114a2e761c554b641742c973867899d38a80967d39e406a0a9642d41e9007a27fc1150a267d143a9f786cd2b5eecbdcc4036273705225b956d5e2f8f5eb95d2532447ae2f5b9e386cd1b50a4550696d957cb4900f03ab84f83ff2df44193496793b847f64e9d6db1b3953682bb95edd096eb1e69bbd357c200992ca78050d0cbe180cfaa018e32448b6c8fd93d6f4cea42bbb345dbc6f0dfdb5bec73a8a257074e82b881cfa06ef3eb4efeca060c2531359abd0eab8af1e3edfa2025fca464ac9c3fd123f6c24a0d788694853244a6f79b60359f141df90a0c745125b131caaffd12b772e180fbf38a051c97dabc8aaa0126a233a9e828cdafcc7422c4bb1f4030a56ba364c54103f26bad91508b5220b7413244b218c5d6af1f979ac42bc68d98a5a0d796c6ab01b659ad0fbd9f515893fdd740b29ba0772dbde9b4635921dd91bd2963a0fc855e31f6338f45b211c4e9dedb7f2eb09de73244b4dd66d7c2c7e57f628210187192fb89d4b99dd40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003244be807dddb074639cd9fa61b47676c064fc50d62cb1f2c71577def3144fabeb75a8a1c8cb5b51d1d1b4a05eec67988b8685008baa17459ec425dbaebc852f496dc92196cd3244cc8e6d00c17eb431350c6c50d8b8f05176b90b11b3a3d4feb825ae9702711566df5dbf38e82add4dd1b573b95d2466fa6501ccb81e9d26a352b96150ccbf7b697fd0a4193244d1d6bf74282782b0b3eb1413c901d6ecf02e8e28939e8fb41b682372335be8070199ad3e8621d1743bcac4cc9d8f0f6e10f41e56461385c8eb5daac804fe3f2bca6ce7393244d93dbfb27e027f5e9e6da52b9e1c413ce35adc110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003244e2d3a739effcd3a99387d015e260eefac72ebea1956c470ddff48cb49300200b5f83497f3a3ccb3aeb83c5edd9818569038e61d197184f4aa6939ea5e9911e3e98ac6d213244e9ae3261a475a27bb1028f140bc2a7c843318afd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003244ea0a6e3c511bbd10f4519ece37dc24887e11b55db2d4c6283c44a1c7bd503aaba7666e9f0c830e0ff016c1c750a5e48757a713d0836b1cabfd5c281b1de3b77d1c1921833244ee226379db83cffc681495730c11fdde79ba4c0cae7bc6faa3f0cc3e6093b633fd7ee4f86970926958d0b7ec80437f936acf212b78f0cd095f4565fff144fd458d233a5b3244ef0274e31810c9df02f98fafde0f841f4e66a1cd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec(); diff --git a/light-client/src/client_state.rs b/light-client/src/client_state.rs index 8292301..43e006f 100644 --- a/light-client/src/client_state.rs +++ b/light-client/src/client_state.rs @@ -234,7 +234,7 @@ mod test { #[test] fn test_try_from_any() { - let relayer_client_state_protobuf = hex!("0a272f6962632e6c69676874636c69656e74732e7061726c69612e76312e436c69656e7453746174651248088f4e1214aa43d337145e8930d01cb4e60abf6595c692921e1a200000000000000000000000000000000000000000000000000000000000000000220310c8012a04080110033064").to_vec(); + let relayer_client_state_protobuf = hex!("0a272f6962632e6c69676874636c69656e74732e7061726c69612e76312e436c69656e745374617465124a088f4e1214aa43d337145e8930d01cb4e60abf6595c692921e1a200000000000000000000000000000000000000000000000000000000000000000220310c8012a020864320410c0843d").to_vec(); let any: Any = relayer_client_state_protobuf.try_into().unwrap(); let cs: ClientState = any.try_into().unwrap(); @@ -244,6 +244,7 @@ mod test { assert_eq!(9999, cs.chain_id.id()); assert_eq!(0, cs.chain_id.version()); assert_eq!(100, cs.trusting_period.as_secs()); + assert_eq!(1, cs.max_clock_drift.as_millis()); assert_eq!( hex!("aa43d337145e8930d01cb4e60abf6595c692921e"), cs.ibc_store_address From 9552fd4c60f7e0e5cd94e601185328e6ab34c198 Mon Sep 17 00:00:00 2001 From: Naohiro Yoshida Date: Tue, 12 Sep 2023 17:51:22 +0900 Subject: [PATCH 7/7] change validation trusting period as ethereum Signed-off-by: Naohiro Yoshida --- Cargo.lock | 1 + light-client/Cargo.toml | 1 + light-client/src/client.rs | 15 ++- light-client/src/client_state.rs | 196 +++++++++++++++++++++++++++- light-client/src/consensus_state.rs | 66 +--------- light-client/src/errors.rs | 10 +- 6 files changed, 213 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d8a421f..e7c025c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1310,6 +1310,7 @@ dependencies = [ "serde", "serde_json", "store", + "time", "tiny-keccak 2.0.2", "trie-db", ] diff --git a/light-client/Cargo.toml b/light-client/Cargo.toml index bf9b391..aa7f8f4 100644 --- a/light-client/Cargo.toml +++ b/light-client/Cargo.toml @@ -30,6 +30,7 @@ hex-literal = "0.4.1" [dev-dependencies] store = { git = "https://github.com/datachainlab/lcp.git", rev = "v0.2.2", default-features = false } ibc-proto = { version = "0.26.0", default-features = false } +time = { version = "0.3", default-features = false, features = ["macros", "parsing"] } [features] default = ["std"] diff --git a/light-client/src/client.rs b/light-client/src/client.rs index 226393b..a8b1c7e 100644 --- a/light-client/src/client.rs +++ b/light-client/src/client.rs @@ -358,6 +358,7 @@ mod test { use light_client::{ClientReader, HostClientReader, HostContext, LightClient}; use patricia_merkle_trie::keccak::keccak_256; + use time::macros::datetime; use crate::client::ParliaLightClient; use crate::client_state::ClientState; @@ -366,7 +367,7 @@ mod test { use crate::header::testdata::mainnet; use crate::header::Header; - use crate::misc::{keccak_256_vec, new_height, new_timestamp, ChainId, Hash}; + use crate::misc::{keccak_256_vec, new_height, ChainId, Hash}; impl Default for ClientState { fn default() -> Self { @@ -376,7 +377,7 @@ mod test { ibc_commitments_slot: hex!( "0000000000000000000000000000000000000000000000000000000000000000" ), - trusting_period: core::time::Duration::new(86400 * 365 * 100, 0), + trusting_period: core::time::Duration::new(86400 * 365, 0), max_clock_drift: core::time::Duration::new(1, 0), latest_height: Default::default(), frozen: false, @@ -388,7 +389,10 @@ mod test { fn default() -> Self { ConsensusState { state_root: [0_u8; 32], - timestamp: new_timestamp(1677130449).unwrap(), + timestamp: Time::from_unix_timestamp_nanos( + datetime!(2023-09-05 9:00 UTC).unix_timestamp_nanos() as u128, + ) + .unwrap(), validators_hash: [0_u8; 32], validators_size: 0, } @@ -402,7 +406,10 @@ mod test { impl HostContext for MockClientReader { fn host_timestamp(&self) -> Time { - new_timestamp(1677130449).unwrap() + Time::from_unix_timestamp_nanos( + datetime!(2023-09-10 9:00 UTC).unix_timestamp_nanos() as u128 + ) + .unwrap() } } diff --git a/light-client/src/client_state.rs b/light-client/src/client_state.rs index 43e006f..c07bb54 100644 --- a/light-client/src/client_state.rs +++ b/light-client/src/client_state.rs @@ -99,8 +99,13 @@ impl ClientState { fn check_header(&self, now: Time, cs: &ConsensusState, header: &Header) -> Result<(), Error> { // Ensure last consensus state is within the trusting period - cs.assert_not_expired(now, self.trusting_period)?; - cs.assert_not_expired(header.timestamp()?, self.trusting_period)?; + validate_within_trusting_period( + now, + self.trusting_period, + self.max_clock_drift, + header.timestamp()?, + cs.timestamp, + )?; // Ensure header revision is same as chain revision let header_height = header.height(); @@ -115,6 +120,34 @@ impl ClientState { } } +// https://github.com/datachainlab/ethereum-ibc-rs/blob/678f0d1efcdb06c5008fcc0a8785838708ee1a7d/crates/ibc/src/client_state.rs#L572 +fn validate_within_trusting_period( + current_timestamp: Time, + trusting_period: Duration, + clock_drift: Duration, + untrusted_header_timestamp: Time, + trusted_consensus_state_timestamp: Time, +) -> Result<(), Error> { + let trusting_period_end = + (trusted_consensus_state_timestamp + trusting_period).map_err(Error::TimeError)?; + let drifted_current_timestamp = (current_timestamp + clock_drift).map_err(Error::TimeError)?; + + if !trusting_period_end.gt(¤t_timestamp) { + return Err(Error::OutOfTrustingPeriod( + current_timestamp, + trusting_period_end, + )); + } + if !drifted_current_timestamp.gt(&untrusted_header_timestamp) { + return Err(Error::HeaderFromFuture( + current_timestamp, + clock_drift, + untrusted_header_timestamp, + )); + } + Ok(()) +} + impl TryFrom for ClientState { type Error = Error; @@ -228,9 +261,12 @@ impl TryFrom for ClientState { #[cfg(test)] mod test { use hex_literal::hex; + use std::time::Duration; + use time::{macros::datetime, OffsetDateTime}; - use crate::client_state::ClientState; - use light_client::types::Any; + use crate::client_state::{validate_within_trusting_period, ClientState}; + use crate::errors::Error; + use light_client::types::{Any, Time}; #[test] fn test_try_from_any() { @@ -254,4 +290,156 @@ mod test { cs.ibc_commitments_slot ); } + + #[test] + fn test_trusting_period_validation() { + { + let current_timestamp = datetime!(2023-08-20 0:00 UTC); + let untrusted_header_timestamp = datetime!(2023-08-20 0:00 UTC); + let trusted_state_timestamp = datetime!(2023-08-20 0:00 UTC); + validate_and_assert_no_error( + current_timestamp, + 1, + 1, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + } + + // trusting_period + { + let current_timestamp = datetime!(2023-08-20 0:00 UTC); + let untrusted_header_timestamp = current_timestamp - Duration::new(0, 1); + let trusted_state_timestamp = untrusted_header_timestamp - Duration::new(0, 1); + validate_and_assert_trusting_period_error( + current_timestamp, + 1, + 0, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + validate_and_assert_trusting_period_error( + current_timestamp, + 2, + 0, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + validate_and_assert_no_error( + current_timestamp, + 3, + 0, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + } + + // clock drift + { + let current_timestamp = datetime!(2023-08-20 0:00 UTC); + let untrusted_header_timestamp = current_timestamp + Duration::new(0, 1); + let trusted_state_timestamp = current_timestamp; + validate_and_assert_clock_drift_error( + current_timestamp, + 1, + 0, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + validate_and_assert_clock_drift_error( + current_timestamp, + 1, + 1, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + validate_and_assert_no_error( + current_timestamp, + 1, + 2, + untrusted_header_timestamp, + trusted_state_timestamp, + ); + } + } + + fn validate_and_assert_no_error( + current_timestamp: OffsetDateTime, + trusting_period: u64, + clock_drift: u64, + untrusted_header_timestamp: OffsetDateTime, + trusted_state_timestamp: OffsetDateTime, + ) { + let result = validate_within_trusting_period( + Time::from_unix_timestamp_nanos(current_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + Duration::from_nanos(trusting_period), + Duration::from_nanos(clock_drift), + Time::from_unix_timestamp_nanos( + untrusted_header_timestamp.unix_timestamp_nanos() as u128 + ) + .unwrap(), + Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + ); + assert!(result.is_ok()); + } + + fn validate_and_assert_trusting_period_error( + current_timestamp: OffsetDateTime, + trusting_period: u64, + clock_drift: u64, + untrusted_header_timestamp: OffsetDateTime, + trusted_state_timestamp: OffsetDateTime, + ) { + let result = validate_within_trusting_period( + Time::from_unix_timestamp_nanos(current_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + Duration::from_nanos(trusting_period), + Duration::from_nanos(clock_drift), + Time::from_unix_timestamp_nanos( + untrusted_header_timestamp.unix_timestamp_nanos() as u128 + ) + .unwrap(), + Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + ); + if let Err(e) = result { + match e { + Error::OutOfTrustingPeriod(_current_timestamp, _trusting_period_end) => {} + _ => panic!("unexpected error: {e}"), + } + } else { + panic!("expected error"); + } + } + + fn validate_and_assert_clock_drift_error( + current_timestamp: OffsetDateTime, + trusting_period: u64, + clock_drift: u64, + untrusted_header_timestamp: OffsetDateTime, + trusted_state_timestamp: OffsetDateTime, + ) { + let result = validate_within_trusting_period( + Time::from_unix_timestamp_nanos(current_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + Duration::from_nanos(trusting_period), + Duration::from_nanos(clock_drift), + Time::from_unix_timestamp_nanos( + untrusted_header_timestamp.unix_timestamp_nanos() as u128 + ) + .unwrap(), + Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128) + .unwrap(), + ); + if let Err(e) = result { + match e { + Error::HeaderFromFuture(_current_timestamp, _clock_drift, _header_timestamp) => {} + _ => panic!("unexpected error: {e}"), + } + } else { + panic!("expected error"); + } + } } diff --git a/light-client/src/consensus_state.rs b/light-client/src/consensus_state.rs index a44b4e3..3ed3ed9 100644 --- a/light-client/src/consensus_state.rs +++ b/light-client/src/consensus_state.rs @@ -1,7 +1,5 @@ use alloc::borrow::ToOwned as _; use alloc::vec::Vec; -use core::ops::Add; -use core::time::Duration; use light_client::types::{Any, Time}; use prost::Message as _; @@ -32,21 +30,6 @@ impl ConsensusState { pub fn canonicalize(self) -> Self { self } - - pub fn assert_not_expired(&self, now: Time, trusting_period: Duration) -> Result<(), Error> { - if self.timestamp > now { - return Err(Error::IllegalTimestamp(self.timestamp, now)); - } - let deadline = self - .timestamp - .add(trusting_period) - .map_err(Error::UnexpectedTimestamp)?; - if deadline < now { - Err(Error::HeaderNotWithinTrustingPeriod(deadline, now)) - } else { - Ok(()) - } - } } impl TryFrom for ConsensusState { @@ -125,58 +108,11 @@ impl TryFrom for ConsensusState { #[cfg(test)] mod test { - use core::time::Duration; - use std::ops::{Add, Sub}; use hex_literal::hex; - use light_client::types::{Any, Time}; + use light_client::types::Any; use crate::consensus_state::ConsensusState; - use crate::errors::Error; - - #[test] - fn test_assert_not_expired() { - let consensus_state = ConsensusState { - state_root: [0u8; 32], - timestamp: Time::from_unix_timestamp_nanos(1_560_000_000_000_000_000).unwrap(), - validators_hash: [0u8; 32], - validators_size: 0, - }; - - // now is after trusting period - let now = consensus_state.timestamp.add(Duration::new(1, 1)).unwrap(); - match consensus_state - .assert_not_expired(now, Duration::new(1, 0)) - .unwrap_err() - { - Error::HeaderNotWithinTrustingPeriod(a, b) => { - assert_eq!( - a, - consensus_state.timestamp.add(Duration::new(1, 0)).unwrap() - ); - assert_eq!(b, now); - } - e => unreachable!("{:?}", e), - } - - // now is within trusting period - assert!(consensus_state - .assert_not_expired(now, Duration::new(1, 1)) - .is_ok()); - - // illegal timestamp - let now = consensus_state.timestamp.sub(Duration::new(1, 0)).unwrap(); - match consensus_state - .assert_not_expired(now, Duration::new(0, 0)) - .unwrap_err() - { - Error::IllegalTimestamp(t1, t2) => { - assert_eq!(t1, consensus_state.timestamp); - assert_eq!(t2, now); - } - e => unreachable!("{:?}", e), - } - } #[test] fn test_try_from_any() { diff --git a/light-client/src/errors.rs b/light-client/src/errors.rs index 5d2bbeb..7002138 100644 --- a/light-client/src/errors.rs +++ b/light-client/src/errors.rs @@ -47,7 +47,8 @@ pub enum Error { MissingParentTrustedValidators(BlockNumber), MissingTargetTrustedValidators(BlockNumber), MissingTrustedValidatorsHeight, - HeaderNotWithinTrustingPeriod(Time, Time), + OutOfTrustingPeriod(Time, Time), + HeaderFromFuture(Time, core::time::Duration, Time), InvalidTrustThreshold(u64, u64), MissingTrustedHeight, MissingTrustingPeriod, @@ -127,8 +128,11 @@ impl core::fmt::Display for Error { } Error::UnexpectedStorageRoot(e) => write!(f, "UnexpectedStorageRoot: {:?}", e), Error::UnexpectedCommitmentValue(e) => write!(f, "UnexpectedCommitmentValue: {:?}", e), - Error::HeaderNotWithinTrustingPeriod(e1, e2) => { - write!(f, "HeaderNotWithinTrustingPeriod: {} {}", e1, e2) + Error::OutOfTrustingPeriod(e1, e2) => { + write!(f, "OutOfTrustingPeriod: {} {}", e1, e2) + } + Error::HeaderFromFuture(e1, e2, e3) => { + write!(f, "HeaderFromFuture: {} {:?} {}", e1, e2, e3) } Error::InvalidTrustThreshold(e1, e2) => { write!(f, "InvalidTrustThreshold: {} {}", e1, e2)