diff --git a/.ci/build_and_test.sh b/.ci/build_and_test.sh index 8277240..404589f 100755 --- a/.ci/build_and_test.sh +++ b/.ci/build_and_test.sh @@ -15,4 +15,11 @@ if [ "$CFG_RELEASE_CHANNEL" == "nightly" ]; then else cargo build --locked fi -cargo test \ No newline at end of file + +cargo test + +if [ "$(uname -s)" != "Darwin" ]; then + # The MacOS CI doesn't support Docker because of licensing issues, so only run them on Linux. + # Also, run the docker tests on a single thread to avoid concurrency issues. + cargo test -F docker-test -- --test-threads 1 docker +fi diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9fe342c --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +./target diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 78b333d..0591fd3 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -26,7 +26,7 @@ jobs: - name: install rustup run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh - sh rustup-init.sh -y --default-toolchain none + sh rustup-init.sh -y --default-toolchain ${{ matrix.cfg_release_channel }} rustup target add ${{ matrix.target }} - name: Build and Test diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index 49918f7..5a3fb27 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -27,7 +27,7 @@ jobs: - name: install rustup run: | curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup-init.sh - sh rustup-init.sh -y --default-toolchain none + sh rustup-init.sh -y --default-toolchain ${{ matrix.cfg_release_channel }} rustup target add ${{ matrix.target }} - name: Build and Test diff --git a/Cargo.lock b/Cargo.lock index 2056791..ce06462 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,17 +72,17 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.18" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +checksum = "45862d1c77f2228b9e10bc609d5bc203d86ebc9b87ad8d5d5167a6c9abf739d9" [[package]] name = "alloy-chains" -version = "0.1.40" +version = "0.1.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4932d790c723181807738cf1ac68198ab581cd699545b155601332541ee47bd" +checksum = "18c5c520273946ecf715c0010b4e3503d7eba9893cd9ce6b7fff5654c4a3c470" dependencies = [ - "alloy-primitives 0.8.9", + "alloy-primitives 0.8.12", "num_enum", "strum", ] @@ -267,9 +267,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.8.9" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71738eb20c42c5fb149571e76536a0f309d142f3957c28791662b96baf77a3d" +checksum = "9fce5dbd6a4f118eecc4719eaa9c7ffc31c315e6c5ccde3642db927802312425" dependencies = [ "bytes", "cfg-if", @@ -307,7 +307,7 @@ dependencies = [ "futures-utils-wasm", "lru", "pin-project", - "reqwest 0.12.8", + "reqwest 0.12.9", "serde", "serde_json", "tokio", @@ -334,7 +334,7 @@ checksum = "2b09cae092c27b6f1bde952653a22708691802e57bfef4a2973b80bea21efd3f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -348,7 +348,7 @@ dependencies = [ "alloy-transport-http", "futures", "pin-project", - "reqwest 0.12.8", + "reqwest 0.12.9", "serde", "serde_json", "tokio", @@ -431,7 +431,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -447,7 +447,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "syn-solidity", "tiny-keccak", ] @@ -463,7 +463,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "syn-solidity", ] @@ -516,7 +516,7 @@ checksum = "2437d145d80ea1aecde8574d2058cceb8b3c9cba05f6aea8e67907c660d46698" dependencies = [ "alloy-json-rpc", "alloy-transport", - "reqwest 0.12.8", + "reqwest 0.12.9", "serde_json", "tower", "tracing", @@ -525,9 +525,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.15" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", @@ -540,36 +540,36 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.1" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.4" +version = "3.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" +checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -730,7 +730,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -741,7 +741,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -763,7 +763,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1030,7 +1030,7 @@ dependencies = [ [[package]] name = "cargo-stylus" -version = "0.5.5" +version = "0.5.6" dependencies = [ "alloy-contract", "alloy-ethers-typecast", @@ -1072,7 +1072,7 @@ dependencies = [ [[package]] name = "cargo-stylus-example" -version = "0.5.5" +version = "0.5.6" dependencies = [ "clap", ] @@ -1093,9 +1093,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.1.31" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +checksum = "fd9de9f2205d5ef3fd67e685b0df337994ddd4495e2a28d185500d0e1edfea47" dependencies = [ "jobserver", "libc", @@ -1129,9 +1129,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ "clap_builder", "clap_derive", @@ -1139,9 +1139,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.20" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19bc80abd44e4bed93ca373a0704ccbd1b710dc5749406201bb018272808dc54" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" dependencies = [ "anstream", "anstyle", @@ -1158,14 +1158,14 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" [[package]] name = "coins-bip32" @@ -1221,9 +1221,9 @@ dependencies = [ [[package]] name = "colorchoice" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "const-hex" @@ -1296,9 +1296,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" +checksum = "0ca741a962e1b0bff6d724a1a0958b686406e853bb14061f218562e1896f95e6" dependencies = [ "libc", ] @@ -1477,7 +1477,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1488,7 +1488,7 @@ checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1550,7 +1550,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.1", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1570,7 +1570,7 @@ checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "unicode-xid", ] @@ -1637,6 +1637,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "dunce" version = "1.0.5" @@ -1693,9 +1704,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.34" +version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ "cfg-if", ] @@ -1756,7 +1767,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1911,7 +1922,7 @@ dependencies = [ "reqwest 0.11.27", "serde", "serde_json", - "syn 2.0.82", + "syn 2.0.87", "toml", "walkdir", ] @@ -1929,7 +1940,7 @@ dependencies = [ "proc-macro2", "quote", "serde_json", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -1955,7 +1966,7 @@ dependencies = [ "serde", "serde_json", "strum", - "syn 2.0.82", + "syn 2.0.87", "tempfile", "thiserror", "tiny-keccak", @@ -2111,9 +2122,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" +checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fastrlp" @@ -2156,9 +2167,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.34" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1b589b4dc103969ad3cf85c950899926ec64300a1a46d76c03a6072957036f0" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", "miniz_oxide", @@ -2297,7 +2308,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -2463,9 +2474,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" dependencies = [ "allocator-api2", "equivalent", @@ -2669,9 +2680,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" +checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" dependencies = [ "bytes", "futures-channel", @@ -2686,6 +2697,124 @@ dependencies = [ "tracing", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -2694,12 +2823,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "icu_normalizer", + "icu_properties", ] [[package]] @@ -2763,7 +2903,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.15.0", + "hashbrown 0.15.1", "serde", ] @@ -2939,9 +3079,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.161" +version = "0.2.162" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" +checksum = "18d287de67fe55fd7e1581fe933d965a5a9477b38e949cfa9f8574ef01506398" [[package]] name = "libloading" @@ -2955,9 +3095,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "libredox" @@ -2975,6 +3115,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" + [[package]] name = "lock_api" version = "0.4.12" @@ -2997,7 +3143,7 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234cf4f4a04dc1f57e24b96cc0cd600cf2af460d4161ac5ecdd0af8e1f3b2a38" dependencies = [ - "hashbrown 0.15.0", + "hashbrown 0.15.1", ] [[package]] @@ -3171,7 +3317,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3237,7 +3383,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3434,7 +3580,7 @@ dependencies = [ "phf_shared 0.11.2", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3457,29 +3603,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf123a161dde1e524adf36f90bc5d8d3462824a9c43553ad07a8183161189ec" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4502d8515ca9f32f1fb543d987f63d95a14934883db45bdb48060b6b69257f8" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] name = "pin-project-lite" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -3526,12 +3672,12 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" [[package]] name = "prettyplease" -version = "0.2.24" +version = "0.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "910d41a655dac3b764f1ade94821093d3610248694320cd072303a8eedcf221d" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" dependencies = [ "proc-macro2", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -3744,9 +3890,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -3756,9 +3902,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -3835,9 +3981,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.12.8" +version = "0.12.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f713147fbe92361e52392c73b8c9e48c04c6625bce969ef54dc901e58e042a7b" +checksum = "a77c62af46e79de0a562e1a9849205ffcb7fc1238876e9bd743357570e04046f" dependencies = [ "base64 0.22.1", "bytes", @@ -4044,9 +4190,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno", @@ -4145,9 +4291,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.11.4" +version = "2.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22760a375f81a31817aeaf6f5081e9ccb7ffd7f2da1809a6e3fc82b6656f10d5" +checksum = "1aa7ffc1c0ef49b0452c6e2986abf2b07743320641ffd5fc63d552458e3b779b" dependencies = [ "cfg-if", "derive_more 1.0.0", @@ -4157,14 +4303,14 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.11.4" +version = "2.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abc61ebe25a5c410c0e245028fc9934bf8fa4817199ef5a24a68092edfd34614" +checksum = "46385cc24172cf615450267463f937c10072516359b3ff1cb24228a4a08bf951" dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.87", ] [[package]] @@ -4239,9 +4385,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.12.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -4288,9 +4434,9 @@ checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" -version = "1.0.213" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" dependencies = [ "serde_derive", ] @@ -4308,13 +4454,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.215" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4461,7 +4607,7 @@ checksum = "9659a8ce0c2f862add056dc8f43cb481176298f1df141ca16ea4d1fe3e6c8ad7" dependencies = [ "convert_case 0.6.0", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4560,7 +4706,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4602,9 +4748,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.82" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -4620,7 +4766,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4638,6 +4784,17 @@ dependencies = [ "futures-core", ] +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "sys-info" version = "0.9.1" @@ -4683,9 +4840,9 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.13.0" +version = "3.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", "fastrand", @@ -4707,22 +4864,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4774,6 +4931,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -4791,9 +4958,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.41.0" +version = "1.41.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" +checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33" dependencies = [ "backtrace", "bytes", @@ -4813,7 +4980,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -4957,7 +5124,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", ] [[package]] @@ -5035,27 +5202,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" -[[package]] -name = "unicode-bidi" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" - [[package]] name = "unicode-ident" version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" -[[package]] -name = "unicode-normalization" -version = "0.1.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-segmentation" version = "1.12.0" @@ -5064,9 +5216,9 @@ checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-width" -version = "0.1.14" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" [[package]] name = "unicode-xid" @@ -5088,9 +5240,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.2" +version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" dependencies = [ "form_urlencoded", "idna", @@ -5103,6 +5255,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -5199,7 +5363,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "wasm-bindgen-shared", ] @@ -5256,7 +5420,7 @@ checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5278,12 +5442,12 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.219.1" +version = "0.220.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29cbbd772edcb8e7d524a82ee8cef8dd046fc14033796a754c3ad246d019fa54" +checksum = "ebf48234b389415b226a4daef6562933d38c7b28a8b8f64c5c4130dad1561ab7" dependencies = [ "leb128", - "wasmparser 0.219.1", + "wasmparser 0.220.0", ] [[package]] @@ -5447,9 +5611,9 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.219.1" +version = "0.220.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c771866898879073c53b565a6c7b49953795159836714ac56a5befb581227c5" +checksum = "e246c2772ce3ebc83f89a2d4487ac5794cad6c309b2071818a88c7db7c36d87b" dependencies = [ "bitflags 2.6.0", "indexmap 2.6.0", @@ -5457,22 +5621,22 @@ dependencies = [ [[package]] name = "wast" -version = "219.0.1" +version = "220.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f79a9d9df79986a68689a6b40bcc8d5d40d807487b235bebc2ac69a242b54a1" +checksum = "4e708c8de08751fd66e70961a32bae9d71901f14a70871e181cb8461a3bb3165" dependencies = [ "bumpalo", "leb128", "memchr", "unicode-width", - "wasm-encoder 0.219.1", + "wasm-encoder 0.220.0", ] [[package]] name = "wat" -version = "1.219.1" +version = "1.220.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bc3cf014fb336883a411cd662f987abf6a1d2a27f2f0008616a0070bbf6bd0d" +checksum = "de4f1d7d59614ba690541360102b995c4eb1b9ed373701d5102cc1a968b1c5a3" dependencies = [ "wast", ] @@ -5764,6 +5928,18 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "ws_stream_wasm" version = "0.7.4" @@ -5798,6 +5974,30 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" +[[package]] +name = "yoke" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -5816,7 +6016,28 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", +] + +[[package]] +name = "zerofrom" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", + "synstructure", ] [[package]] @@ -5836,7 +6057,29 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.82", + "syn 2.0.87", +] + +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 37ce93a..9f5dd2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,11 +4,12 @@ resolver = "2" [workspace.package] authors = ["Offchain Labs"] -version = "0.5.5" +version = "0.5.6" edition = "2021" homepage = "https://arbitrum.io" license = "MIT OR Apache-2.0" repository = "https://github.com/OffchainLabs/cargo-stylus" +readme = "README.md" [workspace.dependencies] alloy-primitives = "=0.7.7" diff --git a/Dockerfile b/Dockerfile index 48fe819..7143a4e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,15 @@ -FROM --platform=linux/amd64 rust:1.80 as builder +ARG BUILD_PLATFORM=linux/amd64 +ARG RUST_VERSION=1.80 +ARG CARGO_STYLUS_VERSION=0.5.6 + +FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS builder RUN apt-get update && apt-get install -y git RUN rustup target add x86_64-unknown-linux-gnu -RUN git clone https://github.com/offchainlabs/cargo-stylus.git +ARG CARGO_STYLUS_VERSION +RUN test -n "$CARGO_STYLUS_VERSION" +RUN git clone --branch v$CARGO_STYLUS_VERSION https://github.com/offchainlabs/cargo-stylus.git WORKDIR /cargo-stylus -RUN git checkout v0.5.2 RUN cargo build --release --manifest-path main/Cargo.toml -FROM --platform=linux/amd64 rust:1.80 -COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus \ No newline at end of file + +FROM --platform=${BUILD_PLATFORM} rust:${RUST_VERSION} AS cargo-stylus-base +COPY --from=builder /cargo-stylus/target/release/cargo-stylus /usr/local/bin/cargo-stylus diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b94b6d --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +CARGO_STYLUS_VERSION := $(shell cargo pkgid --manifest-path main/Cargo.toml | cut -d '@' -f 2) + +.PHONY: build +build: + cargo build + +.PHONY: test +test: + cargo test + +.PHONY: bench +bench: + cargo +nightly bench -F nightly + +.PHONY: fmt +fmt: + cargo fmt + +.PHONY: lint +lint: + cargo clippy --package cargo-stylus --package cargo-stylus-example + +.PHONY: install +install: fmt lint + cargo install --path main + +.PHONY: docker +docker: + docker build -t cargo-stylus-base:$(CARGO_STYLUS_VERSION) --build-arg CARGO_STYLUS_VERSION=$(CARGO_STYLUS_VERSION) . diff --git a/README.md b/README.md index 62c2523..ab0778e 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ Cargo command for developing Arbitrum Stylus projects ### Building the Project Locally Install [Rust](https://www.rust-lang.org/tools/install) -Clone the repo to your local device +Clone the current released version to your local device ``` -git clone https://github.com/OffchainLabs/cargo-stylus.git +git clone --branch v0.5.6 https://github.com/OffchainLabs/cargo-stylus.git cd cargo-stylus ``` @@ -179,7 +179,7 @@ See `--help` for all available flags and default values. ## Verifying Stylus Contracts -See [here](https://hackmd.io/bpeMnrzbSvO4mohhvkrKqw) +See the formal Arbitrum docs on verifying Stylus contracts [here](https://docs.arbitrum.io/stylus/how-tos/verifying-contracts#reproducible-verification) ## Deploying Non-Rust WASM Projects diff --git a/install.sh b/install.sh deleted file mode 100755 index fbed7b3..0000000 --- a/install.sh +++ /dev/null @@ -1,3 +0,0 @@ -cargo fmt -cargo clippy --package cargo-stylus --package cargo-stylus-example -cargo install --path main diff --git a/main/Cargo.toml b/main/Cargo.toml index 98215aa..d09fc9b 100644 --- a/main/Cargo.toml +++ b/main/Cargo.toml @@ -10,6 +10,10 @@ license.workspace = true version.workspace = true repository.workspace = true +[features] +docker-test = [] +nightly = [] + [dependencies] alloy-primitives.workspace = true alloy-json-abi.workspace = true diff --git a/main/src/activate.rs b/main/src/activate.rs index 8526d8f..ccb59e5 100644 --- a/main/src/activate.rs +++ b/main/src/activate.rs @@ -1,24 +1,22 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/stylus/licenses/COPYRIGHT.md +use crate::check::check_activate; +use crate::constants::ARB_WASM_H160; +use crate::macros::greyln; use crate::util::color::{Color, DebugColor}; use crate::util::sys; +use crate::ActivateConfig; use alloy_primitives::Address; use alloy_sol_macro::sol; use alloy_sol_types::SolCall; use ethers::middleware::{Middleware, SignerMiddleware}; use ethers::signers::Signer; use ethers::types::transaction::eip2718::TypedTransaction; -use ethers::types::{Eip1559TransactionRequest, U256}; +use ethers::types::Eip1559TransactionRequest; use ethers::utils::format_units; use eyre::{bail, Context, Result}; -use crate::check::check_activate; -use crate::constants::ARB_WASM_H160; -use crate::macros::greyln; - -use crate::ActivateConfig; - sol! { interface ArbWasm { function activateProgram(address program) @@ -41,25 +39,14 @@ pub async fn activate_contract(cfg: &ActivateConfig) -> Result<()> { let client = SignerMiddleware::new(provider.clone(), wallet); let code = client.get_code(cfg.address, None).await?; - let data_fee = check_activate(code, cfg.address, &provider).await?; - let mut data_fee = alloy_ethers_typecast::alloy_u256_to_ethers(data_fee); - - greyln!( - "obtained estimated activation data fee {}", - format_units(data_fee, "ether")?.debug_lavender() - ); - greyln!( - "bumping estimated activation data fee by {}%", - cfg.data_fee_bump_percent.debug_lavender() - ); - data_fee = bump_data_fee(data_fee, cfg.data_fee_bump_percent); + let data_fee = check_activate(code, cfg.address, &cfg.data_fee, &provider).await?; let contract: Address = cfg.address.to_fixed_bytes().into(); let data = ArbWasm::activateProgramCall { program: contract }.abi_encode(); let tx = Eip1559TransactionRequest::new() .from(client.address()) .to(*ARB_WASM_H160) - .value(data_fee) + .value(alloy_ethers_typecast::alloy_u256_to_ethers(data_fee)) .data(data); let tx = TypedTransaction::Eip1559(tx); if cfg.estimate_gas { @@ -96,8 +83,3 @@ pub async fn activate_contract(cfg: &ActivateConfig) -> Result<()> { } Ok(()) } - -fn bump_data_fee(fee: U256, pct: u64) -> U256 { - let num = 100 + pct; - fee * U256::from(num) / U256::from(100) -} diff --git a/main/src/check.rs b/main/src/check.rs index 5c31ea6..d9e99c1 100644 --- a/main/src/check.rs +++ b/main/src/check.rs @@ -1,13 +1,16 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md -use crate::util::{color::Color, sys, text}; use crate::{ check::ArbWasm::ArbWasmErrors, constants::{ARB_WASM_H160, ONE_ETH, TOOLCHAIN_FILE_NAME}, macros::*, project::{self, extract_toolchain_channel, BuildConfig}, - CheckConfig, + util::{ + color::{Color, GREY, LAVENDER}, + sys, text, + }, + CheckConfig, DataFeeOpts, }; use alloy_primitives::{Address, B256, U256}; use alloy_sol_macro::sol; @@ -87,9 +90,7 @@ pub async fn check(cfg: &CheckConfig) -> Result { } let address = cfg.contract_address.unwrap_or(H160::random()); - let fee = check_activate(code.clone().into(), address, &provider).await?; - let visual_fee = format_data_fee(fee).unwrap_or("???".red()); - greyln!("wasm data fee: {visual_fee} ETH"); + let fee = check_activate(code.clone().into(), address, &cfg.data_fee, &provider).await?; Ok(ContractCheck::Ready { code, fee }) } @@ -112,7 +113,7 @@ impl ContractCheck { pub fn suggest_fee(&self) -> U256 { match self { Self::Active { .. } => U256::default(), - Self::Ready { fee, .. } => fee * U256::from(120) / U256::from(100), + Self::Ready { fee, .. } => *fee, } } } @@ -128,7 +129,7 @@ impl CheckConfig { let cfg = BuildConfig::new(rust_stable); let wasm = project::build_dylib(cfg.clone())?; let project_hash = - project::hash_files(self.common_cfg.source_files_for_project_hash.clone(), cfg)?; + project::hash_project(self.common_cfg.source_files_for_project_hash.clone(), cfg)?; Ok((wasm, project_hash)) } } @@ -148,17 +149,19 @@ pub fn format_file_size(len: usize, mid: u64, max: u64) -> String { } /// Pretty-prints a data fee. -fn format_data_fee(fee: U256) -> Result { - let fee: u64 = (fee / U256::from(1e9)).try_into()?; +fn format_data_fee(fee: U256) -> String { + let Ok(fee): Result = (fee / U256::from(1e9)).try_into() else { + return ("???").red(); + }; let fee: f64 = fee as f64 / 1e9; - let text = format!("{fee:.6}"); - Ok(if fee <= 5e14 { + let text = format!("{fee:.6} ETH"); + if fee <= 5e14 { text.mint() } else if fee <= 5e15 { text.yellow() } else { text.pink() - }) + } } pub struct EthCallError { @@ -247,7 +250,12 @@ Perhaps the Arbitrum node for the endpoint you are connecting to has not yet upg } /// Checks contract activation, returning the data fee. -pub async fn check_activate(code: Bytes, address: H160, provider: &Provider) -> Result { +pub async fn check_activate( + code: Bytes, + address: H160, + opts: &DataFeeOpts, + provider: &Provider, +) -> Result { let contract = Address::from(address.to_fixed_bytes()); let data = ArbWasm::activateProgramCall { program: contract }.abi_encode(); let tx = Eip1559TransactionRequest::new() @@ -256,8 +264,17 @@ pub async fn check_activate(code: Bytes, address: H160, provider: &Provider, Wallet>; /// Deploys a stylus contract, activating if needed. pub async fn deploy(cfg: DeployConfig) -> Result<()> { - macro_rules! run { - ($expr:expr) => { - $expr.await? - }; - ($expr:expr, $($msg:expr),+) => { - $expr.await.wrap_err_with(|| eyre!($($msg),+))? - }; - } - - let contract = run!(check::check(&cfg.check_config), "cargo stylus check failed"); + let contract = check::check(&cfg.check_config) + .await + .expect("cargo stylus check failed"); let verbose = cfg.check_config.common_cfg.verbose; let client = sys::new_provider(&cfg.check_config.common_cfg.endpoint)?; - let chain_id = run!(client.get_chainid(), "failed to get chain id"); + let chain_id = client.get_chainid().await.expect("failed to get chain id"); let wallet = cfg.auth.wallet().wrap_err("failed to load wallet")?; let wallet = wallet.with_chain_id(chain_id.as_u64()); @@ -67,7 +60,10 @@ pub async fn deploy(cfg: DeployConfig) -> Result<()> { if let ContractCheck::Ready { .. } = &contract { // check balance early - let balance = run!(client.get_balance(sender, None), "failed to get balance"); + let balance = client + .get_balance(sender, None) + .await + .expect("failed to get balance"); let balance = alloy_ethers_typecast::ethers_u256_to_alloy(balance); if balance < data_fee && !cfg.estimate_gas { @@ -93,8 +89,16 @@ pub async fn deploy(cfg: DeployConfig) -> Result<()> { match contract { ContractCheck::Ready { .. } => { - cfg.activate(sender, contract_addr, data_fee, &client) - .await? + if cfg.no_activate { + mintln!( + r#"NOTE: You must activate the stylus contract before calling it. To do so, we recommend running: +cargo stylus activate --address {}"#, + hex::encode(contract_addr) + ); + } else { + cfg.activate(sender, contract_addr, data_fee, &client) + .await? + } } ContractCheck::Active { .. } => greyln!("wasm already activated!"), } diff --git a/main/src/docker.rs b/main/src/docker.rs index 62ad2c1..c293727 100644 --- a/main/src/docker.rs +++ b/main/src/docker.rs @@ -12,8 +12,14 @@ use crate::constants::TOOLCHAIN_FILE_NAME; use crate::macros::greyln; use crate::project::extract_toolchain_channel; -fn image_exists(cargo_stylus_version: &str) -> Result { - let image_name = format!("cargo-stylus-base:{}", cargo_stylus_version); +fn image_name(cargo_stylus_version: &str, toolchain_version: &str) -> String { + format!( + "cargo-stylus-base-{}-toolchain-{}", + cargo_stylus_version, toolchain_version + ) +} + +fn image_exists(image_name: &str) -> Result { let output = Command::new("docker") .arg("images") .arg(image_name) @@ -37,21 +43,19 @@ a reproducible deployment, or opt out by using the --no-verify flag for local bu Ok(output.stdout.iter().filter(|c| **c == b'\n').count() > 1) } -fn create_image(cargo_stylus_version: Option, version: &str) -> Result<()> { - let cargo_stylus_version = - cargo_stylus_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); - if image_exists(&cargo_stylus_version)? { +fn create_image(cargo_stylus_version: &str, toolchain_version: &str) -> Result<()> { + let image_name = image_name(cargo_stylus_version, toolchain_version); + if image_exists(&image_name)? { return Ok(()); } - let name = format!( - "cargo-stylus-base-{}-toolchain-{}", - cargo_stylus_version, version + println!( + "Building Docker image for Rust toolchain {}", + toolchain_version ); - println!("Building Docker image for Rust toolchain {}", version,); let mut child = Command::new("docker") .arg("build") .arg("-t") - .arg(name) + .arg(image_name) .arg(".") .arg("-f-") .stdin(Stdio::piped()) @@ -60,32 +64,28 @@ fn create_image(cargo_stylus_version: Option, version: &str) -> Result<( write!( child.stdin.as_mut().unwrap(), "\ - FROM --platform=linux/amd64 offchainlabs/cargo-stylus-base:{} as base + ARG BUILD_PLATFORM=linux/amd64 + FROM --platform=${{BUILD_PLATFORM}} offchainlabs/cargo-stylus-base:{} AS base RUN rustup toolchain install {}-x86_64-unknown-linux-gnu RUN rustup default {}-x86_64-unknown-linux-gnu RUN rustup target add wasm32-unknown-unknown RUN rustup component add rust-src --toolchain {}-x86_64-unknown-linux-gnu ", cargo_stylus_version, - version, - version, - version, + toolchain_version, + toolchain_version, + toolchain_version, )?; child.wait().map_err(|e| eyre!("wait failed: {e}"))?; Ok(()) } fn run_in_docker_container( - cargo_stylus_version: Option, + cargo_stylus_version: &str, toolchain_version: &str, command_line: &[&str], ) -> Result<()> { - let cargo_stylus_version = - cargo_stylus_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); - let name = format!( - "cargo-stylus-base-{}-toolchain-{}", - cargo_stylus_version, toolchain_version - ); + let image_name = image_name(cargo_stylus_version, toolchain_version); let dir = std::env::current_dir().map_err(|e| eyre!("failed to find current directory: {e}"))?; Command::new("docker") @@ -96,7 +96,7 @@ fn run_in_docker_container( .arg("/source") .arg("-v") .arg(format!("{}:/source", dir.as_os_str().to_str().unwrap())) - .arg(name) + .arg(image_name) .args(command_line) .spawn() .map_err(|e| eyre!("failed to execute Docker command: {e}"))? @@ -116,12 +116,14 @@ pub fn run_reproducible( "Running reproducible Stylus command with toolchain {}", toolchain_channel.mint() ); + let cargo_stylus_version = + cargo_stylus_version.unwrap_or_else(|| env!("CARGO_PKG_VERSION").to_string()); let mut command = vec!["cargo", "stylus"]; for s in command_line.iter() { command.push(s); } - create_image(cargo_stylus_version.clone(), &toolchain_channel)?; - run_in_docker_container(cargo_stylus_version, &toolchain_channel, &command) + create_image(&cargo_stylus_version, &toolchain_channel)?; + run_in_docker_container(&cargo_stylus_version, &toolchain_channel, &command) } fn verify_valid_host() -> Result<()> { @@ -146,3 +148,31 @@ fn verify_valid_host() -> Result<()> { } Ok(()) } + +#[cfg(all(test, feature = "docker-test"))] +mod tests { + use super::*; + + #[test] + fn test_create_image_and_check_it_exists() { + let toolchain_version = "1.80.0"; + let cargo_stylus_version = "0.5.3"; + let image_name = image_name(&cargo_stylus_version, toolchain_version); + println!("image name: {}", image_name); + + // Remove existing docker image + Command::new("docker") + .arg("image") + .arg("rm") + .arg("-f") + .arg(&image_name) + .spawn() + .expect("failed to spawn docker image rm") + .wait() + .expect("failed to run docker image rm"); + + assert!(!image_exists(&image_name).unwrap()); + create_image(&cargo_stylus_version, toolchain_version).unwrap(); + assert!(image_exists(&image_name).unwrap()); + } +} diff --git a/main/src/main.rs b/main/src/main.rs index e6c3f87..acb510f 100644 --- a/main/src/main.rs +++ b/main/src/main.rs @@ -1,14 +1,19 @@ // Copyright 2023-2024, Offchain Labs, Inc. // For licensing, see https://github.com/OffchainLabs/cargo-stylus/blob/main/licenses/COPYRIGHT.md +// Enable unstable test feature for benchmarks when nightly is available +#![cfg_attr(feature = "nightly", feature(test))] + use alloy_primitives::TxHash; use clap::{ArgGroup, Args, CommandFactory, Parser, Subcommand}; use constants::DEFAULT_ENDPOINT; use ethers::abi::Bytes; use ethers::types::{H160, U256}; use eyre::{bail, eyre, Context, Result}; -use std::path::PathBuf; -use std::{fmt, path::Path}; +use std::{ + fmt, + path::{Path, PathBuf}, +}; use tokio::runtime::Builder; use trace::Trace; use util::{color::Color, sys}; @@ -179,15 +184,14 @@ pub struct CacheSuggestionsConfig { pub struct ActivateConfig { #[command(flatten)] common_cfg: CommonConfig, + #[command(flatten)] + data_fee: DataFeeOpts, /// Wallet source to use. #[command(flatten)] auth: AuthOpts, /// Deployed Stylus contract address to activate. #[arg(long)] address: H160, - /// Percent to bump the estimated activation data fee by. Default of 20% - #[arg(long, default_value = "20")] - data_fee_bump_percent: u64, /// Whether or not to just estimate gas without sending a tx. #[arg(long)] estimate_gas: bool, @@ -197,6 +201,8 @@ pub struct ActivateConfig { pub struct CheckConfig { #[command(flatten)] common_cfg: CommonConfig, + #[command(flatten)] + data_fee: DataFeeOpts, /// The WASM to check (defaults to any found in the current directory). #[arg(long)] wasm_file: Option, @@ -223,6 +229,9 @@ struct DeployConfig { /// If not set, uses the default version of the local cargo stylus binary. #[arg(long)] cargo_stylus_version: Option, + /// If set, do not activate the program after deploying it + #[arg(long)] + no_activate: bool, } #[derive(Args, Clone, Debug)] @@ -309,6 +318,13 @@ pub struct SimulateArgs { use_native_tracer: bool, } +#[derive(Clone, Debug, Args)] +struct DataFeeOpts { + /// Percent to bump the estimated activation data fee by. + #[arg(long, default_value = "20")] + data_fee_bump_percent: u64, +} + #[derive(Clone, Debug, Args)] #[clap(group(ArgGroup::new("key").required(true).args(&["private_key_path", "private_key", "keystore_path"])))] struct AuthOpts { @@ -611,43 +627,63 @@ async fn simulate(args: SimulateArgs) -> Result<()> { } async fn replay(args: ReplayArgs) -> Result<()> { + let macos = cfg!(target_os = "macos"); if !args.child { - let rust_gdb = sys::command_exists("rust-gdb"); - if !rust_gdb { - println!( - "{} not installed, falling back to {}", - "rust-gdb".red(), - "gdb".red() - ); - } - - let mut cmd = match rust_gdb { - true => sys::new_command("rust-gdb"), - false => sys::new_command("gdb"), + let gdb_args = [ + "--quiet", + "-ex=set breakpoint pending on", + "-ex=b user_entrypoint", + "-ex=r", + "--args", + ] + .as_slice(); + let lldb_args = [ + "--source-quietly", + "-o", + "b user_entrypoint", + "-o", + "r", + "--", + ] + .as_slice(); + let (cmd_name, args) = if sys::command_exists("rust-gdb") && !macos { + ("rust-gdb", &gdb_args) + } else if sys::command_exists("rust-lldb") { + ("rust-lldb", &lldb_args) + } else { + println!("rust specific debugger not installed, falling back to generic debugger"); + if sys::command_exists("gdb") && !macos { + ("gdb", &gdb_args) + } else if sys::command_exists("lldb") { + ("lldb", &lldb_args) + } else { + bail!("no debugger found") + } }; - cmd.arg("--quiet"); - cmd.arg("-ex=set breakpoint pending on"); - cmd.arg("-ex=b user_entrypoint"); - cmd.arg("-ex=r"); - cmd.arg("--args"); + let mut cmd = sys::new_command(cmd_name); + for arg in args.iter() { + cmd.arg(arg); + } for arg in std::env::args() { cmd.arg(arg); } cmd.arg("--child"); + #[cfg(unix)] let err = cmd.exec(); #[cfg(windows)] let err = cmd.status(); - bail!("failed to exec gdb {:?}", err); + bail!("failed to exec {cmd_name} {:?}", err); } let provider = sys::new_provider(&args.trace.endpoint)?; let trace = Trace::new(provider, args.trace.tx, args.trace.use_native_tracer).await?; - build_so(&args.trace.project)?; - let so = find_so(&args.trace.project)?; + build_shared_library(&args.trace.project)?; + let library_extension = if macos { ".dylib" } else { ".so" }; + let shared_library = find_shared_library(&args.trace.project, library_extension)?; // TODO: don't assume the contract is top-level let args_len = trace.tx.input.len(); @@ -656,7 +692,7 @@ async fn replay(args: ReplayArgs) -> Result<()> { *hostio::FRAME.lock() = Some(trace.reader()); type Entrypoint = unsafe extern "C" fn(usize) -> usize; - let lib = libloading::Library::new(so)?; + let lib = libloading::Library::new(shared_library)?; let main: libloading::Symbol = lib.get(b"user_entrypoint")?; match main(args_len) { @@ -668,7 +704,7 @@ async fn replay(args: ReplayArgs) -> Result<()> { Ok(()) } -pub fn build_so(path: &Path) -> Result<()> { +pub fn build_shared_library(path: &Path) -> Result<()> { let mut cargo = sys::new_command("cargo"); cargo @@ -682,7 +718,7 @@ pub fn build_so(path: &Path) -> Result<()> { Ok(()) } -pub fn find_so(project: &Path) -> Result { +pub fn find_shared_library(project: &Path, extension: &str) -> Result { let triple = rustc_host::from_cli()?; let so_dir = project.join(format!("target/{triple}/debug/")); let so_dir = std::fs::read_dir(&so_dir) @@ -698,7 +734,7 @@ pub fn find_so(project: &Path) -> Result { }; let ext = ext.to_string_lossy(); - if ext.contains(".so") { + if ext.contains(extension) { if let Some(other) = file { let other = other.file_name().unwrap().to_string_lossy(); bail!("more than one .so found: {ext} and {other}",); diff --git a/main/src/new.rs b/main/src/new.rs index a9ecc2b..6a1fdf8 100644 --- a/main/src/new.rs +++ b/main/src/new.rs @@ -7,31 +7,18 @@ use crate::util::{ sys, }; use eyre::{bail, Context, Result}; -use std::{env::current_dir, path::Path}; +use std::{env, fs, path::Path}; -/// Creates a new Stylus project in the current directory -pub fn new(name: &Path, minimal: bool) -> Result<()> { - let repo = match minimal { - true => GITHUB_TEMPLATE_REPO_MINIMAL, - false => GITHUB_TEMPLATE_REPO, - }; - let output = sys::new_command("git") - .arg("clone") - .arg(repo) - .arg(name) - .output() - .wrap_err("git clone failed")?; - - if !output.status.success() { - bail!("git clone command failed"); - } - let path = current_dir().wrap_err("no current dir")?.join(name); - println!("{GREY}new project at: {}", path.to_string_lossy().mint()); - Ok(()) +/// Creates a new directory given the path and then initialize a stylus project. +pub fn new(path: &Path, minimal: bool) -> Result<()> { + fs::create_dir_all(path).wrap_err("failed to create project dir")?; + env::set_current_dir(path).wrap_err("failed to set project dir")?; + init(minimal) } +/// Creates a new Stylus project in the current directory. pub fn init(minimal: bool) -> Result<()> { - let current_dir = current_dir().wrap_err("no current dir")?; + let current_dir = env::current_dir().wrap_err("no current dir")?; let repo = if minimal { GITHUB_TEMPLATE_REPO_MINIMAL } else { @@ -51,6 +38,17 @@ pub fn init(minimal: bool) -> Result<()> { bail!("git clone command failed"); } + let output = sys::new_command("git") + .arg("remote") + .arg("remove") + .arg("origin") + .output() + .wrap_err("git remote remove failed")?; + + if !output.status.success() { + bail!("git remote remove command failed"); + } + println!( "{GREY}initialized project in: {}", current_dir.to_string_lossy().mint() diff --git a/main/src/project.rs b/main/src/project.rs index 5de4872..e9b3fb5 100644 --- a/main/src/project.rs +++ b/main/src/project.rs @@ -18,6 +18,8 @@ use std::{ io::Read, path::{Path, PathBuf}, process, + sync::mpsc, + thread, }; use std::{ops::Range, process::Command}; use tiny_keccak::{Hasher, Keccak}; @@ -228,8 +230,22 @@ pub fn extract_cargo_toml_version(cargo_toml_path: &PathBuf) -> Result { Ok(version.to_string()) } -pub fn hash_files(source_file_patterns: Vec, cfg: BuildConfig) -> Result<[u8; 32]> { - let mut keccak = Keccak::v256(); +pub fn read_file_preimage(filename: &Path) -> Result> { + let mut contents = Vec::with_capacity(1024); + { + let filename = filename.as_os_str(); + contents.extend_from_slice(&(filename.len() as u64).to_be_bytes()); + contents.extend_from_slice(filename.as_encoded_bytes()); + } + let mut file = std::fs::File::open(filename) + .map_err(|e| eyre!("failed to open file {}: {e}", filename.display()))?; + contents.extend_from_slice(&file.metadata().unwrap().len().to_be_bytes()); + file.read_to_end(&mut contents) + .map_err(|e| eyre!("Unable to read file {}: {e}", filename.display()))?; + Ok(contents) +} + +pub fn hash_project(source_file_patterns: Vec, cfg: BuildConfig) -> Result<[u8; 32]> { let mut cmd = Command::new("cargo"); cmd.arg("--version"); let output = cmd @@ -238,33 +254,23 @@ pub fn hash_files(source_file_patterns: Vec, cfg: BuildConfig) -> Result if !output.status.success() { bail!("cargo version command failed"); } - keccak.update(&output.stdout); + + hash_files(&output.stdout, source_file_patterns, cfg) +} + +pub fn hash_files( + cargo_version_output: &[u8], + source_file_patterns: Vec, + cfg: BuildConfig, +) -> Result<[u8; 32]> { + let mut keccak = Keccak::v256(); + keccak.update(cargo_version_output); if cfg.opt_level == OptLevel::Z { keccak.update(&[0]); } else { keccak.update(&[1]); } - let mut buf = vec![0u8; 0x100000]; - - let mut hash_file = |filename: &Path| -> Result<()> { - keccak.update(&(filename.as_os_str().len() as u64).to_be_bytes()); - keccak.update(filename.as_os_str().as_encoded_bytes()); - let mut file = std::fs::File::open(filename) - .map_err(|e| eyre!("failed to open file {}: {e}", filename.display()))?; - keccak.update(&file.metadata().unwrap().len().to_be_bytes()); - loop { - let bytes_read = file - .read(&mut buf) - .map_err(|e| eyre!("Unable to read file {}: {e}", filename.display()))?; - if bytes_read == 0 { - break; - } - keccak.update(&buf[..bytes_read]); - } - Ok(()) - }; - // Fetch the Rust toolchain toml file from the project root. Assert that it exists and add it to the // files in the directory to hash. let toolchain_file_path = PathBuf::from(".").as_path().join(TOOLCHAIN_FILE_NAME); @@ -277,12 +283,20 @@ pub fn hash_files(source_file_patterns: Vec, cfg: BuildConfig) -> Result paths.push(toolchain_file_path); paths.sort(); - for filename in paths.iter() { - greyln!( - "File used for deployment hash: {}", - filename.as_os_str().to_string_lossy() - ); - hash_file(filename)?; + // Read the file contents in another thread and process the keccak in the main thread. + let (tx, rx) = mpsc::channel(); + thread::spawn(move || { + for filename in paths.iter() { + greyln!( + "File used for deployment hash: {}", + filename.as_os_str().to_string_lossy() + ); + tx.send(read_file_preimage(filename)) + .expect("failed to send preimage (impossible)"); + } + }); + for result in rx { + keccak.update(result?.as_slice()); } let mut hash = [0u8; 32]; @@ -405,9 +419,50 @@ fn strip_user_metadata(wasm_file_bytes: &[u8]) -> Result> { #[cfg(test)] mod test { use super::*; - use std::fs::{self, File}; - use std::io::Write; - use tempfile::tempdir; + use std::{ + env, + fs::{self, File}, + io::Write, + path::Path, + }; + use tempfile::{tempdir, TempDir}; + + #[cfg(feature = "nightly")] + extern crate test; + + fn write_valid_toolchain_file(toolchain_file_path: &Path) -> Result<()> { + let toolchain_contents = r#" + [toolchain] + channel = "nightly-2020-07-10" + components = [ "rustfmt", "rustc-dev" ] + targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ] + profile = "minimal" + "#; + fs::write(&toolchain_file_path, toolchain_contents)?; + Ok(()) + } + + fn write_hash_files(num_files: usize, num_lines: usize) -> Result { + let dir = tempdir()?; + env::set_current_dir(dir.path())?; + + let toolchain_file_path = dir.path().join(TOOLCHAIN_FILE_NAME); + write_valid_toolchain_file(&toolchain_file_path)?; + + fs::create_dir(dir.path().join("src"))?; + let mut contents = String::new(); + for _ in 0..num_lines { + contents.push_str("// foo"); + } + for i in 0..num_files { + let file_path = dir.path().join(format!("src/f{i}.rs")); + fs::write(&file_path, &contents)?; + } + fs::write(dir.path().join("Cargo.toml"), "")?; + fs::write(dir.path().join("Cargo.lock"), "")?; + + Ok(dir) + } #[test] fn test_extract_toolchain_channel() -> Result<()> { @@ -438,15 +493,7 @@ mod test { }; assert!(err_details.to_string().contains("is not a string"),); - let toolchain_contents = r#" - [toolchain] - channel = "nightly-2020-07-10" - components = [ "rustfmt", "rustc-dev" ] - targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ] - profile = "minimal" - "#; - std::fs::write(&toolchain_file_path, toolchain_contents)?; - + write_valid_toolchain_file(&toolchain_file_path)?; let channel = extract_toolchain_channel(&toolchain_file_path)?; assert_eq!(channel, "nightly-2020-07-10"); Ok(()) @@ -496,4 +543,28 @@ mod test { Ok(()) } + + #[test] + pub fn test_hash_files() -> Result<()> { + let _dir = write_hash_files(10, 100)?; + let rust_version = "cargo 1.80.0 (376290515 2024-07-16)\n".as_bytes(); + let hash = hash_files(rust_version, vec![], BuildConfig::new(false))?; + assert_eq!( + hex::encode(hash), + "06b50fcc53e0804f043eac3257c825226e59123018b73895cb946676148cb262" + ); + Ok(()) + } + + #[cfg(feature = "nightly")] + #[bench] + pub fn bench_hash_files(b: &mut test::Bencher) -> Result<()> { + let _dir = write_hash_files(1000, 10000)?; + let rust_version = "cargo 1.80.0 (376290515 2024-07-16)\n".as_bytes(); + b.iter(|| { + hash_files(rust_version, vec![], BuildConfig::new(false)) + .expect("failed to hash files"); + }); + Ok(()) + } } diff --git a/main/src/verify.rs b/main/src/verify.rs index c65223b..c8087f2 100644 --- a/main/src/verify.rs +++ b/main/src/verify.rs @@ -18,7 +18,7 @@ use crate::{ constants::TOOLCHAIN_FILE_NAME, deploy::{self, extract_compressed_wasm, extract_contract_evm_deployment_prelude}, project::{self, extract_toolchain_channel}, - CheckConfig, VerifyConfig, + CheckConfig, DataFeeOpts, VerifyConfig, }; #[derive(Debug, Deserialize, Serialize)] @@ -52,6 +52,9 @@ pub async fn verify(cfg: VerifyConfig) -> eyre::Result<()> { } let check_cfg = CheckConfig { common_cfg: cfg.common_cfg.clone(), + data_fee: DataFeeOpts { + data_fee_bump_percent: 20, + }, wasm_file: None, contract_address: None, }; @@ -65,7 +68,7 @@ pub async fn verify(cfg: VerifyConfig) -> eyre::Result<()> { let wasm_file: PathBuf = project::build_dylib(build_cfg.clone()) .map_err(|e| eyre!("could not build project to WASM: {e}"))?; let project_hash = - project::hash_files(cfg.common_cfg.source_files_for_project_hash, build_cfg)?; + project::hash_project(cfg.common_cfg.source_files_for_project_hash, build_cfg)?; let (_, init_code) = project::compress_wasm(&wasm_file, project_hash)?; let deployment_data = deploy::contract_deployment_calldata(&init_code); if deployment_data == *result.input {