From 2b67796c31dddcb76a4a1c0d4e548f0a58de3aaa Mon Sep 17 00:00:00 2001 From: Leonid Tyurin Date: Fri, 10 Nov 2023 19:48:37 +0400 Subject: [PATCH] Add tests --- smart-contract-verifier/Cargo.lock | 376 ++++++++++++++---- .../smart-contract-verifier-server/Cargo.toml | 3 +- .../src/settings.rs | 3 +- .../tests/lookup_methods.rs | 114 ++++++ .../import/AbstractContract.sol | 10 + .../import/DerivedContract.sol | 21 + .../import/config.json | 4 + .../simple/Greeter.sol | 18 + .../simple/config.json | 4 + .../src/lookup_methods/disassemble.rs | 2 +- .../src/lookup_methods/find_methods.rs | 37 +- 11 files changed, 500 insertions(+), 92 deletions(-) create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/lookup_methods.rs create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/AbstractContract.sol create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/DerivedContract.sol create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/config.json create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/Greeter.sol create mode 100644 smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/config.json diff --git a/smart-contract-verifier/Cargo.lock b/smart-contract-verifier/Cargo.lock index f27ae6fb7..3cdd4fc81 100644 --- a/smart-contract-verifier/Cargo.lock +++ b/smart-contract-verifier/Cargo.lock @@ -145,7 +145,7 @@ dependencies = [ "futures-util", "mio", "num_cpus", - "socket2", + "socket2 0.4.9", "tokio", "tracing", ] @@ -206,7 +206,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "smallvec", - "socket2", + "socket2 0.4.9", "time 0.3.21", "url", ] @@ -235,6 +235,15 @@ dependencies = [ "prometheus", ] +[[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" @@ -470,7 +479,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aeeee1a5defa63cba39097a510dfe63ef53658fc8995202a610f6a8a4d03639" dependencies = [ "attohttpc", - "dirs", + "dirs 4.0.0", "rust-ini", "serde", "serde-xml-rs", @@ -533,6 +542,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" @@ -619,22 +643,24 @@ dependencies = [ [[package]] name = "blockscout-service-launcher" -version = "0.6.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cb6b37fb1a21e3c5525ff9cc9fce568f5e13e4d5968ab932995034f66d01316" +checksum = "662512331ca49faf635aab7d25d29b2e66c020a807354d8cbd3d8a921600aa24" dependencies = [ "actix-web", "actix-web-prom", "anyhow", + "config", "futures", - "opentelemetry 0.18.0", - "opentelemetry-jaeger 0.17.0", + "opentelemetry 0.19.0", + "opentelemetry-jaeger 0.18.0", "prometheus", + "reqwest", "serde", "tokio", "tonic", "tracing", - "tracing-opentelemetry 0.18.0", + "tracing-opentelemetry 0.19.0", "tracing-subscriber", ] @@ -1099,7 +1125,16 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" dependencies = [ - "dirs-sys", + "dirs-sys 0.3.7", +] + +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys 0.4.1", ] [[package]] @@ -1123,6 +1158,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + [[package]] name = "dirs-sys-next" version = "0.1.2" @@ -1307,16 +1354,17 @@ dependencies = [ [[package]] name = "ethers-solc" -version = "2.0.7" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81c89f121595cf8959e746045bb8b25a6a38d72588561e1a3b7992fc213f674" +checksum = "de34e484e7ae3cab99fbfd013d6c5dc7f9013676a4e0e414d8b12e1213e8b3ba" dependencies = [ "cfg-if", + "const-hex", + "dirs 5.0.1", "dunce", "ethers-core", "futures-util", "glob", - "hex", "home", "md-5", "num_cpus", @@ -1604,6 +1652,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gimli" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" + [[package]] name = "glob" version = "0.3.1" @@ -1655,15 +1709,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.1" @@ -1766,7 +1811,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.4.9", "tokio", "tower-service", "tracing", @@ -1938,7 +1983,7 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi", "libc", "windows-sys 0.48.0", ] @@ -1955,7 +2000,7 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "hermit-abi 0.3.1", + "hermit-abi", "io-lifetimes", "rustix 0.37.19", "windows-sys 0.48.0", @@ -1970,6 +2015,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.6" @@ -2029,20 +2083,20 @@ dependencies = [ [[package]] name = "lalrpop" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +checksum = "da4081d44f4611b66c6dd725e6de3169f9f63905421e8626fcb86b6a898998b8" dependencies = [ "ascii-canvas", "bit-set", "diff", "ena", "is-terminal", - "itertools", + "itertools 0.10.5", "lalrpop-util", "petgraph", "regex", - "regex-syntax 0.6.29", + "regex-syntax 0.7.5", "string_cache", "term", "tiny-keccak", @@ -2051,9 +2105,9 @@ dependencies = [ [[package]] name = "lalrpop-util" -version = "0.19.12" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" +checksum = "3f35c735096c0293d313e8f2a641627472b83d01b937177fe76e5e2708d31e0d" [[package]] name = "language-tags" @@ -2137,7 +2191,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" dependencies = [ - "regex-automata", + "regex-automata 0.1.10", ] [[package]] @@ -2249,9 +2303,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" dependencies = [ "libc", "log", @@ -2363,11 +2417,11 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -2392,11 +2446,20 @@ dependencies = [ "syn 2.0.18", ] +[[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.2" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "open-fastrlp" @@ -2494,8 +2557,18 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" dependencies = [ - "opentelemetry_api", - "opentelemetry_sdk", + "opentelemetry_api 0.18.0", + "opentelemetry_sdk 0.18.0", +] + +[[package]] +name = "opentelemetry" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4b8347cc26099d3aeee044065ecc3ae11469796b4d65d065a23a584ed92a6f" +dependencies = [ + "opentelemetry_api 0.19.0", + "opentelemetry_sdk 0.19.0", ] [[package]] @@ -2530,6 +2603,23 @@ dependencies = [ "tokio", ] +[[package]] +name = "opentelemetry-jaeger" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08e028dc9f4f304e9320ce38c80e7cf74067415b1ad5a8750a38bae54a4d450d" +dependencies = [ + "async-trait", + "futures", + "futures-executor", + "once_cell", + "opentelemetry 0.19.0", + "opentelemetry-semantic-conventions 0.11.0", + "thiserror", + "thrift 0.17.0", + "tokio", +] + [[package]] name = "opentelemetry-semantic-conventions" version = "0.9.0" @@ -2548,6 +2638,15 @@ dependencies = [ "opentelemetry 0.18.0", ] +[[package]] +name = "opentelemetry-semantic-conventions" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24e33428e6bf08c6f7fcea4ddb8e358fab0fe48ab877a87c70c6ebe20f673ce5" +dependencies = [ + "opentelemetry 0.19.0", +] + [[package]] name = "opentelemetry_api" version = "0.18.0" @@ -2564,6 +2663,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "opentelemetry_api" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed41783a5bf567688eb38372f2b7a8530f5a607a4b49d38dd7573236c23ca7e2" +dependencies = [ + "fnv", + "futures-channel", + "futures-util", + "indexmap", + "once_cell", + "pin-project-lite", + "thiserror", + "urlencoding", +] + [[package]] name = "opentelemetry_sdk" version = "0.18.0" @@ -2578,7 +2693,7 @@ dependencies = [ "futures-executor", "futures-util", "once_cell", - "opentelemetry_api", + "opentelemetry_api 0.18.0", "percent-encoding", "rand 0.8.5", "thiserror", @@ -2586,6 +2701,34 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "opentelemetry_sdk" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b3a2a91fdbfdd4d212c0dcc2ab540de2c2bcbbd90be17de7a7daf8822d010c1" +dependencies = [ + "async-trait", + "crossbeam-channel", + "dashmap", + "fnv", + "futures-channel", + "futures-executor", + "futures-util", + "once_cell", + "opentelemetry_api 0.19.0", + "percent-encoding", + "rand 0.8.5", + "thiserror", + "tokio", + "tokio-stream", +] + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-float" version = "1.1.1" @@ -2595,6 +2738,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "ordered-float" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c" +dependencies = [ + "num-traits", +] + [[package]] name = "ordered-multimap" version = "0.4.3" @@ -2874,9 +3026,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "pin-utils" @@ -2920,7 +3072,7 @@ checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" dependencies = [ "difflib", "float-cmp", - "itertools", + "itertools 0.10.5", "normalize-line-endings", "predicates-core", "regex", @@ -3048,7 +3200,7 @@ dependencies = [ "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax 0.7.2", + "regex-syntax 0.7.5", "unarray", ] @@ -3070,7 +3222,7 @@ checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", "heck", - "itertools", + "itertools 0.10.5", "lazy_static", "log", "multimap", @@ -3091,7 +3243,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", @@ -3270,13 +3422,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.3" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ "aho-corasick", "memchr", - "regex-syntax 0.7.2", + "regex-automata 0.3.7", + "regex-syntax 0.7.5", ] [[package]] @@ -3288,6 +3441,17 @@ dependencies = [ "regex-syntax 0.6.29", ] +[[package]] +name = "regex-automata" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.7.5", +] + [[package]] name = "regex-syntax" version = "0.6.29" @@ -3296,9 +3460,15 @@ checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + +[[package]] +name = "relative-path" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "c707298afce11da2efef2f600116fa93ffa7a032b5d7b628aa17711ec81383ca" [[package]] name = "reqwest" @@ -3519,13 +3689,13 @@ dependencies = [ [[package]] name = "rstest" -version = "0.16.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b07f2d176c472198ec1e6551dc7da28f1c089652f66a7b722676c2238ebc0edf" +checksum = "97eeab2f3c0a199bc4be135c36c924b6590b88c377d416494288c14f2db30199" dependencies = [ "futures", "futures-timer", - "rstest_macros 0.16.0", + "rstest_macros 0.18.2", "rustc_version", ] @@ -3544,15 +3714,18 @@ dependencies = [ [[package]] name = "rstest_macros" -version = "0.16.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7" +checksum = "d428f8247852f894ee1be110b375111b586d4fa431f6c46e64ba5a0dcccbe605" dependencies = [ "cfg-if", + "glob", "proc-macro2", "quote", + "regex", + "relative-path", "rustc_version", - "syn 1.0.109", + "syn 2.0.18", "unicode-ident", ] @@ -3597,6 +3770,12 @@ dependencies = [ "url", ] +[[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" @@ -3923,9 +4102,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -4150,7 +4329,7 @@ dependencies = [ "pretty_assertions", "prometheus", "reqwest", - "rstest 0.16.0", + "rstest 0.18.2", "rust-s3", "serde", "serde_json", @@ -4188,13 +4367,23 @@ dependencies = [ "winapi", ] +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "solang-parser" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a94494913728908efa7a25a2dd2e4f037e714897985c24273c40596638ed909" +checksum = "7cb9fa2fa2fa6837be8a2495486ff92e3ffe68a99b6eeba288e139efdd842457" dependencies = [ - "itertools", + "itertools 0.11.0", "lalrpop", "lalrpop-util", "phf", @@ -4327,13 +4516,13 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "svm-rs" -version = "0.2.23" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a04fc4f5cd35c700153b233f5575ccb3237e0f941fa5049d9e98254d10bf2fe" +checksum = "20689c7d03b6461b502d0b95d6c24874c7d24dea2688af80486a130a06af3b07" dependencies = [ + "dirs 5.0.1", "fs2", "hex", - "home", "once_cell", "reqwest", "semver", @@ -4347,9 +4536,9 @@ dependencies = [ [[package]] name = "svm-rs-builds" -version = "0.1.15" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32deae08684d03d8a4ba99b8a3b0a1575364820339930f6fa2afdfa3a6d98c84" +checksum = "aa64b5e8eecd3a8af7cfc311e29db31a268a62d5953233d3e8243ec77a71c4e3" dependencies = [ "build_const", "hex", @@ -4479,7 +4668,7 @@ dependencies = [ "byteorder", "integer-encoding", "log", - "ordered-float", + "ordered-float 1.1.1", "threadpool", ] @@ -4492,7 +4681,20 @@ dependencies = [ "byteorder", "integer-encoding", "log", - "ordered-float", + "ordered-float 1.1.1", + "threadpool", +] + +[[package]] +name = "thrift" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e54bc85fc7faa8bc175c4bab5b92ba8d9a3ce893d0e9f42cc455c8ab16a9e09" +dependencies = [ + "byteorder", + "integer-encoding", + "log", + "ordered-float 2.10.1", "threadpool", ] @@ -4560,11 +4762,11 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.28.2" +version = "1.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94d7b1cfd2aa4011f2de74c2c4c63665e27a71006b0a192dcd2710272e73dfa2" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", "mio", @@ -4572,7 +4774,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", ] @@ -4589,9 +4791,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", @@ -4841,6 +5043,20 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-opentelemetry" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00a39dcf9bfc1742fa4d6215253b33a6e474be78275884c216fc2a06267b3600" +dependencies = [ + "once_cell", + "opentelemetry 0.19.0", + "tracing", + "tracing-core", + "tracing-log", + "tracing-subscriber", +] + [[package]] name = "tracing-serde" version = "0.1.3" @@ -4968,6 +5184,12 @@ dependencies = [ "serde", ] +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "uuid" version = "1.3.3" diff --git a/smart-contract-verifier/smart-contract-verifier-server/Cargo.toml b/smart-contract-verifier/smart-contract-verifier-server/Cargo.toml index a6ad69bd7..9f5f6227b 100644 --- a/smart-contract-verifier/smart-contract-verifier-server/Cargo.toml +++ b/smart-contract-verifier/smart-contract-verifier-server/Cargo.toml @@ -20,7 +20,7 @@ blockscout-service-launcher = { version = "0.9.0" } bytes = "1.3" config = "0.13" cron = "0.11" -ethers-solc = "2.0.6" +ethers-solc = "2.0.10" ethers-core = "2.0.10" futures = "0.3" lazy_static = "1" @@ -40,6 +40,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } url = "2.3" [dev-dependencies] +ethers-solc = { version = "2.0.10", features = ["svm-solc"] } blockscout-service-launcher = { version = "0.9.0" , features = ["test-server"]} ethabi = "18.0" pretty_assertions = "1.3" diff --git a/smart-contract-verifier/smart-contract-verifier-server/src/settings.rs b/smart-contract-verifier/smart-contract-verifier-server/src/settings.rs index 749b3e767..c981c7407 100644 --- a/smart-contract-verifier/smart-contract-verifier-server/src/settings.rs +++ b/smart-contract-verifier/smart-contract-verifier-server/src/settings.rs @@ -1,7 +1,6 @@ use anyhow::anyhow; -use blockscout_service_launcher::launcher::ConfigSettings; use blockscout_service_launcher::{ - launcher::{MetricsSettings, ServerSettings}, + launcher::{ConfigSettings, MetricsSettings, ServerSettings}, tracing::{JaegerSettings, TracingSettings}, }; use cron::Schedule; diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/lookup_methods.rs b/smart-contract-verifier/smart-contract-verifier-server/tests/lookup_methods.rs new file mode 100644 index 000000000..75a8a1ff9 --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/lookup_methods.rs @@ -0,0 +1,114 @@ +use blockscout_service_launcher::{ + launcher::ConfigSettings, + test_server::{get_test_server_settings, init_server, send_post_request}, +}; +use ethers_solc::{CompilerInput, CompilerOutput, EvmVersion, Solc}; +use lazy_static::lazy_static; +use rstest::rstest; +use serde::Deserialize; +use smart_contract_verifier_proto::blockscout::smart_contract_verifier::v2::{ + LookupMethodsRequest, LookupMethodsResponse, +}; +use smart_contract_verifier_server::Settings; +use std::{ + collections::{BTreeMap, BTreeSet}, + path::PathBuf, +}; +use tokio::sync::Semaphore; + +const ROUTE: &str = "/api/v2/verifier/solidity/methods:lookup"; + +lazy_static! { + static ref COMPILER_LOCK: Semaphore = Semaphore::new(1); +} + +fn process_compiler_output( + output: &CompilerOutput, + contract_name: &str, +) -> anyhow::Result<(LookupMethodsRequest, BTreeMap)> { + let (_, contract) = output + .contracts_iter() + .find(|(name, _)| *name == contract_name) + .ok_or_else(|| anyhow::anyhow!("contract not found"))?; + let evm = contract.evm.as_ref().expect("evm included"); + let deployed_bytecode = evm + .deployed_bytecode + .as_ref() + .expect("deployed bytecode included") + .bytecode + .as_ref() + .expect("bytecode included"); + let methods = evm.method_identifiers.clone(); + + let bytecode = deployed_bytecode + .object + .clone() + .into_bytes() + .unwrap() + .to_string(); + let abi = serde_json::to_string(&contract.abi.clone().expect("abi included"))?; + let source_map = deployed_bytecode + .source_map + .as_ref() + .expect("srcmap included") + .clone(); + let file_ids = output + .sources + .iter() + .map(|(name, file)| (file.id, name.clone())) + .collect(); + + let request = LookupMethodsRequest { + abi, + bytecode, + file_ids, + source_map, + }; + Ok((request, methods)) +} + +#[derive(Deserialize)] +struct TestCase { + version: String, + contract_name: String, +} + +#[rstest] +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn test_lookup_methods(#[files("tests/test_cases_lookup_methods/*")] test_dir: PathBuf) { + let mut settings = Settings::build().expect("Failed to build settings"); + let (server_settings, base) = get_test_server_settings(); + settings.server = server_settings; + settings.vyper.enabled = false; + settings.solidity.enabled = true; + settings.sourcify.enabled = false; + settings.jaeger.enabled = false; + settings.tracing.enabled = false; + + init_server(|| smart_contract_verifier_server::run(settings), &base).await; + + let test_case: TestCase = serde_json::from_str( + std::fs::read_to_string(test_dir.join("config.json")) + .unwrap() + .as_str(), + ) + .expect("Failed to parse test case"); + + let solc = { + let _permit = COMPILER_LOCK.acquire().await.unwrap(); + Solc::find_or_install_svm_version(test_case.version).expect("failed to install version") + }; + + let inputs = CompilerInput::new(test_dir).expect("failed to read dir"); + let input = inputs[0].clone().evm_version(EvmVersion::London); + let output = solc.compile(&input).expect("failed to compile"); + + let (request, methods) = process_compiler_output(&output, &test_case.contract_name).unwrap(); + let res: LookupMethodsResponse = send_post_request(&base, ROUTE, &request).await; + + // Make sure we extracted all methods + assert_eq!( + methods.values().collect::>(), + res.methods.keys().collect::>() + ); +} diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/AbstractContract.sol b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/AbstractContract.sol new file mode 100644 index 000000000..4daec359d --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/AbstractContract.sol @@ -0,0 +1,10 @@ +pragma solidity ^0.8.0; + +abstract contract AbstractContract { + // Declaring functions + function getStr( + string memory _strIn) public view virtual returns( + string memory); + function setValue(uint _in1, uint _in2) public virtual; + function add() public virtual returns(uint); +} \ No newline at end of file diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/DerivedContract.sol b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/DerivedContract.sol new file mode 100644 index 000000000..46d0d69d5 --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/DerivedContract.sol @@ -0,0 +1,21 @@ +pragma solidity ^0.8.0; + +import "./AbstractContract.sol"; + +contract DerivedContract is AbstractContract{ + uint private num1; + uint private num2; + + function getStr(string memory _strIn) public pure override returns(string memory) { + return _strIn; + } + + function setValue(uint _in1, uint _in2) public override { + num1 = _in1; + num2 = _in2; + } + + function add() public view override returns(uint) { + return (num2 + num1); + } +} \ No newline at end of file diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/config.json b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/config.json new file mode 100644 index 000000000..70267dbf5 --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/import/config.json @@ -0,0 +1,4 @@ +{ + "version": "0.8.17", + "contract_name": "DerivedContract" +} \ No newline at end of file diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/Greeter.sol b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/Greeter.sol new file mode 100644 index 000000000..5496798ff --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/Greeter.sol @@ -0,0 +1,18 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.0; + +contract Greeter { + string private greeting; + + constructor(string memory _greeting) { + greeting = _greeting; + } + + function greet() public view returns (string memory) { + return greeting; + } + + function setGreeting(string memory _greeting) public { + greeting = _greeting; + } +} diff --git a/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/config.json b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/config.json new file mode 100644 index 000000000..ecb1de7f0 --- /dev/null +++ b/smart-contract-verifier/smart-contract-verifier-server/tests/test_cases_lookup_methods/simple/config.json @@ -0,0 +1,4 @@ +{ + "version": "0.8.17", + "contract_name": "Greeter" +} \ No newline at end of file diff --git a/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/disassemble.rs b/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/disassemble.rs index 35879008b..acc144768 100644 --- a/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/disassemble.rs +++ b/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/disassemble.rs @@ -1,6 +1,6 @@ use super::opcodes::{opcode, Opcode}; use bytes::Bytes; -use std::fmt::{Debug, Display}; +use std::fmt::Debug; pub struct DisassembledOpcode { pub operation: Opcode, diff --git a/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/find_methods.rs b/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/find_methods.rs index 768235144..12d4f7912 100644 --- a/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/find_methods.rs +++ b/smart-contract-verifier/smart-contract-verifier/src/lookup_methods/find_methods.rs @@ -53,17 +53,6 @@ pub fn find_methods(request: LookupMethodsRequest) -> LookupMethodsResponse { LookupMethodsResponse { methods } } -fn prepend_selector(partial_selector: &Vec) -> anyhow::Result> { - if partial_selector.len() > 4 { - return Err(anyhow::anyhow!("selector is too long")); - }; - - // prepend selector with 0s if it's shorter than 4 bytes - let mut selector = partial_selector.clone(); - selector.splice(..0, repeat(0).take(4 - partial_selector.len())); - Ok(selector) -} - fn find_src_map_index(selector: &[u8; 4], opcodes: &[DisassembledOpcode]) -> Option { for window in opcodes.windows(5) { if window[0].operation.name.starts_with("PUSH") @@ -122,3 +111,29 @@ fn parse_selectors(abi: Abi) -> BTreeMap { .map(|f| (f.signature(), f.short_signature())) .collect() } + +fn prepend_selector(partial_selector: &Vec) -> anyhow::Result> { + if partial_selector.len() > 4 { + return Err(anyhow::anyhow!("selector is too long")); + }; + + // prepend selector with 0s if it's shorter than 4 bytes + let mut selector = partial_selector.clone(); + selector.splice(..0, repeat(0).take(4 - partial_selector.len())); + Ok(selector) +} + +#[cfg(test)] +mod tests { + use super::prepend_selector; + + #[test] + fn test_prepend_selector() { + assert_eq!( + prepend_selector(&vec![1, 2, 3, 4]).unwrap(), + vec![1, 2, 3, 4] + ); + assert_eq!(prepend_selector(&vec![1, 2]).unwrap(), vec![0, 0, 1, 2]); + assert!(prepend_selector(&vec![1, 2, 3, 4, 5]).is_err()); + } +}