diff --git a/relayer/Cargo.lock b/relayer/Cargo.lock index e24cedf4..c644669a 100644 --- a/relayer/Cargo.lock +++ b/relayer/Cargo.lock @@ -28,6 +28,18 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "1.1.3" @@ -37,6 +49,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "allocator-api2" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" + [[package]] name = "android-tzdata" version = "0.1.1" @@ -58,6 +76,70 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits 0.2.19", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits 0.2.19", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits 0.2.19", + "rand", +] + [[package]] name = "arrayref" version = "0.3.8" @@ -70,6 +152,21 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "assert_matches" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" + [[package]] name = "async-lock" version = "3.4.0" @@ -254,6 +351,21 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitcoin" version = "0.31.2" @@ -423,6 +535,171 @@ dependencies = [ "serde", ] +[[package]] +name = "cainome-cairo-serde" +version = "0.1.0" +source = "git+https://github.com/cartridge-gg/cainome#595c04414f1a2ab75c806a4e44c173776b6a790d" +dependencies = [ + "serde", + "starknet", + "thiserror", +] + +[[package]] +name = "cairo-felt" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae932292b9ba497a4e892b56aa4e0c6f329a455180fdbdc132700dfe68d9b153" +dependencies = [ + "lazy_static", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "serde", +] + +[[package]] +name = "cairo-lang-casm" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-lang-utils", + "indoc", + "num-bigint", + "num-traits 0.2.19", + "parity-scale-codec", + "serde", +] + +[[package]] +name = "cairo-lang-eq-solver" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-lang-utils", + "good_lp", +] + +[[package]] +name = "cairo-lang-sierra" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "anyhow", + "cairo-felt", + "cairo-lang-utils", + "const-fnv1a-hash", + "convert_case", + "derivative", + "itertools 0.11.0", + "lalrpop", + "lalrpop-util", + "num-bigint", + "num-traits 0.2.19", + "regex", + "salsa", + "serde", + "serde_json", + "sha3", + "smol_str", + "thiserror", +] + +[[package]] +name = "cairo-lang-sierra-ap-change" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-lang-eq-solver", + "cairo-lang-sierra", + "cairo-lang-sierra-type-size", + "cairo-lang-utils", + "itertools 0.11.0", + "num-traits 0.2.19", + "thiserror", +] + +[[package]] +name = "cairo-lang-sierra-gas" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-lang-eq-solver", + "cairo-lang-sierra", + "cairo-lang-sierra-type-size", + "cairo-lang-utils", + "itertools 0.11.0", + "num-traits 0.2.19", + "thiserror", +] + +[[package]] +name = "cairo-lang-sierra-to-casm" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "assert_matches", + "cairo-felt", + "cairo-lang-casm", + "cairo-lang-sierra", + "cairo-lang-sierra-ap-change", + "cairo-lang-sierra-gas", + "cairo-lang-sierra-type-size", + "cairo-lang-utils", + "indoc", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.19", + "thiserror", +] + +[[package]] +name = "cairo-lang-sierra-type-size" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-lang-sierra", + "cairo-lang-utils", +] + +[[package]] +name = "cairo-lang-starknet-classes" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "cairo-felt", + "cairo-lang-casm", + "cairo-lang-sierra", + "cairo-lang-sierra-to-casm", + "cairo-lang-utils", + "convert_case", + "itertools 0.11.0", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "once_cell", + "serde", + "serde_json", + "sha3", + "smol_str", + "starknet-crypto 0.6.2", + "thiserror", +] + +[[package]] +name = "cairo-lang-utils" +version = "2.6.4" +source = "git+https://github.com/starkware-libs/cairo?tag=v2.6.4#b4459a56578d26746658704fda9841772f84d4af" +dependencies = [ + "hashbrown 0.14.5", + "indexmap 2.2.6", + "itertools 0.11.0", + "num-bigint", + "num-traits 0.2.19", + "schemars", + "serde", +] + [[package]] name = "cc" version = "1.1.7" @@ -576,7 +853,7 @@ checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", - "num-traits", + "num-traits 0.2.19", "serde", "windows-targets 0.52.6", ] @@ -600,6 +877,12 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "const-fnv1a-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b13ea120a812beba79e34316b3942a857c86ec1593cb34f27bb28272ce2cca" + [[package]] name = "const-oid" version = "0.9.6" @@ -623,6 +906,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "core-foundation" version = "0.9.4" @@ -813,7 +1105,7 @@ dependencies = [ "hashbrown 0.14.5", "lock_api", "once_cell", - "parking_lot_core", + "parking_lot_core 0.9.10", ] [[package]] @@ -848,6 +1140,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e5c37193a1db1d8ed868c03ec7b152175f26160a5b740e5e484143877e0adf0" +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_more" version = "0.99.18" @@ -1008,6 +1311,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ena" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5" +dependencies = [ + "log", +] + [[package]] name = "encoding_rs" version = "0.8.34" @@ -1131,6 +1443,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.30" @@ -1291,6 +1609,16 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "good_lp" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3198bd13dea84c76a64621d6ee8ee26a4960a9a0d538eca95ca8f1320a469ac9" +dependencies = [ + "fnv", + "minilp", +] + [[package]] name = "group" version = "0.13.0" @@ -1338,6 +1666,11 @@ name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +dependencies = [ + "ahash", + "allocator-api2", + "serde", +] [[package]] name = "hdpath" @@ -1348,6 +1681,15 @@ dependencies = [ "byteorder", ] +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "heck" version = "0.4.1" @@ -1628,9 +1970,11 @@ dependencies = [ name = "hermes-starknet-chain-components" version = "0.1.0" dependencies = [ + "cairo-lang-starknet-classes", "cgp-core", "hermes-relayer-components", "hermes-test-components", + "serde_json", "starknet", ] @@ -1638,6 +1982,7 @@ dependencies = [ name = "hermes-starknet-chain-context" version = "0.1.0" dependencies = [ + "cairo-lang-starknet-classes", "cgp-core", "eyre", "hermes-error", @@ -1649,6 +1994,7 @@ dependencies = [ "hermes-starknet-chain-components", "hermes-starknet-test-components", "hermes-test-components", + "serde_json", "starknet", "url", ] @@ -1657,6 +2003,7 @@ dependencies = [ name = "hermes-starknet-integration-tests" version = "0.1.0" dependencies = [ + "cainome-cairo-serde", "cgp-core", "eyre", "hermes-cosmos-integration-tests", @@ -1669,6 +2016,7 @@ dependencies = [ "hermes-starknet-chain-context", "hermes-starknet-test-components", "hermes-test-components", + "serde_json", "starknet", "tokio", "url", @@ -2609,8 +2957,15 @@ checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.5", + "serde", ] +[[package]] +name = "indoc" +version = "2.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5" + [[package]] name = "informalsystems-pbjson" version = "0.7.0" @@ -2630,12 +2985,30 @@ dependencies = [ "generic-array", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "ipnet" version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.11.0" @@ -2690,6 +3063,37 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "lalrpop" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cb077ad656299f160924eb2912aa147d7339ea7d69e1b5517326fdcec3c1ca" +dependencies = [ + "ascii-canvas", + "bit-set", + "ena", + "itertools 0.11.0", + "lalrpop-util", + "petgraph", + "pico-args", + "regex", + "regex-syntax 0.8.4", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", + "walkdir", +] + +[[package]] +name = "lalrpop-util" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507460a910eb7b32ee961886ff48539633b788a36b65692b95f225b844c82553" +dependencies = [ + "regex-automata 0.4.7", +] + [[package]] name = "lambdaworks-crypto" version = "0.7.0" @@ -2717,6 +3121,9 @@ name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] [[package]] name = "libc" @@ -2765,6 +3172,15 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" +[[package]] +name = "matrixmultiply" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916806ba0031cd542105d916a97c8572e1fa6dd79c9c51e7eb43a09ec2dd84c1" +dependencies = [ + "rawpointer", +] + [[package]] name = "memchr" version = "2.7.4" @@ -2777,6 +3193,16 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minilp" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82a7750a9e5076c660b7bec5e6457b4dbff402b9863c8d112891434e18fd5385" +dependencies = [ + "log", + "sprs", +] + [[package]] name = "miniz_oxide" version = "0.7.4" @@ -2812,7 +3238,7 @@ dependencies = [ "event-listener", "futures-util", "once_cell", - "parking_lot", + "parking_lot 0.12.3", "quanta", "rustc_version", "smallvec", @@ -2822,6 +3248,25 @@ dependencies = [ "uuid 1.10.0", ] +[[package]] +name = "ndarray" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac06db03ec2f46ee0ecdca1a1c34a99c0d188a0d83439b84bf0cb4b386e4ab09" +dependencies = [ + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits 0.2.19", + "rawpointer", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + [[package]] name = "nu-ansi-term" version = "0.46.0" @@ -2839,10 +3284,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ "num-integer", - "num-traits", + "num-traits 0.2.19", "serde", ] +[[package]] +name = "num-complex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95" +dependencies = [ + "autocfg", + "num-traits 0.2.19", +] + [[package]] name = "num-conv" version = "0.1.0" @@ -2855,7 +3310,7 @@ version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "num-traits", + "num-traits 0.2.19", ] [[package]] @@ -2866,10 +3321,19 @@ checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ "num-bigint", "num-integer", - "num-traits", + "num-traits 0.2.19", "serde", ] +[[package]] +name = "num-traits" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" +dependencies = [ + "num-traits 0.2.19", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -2904,6 +3368,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "opaque-debug" version = "0.3.1" @@ -3032,6 +3502,17 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.3" @@ -3039,7 +3520,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.10", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -3050,7 +3545,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.3", "smallvec", "windows-targets 0.52.6", ] @@ -3103,6 +3598,31 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap 2.2.6", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + [[package]] name = "pin-project" version = "1.1.5" @@ -3157,6 +3677,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "prettyplease" version = "0.2.20" @@ -3231,7 +3757,7 @@ dependencies = [ "fnv", "lazy_static", "memchr", - "parking_lot", + "parking_lot 0.12.3", "protobuf", "thiserror", ] @@ -3253,7 +3779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.72", @@ -3343,6 +3869,21 @@ dependencies = [ "bitflags 2.6.0", ] +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.3" @@ -3635,6 +4176,35 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "salsa" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b84d9f96071f3f3be0dc818eae3327625d8ebc95b58da37d6850724f31d3403" +dependencies = [ + "crossbeam-utils", + "indexmap 1.9.3", + "lock_api", + "log", + "oorandom", + "parking_lot 0.11.2", + "rustc-hash", + "salsa-macros", + "smallvec", +] + +[[package]] +name = "salsa-macros" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3904a4ba0a9d0211816177fd34b04c7095443f8cdacd11175064fe541c8fe2" +dependencies = [ + "heck 0.3.3", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "salsa20" version = "0.10.2" @@ -3693,6 +4263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", + "indexmap 1.9.3", "schemars_derive", "serde", "serde_json", @@ -4027,6 +4598,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + [[package]] name = "slab" version = "0.4.9" @@ -4042,6 +4619,15 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "smol_str" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd538fb6910ac1099850255cf94a94df6551fbdd602454387d0adb2d1ca6dead" +dependencies = [ + "serde", +] + [[package]] name = "socket2" version = "0.5.7" @@ -4068,6 +4654,17 @@ dependencies = [ "der", ] +[[package]] +name = "sprs" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec63571489873d4506683915840eeb1bb16b3198ee4894cc6f2fe3013d505e56" +dependencies = [ + "ndarray", + "num-complex", + "num-traits 0.1.43", +] + [[package]] name = "stable-eyre" version = "0.2.2" @@ -4088,7 +4685,7 @@ dependencies = [ "starknet-accounts", "starknet-contract", "starknet-core", - "starknet-crypto", + "starknet-crypto 0.7.1", "starknet-macros", "starknet-providers", "starknet-signers", @@ -4103,7 +4700,7 @@ dependencies = [ "async-trait", "auto_impl", "starknet-core", - "starknet-crypto", + "starknet-crypto 0.7.1", "starknet-providers", "starknet-signers", "thiserror", @@ -4139,10 +4736,30 @@ dependencies = [ "serde_json_pythonic", "serde_with", "sha3", - "starknet-crypto", + "starknet-crypto 0.7.1", "starknet-types-core", ] +[[package]] +name = "starknet-crypto" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e2c30c01e8eb0fc913c4ee3cf676389fffc1d1182bfe5bb9670e4e72e968064" +dependencies = [ + "crypto-bigint", + "hex", + "hmac", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "rfc6979", + "sha2 0.10.8", + "starknet-crypto-codegen 0.3.3", + "starknet-curve 0.4.2", + "starknet-ff", + "zeroize", +] + [[package]] name = "starknet-crypto" version = "0.7.1" @@ -4154,26 +4771,46 @@ dependencies = [ "hmac", "num-bigint", "num-integer", - "num-traits", + "num-traits 0.2.19", "rfc6979", "sha2 0.10.8", - "starknet-crypto-codegen", - "starknet-curve", + "starknet-crypto-codegen 0.4.0", + "starknet-curve 0.5.0", "starknet-types-core", "zeroize", ] +[[package]] +name = "starknet-crypto-codegen" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" +dependencies = [ + "starknet-curve 0.4.2", + "starknet-ff", + "syn 2.0.72", +] + [[package]] name = "starknet-crypto-codegen" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e179dedc3fa6da064e56811d3e05d446aa2f7459e4eb0e3e49378a337235437" dependencies = [ - "starknet-curve", + "starknet-curve 0.5.0", "starknet-types-core", "syn 2.0.72", ] +[[package]] +name = "starknet-curve" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1c383518bb312751e4be80f53e8644034aa99a0afb29d7ac41b89a997db875b" +dependencies = [ + "starknet-ff", +] + [[package]] name = "starknet-curve" version = "0.5.0" @@ -4183,6 +4820,18 @@ dependencies = [ "starknet-types-core", ] +[[package]] +name = "starknet-ff" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abf1b44ec5b18d87c1ae5f54590ca9d0699ef4dd5b2ffa66fc97f24613ec585" +dependencies = [ + "ark-ff", + "crypto-bigint", + "getrandom", + "hex", +] + [[package]] name = "starknet-macros" version = "0.2.0" @@ -4227,7 +4876,7 @@ dependencies = [ "getrandom", "rand", "starknet-core", - "starknet-crypto", + "starknet-crypto 0.7.1", "thiserror", ] @@ -4241,7 +4890,7 @@ dependencies = [ "lambdaworks-math", "num-bigint", "num-integer", - "num-traits", + "num-traits 0.2.19", "serde", ] @@ -4251,6 +4900,19 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot 0.12.3", + "phf_shared", + "precomputed-hash", +] + [[package]] name = "strsim" version = "0.11.1" @@ -4272,7 +4934,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -4386,7 +5048,7 @@ dependencies = [ "flex-error", "futures", "k256", - "num-traits", + "num-traits 0.2.19", "once_cell", "prost", "prost-types", @@ -4529,6 +5191,17 @@ dependencies = [ "walkdir", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "thiserror" version = "1.0.63" @@ -4643,7 +5316,7 @@ dependencies = [ "bytes", "libc", "mio", - "parking_lot", + "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", "socket2", @@ -4972,6 +5645,18 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + [[package]] name = "untrusted" version = "0.9.0" @@ -5361,6 +6046,26 @@ dependencies = [ "tap", ] +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", +] + [[package]] name = "zeroize" version = "1.8.1" diff --git a/relayer/Cargo.toml b/relayer/Cargo.toml index 764f889a..8f2647bc 100644 --- a/relayer/Cargo.toml +++ b/relayer/Cargo.toml @@ -23,17 +23,20 @@ rust-version = "1.79" overflow-checks = true [workspace.dependencies] -async-trait = { version = "0.1.81" } ibc = { version = "0.53.0" } cgp-core = { version = "0.1.0" } cgp-error-eyre = { version = "0.1.0" } cgp-component-macro = { version = "0.1.0" } -clap = { version = "4.5.8" } -starknet = { version = "0.11.0" } -url = { version = "2.4.0" } -eyre = { version = "0.6.12" } -tokio = { version = "1.38" } +clap = { version = "4.5.8" } +starknet = { version = "0.11.0" } +url = { version = "2.4.0" } +eyre = { version = "0.6.12" } +tokio = { version = "1.38" } +serde_json = { version = "1.0" } + +cairo-lang-starknet-classes = { version = "2.6.4" } +cainome-cairo-serde = { version = "0.1.0" } hermes-runtime-components = { version = "0.1.0" } hermes-async-runtime-components = { version = "0.1.0" } @@ -127,3 +130,6 @@ hermes-wasm-test-components = { git = "https://github.com/informalsystems/herm hermes-starknet-chain-components = { path = "./crates/starknet-chain-components" } hermes-starknet-test-components = { path = "./crates/starknet-test-components" } hermes-starknet-chain-context = { path = "./crates/starknet-chain-context" } + +cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", tag = "v2.6.4" } +cainome-cairo-serde = { git = "https://github.com/cartridge-gg/cainome" } diff --git a/relayer/crates/starknet-chain-components/Cargo.toml b/relayer/crates/starknet-chain-components/Cargo.toml index c1e8f83e..5699c75e 100644 --- a/relayer/crates/starknet-chain-components/Cargo.toml +++ b/relayer/crates/starknet-chain-components/Cargo.toml @@ -14,4 +14,6 @@ cgp-core = { workspace = true } hermes-relayer-components = { workspace = true } hermes-test-components = { workspace = true } -starknet = { workspace = true } +starknet = { workspace = true } +serde_json = { workspace = true } +cairo-lang-starknet-classes = { workspace = true } diff --git a/relayer/crates/starknet-chain-components/src/components.rs b/relayer/crates/starknet-chain-components/src/components.rs index 041f59d2..249568e8 100644 --- a/relayer/crates/starknet-chain-components/src/components.rs +++ b/relayer/crates/starknet-chain-components/src/components.rs @@ -18,6 +18,8 @@ pub use hermes_test_components::chain::traits::types::amount::AmountTypeComponen pub use hermes_test_components::chain::traits::types::denom::DenomTypeComponent; use crate::impls::contract::call::CallStarknetContract; +use crate::impls::contract::declare::DeclareSierraContract; +use crate::impls::contract::deploy::DeployStarknetContract; use crate::impls::contract::invoke::InvokeStarknetContract; use crate::impls::contract::message::BuildInvokeContractCall; use crate::impls::messages::transfer::BuildTransferErc20TokenMessage; @@ -30,6 +32,7 @@ use crate::impls::types::address::ProvideFeltAddressType; use crate::impls::types::amount::ProvideU256Amount; use crate::impls::types::blob::ProvideFeltBlobType; use crate::impls::types::chain_id::ProvideFeltChainId; +use crate::impls::types::contract::ProvideStarknetContractTypes; use crate::impls::types::denom::ProvideTokenAddressDenom; use crate::impls::types::event::ProvideStarknetEvent; use crate::impls::types::message::ProvideCallMessage; @@ -38,12 +41,17 @@ use crate::impls::types::transaction::ProvideCallTransaction; use crate::impls::types::tx_hash::ProvideFeltTxHash; use crate::impls::types::tx_response::ProvideStarknetTxResponse; pub use crate::traits::contract::call::ContractCallerComponent; +pub use crate::traits::contract::declare::ContractDeclarerComponent; +pub use crate::traits::contract::deploy::ContractDeployerComponent; pub use crate::traits::contract::invoke::ContractInvokerComponent; pub use crate::traits::contract::message::InvokeContractMessageBuilderComponent; pub use crate::traits::messages::transfer::TransferTokenMessageBuilderComponent; pub use crate::traits::queries::token_balance::TokenBalanceQuerierComponent; pub use crate::traits::transfer::TokenTransferComponent; pub use crate::traits::types::blob::BlobTypeComponent; +pub use crate::traits::types::contract_class::{ + ContractClassHashTypeComponent, ContractClassTypeComponent, +}; pub use crate::traits::types::method::MethodSelectorTypeComponent; define_components! { @@ -70,6 +78,11 @@ define_components! { ProvideStarknetTxResponse, MethodSelectorTypeComponent: ProvideFeltMethodSelector, + [ + ContractClassTypeComponent, + ContractClassHashTypeComponent, + ]: + ProvideStarknetContractTypes, MessageSenderComponent: SendCallMessages, TxSubmitterComponent: @@ -84,6 +97,10 @@ define_components! { CallStarknetContract, ContractInvokerComponent: InvokeStarknetContract, + ContractDeclarerComponent: + DeclareSierraContract, + ContractDeployerComponent: + DeployStarknetContract, InvokeContractMessageBuilderComponent: BuildInvokeContractCall, RetryableErrorComponent: diff --git a/relayer/crates/starknet-chain-components/src/impls/contract/declare.rs b/relayer/crates/starknet-chain-components/src/impls/contract/declare.rs new file mode 100644 index 00000000..2b7da556 --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/impls/contract/declare.rs @@ -0,0 +1,97 @@ +use std::sync::Arc; + +use cairo_lang_starknet_classes::casm_contract_class::{ + CasmContractClass, StarknetSierraCompilationError, +}; +use cairo_lang_starknet_classes::contract_class::ContractClass; +use cgp_core::error::CanRaiseError; +use hermes_relayer_components::transaction::traits::poll_tx_response::CanPollTxResponse; +use starknet::accounts::Account; +use starknet::core::types::contract::{ + CompiledClass, ComputeClassHashError, JsonError, SierraClass, +}; +use starknet::core::types::{BlockId, BlockTag, Felt, RevertedInvocation}; +use starknet::providers::Provider; + +use crate::traits::account::{CanRaiseAccountErrors, HasStarknetAccount}; +use crate::traits::contract::declare::ContractDeclarer; +use crate::traits::provider::HasStarknetProvider; +use crate::traits::types::contract_class::{HasContractClassHashType, HasContractClassType}; +use crate::types::tx_response::TxResponse; + +pub struct DeclareSierraContract; + +impl ContractDeclarer for DeclareSierraContract +where + Chain: HasContractClassType + + HasContractClassHashType + + HasStarknetProvider + + HasStarknetAccount + + CanPollTxResponse + + CanRaiseAccountErrors + + CanRaiseError + + CanRaiseError + + CanRaiseError + + CanRaiseError + + CanRaiseError, +{ + async fn declare_contract( + chain: &Chain, + contract_class: &SierraClass, + ) -> Result { + let provider = chain.provider(); + let account = chain.account(); + + let class_hash = contract_class.class_hash().map_err(Chain::raise_error)?; + + let class_exist_result = provider + .get_class(BlockId::Tag(BlockTag::Pending), class_hash) + .await; + + if class_exist_result.is_ok() { + return Ok(class_hash); + } + + // Compile Sierra class to Casm, following code in starkli + let casm_class_hash = { + let mut class = contract_class.clone(); + class.abi.clear(); + + let sierra_class_json = serde_json::to_string(&class).map_err(Chain::raise_error)?; + + let contract_class: ContractClass = + serde_json::from_str(&sierra_class_json).map_err(Chain::raise_error)?; + + let casm_contract = + CasmContractClass::from_contract_class(contract_class, false, 180000) + .map_err(Chain::raise_error)?; + + let casm_class_json = + serde_json::to_string(&casm_contract).map_err(Chain::raise_error)?; + + let casm_class = serde_json::from_str::(&casm_class_json) + .map_err(Chain::raise_error)?; + + casm_class.class_hash().map_err(Chain::raise_error)? + }; + + let flattened_class = contract_class + .clone() + .flatten() + .map_err(Chain::raise_error)?; + + let declaration = account.declare_v3(Arc::new(flattened_class), casm_class_hash); + + let declare_result = declaration.send().await.map_err(Chain::raise_error)?; + + let tx_response = chain + .poll_tx_response(&declare_result.transaction_hash) + .await?; + + if let Some(reverted) = tx_response.is_reverted() { + return Err(Chain::raise_error(reverted)); + } + + Ok(declare_result.class_hash) + } +} diff --git a/relayer/crates/starknet-chain-components/src/impls/contract/deploy.rs b/relayer/crates/starknet-chain-components/src/impls/contract/deploy.rs new file mode 100644 index 00000000..2d2137fd --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/impls/contract/deploy.rs @@ -0,0 +1,60 @@ +use cgp_core::error::CanRaiseError; +use hermes_relayer_components::transaction::traits::poll_tx_response::CanPollTxResponse; +use hermes_test_components::chain::traits::types::address::HasAddressType; +use starknet::contract::ContractFactory; +use starknet::core::types::{Felt, RevertedInvocation}; +use starknet::macros::felt; +use starknet::signers::SigningKey; + +use crate::traits::account::{CanRaiseAccountErrors, HasStarknetAccount}; +use crate::traits::contract::deploy::ContractDeployer; +use crate::traits::types::blob::HasBlobType; +use crate::traits::types::contract_class::HasContractClassHashType; +use crate::types::tx_response::TxResponse; + +pub struct DeployStarknetContract; + +const DEFAULT_UDC_ADDRESS: Felt = + felt!("0x041a78e741e5af2fec34b695679bc6891742439f7afb8484ecd7766661ad02bf"); + +impl ContractDeployer for DeployStarknetContract +where + Chain: HasContractClassHashType + + HasAddressType
+ + HasBlobType> + + CanPollTxResponse + + HasStarknetAccount + + CanRaiseAccountErrors + + CanRaiseError, +{ + async fn deploy_contract( + chain: &Chain, + class_hash: &Felt, + unique: bool, + constructor_call_data: &Vec, + ) -> Result { + let account = chain.account(); + + let factory = ContractFactory::new_with_udc(*class_hash, account, DEFAULT_UDC_ADDRESS); + + let salt = SigningKey::from_random().secret_scalar(); + + let contract_deployment = factory.deploy_v3(constructor_call_data.clone(), salt, unique); + + let deployed_address = contract_deployment.deployed_address(); + + let tx_hash = contract_deployment + .send() + .await + .map_err(Chain::raise_error)? + .transaction_hash; + + let tx_response = chain.poll_tx_response(&tx_hash).await?; + + if let Some(reverted) = tx_response.is_reverted() { + return Err(Chain::raise_error(reverted)); + } + + Ok(deployed_address) + } +} diff --git a/relayer/crates/starknet-chain-components/src/impls/contract/mod.rs b/relayer/crates/starknet-chain-components/src/impls/contract/mod.rs index b5abf3c4..f7a3d793 100644 --- a/relayer/crates/starknet-chain-components/src/impls/contract/mod.rs +++ b/relayer/crates/starknet-chain-components/src/impls/contract/mod.rs @@ -1,3 +1,5 @@ pub mod call; +pub mod declare; +pub mod deploy; pub mod invoke; pub mod message; diff --git a/relayer/crates/starknet-chain-components/src/impls/types/contract.rs b/relayer/crates/starknet-chain-components/src/impls/types/contract.rs new file mode 100644 index 00000000..88e9d8bf --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/impls/types/contract.rs @@ -0,0 +1,17 @@ +use cgp_core::Async; +use starknet::core::types::contract::SierraClass; +use starknet::core::types::Felt; + +use crate::traits::types::contract_class::{ + ProvideContractClassHashType, ProvideContractClassType, +}; + +pub struct ProvideStarknetContractTypes; + +impl ProvideContractClassType for ProvideStarknetContractTypes { + type ContractClass = SierraClass; +} + +impl ProvideContractClassHashType for ProvideStarknetContractTypes { + type ContractClassHash = Felt; +} diff --git a/relayer/crates/starknet-chain-components/src/impls/types/mod.rs b/relayer/crates/starknet-chain-components/src/impls/types/mod.rs index cf3949d2..72a34c67 100644 --- a/relayer/crates/starknet-chain-components/src/impls/types/mod.rs +++ b/relayer/crates/starknet-chain-components/src/impls/types/mod.rs @@ -2,6 +2,7 @@ pub mod address; pub mod amount; pub mod blob; pub mod chain_id; +pub mod contract; pub mod denom; pub mod event; pub mod message; diff --git a/relayer/crates/starknet-chain-components/src/traits/contract/declare.rs b/relayer/crates/starknet-chain-components/src/traits/contract/declare.rs new file mode 100644 index 00000000..bccc1ebd --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/traits/contract/declare.rs @@ -0,0 +1,14 @@ +use cgp_core::prelude::*; + +use crate::traits::types::contract_class::{HasContractClassHashType, HasContractClassType}; + +#[derive_component(ContractDeclarerComponent, ContractDeclarer)] +#[async_trait] +pub trait CanDeclareContract: + HasContractClassType + HasContractClassHashType + HasErrorType +{ + async fn declare_contract( + &self, + contract_class: &Self::ContractClass, + ) -> Result; +} diff --git a/relayer/crates/starknet-chain-components/src/traits/contract/deploy.rs b/relayer/crates/starknet-chain-components/src/traits/contract/deploy.rs new file mode 100644 index 00000000..2295a39b --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/traits/contract/deploy.rs @@ -0,0 +1,18 @@ +use cgp_core::prelude::*; +use hermes_test_components::chain::traits::types::address::HasAddressType; + +use crate::traits::types::blob::HasBlobType; +use crate::traits::types::contract_class::HasContractClassHashType; + +#[derive_component(ContractDeployerComponent, ContractDeployer)] +#[async_trait] +pub trait CanDeployContract: + HasContractClassHashType + HasBlobType + HasAddressType + HasErrorType +{ + async fn deploy_contract( + &self, + class_hash: &Self::ContractClassHash, + unique: bool, + constructor_call_data: &Self::Blob, + ) -> Result; +} diff --git a/relayer/crates/starknet-chain-components/src/traits/contract/mod.rs b/relayer/crates/starknet-chain-components/src/traits/contract/mod.rs index b5abf3c4..f7a3d793 100644 --- a/relayer/crates/starknet-chain-components/src/traits/contract/mod.rs +++ b/relayer/crates/starknet-chain-components/src/traits/contract/mod.rs @@ -1,3 +1,5 @@ pub mod call; +pub mod declare; +pub mod deploy; pub mod invoke; pub mod message; diff --git a/relayer/crates/starknet-chain-components/src/traits/types/address.rs b/relayer/crates/starknet-chain-components/src/traits/types/address.rs deleted file mode 100644 index 8435200d..00000000 --- a/relayer/crates/starknet-chain-components/src/traits/types/address.rs +++ /dev/null @@ -1,6 +0,0 @@ -use cgp_core::prelude::*; - -#[derive_component(AddressTypeComponent, ProvideAddressType)] -pub trait HasAddressType: Async { - type Address: Async; -} diff --git a/relayer/crates/starknet-chain-components/src/traits/types/amount.rs b/relayer/crates/starknet-chain-components/src/traits/types/amount.rs deleted file mode 100644 index ad82c64b..00000000 --- a/relayer/crates/starknet-chain-components/src/traits/types/amount.rs +++ /dev/null @@ -1,6 +0,0 @@ -use cgp_core::prelude::*; - -#[derive_component(AmountTypeComponent, ProvideAmountType)] -pub trait HasAmountType: Async { - type Amount: Async; -} diff --git a/relayer/crates/starknet-chain-components/src/traits/types/contract_class.rs b/relayer/crates/starknet-chain-components/src/traits/types/contract_class.rs new file mode 100644 index 00000000..a0b2b9b8 --- /dev/null +++ b/relayer/crates/starknet-chain-components/src/traits/types/contract_class.rs @@ -0,0 +1,11 @@ +use cgp_core::prelude::*; + +#[derive_component(ContractClassTypeComponent, ProvideContractClassType)] +pub trait HasContractClassType: Async { + type ContractClass: Async; +} + +#[derive_component(ContractClassHashTypeComponent, ProvideContractClassHashType)] +pub trait HasContractClassHashType: Async { + type ContractClassHash: Async; +} diff --git a/relayer/crates/starknet-chain-components/src/traits/types/mod.rs b/relayer/crates/starknet-chain-components/src/traits/types/mod.rs index ea0a4540..f495d333 100644 --- a/relayer/crates/starknet-chain-components/src/traits/types/mod.rs +++ b/relayer/crates/starknet-chain-components/src/traits/types/mod.rs @@ -1,2 +1,3 @@ pub mod blob; +pub mod contract_class; pub mod method; diff --git a/relayer/crates/starknet-chain-components/src/types/tx_response.rs b/relayer/crates/starknet-chain-components/src/types/tx_response.rs index 61802954..662b605f 100644 --- a/relayer/crates/starknet-chain-components/src/types/tx_response.rs +++ b/relayer/crates/starknet-chain-components/src/types/tx_response.rs @@ -1,7 +1,62 @@ -use starknet::core::types::{TransactionReceiptWithBlockInfo, TransactionTrace}; +use starknet::core::types::{ + ExecutionResult, RevertedInvocation, TransactionReceipt, TransactionReceiptWithBlockInfo, + TransactionTrace, +}; #[derive(Debug)] pub struct TxResponse { pub receipt: TransactionReceiptWithBlockInfo, pub trace: TransactionTrace, } + +impl TxResponse { + pub fn is_reverted(&self) -> Option { + match &self.receipt.receipt { + TransactionReceipt::Invoke(receipt) => { + if let ExecutionResult::Reverted { ref reason } = receipt.execution_result { + Some(RevertedInvocation { + revert_reason: reason.clone(), + }) + } else { + None + } + } + TransactionReceipt::L1Handler(receipt) => { + if let ExecutionResult::Reverted { ref reason } = receipt.execution_result { + Some(RevertedInvocation { + revert_reason: reason.clone(), + }) + } else { + None + } + } + TransactionReceipt::Declare(receipt) => { + if let ExecutionResult::Reverted { ref reason } = receipt.execution_result { + Some(RevertedInvocation { + revert_reason: reason.clone(), + }) + } else { + None + } + } + TransactionReceipt::Deploy(receipt) => { + if let ExecutionResult::Reverted { ref reason } = receipt.execution_result { + Some(RevertedInvocation { + revert_reason: reason.clone(), + }) + } else { + None + } + } + TransactionReceipt::DeployAccount(receipt) => { + if let ExecutionResult::Reverted { ref reason } = receipt.execution_result { + Some(RevertedInvocation { + revert_reason: reason.clone(), + }) + } else { + None + } + } + } + } +} diff --git a/relayer/crates/starknet-chain-context/Cargo.toml b/relayer/crates/starknet-chain-context/Cargo.toml index 43468d77..d55b8c63 100644 --- a/relayer/crates/starknet-chain-context/Cargo.toml +++ b/relayer/crates/starknet-chain-context/Cargo.toml @@ -21,6 +21,8 @@ hermes-test-components = { workspace = true } hermes-starknet-chain-components = { workspace = true } hermes-starknet-test-components = { workspace = true } -starknet = { workspace = true } -url = { workspace = true } -eyre = { workspace = true } +starknet = { workspace = true } +url = { workspace = true } +eyre = { workspace = true } +serde_json = { workspace = true } +cairo-lang-starknet-classes = { workspace = true } diff --git a/relayer/crates/starknet-chain-context/src/contexts/chain.rs b/relayer/crates/starknet-chain-context/src/contexts/chain.rs index db22e3a4..750fc937 100644 --- a/relayer/crates/starknet-chain-context/src/contexts/chain.rs +++ b/relayer/crates/starknet-chain-context/src/contexts/chain.rs @@ -25,6 +25,8 @@ use hermes_starknet_chain_components::traits::account::{ }; use hermes_starknet_chain_components::traits::client::JsonRpcClientGetter; use hermes_starknet_chain_components::traits::contract::call::CanCallContract; +use hermes_starknet_chain_components::traits::contract::declare::CanDeclareContract; +use hermes_starknet_chain_components::traits::contract::deploy::CanDeployContract; use hermes_starknet_chain_components::traits::contract::invoke::CanInvokeContract; use hermes_starknet_chain_components::traits::provider::{ HasStarknetProvider, StarknetProviderGetterComponent, StarknetProviderTypeComponent, @@ -122,6 +124,8 @@ pub trait CanUseStarknetChain: + CanPollTxResponse + CanCallContract + CanInvokeContract + + CanDeclareContract + + CanDeployContract + CanQueryTokenBalance + CanTransferToken + HasRetryableError diff --git a/relayer/crates/starknet-chain-context/src/impls/error.rs b/relayer/crates/starknet-chain-context/src/impls/error.rs index ea50707e..5bdd660b 100644 --- a/relayer/crates/starknet-chain-context/src/impls/error.rs +++ b/relayer/crates/starknet-chain-context/src/impls/error.rs @@ -1,5 +1,6 @@ use std::convert::Infallible; +use cairo_lang_starknet_classes::casm_contract_class::StarknetSierraCompilationError; use cgp_core::prelude::*; use eyre::Report; use hermes_error::handlers::debug::DebugError; @@ -15,6 +16,7 @@ use hermes_relayer_components::transaction::traits::types::tx_hash::HasTransacti use hermes_runtime::types::error::TokioRuntimeError; use hermes_starknet_chain_components::impls::send_message::UnexpectedTransactionTraceType; use starknet::accounts::{single_owner, AccountError}; +use starknet::core::types::contract::{ComputeClassHashError, JsonError}; use starknet::core::types::RevertedInvocation; use starknet::providers::ProviderError; use starknet::signers::local_wallet; @@ -33,6 +35,10 @@ delegate_components! { SignError, TokioRuntimeError, AccountError, + serde_json::error::Error, + JsonError, + ComputeClassHashError, + StarknetSierraCompilationError, ]: ReportError, [ <'a> &'a str, diff --git a/relayer/crates/starknet-integration-tests/Cargo.toml b/relayer/crates/starknet-integration-tests/Cargo.toml index 942990f3..99e75b66 100644 --- a/relayer/crates/starknet-integration-tests/Cargo.toml +++ b/relayer/crates/starknet-integration-tests/Cargo.toml @@ -22,7 +22,9 @@ hermes-starknet-chain-context = { workspace = true } hermes-cosmos-test-components = { workspace = true } hermes-cosmos-integration-tests = { workspace = true } -starknet = { workspace = true } -url = { workspace = true } -eyre = { workspace = true } -tokio = { workspace = true } +starknet = { workspace = true } +url = { workspace = true } +eyre = { workspace = true } +tokio = { workspace = true } +serde_json = { workspace = true } +cainome-cairo-serde = { workspace = true } diff --git a/relayer/crates/starknet-integration-tests/tests/chain.rs b/relayer/crates/starknet-integration-tests/tests/chain.rs index 7e0797dd..122f3897 100644 --- a/relayer/crates/starknet-integration-tests/tests/chain.rs +++ b/relayer/crates/starknet-integration-tests/tests/chain.rs @@ -1,11 +1,18 @@ +use std::time::SystemTime; + +use cainome_cairo_serde::{ByteArray, CairoSerde, U256}; use hermes_cosmos_integration_tests::init::init_test_runtime; use hermes_error::types::Error; use hermes_relayer_components::chain::traits::send_message::CanSendMessages; +use hermes_runtime_components::traits::fs::read_file::CanReadFileAsString; +use hermes_starknet_chain_components::traits::contract::declare::CanDeclareContract; +use hermes_starknet_chain_components::traits::contract::deploy::CanDeployContract; use hermes_starknet_chain_components::traits::messages::transfer::CanBuildTransferTokenMessage; use hermes_starknet_chain_components::traits::queries::token_balance::CanQueryTokenBalance; use hermes_starknet_chain_components::types::amount::StarknetAmount; use hermes_starknet_integration_tests::contexts::bootstrap::StarknetBootstrap; use hermes_test_components::bootstrap::traits::chain::CanBootstrapChain; +use starknet::core::types::contract::SierraClass; // Note: the test needs to be run with starknet-devnet-rs with the seed 0: // @@ -22,65 +29,114 @@ fn test_starknet_chain_client() { .unwrap_or("starknet-devnet".into()) .into(); + let timestamp = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH)? + .as_secs(); + let bootstrap = StarknetBootstrap { runtime: runtime.clone(), chain_command_path, - chain_store_dir: "./test-data".into(), + chain_store_dir: format!("./test-data/{timestamp}").into(), }; let chain_driver = bootstrap.bootstrap_chain("starknet").await?; let chain = &chain_driver.chain; - let account_address = chain_driver.relayer_wallet.account_address; + { + // Test local ERC20 token transfer + + let account_address = chain_driver.relayer_wallet.account_address; + + let token_address = chain_driver.genesis_config.transfer_denom; + + let recipient_address = chain_driver.user_wallet_a.account_address; + + let sender_balance_a = chain + .query_token_balance(&token_address, &account_address) + .await?; + + println!("sender balance before: {}", sender_balance_a); + + let recipient_balance_a = chain + .query_token_balance(&token_address, &recipient_address) + .await?; + + println!("recipient balance before: {}", recipient_balance_a); + + let message = chain.build_transfer_token_message( + &recipient_address, + &StarknetAmount::new(100u32.into(), token_address), + ); + + let events = chain.send_messages(vec![message]).await?; + + println!("events from sending transfer token message: {:?}", events); + + println!("performed transfer of 100 ETH"); + + let sender_balance_b = chain + .query_token_balance(&token_address, &account_address) + .await?; + + println!("sender balance after transfer: {}", sender_balance_b); + + let recipient_balance_b = chain + .query_token_balance(&token_address, &recipient_address) + .await?; + + println!("recipient balance transfer: {}", recipient_balance_b); + + assert_eq!( + sender_balance_b.quantity, + sender_balance_a.quantity - 100u32.into() + ); + assert_eq!( + recipient_balance_b.quantity, + recipient_balance_a.quantity + 100u32.into() + ); + } + + { + // Test deployment of ERC20 contract + + let contract_path = std::env::var("ERC20_CONTRACT")?; - let token_address = chain_driver.genesis_config.transfer_denom; + let contract_str = runtime.read_file_as_string(&contract_path.into()).await?; - let recipient_address = chain_driver.user_wallet_a.account_address; + let contract: SierraClass = serde_json::from_str(&contract_str)?; - let sender_balance_a = chain - .query_token_balance(&token_address, &account_address) - .await?; + let class_hash = chain.declare_contract(&contract).await?; - println!("sender balance before: {}", sender_balance_a); + println!("declared class: {:?}", class_hash); - let recipient_balance_a = chain - .query_token_balance(&token_address, &recipient_address) - .await?; + let mut calldata = Vec::new(); - println!("recipient balance before: {}", recipient_balance_a); + let relayer_address = chain_driver.relayer_wallet.account_address; - let message = chain.build_transfer_token_message( - &recipient_address, - &StarknetAmount::new(100u32.into(), token_address), - ); + let token_name = ByteArray::cairo_serialize(&ByteArray::from_string("token")?); - let events = chain.send_messages(vec![message]).await?; + // Manually construct the contract arguments into Vec calldata for now - println!("events from sending transfer token message: {:?}", events); + calldata.extend(token_name.clone()); //name: ByteArray + calldata.extend(token_name.clone()); // symbol: ByteArray - println!("performed transfer of 100 ETH"); + calldata.extend(U256::cairo_serialize(&U256 { low: 100, high: 0 })); // fixed_supply: u256 + calldata.push(relayer_address); // recipient: ContractAddress + calldata.push(relayer_address); // owner: ContractAddress - let sender_balance_b = chain - .query_token_balance(&token_address, &account_address) - .await?; + let token_address = chain.deploy_contract(&class_hash, false, &calldata).await?; - println!("sender balance after transfer: {}", sender_balance_b); + println!("deployed contract to address: {:?}", token_address); - let recipient_balance_b = chain - .query_token_balance(&token_address, &recipient_address) - .await?; + let balance = chain + .query_token_balance(&token_address, &relayer_address) + .await?; - println!("recipient balance transfer: {}", recipient_balance_b); + println!("initial balance: {}", balance); - assert_eq!( - sender_balance_b.quantity, - sender_balance_a.quantity - 100u32.into() - ); - assert_eq!( - recipient_balance_b.quantity, - recipient_balance_a.quantity + 100u32.into() - ); + assert_eq!(balance.quantity, 100u32.into()); + } >::Ok(()) }) diff --git a/relayer/crates/starknet-test-components/src/impls/bootstrap/start_chain.rs b/relayer/crates/starknet-test-components/src/impls/bootstrap/start_chain.rs index 93331bbd..fbfea719 100644 --- a/relayer/crates/starknet-test-components/src/impls/bootstrap/start_chain.rs +++ b/relayer/crates/starknet-test-components/src/impls/bootstrap/start_chain.rs @@ -29,11 +29,20 @@ where ) -> Result { let chain_command = bootstrap.chain_command_path(); + let chain_state_path = Runtime::join_file_path( + chain_home_dir, + &Runtime::file_path_from_string("chain-state.json"), + ); + let args = [ "--seed", &chain_genesis_config.seed.to_string(), "--port", &chain_node_config.rpc_port.to_string(), + "--dump-on", + "block", + "--dump-path", + &Runtime::file_path_to_string(&chain_state_path), ]; let stdout_path = Runtime::join_file_path(