diff --git a/Cargo.lock b/Cargo.lock index dc76ab6882..3eb0fa071e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,9 +71,9 @@ checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bitflags" @@ -147,9 +147,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.0" +version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "byte-slice-cast" @@ -198,13 +198,13 @@ dependencies = [ [[package]] name = "console" -version = "0.15.1" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89eab4d20ce20cea182308bca13088fecea9c05f6776cf287205d41a0ed3c847" +checksum = "c050367d967ced717c04b65d8c619d863ef9292ce0c5760028655a2fb298718c" dependencies = [ "encode_unicode", + "lazy_static", "libc", - "once_cell", "terminal_size", "unicode-width", "winapi", @@ -255,9 +255,9 @@ checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f2b443d17d49dad5ef0ede301c3179cc923b8822f3393b4d2c28c269dd4a122" +checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" dependencies = [ "generic-array", "rand_core", @@ -308,9 +308,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ "block-buffer 0.10.3", "crypto-common", @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "ecdsa" -version = "0.14.4" +version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e852f4174d2a8646a0fa8a34b55797856c722f86267deb0aa1e93f7f247f800e" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" dependencies = [ "der", "elliptic-curve", @@ -338,7 +338,7 @@ dependencies = [ "base16ct", "crypto-bigint", "der", - "digest 0.10.3", + "digest 0.10.5", "ff", "generic-array", "group", @@ -459,11 +459,10 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] @@ -481,9 +480,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" +checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0" dependencies = [ "futures-channel", "futures-core", @@ -496,9 +495,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", "futures-sink", @@ -506,15 +505,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" +checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-executor" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" +checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2" dependencies = [ "futures-core", "futures-task", @@ -523,15 +522,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" +checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-macro" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" +checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d" dependencies = [ "proc-macro2", "quote", @@ -540,15 +539,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" +checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" +checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-timer" @@ -558,9 +557,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-channel", "futures-core", @@ -586,9 +585,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "js-sys", @@ -599,9 +598,9 @@ dependencies = [ [[package]] name = "group" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7391856def869c1c81063a03457c676fbcd419709c3dfb33d8d319de484b154d" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" dependencies = [ "ff", "rand_core", @@ -610,9 +609,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes", "fnv", @@ -623,7 +622,7 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.7.3", + "tokio-util 0.7.4", "tracing", ] @@ -701,7 +700,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -786,6 +785,16 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "impl-codec" version = "0.5.1" @@ -801,7 +810,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" dependencies = [ - "parity-scale-codec 3.1.5", + "parity-scale-codec 3.2.1", ] [[package]] @@ -845,9 +854,9 @@ dependencies = [ [[package]] name = "indicatif" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc42b206e70d86ec03285b123e65a5458c92027d1fb2ae3555878b8113b3ddf" +checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b" dependencies = [ "console", "number_prefix", @@ -871,15 +880,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -901,15 +910,15 @@ dependencies = [ [[package]] name = "k256" -version = "0.11.4" +version = "0.11.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2573d3fd3e4cc741affc9b5ce1a8ce36cf29f09f80f36da4309d0ae6d7854" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" dependencies = [ "cfg-if", "ecdsa", "elliptic-curve", "sha2", - "sha3 0.10.4", + "sha3 0.10.6", ] [[package]] @@ -929,15 +938,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.132" +version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "lock_api" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -972,14 +981,14 @@ checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mio" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1115,9 +1124,9 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.14.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "opaque-debug" @@ -1127,9 +1136,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -1159,9 +1168,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg", "cc", @@ -1186,9 +1195,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.1.5" +version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9182e4a71cae089267ab03e67c99368db7cd877baf50f931e5d6d4b71e195ac0" +checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" dependencies = [ "arrayvec", "bitvec 1.0.1", @@ -1234,22 +1243,22 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "4dc9e0dc2adc1c69d09143aff38d3d30c5c3f0df0dad82e6d25547af174ebec0" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project" @@ -1285,9 +1294,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "plain_hasher" @@ -1367,9 +1376,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.43" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] @@ -1418,9 +1427,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -1445,9 +1454,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -1461,10 +1470,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -1495,8 +1504,9 @@ dependencies = [ "primitive-types 0.11.1", "revm_precompiles", "rlp", + "ruint", "serde", - "sha3 0.10.4", + "sha3 0.10.6", "tokio", "web3", ] @@ -1523,9 +1533,10 @@ dependencies = [ "once_cell", "primitive-types 0.11.1", "ripemd", - "secp256k1 0.24.0", + "ruint", + "secp256k1 0.24.1", "sha2", - "sha3 0.10.4", + "sha3 0.10.6", "substrate-bn", ] @@ -1542,10 +1553,11 @@ dependencies = [ "primitive-types 0.11.1", "revm", "rlp", + "ruint", "serde", "serde_derive", "serde_json", - "sha3 0.10.4", + "sha3 0.10.6", "structopt", "thiserror", "triehash", @@ -1563,6 +1575,7 @@ dependencies = [ "js-sys", "primitive-types 0.11.1", "revm", + "ruint", "wasm-bindgen", ] @@ -1579,23 +1592,44 @@ dependencies = [ [[package]] name = "ripemd" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1facec54cb5e0dc08553501fa740091086d0259ad0067e0d4103448e4cb22ed3" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", ] [[package]] name = "rlp" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "999508abb0ae792aabed2460c45b89106d97fe4adac593bdaef433c2605847b5" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" dependencies = [ "bytes", "rustc-hex", ] +[[package]] +name = "ruint" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74b92a24f662eff8808c3ae2959bdc9bc53b5a086d3a2ff7fead2eac347b3dce" +dependencies = [ + "bn-rs", + "primitive-types 0.10.1", + "rlp", + "ruint-macro", + "rustc_version", + "serde", + "thiserror", +] + +[[package]] +name = "ruint-macro" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c827ed98ab2233b4647e6e783d6238f4646a16680fe527a599b3d56f6ea73e2d" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -1633,7 +1667,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -1666,11 +1700,11 @@ dependencies = [ [[package]] name = "secp256k1" -version = "0.24.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" +checksum = "ff55dc09d460954e9ef2fa8a7ced735a964be9981fd50e870b2b3b0705e14964" dependencies = [ - "secp256k1-sys 0.6.0", + "secp256k1-sys 0.6.1", ] [[package]] @@ -1684,9 +1718,9 @@ dependencies = [ [[package]] name = "secp256k1-sys" -version = "0.6.0" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b" +checksum = "83080e2c2fc1006e625be82e5d1eb6a43b7fd9578b617fcc55814daf286bba4b" dependencies = [ "cc", ] @@ -1716,24 +1750,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.13" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.144" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.144" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -1742,9 +1776,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "6ce777b7b150d76b9cf60d28b55f5847135a003f7d7350c6be7a773508ce7d45" dependencies = [ "itoa", "ryu", @@ -1778,24 +1812,24 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.4" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006769ba83e921b3085caa8334186b00cf92b4cb1a6cf4632fbccc8eff5c7549" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] name = "sha2" -version = "0.10.5" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9db03534dff993187064c4e0c05a5708d2a9728ace9a8959b77bedf415dac5" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.3", + "digest 0.10.5", ] [[package]] @@ -1812,11 +1846,11 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.4" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaedf34ed289ea47c2b741bb72e5357a209512d67bcd4bda44359e5bf0470f56" +checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", "keccak", ] @@ -1831,11 +1865,11 @@ dependencies = [ [[package]] name = "signature" -version = "1.6.0" +version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ea32af43239f0d353a7dd75a22d94c329c8cdaafdcb4c1c1335aa10c298a4a" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" dependencies = [ - "digest 0.10.3", + "digest 0.10.5", "rand_core", ] @@ -1850,9 +1884,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" @@ -1942,9 +1976,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.99" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", @@ -1992,18 +2026,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.34" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.34" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -2036,9 +2070,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.21.0" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -2046,7 +2080,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -2078,9 +2111,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df54d54117d6fdc4e4fea40fe1e4e566b3505700e148a6827e59b34b0d2600d9" +checksum = "d660770404473ccd7bc9f8b28494a811bc18542b915c0855c51e8f419d5223ce" dependencies = [ "futures-core", "pin-project-lite", @@ -2104,9 +2137,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -2133,9 +2166,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.36" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "pin-project-lite", @@ -2144,9 +2177,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", ] @@ -2175,9 +2208,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "uint" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f03af7ccf01dd611cc450a0d10dbc9b745770d096473e2faf0ca6e2d66d1e0" +checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" dependencies = [ "byteorder", "crunchy", @@ -2193,40 +2226,39 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", - "idna", - "matches", + "idna 0.3.0", "percent-encoding", ] @@ -2277,9 +2309,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2287,9 +2319,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -2302,9 +2334,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -2314,9 +2346,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2324,9 +2356,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -2337,15 +2369,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -2367,7 +2399,7 @@ dependencies = [ "futures-timer", "headers", "hex", - "idna", + "idna 0.2.3", "jsonrpc-core", "log", "once_cell", @@ -2436,43 +2468,100 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index 76f34fcfbc..87c6e2298a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,8 @@ default-members = ["crates/revm"] [profile.release] # debug = true +lto = true +codegen-units = 1 [profile.ethtests] inherits = "test" diff --git a/README.md b/README.md index 174f1ed2a0..974fdb31a9 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,16 @@ run tests with command: `cargo run --release -- statetest tests/GeneralStateTest `GeneralStateTests` contains all tests related to EVM. +## Running benchmarks + +```shell +cargo run --package revm-test --release --bin snailtracer +``` + +```shell +cargo flamegraph --root --freq 4000 --min-width 0.001 --package revm-test --bin snailtracer +``` + # Used by * Foundry project (as their main EVM): https://github.com/foundry-rs/foundry @@ -46,5 +56,3 @@ run tests with command: `cargo run --release -- statetest tests/GeneralStateTest There is public telegram group: https://t.me/+Ig4WDWOzikA3MzA0 Or if you want to hire me or contact me directly, here is my email: dragan0rakita@gmail.com and telegram: https://t.me/draganrakita - - diff --git a/bins/revm-test/src/bin/snailtracer.rs b/bins/revm-test/src/bin/snailtracer.rs index bbe21171fc..db2ec11e24 100644 --- a/bins/revm-test/src/bin/snailtracer.rs +++ b/bins/revm-test/src/bin/snailtracer.rs @@ -32,7 +32,7 @@ pub fn simple_example() { let mut times = times[5..].to_vec(); times.sort(); for (i, time) in times.iter().rev().enumerate() { - println!("{}: {:?}", i, time); + println!("{i}: {time:?}"); } } diff --git a/bins/revme/Cargo.toml b/bins/revme/Cargo.toml index 8b753a8fe4..62c8e8359e 100644 --- a/bins/revme/Cargo.toml +++ b/bins/revme/Cargo.toml @@ -19,6 +19,7 @@ plain_hasher = "0.2" primitive-types = { version = "0.11", features = ["rlp", "serde"] } revm = { path = "../../crates/revm", version = "2.1", default-features = false, features = ["web3db","std","secp256k1"] } rlp = { version = "0.5", default-features = false } +ruint = { version = "1.6.0", features = ["rlp", "serde"] } serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/bins/revme/src/cli_env.rs b/bins/revme/src/cli_env.rs index d307d48507..0f2a5feabb 100644 --- a/bins/revme/src/cli_env.rs +++ b/bins/revme/src/cli_env.rs @@ -1,8 +1,9 @@ use std::str::FromStr; use bytes::Bytes; -use primitive_types::{H160, U256}; +use primitive_types::H160; use revm::{Env, TransactTo}; +use ruint::aliases::U256; use structopt::StructOpt; #[derive(StructOpt, Clone, Debug)] diff --git a/bins/revme/src/statetest/cmd.rs b/bins/revme/src/statetest/cmd.rs index 18802f6d3d..7e4563a34a 100644 --- a/bins/revme/src/statetest/cmd.rs +++ b/bins/revme/src/statetest/cmd.rs @@ -12,7 +12,7 @@ pub struct Cmd { impl Cmd { pub fn run(&self) -> Result<(), TestError> { for path in &self.path { - println!("Start running tests on: {:?}", path); + println!("Start running tests on: {path:?}"); let test_files = find_all_json_tests(path); run(test_files)? } diff --git a/bins/revme/src/statetest/merkle_trie.rs b/bins/revme/src/statetest/merkle_trie.rs index bfd4c1afda..80e5f43608 100644 --- a/bins/revme/src/statetest/merkle_trie.rs +++ b/bins/revme/src/statetest/merkle_trie.rs @@ -1,9 +1,10 @@ use bytes::Bytes; use hash_db::Hasher; use plain_hasher::PlainHasher; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; use revm::{db::DbAccount, Log}; use rlp::RlpStream; +use ruint::aliases::U256; use sha3::{Digest, Keccak256}; use triehash::sec_trie_root; @@ -44,12 +45,8 @@ pub fn trie_account_rlp(acc: &DbAccount) -> Bytes { sec_trie_root::( acc.storage .iter() - .filter(|(_k, &v)| v != U256::zero()) - .map(|(k, v)| { - let mut temp: [u8; 32] = [0; 32]; - k.to_big_endian(&mut temp); - (H256::from(temp), rlp::encode(v)) - }), + .filter(|(_k, &v)| v != U256::ZERO) + .map(|(k, v)| (H256::from(k.to_be_bytes()), rlp::encode(v))), ) }); stream.append(&acc.info.code_hash.as_bytes()); diff --git a/bins/revme/src/statetest/models/deserializer.rs b/bins/revme/src/statetest/models/deserializer.rs index b83a02511e..16c2d04952 100644 --- a/bins/revme/src/statetest/models/deserializer.rs +++ b/bins/revme/src/statetest/models/deserializer.rs @@ -1,7 +1,8 @@ use std::str::FromStr; use bytes::Bytes; -use primitive_types::{H160, U256}; +use primitive_types::H160; +use ruint::aliases::U256; use serde::{ de::{self, Error}, Deserialize, @@ -27,12 +28,7 @@ where D: de::Deserializer<'de>, { let string = String::deserialize(deserializer)?; - - let output = if let Some(stripped) = string.strip_prefix("0x") { - U256::from_str_radix(stripped, 16).unwrap() - } else { - U256::from_dec_str(&string).unwrap() - }; + let output = string.parse().unwrap(); Ok(output) } diff --git a/bins/revme/src/statetest/models/mod.rs b/bins/revme/src/statetest/models/mod.rs index 2b44caac1d..545dbc1e1b 100644 --- a/bins/revme/src/statetest/models/mod.rs +++ b/bins/revme/src/statetest/models/mod.rs @@ -1,5 +1,6 @@ use bytes::Bytes; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; use std::collections::{BTreeMap, HashMap}; mod deserializer; mod spec; @@ -17,7 +18,7 @@ pub struct TestSuit(pub BTreeMap); pub struct TestUnit { pub env: Env, pub pre: HashMap, - pub post: HashMap>, + pub post: BTreeMap>, pub transaction: TransactionParts, } @@ -112,7 +113,7 @@ mod tests { } let out: Test = serde_json::from_str(json)?; - println!("out:{:?}", out); + println!("out:{out:?}"); Ok(()) } } diff --git a/bins/revme/src/statetest/runner.rs b/bins/revme/src/statetest/runner.rs index 69ec674ec5..9d38921030 100644 --- a/bins/revme/src/statetest/runner.rs +++ b/bins/revme/src/statetest/runner.rs @@ -10,8 +10,9 @@ use std::{ use sha3::{Digest, Keccak256}; use indicatif::ProgressBar; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; use revm::{db::AccountState, Bytecode, CreateScheme, Env, ExecutionResult, SpecId, TransactTo}; +use ruint::aliases::U256; use std::sync::atomic::Ordering; use walkdir::{DirEntry, WalkDir}; @@ -141,7 +142,7 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc>) -> Result< } let mut env = Env::default(); // cfg env. SpecId is set down the road - env.cfg.chain_id = 1i32.into(); // for mainnet + env.cfg.chain_id = U256::from(1); // for mainnet // block env env.block.number = unit.env.current_number; @@ -178,11 +179,7 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc>) -> Result< for (id, test) in tests.into_iter().enumerate() { let gas_limit = *unit.transaction.gas_limit.get(test.indexes.gas).unwrap(); - let gas_limit = if gas_limit > U256::from(u64::MAX) { - u64::MAX - } else { - gas_limit.as_u64() - }; + let gas_limit = u64::try_from(gas_limit).unwrap_or(u64::MAX); env.tx.gas_limit = gas_limit; env.tx.data = unit .transaction @@ -204,7 +201,7 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc>) -> Result< item.address, item.storage_keys .iter() - .map(|f| U256::from_big_endian(f.as_ref())) + .map(|f| U256::from_be_bytes(f.0)) .collect::>(), ) }) @@ -253,20 +250,20 @@ pub fn execute_test_suit(path: &Path, elapsed: &Arc>) -> Result< let logs_root = log_rlp_hash(logs); if test.hash != state_root || test.logs != logs_root { println!( - "ROOTS mismath:\nstate_root:{:?}:{:?}\nlogs_root:{:?}:{:?}", - test.hash, state_root, test.logs, logs_root + "ROOTS mismath:\nstate_root:{:?}:{state_root:?}\nlogs_root:{:?}:{logs_root:?}", + test.hash, test.logs ); let mut database_cloned = database.clone(); evm.database(&mut database_cloned); evm.inspect_commit(CustomPrintTracer::new()); let db = evm.db().unwrap(); - println!("{:?} UNIT_TEST:{}\n", path, name); + println!("{path:?} UNIT_TEST:{name}\n"); println!( "fail reson: {:?} {:?} UNIT_TEST:{}\n gas:{:?} ({:?} refunded)", exit_reason, path, name, gas_used, gas_refunded, ); - println!("\nApplied state:{:?}\n", db); - println!("\nStateroot: {:?}\n", state_root); + println!("\nApplied state:{db:?}\n"); + println!("\nStateroot: {state_root:?}\n"); return Err(TestError::RootMissmatch { spec_id: env.cfg.spec_id, id, @@ -311,7 +308,7 @@ pub fn run(test_files: Vec) -> Result<(), TestError> { //println!("Test:{:?}\n",test_path); if let Err(err) = execute_test_suit(&test_path, &elapsed) { endjob.store(true, Ordering::SeqCst); - println!("Test[{}] named:\n{:?} failed: {}\n", index, test_path, err); + println!("Test[{index}] named:\n{test_path:?} failed: {err}\n"); return Err(err); } diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index d3f2a7cf4d..3e9d67a121 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -16,11 +16,12 @@ bytes = { version = "1.1", default-features = false } futures = { version = "0.3.24", optional = true } hashbrown = { version = "0.12" } hex = { version = "0.4", optional = true } -num_enum = { version = "0.5", default-features = false }#used for SpecId from u8 cast +num_enum = { version = "0.5", default-features = false } # used for SpecId from u8 cast parking_lot = { version = "0.12", optional = true } primitive-types = { version = "0.11", default-features = false, features = ["rlp"] } revm_precompiles = { path = "../revm_precompiles", version = "1.1.1", default-features = false } -rlp = { version = "0.5", default-features = false }#used for create2 address calculation +rlp = { version = "0.5", default-features = false } # used for create2 address calculation +ruint = { version = "1.6.0", features = ["rlp"] } serde = { version = "1.0", features = ["derive","rc"], optional = true } sha3 = { version = "0.10", default-features = false } tokio = { version = "1.21", features = ["rt-multi-thread", "macros"], optional = true } diff --git a/crates/revm/src/db.rs b/crates/revm/src/db.rs index 733729498a..fbcdf97c10 100644 --- a/crates/revm/src/db.rs +++ b/crates/revm/src/db.rs @@ -9,7 +9,8 @@ pub use in_memory_db::{AccountState, BenchmarkDB, CacheDB, DbAccount, EmptyDB, I use crate::{interpreter::bytecode::Bytecode, Account}; use hashbrown::HashMap as Map; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; use crate::AccountInfo; use auto_impl::auto_impl; diff --git a/crates/revm/src/db/in_memory_db.rs b/crates/revm/src/db/in_memory_db.rs index b9b547986f..638f846482 100644 --- a/crates/revm/src/db/in_memory_db.rs +++ b/crates/revm/src/db/in_memory_db.rs @@ -4,7 +4,8 @@ use crate::{Account, AccountInfo, Log}; use alloc::vec::Vec; use core::convert::Infallible; use hashbrown::{hash_map::Entry, HashMap as Map}; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; use sha3::{Digest, Keccak256}; pub type InMemoryDB = CacheDB; @@ -84,7 +85,7 @@ pub enum AccountState { /// EVM touched this account. For newer hardfork this means it can be clearead/removed from state. Touched, /// EVM cleared storage of this account, mostly by selfdestruct, we dont ask database for storage slots - /// and asume they are U256::zero() + /// and asume they are U256::ZERO StorageCleared, /// EVM didnt interacted with this account #[default] @@ -240,7 +241,7 @@ impl Database for CacheDB { acc_entry.account_state, AccountState::StorageCleared | AccountState::NotExisting ) { - Ok(U256::zero()) + Ok(U256::ZERO) } else { let slot = self.db.storage(address, index)?; entry.insert(slot); @@ -258,7 +259,7 @@ impl Database for CacheDB { account.storage.insert(index, value); (account, value) } else { - (info.into(), U256::zero()) + (info.into(), U256::ZERO) }; acc_entry.insert(account); Ok(value) @@ -296,7 +297,7 @@ impl DatabaseRef for CacheDB { acc_entry.account_state, AccountState::StorageCleared | AccountState::NotExisting ) { - Ok(U256::zero()) + Ok(U256::ZERO) } else { self.db.storage(address, index) } @@ -342,9 +343,9 @@ impl DatabaseRef for EmptyDB { // History related fn block_hash(&self, number: U256) -> Result { - let mut buffer: [u8; 4 * 8] = [0; 4 * 8]; - number.to_big_endian(&mut buffer); - Ok(H256::from_slice(&Keccak256::digest(buffer))) + Ok(H256::from_slice(&Keccak256::digest( + number.to_be_bytes::<{ U256::BYTES }>(), + ))) } } @@ -395,6 +396,7 @@ impl Database for BenchmarkDB { #[cfg(test)] mod tests { use primitive_types::H160; + use ruint::aliases::U256; use crate::{AccountInfo, Database}; @@ -413,7 +415,7 @@ mod tests { }, ); - let (key, value) = (123u64.into(), 456u64.into()); + let (key, value) = (U256::from(123), U256::from(456)); let mut new_state = CacheDB::new(init_state); let _ = new_state.insert_account_storage(account, key, value); @@ -434,15 +436,15 @@ mod tests { }, ); - let (key0, value0) = (123u64.into(), 456u64.into()); - let (key1, value1) = (789u64.into(), 999u64.into()); + let (key0, value0) = (U256::from(123), U256::from(456)); + let (key1, value1) = (U256::from(789), U256::from(999)); let _ = init_state.insert_account_storage(account, key0, value0); let mut new_state = CacheDB::new(init_state); let _ = new_state.replace_account_storage(account, [(key1, value1)].into()); assert_eq!(new_state.basic(account).unwrap().unwrap().nonce, nonce); - assert_eq!(new_state.storage(account, key0), Ok(0.into())); + assert_eq!(new_state.storage(account, key0), Ok(U256::ZERO)); assert_eq!(new_state.storage(account, key1), Ok(value1)); } } diff --git a/crates/revm/src/db/web3db.rs b/crates/revm/src/db/web3db.rs index 318bc0f703..e13a637edb 100644 --- a/crates/revm/src/db/web3db.rs +++ b/crates/revm/src/db/web3db.rs @@ -1,6 +1,7 @@ use crate::{interpreter::bytecode::Bytecode, AccountInfo, Database, KECCAK_EMPTY}; use bytes::Bytes; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; use tokio::runtime::{Handle, Runtime}; use web3::{ transports::Http, @@ -61,16 +62,16 @@ impl Database for Web3DB { let (nonce, balance, code) = self.block_on(f); // panic on not getting data? Ok(Some(AccountInfo::new( - U256( + U256::from_limbs( balance - .unwrap_or_else(|e| panic!("web3 get balance error:{:?}", e)) + .unwrap_or_else(|e| panic!("web3 get balance error:{e:?}")) .0, ), nonce - .unwrap_or_else(|e| panic!("web3 get nonce error:{:?}", e)) + .unwrap_or_else(|e| panic!("web3 get nonce error:{e:?}")) .as_u64(), Bytecode::new_raw(Bytes::from( - code.unwrap_or_else(|e| panic!("web3 get node error:{:?}", e)) + code.unwrap_or_else(|e| panic!("web3 get node error:{e:?}")) .0, )), ))) @@ -84,10 +85,10 @@ impl Database for Web3DB { fn storage( &mut self, address: primitive_types::H160, - index: primitive_types::U256, - ) -> Result { + index: U256, + ) -> Result { let add = wH160(address.0); - let index = wU256(index.0); + let index = wU256(index.into_limbs()); let f = async { let storage = self .web3 @@ -95,19 +96,16 @@ impl Database for Web3DB { .storage(add, index, self.block_number) .await .unwrap(); - U256::from_big_endian(storage.as_bytes()) + U256::from_be_bytes(storage.to_fixed_bytes()) }; Ok(self.block_on(f)) } - fn block_hash( - &mut self, - number: primitive_types::U256, - ) -> Result { + fn block_hash(&mut self, number: U256) -> Result { if number > U256::from(u64::MAX) { return Ok(KECCAK_EMPTY); } - let number = number.as_u64(); + let number = u64::try_from(number).unwrap(); if let Some(block_num) = self.block_number { match block_num { BlockNumber::Number(t) if t.as_u64() > number => return Ok(KECCAK_EMPTY), diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 0cecedc5e2..4a3c5bd297 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -14,8 +14,9 @@ use alloc::vec::Vec; use bytes::Bytes; use core::{cmp::min, marker::PhantomData}; use hashbrown::HashMap as Map; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; use revm_precompiles::{Precompile, PrecompileOutput, Precompiles}; +use ruint::aliases::U256; use sha3::{Digest, Keccak256}; pub struct EVMData<'a, DB: Database> { @@ -235,7 +236,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, acc_caller.info.balance = acc_caller .info .balance - .saturating_add(effective_gas_price * (gas.remaining() + gas_refunded)); + .saturating_add(effective_gas_price * U256::from(gas.remaining() + gas_refunded)); // EIP-1559 let coinbase_gas_price = if SPEC::enabled(LONDON) { @@ -259,7 +260,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, acc_coinbase.info.balance = acc_coinbase .info .balance - .saturating_add(coinbase_gas_price * (gas.spend() - gas_refunded)); + .saturating_add(coinbase_gas_price * U256::from(gas.spend() - gas_refunded)); (gas.spend() - gas_refunded, gas_refunded) } else { // touch coinbase @@ -577,7 +578,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, let checkpoint = self.data.journaled_state.checkpoint(); // Touch address. For "EIP-158 State Clear", this will erase empty accounts. - if inputs.transfer.value.is_zero() { + if inputs.transfer.value == U256::ZERO { self.load_account(inputs.context.address); self.data.journaled_state.touch(&inputs.context.address); } @@ -827,13 +828,10 @@ pub fn create_address(caller: H160, nonce: u64) -> H160 { /// Returns the address for the `CREATE2` scheme: [`CreateScheme::Create2`] pub fn create2_address(caller: H160, code_hash: H256, salt: U256) -> H160 { - let mut temp: [u8; 32] = [0; 32]; - salt.to_big_endian(&mut temp); - let mut hasher = Keccak256::new(); hasher.update([0xff]); hasher.update(&caller[..]); - hasher.update(temp); + hasher.update(salt.to_be_bytes::<{ U256::BYTES }>()); hasher.update(&code_hash[..]); H160::from_slice(&hasher.finalize().as_slice()[12..]) } diff --git a/crates/revm/src/gas/calc.rs b/crates/revm/src/gas/calc.rs index f6888b515e..5a3df2908e 100644 --- a/crates/revm/src/gas/calc.rs +++ b/crates/revm/src/gas/calc.rs @@ -1,6 +1,6 @@ use super::constants::*; use crate::{models::SelfDestructResult, Spec, SpecId::*}; -use primitive_types::U256; +use ruint::aliases::U256; #[allow(clippy::collapsible_else_if)] pub fn sstore_refund(original: U256, current: U256, new: U256) -> i64 { @@ -14,15 +14,15 @@ pub fn sstore_refund(original: U256, current: U256, new: U256) -> i6 if current == new { 0 } else { - if original == current && new.is_zero() { + if original == current && new == U256::ZERO { sstore_clears_schedule } else { let mut refund = 0; - if !original.is_zero() { - if current.is_zero() { + if original != U256::ZERO { + if current == U256::ZERO { refund -= sstore_clears_schedule; - } else if new.is_zero() { + } else if new == U256::ZERO { refund += sstore_clears_schedule; } } @@ -33,7 +33,7 @@ pub fn sstore_refund(original: U256, current: U256, new: U256) -> i6 } else { (SSTORE_RESET, sload_cost::(false)) }; - if original.is_zero() { + if original == U256::ZERO { refund += (SSTORE_SET - gas_sload) as i64; } else { refund += (gas_sstore_reset - gas_sload) as i64; @@ -44,7 +44,7 @@ pub fn sstore_refund(original: U256, current: U256, new: U256) -> i6 } } } else { - if !current.is_zero() && new.is_zero() { + if current != U256::ZERO && new == U256::ZERO { REFUND_SSTORE_CLEARS } else { 0 @@ -64,14 +64,14 @@ pub fn create2_cost(len: usize) -> Option { } fn log2floor(value: U256) -> u64 { - assert!(!value.is_zero()); + assert!(value != U256::ZERO); let mut l: u64 = 256; for i in 0..4 { let i = 3 - i; - if value.0[i] == 0u64 { + if value.as_limbs()[i] == 0u64 { l -= 64; } else { - l -= value.0[i].leading_zeros() as u64; + l -= value.as_limbs()[i].leading_zeros() as u64; if l == 0 { return l; } else { @@ -83,7 +83,7 @@ fn log2floor(value: U256) -> u64 { } pub fn exp_cost(power: U256) -> Option { - if power.is_zero() { + if power == U256::ZERO { Some(EXP) } else { let gas_byte = U256::from(if SPEC::enabled(SPURIOUS_DRAGON) { @@ -94,11 +94,7 @@ pub fn exp_cost(power: U256) -> Option { let gas = U256::from(EXP) .checked_add(gas_byte.checked_mul(U256::from(log2floor(power) / 8 + 1))?)?; - if gas > U256::from(u64::MAX) { - return None; - } - - Some(gas.as_u64()) + u64::try_from(gas).ok() } } @@ -192,7 +188,7 @@ pub fn sstore_cost( gas_sload } else { if original == current { - if original.is_zero() { + if original == U256::ZERO { SSTORE_SET } else { gas_sstore_reset @@ -202,7 +198,7 @@ pub fn sstore_cost( } } } else { - if current.is_zero() && !new.is_zero() { + if current == U256::ZERO && new != U256::ZERO { SSTORE_SET } else { gas_sstore_reset diff --git a/crates/revm/src/instructions.rs b/crates/revm/src/instructions.rs index e1b146f127..296f46e57f 100644 --- a/crates/revm/src/instructions.rs +++ b/crates/revm/src/instructions.rs @@ -15,7 +15,7 @@ pub use opcode::{OpCode, OPCODE_JUMPMAP}; use crate::{interpreter::Interpreter, CallScheme, Host, Spec, SpecId::*}; use core::ops::{BitAnd, BitOr, BitXor}; -use primitive_types::U256; +use ruint::aliases::U256; #[macro_export] macro_rules! return_ok { @@ -86,9 +86,9 @@ pub fn eval(opcode: u8, interp: &mut Interpreter, host: &mut H 246_u8..=249_u8 => Return::OpcodeNotFound, 251_u8..=252_u8 => Return::OpcodeNotFound,*/ opcode::STOP => Return::Stop, - opcode::ADD => op2_u256_tuple!(interp, overflowing_add), - opcode::MUL => op2_u256_tuple!(interp, overflowing_mul), - opcode::SUB => op2_u256_tuple!(interp, overflowing_sub), + opcode::ADD => op2_u256!(interp, wrapping_add), + opcode::MUL => op2_u256!(interp, wrapping_mul), + opcode::SUB => op2_u256!(interp, wrapping_sub), opcode::DIV => op2_u256_fn!(interp, arithmetic::div), opcode::SDIV => op2_u256_fn!(interp, arithmetic::sdiv), opcode::MOD => op2_u256_fn!(interp, arithmetic::rem), diff --git a/crates/revm/src/instructions/arithmetic.rs b/crates/revm/src/instructions/arithmetic.rs index 6c7dacd439..ebb7a43f3a 100644 --- a/crates/revm/src/instructions/arithmetic.rs +++ b/crates/revm/src/instructions/arithmetic.rs @@ -1,16 +1,10 @@ use crate::{gas, Interpreter, Return, Spec}; use super::i256::{i256_div, i256_mod}; -use core::{convert::TryInto, ops::Rem}; -use primitive_types::{U256, U512}; +use ruint::aliases::U256; pub fn div(op1: U256, op2: U256) -> U256 { - if op2.is_zero() { - U256::zero() - } else { - //op1 / op2 - super::i256::div_u256::div_mod(op1, op2).0 - } + op1.checked_div(op2).unwrap_or_default() } pub fn sdiv(op1: U256, op2: U256) -> U256 { @@ -18,60 +12,27 @@ pub fn sdiv(op1: U256, op2: U256) -> U256 { } pub fn rem(op1: U256, op2: U256) -> U256 { - if op2.is_zero() { - U256::zero() - } else { - op1.rem(op2) - } + op1.checked_rem(op2).unwrap_or_default() } pub fn smod(op1: U256, op2: U256) -> U256 { - if op2.is_zero() { - U256::zero() + if op2 == U256::ZERO { + U256::ZERO } else { i256_mod(op1, op2) } } pub fn addmod(op1: U256, op2: U256, op3: U256) -> U256 { - if op3.is_zero() { - U256::zero() - } else { - let op1: U512 = op1.into(); - let op2: U512 = op2.into(); - let op3: U512 = op3.into(); - let v = (op1 + op2) % op3; - v.try_into() - .expect("op3 is less than U256::MAX, thus it never overflows; qed") - } + op1.add_mod(op2, op3) } pub fn mulmod(op1: U256, op2: U256, op3: U256) -> U256 { - if op3.is_zero() { - U256::zero() - } else { - let op1: U512 = op1.into(); - let op2: U512 = op2.into(); - let op3: U512 = op3.into(); - let v = (op1 * op2) % op3; - v.try_into() - .expect("op3 is less than U256::MAX, thus it never overflows; qed") - } + op1.mul_mod(op2, op3) } pub fn exp(op1: U256, op2: U256) -> U256 { - let mut op1 = op1; - let mut op2 = op2; - let mut r: U256 = 1.into(); - - while op2 != 0.into() { - if op2 & 1.into() != 0.into() { - r = r.overflowing_mul(op1).0; - } - op2 >>= 1; - op1 = op1.overflowing_mul(op1).0; - } - r + op1.pow(op2) } pub fn eval_exp(interp: &mut Interpreter) -> Return { @@ -102,9 +63,9 @@ pub fn eval_exp(interp: &mut Interpreter) -> Return { pub fn signextend(op1: U256, op2: U256) -> U256 { if op1 < U256::from(32) { // `low_u32` works since op1 < 32 - let bit_index = (8 * op1.low_u32() + 7) as usize; + let bit_index = (8 * op1.as_limbs()[0] + 7) as usize; let bit = op2.bit(bit_index); - let mask = (U256::one() << bit_index) - U256::one(); + let mask = (U256::from(1) << bit_index) - U256::from(1); if bit { op2 | !mask } else { @@ -126,21 +87,21 @@ mod tests { #[test] fn test_signextend() { let test_values = vec![ - U256::zero(), - U256::one(), + U256::ZERO, + U256::from(1), U256::from(8), U256::from(10), U256::from(65), U256::from(100), U256::from(128), - U256::from(11) * (U256::one() << 65), - U256::from(7) * (U256::one() << 123), - U256::MAX / 167, + U256::from(11) * (U256::from(1) << 65), + U256::from(7) * (U256::from(1) << 123), + U256::MAX / U256::from(167), U256::MAX, ]; for x in 0..64 { for y in test_values.iter() { - compare_old_signextend(x.into(), *y); + compare_old_signextend(U256::from(x), *y); } } } @@ -156,13 +117,13 @@ mod tests { if op1 > U256::from(32) { op2 } else { - let mut ret = U256::zero(); - let len: usize = op1.as_usize(); + let mut ret = U256::ZERO; + let len = usize::try_from(op1).unwrap(); let t: usize = 8 * (len + 1) - 1; - let t_bit_mask = U256::one() << t; + let t_bit_mask = U256::from(1) << t; let t_value = (op2 & t_bit_mask) >> t; for i in 0..256 { - let bit_mask = U256::one() << i; + let bit_mask = U256::from(1) << i; let i_value = (op2 & bit_mask) >> i; if i <= t { ret = ret.overflowing_add(i_value << i).0; diff --git a/crates/revm/src/instructions/bitwise.rs b/crates/revm/src/instructions/bitwise.rs index 69896e5f2e..d7a9e19c8d 100644 --- a/crates/revm/src/instructions/bitwise.rs +++ b/crates/revm/src/instructions/bitwise.rs @@ -1,29 +1,29 @@ use core::cmp::Ordering; use super::i256::{i256_cmp, i256_sign, two_compl, Sign}; -use primitive_types::U256; +use ruint::aliases::U256; pub fn slt(op1: U256, op2: U256) -> U256 { if i256_cmp(op1, op2) == Ordering::Less { - U256::one() + U256::from(1) } else { - U256::zero() + U256::ZERO } } pub fn sgt(op1: U256, op2: U256) -> U256 { if i256_cmp(op1, op2) == Ordering::Greater { - U256::one() + U256::from(1) } else { - U256::zero() + U256::ZERO } } pub fn iszero(op1: U256) -> U256 { - if op1.is_zero() { - U256::one() + if op1 == U256::ZERO { + U256::from(1) } else { - U256::zero() + U256::ZERO } } @@ -32,13 +32,13 @@ pub fn not(op1: U256) -> U256 { } pub fn byte(op1: U256, op2: U256) -> U256 { - let mut ret = U256::zero(); + let mut ret = U256::ZERO; for i in 0..256 { - if i < 8 && op1 < 32.into() { - let o: usize = op1.as_usize(); + if i < 8 && op1 < U256::from(32) { + let o = u128::try_from(op1).unwrap() as usize; let t = 255 - (7 - i + 8 * o); - let bit_mask = U256::one() << t; + let bit_mask = U256::from(1) << t; let value = (op2 & bit_mask) >> t; ret = ret.overflowing_add(value << i).0; } @@ -48,41 +48,31 @@ pub fn byte(op1: U256, op2: U256) -> U256 { } pub fn shl(shift: U256, value: U256) -> U256 { - if value.is_zero() || shift >= U256::from(256) { - U256::zero() - } else { - let shift: u64 = shift.as_u64(); - value << shift as usize - } + value << usize::try_from(shift).unwrap_or(256) } pub fn shr(shift: U256, value: U256) -> U256 { - if value.is_zero() || shift >= U256::from(256) { - U256::zero() - } else { - let shift: u64 = shift.as_u64(); - value >> shift as usize - } + value >> usize::try_from(shift).unwrap_or(256) } pub fn sar(shift: U256, mut value: U256) -> U256 { let value_sign = i256_sign::(&mut value); - if value.is_zero() || shift >= U256::from(256) { + if value == U256::ZERO || shift >= U256::from(256) { match value_sign { // value is 0 or >=1, pushing 0 - Sign::Plus | Sign::Zero => U256::zero(), + Sign::Plus | Sign::Zero => U256::ZERO, // value is <0, pushing -1 - Sign::Minus => two_compl(U256::one()), + Sign::Minus => two_compl(U256::from(1)), } } else { - let shift: u64 = shift.as_u64(); + let shift = usize::try_from(shift).unwrap(); match value_sign { - Sign::Plus | Sign::Zero => value >> shift as usize, + Sign::Plus | Sign::Zero => value >> shift, Sign::Minus => { - let shifted = ((value.overflowing_sub(U256::one()).0) >> shift as usize) - .overflowing_add(U256::one()) + let shifted = ((value.overflowing_sub(U256::from(1)).0) >> shift) + .overflowing_add(U256::from(1)) .0; two_compl(shifted) } diff --git a/crates/revm/src/instructions/control.rs b/crates/revm/src/instructions/control.rs index b0ddb873bf..ed24c0fde4 100644 --- a/crates/revm/src/instructions/control.rs +++ b/crates/revm/src/instructions/control.rs @@ -1,5 +1,5 @@ use crate::{gas, interpreter::Interpreter, Return, Spec, SpecId::*}; -use primitive_types::U256; +use ruint::aliases::U256; pub fn jump(interp: &mut Interpreter) -> Return { // gas!(interp, gas::MID); @@ -18,7 +18,7 @@ pub fn jump(interp: &mut Interpreter) -> Return { pub fn jumpi(interp: &mut Interpreter) -> Return { // gas!(interp, gas::HIGH); pop!(interp, dest, value); - if !value.is_zero() { + if value != U256::ZERO { let dest = as_usize_or_fail!(dest, Return::InvalidJump); if interp.contract.is_valid_jump(dest) { // Safety: In analysis we are checking if jump is valid destination and diff --git a/crates/revm/src/instructions/host.rs b/crates/revm/src/instructions/host.rs index d6490fc31d..4f482ee6f8 100644 --- a/crates/revm/src/instructions/host.rs +++ b/crates/revm/src/instructions/host.rs @@ -9,7 +9,8 @@ use crate::{ }; use bytes::Bytes; use core::cmp::min; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; pub fn balance(interp: &mut Interpreter, host: &mut H) -> Return { pop_address!(interp, address); @@ -120,11 +121,11 @@ pub fn blockhash(interp: &mut Interpreter, host: &mut H) -> Return { if ret.is_none() { return Return::FatalExternalError; } - *number = U256::from_big_endian(ret.unwrap().as_ref()); + *number = U256::from_be_bytes(ret.unwrap().0); return Return::Continue; } } - *number = U256::zero(); + *number = U256::ZERO; Return::Continue } @@ -178,10 +179,8 @@ pub fn log(interp: &mut Interpreter, n: u8, host: &mut H) - let mut topics = Vec::with_capacity(n); for _ in 0..(n) { - let mut t = H256::zero(); // Safety: stack bounds already checked few lines above - unsafe { interp.stack.pop_unsafe().to_big_endian(t.as_bytes_mut()) }; - topics.push(t); + topics.push(unsafe { interp.stack.pop_unsafe() }.to_be_bytes().into()); } host.log(interp.contract.address, topics, data); @@ -292,11 +291,7 @@ pub fn call( pop!(interp, local_gas_limit); pop_address!(interp, to); - let local_gas_limit = if local_gas_limit > U256::from(u64::MAX) { - u64::MAX - } else { - local_gas_limit.as_u64() - }; + let local_gas_limit = u64::try_from(local_gas_limit).unwrap_or(u64::MAX); let value = match scheme { CallScheme::CallCode => { @@ -305,12 +300,12 @@ pub fn call( } CallScheme::Call => { pop!(interp, value); - if SPEC::IS_STATIC_CALL && !value.is_zero() { + if SPEC::IS_STATIC_CALL && value != U256::ZERO { return Return::CallNotAllowedInsideStatic; } value } - CallScheme::DelegateCall | CallScheme::StaticCall => U256::zero(), + CallScheme::DelegateCall | CallScheme::StaticCall => U256::ZERO, }; pop!(interp, in_offset, in_len, out_offset, out_len); @@ -374,7 +369,7 @@ pub fn call( Transfer { source: interp.contract.address, target: interp.contract.address, - value: U256::zero(), + value: U256::ZERO, } }; @@ -409,7 +404,7 @@ pub fn call( gas!(interp, gas_limit); // add call stipend if there is value to be transferred. - if matches!(scheme, CallScheme::Call | CallScheme::CallCode) && !transfer.value.is_zero() { + if matches!(scheme, CallScheme::Call | CallScheme::CallCode) && transfer.value != U256::ZERO { gas_limit = gas_limit.saturating_add(gas::CALL_STIPEND); } let is_static = matches!(scheme, CallScheme::StaticCall); @@ -439,18 +434,18 @@ pub fn call( interp .memory .set(out_offset, &interp.return_data_buffer[..target_len]); - push!(interp, U256::one()); + push!(interp, U256::from(1)); } return_revert!() => { interp.gas.erase_cost(gas.remaining()); interp .memory .set(out_offset, &interp.return_data_buffer[..target_len]); - push!(interp, U256::zero()); + push!(interp, U256::ZERO); } Return::FatalExternalError => return Return::FatalExternalError, _ => { - push!(interp, U256::zero()); + push!(interp, U256::ZERO); } } interp.add_next_gas_block(interp.program_counter() - 1) diff --git a/crates/revm/src/instructions/i256.rs b/crates/revm/src/instructions/i256.rs index 45ef39960b..be4adedd42 100644 --- a/crates/revm/src/instructions/i256.rs +++ b/crates/revm/src/instructions/i256.rs @@ -1,5 +1,6 @@ use core::cmp::Ordering; -use primitive_types::U256; +use ruint::aliases::U256; +use ruint::uint; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Sign { @@ -8,29 +9,19 @@ pub enum Sign { Zero, } -pub const SIGN_BIT_MASK: U256 = U256([ - 0xffffffffffffffff, - 0xffffffffffffffff, - 0xffffffffffffffff, - FLIPH_BITMASK_U64, -]); +pub const SIGN_BIT_MASK: U256 = + uint!(0x7FFFFFFFFFFFFFFF_FFFFFFFFFFFFFFFF_FFFFFFFFFFFFFFFF_FFFFFFFFFFFFFFFF_U256); +pub const MIN_NEGATIVE_VALUE: U256 = + uint!(0x8000000000000000_0000000000000000_0000000000000000_0000000000000000_U256); -pub const MIN_NEGATIVE_VALUE: U256 = U256([ - 0x0000000000000000, - 0x0000000000000000, - 0x0000000000000000, - 0x8000000000000000, -]); - -const SIGN_BITMASK_U64: u64 = 0x8000000000000000; const FLIPH_BITMASK_U64: u64 = 0x7FFFFFFFFFFFFFFF; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub struct I256(pub Sign, pub U256); #[inline(always)] pub fn i256_sign(val: &mut U256) -> Sign { - if val.0[3] & SIGN_BITMASK_U64 == 0 { - if val.is_zero() { + if !val.bit(U256::BITS - 1) { + if *val == U256::ZERO { Sign::Zero } else { Sign::Plus @@ -45,7 +36,9 @@ pub fn i256_sign(val: &mut U256) -> Sign { #[inline(always)] fn u256_remove_sign(val: &mut U256) { - val.0[3] &= FLIPH_BITMASK_U64; + unsafe { + val.as_limbs_mut()[3] &= FLIPH_BITMASK_U64; + } } #[inline(always)] @@ -54,7 +47,7 @@ pub fn two_compl_mut(op: &mut U256) { } pub fn two_compl(op: U256) -> U256 { - !op + U256::one() + op.wrapping_neg() } #[inline(always)] @@ -78,21 +71,21 @@ pub fn i256_cmp(mut first: U256, mut second: U256) -> Ordering { pub fn i256_div(mut first: U256, mut second: U256) -> U256 { let second_sign = i256_sign::(&mut second); if second_sign == Sign::Zero { - return U256::zero(); + return U256::ZERO; } let first_sign = i256_sign::(&mut first); - if first_sign == Sign::Minus && first == MIN_NEGATIVE_VALUE && second == U256::one() { + if first_sign == Sign::Minus && first == MIN_NEGATIVE_VALUE && second == U256::from(1) { return two_compl(MIN_NEGATIVE_VALUE); } //let mut d = first / second; - let mut d = div_u256::div_mod(first, second).0; + let mut d = first.div_rem(second).0; u256_remove_sign(&mut d); //set sign bit to zero - if d.is_zero() { - return U256::zero(); + if d == U256::ZERO { + return U256::ZERO; } match (first_sign, second_sign) { @@ -112,14 +105,14 @@ pub fn i256_div(mut first: U256, mut second: U256) -> U256 { pub fn i256_mod(mut first: U256, mut second: U256) -> U256 { let first_sign = i256_sign::(&mut first); if first_sign == Sign::Zero { - return U256::zero(); + return U256::ZERO; } let _ = i256_sign::(&mut second); let mut r = first % second; u256_remove_sign(&mut r); - if r.is_zero() { - return U256::zero(); + if r == U256::ZERO { + return U256::ZERO; } if first_sign == Sign::Minus { two_compl(r) @@ -128,272 +121,11 @@ pub fn i256_mod(mut first: U256, mut second: U256) -> U256 { } } -pub mod div_u256 { - use super::*; - - const WORD_BITS: usize = 64; - /// Returns a pair `(self / other, self % other)`. - /// - /// # Panics - /// - /// Panics if `other` is zero. - #[inline(always)] - pub fn div_mod(me: U256, other: U256) -> (U256, U256) { - let my_bits = me.bits(); - let your_bits = other.bits(); - - assert!(your_bits != 0, "division by zero"); - - // Early return in case we are dividing by a larger number than us - if my_bits < your_bits { - return (U256::zero(), me); - } - - if your_bits <= WORD_BITS { - return div_mod_small(me, other.low_u64()); - } - - let (n, m) = { - let my_words = words(my_bits); - let your_words = words(your_bits); - (your_words, my_words - your_words) - }; - - div_mod_knuth(me, other, n, m) - } - - #[inline(always)] - fn div_mod_small(mut me: U256, other: u64) -> (U256, U256) { - let mut rem = 0u64; - for d in me.0.iter_mut().rev() { - let (q, r) = div_mod_word(rem, *d, other); - *d = q; - rem = r; - } - (me, rem.into()) - } - - // Whether this fits u64. - #[inline(always)] - fn fits_word(me: &U256) -> bool { - let U256(ref arr) = me; - for i in arr.iter().take(4).skip(1) { - if *i != 0 { - return false; - } - } - true - } - - // See Knuth, TAOCP, Volume 2, section 4.3.1, Algorithm D. - #[inline(always)] - fn div_mod_knuth(me: U256, mut v: U256, n: usize, m: usize) -> (U256, U256) { - debug_assert!(me.bits() >= v.bits() && !fits_word(&v)); - debug_assert!(n + m <= 4); - // D1. - // Make sure 64th bit in v's highest word is set. - // If we shift both self and v, it won't affect the quotient - // and the remainder will only need to be shifted back. - let shift = v.0[n - 1].leading_zeros(); - v <<= shift; - // u will store the remainder (shifted) - let mut u = full_shl(me, shift); - - // quotient - let mut q = U256::zero(); - let v_n_1 = v.0[n - 1]; - let v_n_2 = v.0[n - 2]; - - // D2. D7. - // iterate from m downto 0 - for j in (0..=m).rev() { - let u_jn = u[j + n]; - - // D3. - // q_hat is our guess for the j-th quotient digit - // q_hat = min(b - 1, (u_{j+n} * b + u_{j+n-1}) / v_{n-1}) - // b = 1 << WORD_BITS - // Theorem B: q_hat >= q_j >= q_hat - 2 - let mut q_hat = if u_jn < v_n_1 { - let (mut q_hat, mut r_hat) = div_mod_word(u_jn, u[j + n - 1], v_n_1); - // this loop takes at most 2 iterations - loop { - // check if q_hat * v_{n-2} > b * r_hat + u_{j+n-2} - let (hi, lo) = split_u128(u128::from(q_hat) * u128::from(v_n_2)); - if (hi, lo) <= (r_hat, u[j + n - 2]) { - break; - } - // then iterate till it doesn't hold - q_hat -= 1; - let (new_r_hat, overflow) = r_hat.overflowing_add(v_n_1); - r_hat = new_r_hat; - // if r_hat overflowed, we're done - if overflow { - break; - } - } - q_hat - } else { - // here q_hat >= q_j >= q_hat - 1 - u64::max_value() - }; - - // ex. 20: - // since q_hat * v_{n-2} <= b * r_hat + u_{j+n-2}, - // either q_hat == q_j, or q_hat == q_j + 1 - - // D4. - // let's assume optimistically q_hat == q_j - // subtract (q_hat * v) from u[j..] - let q_hat_v = full_mul_u64(v, q_hat); - // u[j..] -= q_hat_v; - let c = sub_slice(&mut u[j..], &q_hat_v[..n + 1]); - - // D6. - // actually, q_hat == q_j + 1 and u[j..] has overflowed - // highly unlikely ~ (1 / 2^63) - if c { - q_hat -= 1; - // add v to u[j..] - let c = add_slice(&mut u[j..], &v.0[..n]); - u[j + n] = u[j + n].wrapping_add(u64::from(c)); - } - - // D5. - q.0[j] = q_hat; - } - - // D8. - let remainder = full_shr(u, shift); - - (q, remainder) - } - - #[inline(always)] - fn add_slice(a: &mut [u64], b: &[u64]) -> bool { - binop_slice(a, b, u64::overflowing_add) - } - - #[inline(always)] - fn sub_slice(a: &mut [u64], b: &[u64]) -> bool { - binop_slice(a, b, u64::overflowing_sub) - } - - #[inline(always)] - fn binop_slice( - a: &mut [u64], - b: &[u64], - binop: impl Fn(u64, u64) -> (u64, bool) + Copy, - ) -> bool { - let mut c = false; - a.iter_mut().zip(b.iter()).for_each(|(x, y)| { - let (res, carry) = binop_carry(*x, *y, c, binop); - *x = res; - c = carry; - }); - c - } - - #[inline(always)] - fn binop_carry( - a: u64, - b: u64, - c: bool, - binop: impl Fn(u64, u64) -> (u64, bool), - ) -> (u64, bool) { - let (res1, overflow1) = b.overflowing_add(u64::from(c)); - let (res2, overflow2) = binop(a, res1); - (res2, overflow1 || overflow2) - } - - #[inline(always)] - fn full_shl(me: U256, shift: u32) -> [u64; 4 + 1] { - debug_assert!(shift < WORD_BITS as u32); - let mut u = [0u64; 4 + 1]; - let u_lo = me.0[0] << shift; - let u_hi = me >> (WORD_BITS as u32 - shift); - u[0] = u_lo; - u[1..].copy_from_slice(&u_hi.0[..]); - u - } - - #[inline(always)] - fn full_shr(u: [u64; 4 + 1], shift: u32) -> U256 { - debug_assert!(shift < WORD_BITS as u32); - let mut res = U256::zero(); - for (i, item) in u.iter().enumerate().take(4) { - res.0[i] = item >> shift; - } - // carry - if shift > 0 { - for (i, item) in u.iter().enumerate().skip(1) { - res.0[i - 1] |= item << (WORD_BITS as u32 - shift); - } - } - res - } - - #[inline(always)] - fn full_mul_u64(me: U256, by: u64) -> [u64; 4 + 1] { - let (prod, carry) = overflowing_mul_u64(me, by); - let mut res = [0u64; 4 + 1]; - res[..4].copy_from_slice(&prod.0[..]); - res[4] = carry; - res - } - - /// Overflowing multiplication by u64. - /// Returns the result and carry. - #[inline(always)] - fn overflowing_mul_u64(mut me: U256, other: u64) -> (U256, u64) { - let mut carry = 0u64; - - for d in me.0.iter_mut() { - let (res, c) = mul_u64(*d, other, carry); - *d = res; - carry = c; - } - - (me, carry) - } - - #[inline(always)] - // Returns the least number of words needed to represent the nonzero number - fn words(bits: usize) -> usize { - debug_assert!(bits > 0); - 1 + (bits - 1) / WORD_BITS - } - - #[inline(always)] - fn mul_u64(a: u64, b: u64, carry: u64) -> (u64, u64) { - let (hi, lo) = split_u128(a as u128 * b as u128 + carry as u128); - (lo, hi) - } - - #[inline(always)] - const fn split(a: u64) -> (u64, u64) { - (a >> 32, a & 0xFFFF_FFFF) - } - - #[inline(always)] - const fn split_u128(a: u128) -> (u64, u64) { - ((a >> 64) as _, (a & 0xFFFFFFFFFFFFFFFF) as _) - } - - #[inline(always)] - fn div_mod_word(hi: u64, lo: u64, y: u64) -> (u64, u64) { - debug_assert!(hi < y); - let x = (u128::from(hi) << 64) + u128::from(lo); - let d = u128::from(y); - ((x / d) as u64, (x % d) as u64) - } -} - #[cfg(test)] mod tests { use super::*; use core::num::Wrapping; - use primitive_types::U256; + use ruint::aliases::U256; #[test] fn div_i256() { @@ -411,8 +143,8 @@ mod tests { let neg_one_hundred = U256::from(100); let _neg_one_hundred_sign = Sign::Minus; let minus_one = U256::from(1); - let max_value = U256::from(2).pow(U256::from(255)) - 1; - let neg_max_value = U256::from(2).pow(U256::from(255)) - 1; + let max_value = U256::from(2).pow(U256::from(255)) - U256::from(1); + let neg_max_value = U256::from(2).pow(U256::from(255)) - U256::from(1); assert_eq!(i256_div(MIN_NEGATIVE_VALUE, minus_one), MIN_NEGATIVE_VALUE); assert_eq!(i256_div(MIN_NEGATIVE_VALUE, one), MIN_NEGATIVE_VALUE); diff --git a/crates/revm/src/instructions/macros.rs b/crates/revm/src/instructions/macros.rs index 323327d2db..0512222153 100644 --- a/crates/revm/src/instructions/macros.rs +++ b/crates/revm/src/instructions/macros.rs @@ -69,17 +69,10 @@ macro_rules! pop_address { if $interp.stack.len() < 1 { return Return::StackUnderflow; } - let mut temp = H256::zero(); // Safety: Length is checked above. - let $x1: H160 = { - unsafe { - $interp - .stack - .pop_unsafe() - .to_big_endian(temp.as_bytes_mut()) - }; - temp.into() - }; + let $x1: H160 = H160::from_slice( + &unsafe { $interp.stack.pop_unsafe() }.to_be_bytes::<{ U256::BYTES }>()[12..], + ); }; ( $interp:expr, $x1:ident, $x2:ident) => { if $interp.stack.len() < 2 { @@ -203,7 +196,7 @@ macro_rules! op2_u256_bool_ref { // gas!($interp, $gas); pop_top!($interp, op1, op2); let ret = op1.$op(&op2); - *op2 = if ret { U256::one() } else { U256::zero() }; + *op2 = if ret { U256::from(1) } else { U256::ZERO }; Return::Continue }}; @@ -218,25 +211,6 @@ macro_rules! op2_u256 { }}; } -macro_rules! op2_u256_tuple { - ( $interp:expr, $op:ident) => {{ - // gas!($interp, $gas); - - pop_top!($interp, op1, op2); - let (ret, ..) = op1.$op(*op2); - *op2 = ret; - - Return::Continue - }}; - ( $interp:expr, $op:ident ) => {{ - pop_top!($interp, op1, op2); - let (ret, ..) = op1.$op(op2); - *op2 = ret; - - Return::Continue - }}; -} - macro_rules! op2_u256_fn { ( $interp:expr, $op:path ) => {{ // gas!($interp, $gas); @@ -268,29 +242,20 @@ macro_rules! op3_u256_fn { } macro_rules! as_usize_saturated { - ( $v:expr ) => {{ - if $v.0[1] != 0 || $v.0[2] != 0 || $v.0[3] != 0 { - usize::MAX - } else { - $v.0[0] as usize - } - }}; + ( $v:expr ) => { + $v.saturating_to::() + }; } macro_rules! as_usize_or_fail { ( $v:expr ) => {{ - if $v.0[1] != 0 || $v.0[2] != 0 || $v.0[3] != 0 { - return Return::OutOfGas; - } - - $v.0[0] as usize + as_usize_or_fail!($v, Return::OutOfGas) }}; - ( $v:expr, $reason:expr ) => {{ - if $v.0[1] != 0 || $v.0[2] != 0 || $v.0[3] != 0 { - return $reason; + ( $v:expr, $reason:expr ) => { + match usize::try_from($v) { + Ok(value) => value, + Err(_) => return $reason, } - - $v.0[0] as usize - }}; + }; } diff --git a/crates/revm/src/instructions/memory.rs b/crates/revm/src/instructions/memory.rs index 486a5b9cb5..452ba09e79 100644 --- a/crates/revm/src/instructions/memory.rs +++ b/crates/revm/src/instructions/memory.rs @@ -1,5 +1,5 @@ use crate::{interpreter::Interpreter, Return}; -use primitive_types::U256; +use ruint::aliases::U256; pub fn mload(interp: &mut Interpreter) -> Return { // gas!(interp, gas::VERYLOW); @@ -8,7 +8,9 @@ pub fn mload(interp: &mut Interpreter) -> Return { memory_resize!(interp, index, 32); push!( interp, - U256::from_big_endian(interp.memory.get_slice(index, 32)) + U256::from_be_bytes::<{ U256::BYTES }>( + interp.memory.get_slice(index, 32).try_into().unwrap() + ) ); Return::Continue } @@ -27,7 +29,7 @@ pub fn mstore8(interp: &mut Interpreter) -> Return { pop!(interp, index, value); let index = as_usize_or_fail!(index, Return::OutOfGas); memory_resize!(interp, index, 1); - let value = (value.low_u32() & 0xff) as u8; + let value = value.as_le_bytes()[0]; // Safety: we resized our memory two lines above. unsafe { interp.memory.set_byte(index, value) } Return::Continue diff --git a/crates/revm/src/instructions/system.rs b/crates/revm/src/instructions/system.rs index fabfb58776..d9af59d72f 100644 --- a/crates/revm/src/instructions/system.rs +++ b/crates/revm/src/instructions/system.rs @@ -1,7 +1,8 @@ use std::cmp::min; use crate::{gas, interpreter::Interpreter, Return, Spec, SpecId::*, KECCAK_EMPTY}; -use primitive_types::{H256, U256}; +use primitive_types::H256; +use ruint::aliases::U256; use sha3::{Digest, Keccak256}; @@ -90,9 +91,7 @@ pub fn calldatasize(interp: &mut Interpreter) -> Return { pub fn callvalue(interp: &mut Interpreter) -> Return { // gas!(interp, gas::BASE); - let mut ret = H256::default(); - interp.contract.value.to_big_endian(&mut ret[..]); - push_h256!(interp, ret); + push_h256!(interp, interp.contract.value.to_be_bytes().into()); Return::Continue } diff --git a/crates/revm/src/interpreter/contract.rs b/crates/revm/src/interpreter/contract.rs index a2bbf837be..87571634cb 100644 --- a/crates/revm/src/interpreter/contract.rs +++ b/crates/revm/src/interpreter/contract.rs @@ -1,7 +1,8 @@ use super::bytecode::{Bytecode, BytecodeLocked}; use crate::{alloc::vec::Vec, CallContext, Spec}; use bytes::Bytes; -use primitive_types::{H160, U256}; +use primitive_types::H160; +use ruint::aliases::U256; use std::sync::Arc; pub struct Contract { diff --git a/crates/revm/src/interpreter/memory.rs b/crates/revm/src/interpreter/memory.rs index b5067bb07c..591e609780 100644 --- a/crates/revm/src/interpreter/memory.rs +++ b/crates/revm/src/interpreter/memory.rs @@ -3,7 +3,7 @@ use core::{ cmp::min, ops::{BitAnd, Not}, }; -use primitive_types::U256; +use ruint::aliases::U256; /// A sequencial memory. It uses Rust's `Vec` for internal /// representation. @@ -74,7 +74,7 @@ impl Memory { #[inline(always)] pub fn set_u256(&mut self, index: usize, value: U256) { - value.to_big_endian(&mut self.data[index..index + 32]) + self.data[index..index + 32].copy_from_slice(&value.to_be_bytes::<{ U256::BYTES }>()); } /// Set memory region at given offset. The offset and value are already checked diff --git a/crates/revm/src/interpreter/stack.rs b/crates/revm/src/interpreter/stack.rs index 0a3dba6f2f..f2cb466344 100644 --- a/crates/revm/src/interpreter/stack.rs +++ b/crates/revm/src/interpreter/stack.rs @@ -1,5 +1,6 @@ use crate::{alloc::vec::Vec, Return}; -use primitive_types::{H256, U256}; +use primitive_types::H256; +use ruint::aliases::U256; pub const STACK_LIMIT: usize = 1024; @@ -185,7 +186,7 @@ impl Stack { if self.data.len() + 1 > STACK_LIMIT { return Err(Return::StackOverflow); } - self.data.push(U256::from_big_endian(value.as_ref())); + self.data.push(U256::from_be_bytes(value.0)); Ok(()) } @@ -259,34 +260,39 @@ impl Stack { slot = self.data.get_unchecked_mut(new_len - 1); } - slot.0 = [0u64; 4]; - let mut dangling = [0u8; 8]; - if N < 8 { - dangling[8 - N..].copy_from_slice(slice); - slot.0[0] = u64::from_be_bytes(dangling); - } else if N < 16 { - slot.0[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); - if N != 8 { - dangling[8 * 2 - N..].copy_from_slice(&slice[..N - 8]); - slot.0[1] = u64::from_be_bytes(dangling); - } - } else if N < 24 { - slot.0[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); - slot.0[1] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 16, 8)); - if N != 16 { - dangling[8 * 3 - N..].copy_from_slice(&slice[..N - 16]); - slot.0[2] = u64::from_be_bytes(dangling); - } - } else { - // M<32 - slot.0[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); - slot.0[1] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 16, 8)); - slot.0[2] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 24, 8)); - if N == 32 { - slot.0[3] = u64::from_be_bytes(*arrayref::array_ref!(slice, 0, 8)); - } else if N != 24 { - dangling[8 * 4 - N..].copy_from_slice(&slice[..N - 24]); - slot.0[3] = u64::from_be_bytes(dangling); + unsafe { + *slot.as_limbs_mut() = [0u64; 4]; + let mut dangling = [0u8; 8]; + if N < 8 { + dangling[8 - N..].copy_from_slice(slice); + slot.as_limbs_mut()[0] = u64::from_be_bytes(dangling); + } else if N < 16 { + slot.as_limbs_mut()[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); + if N != 8 { + dangling[8 * 2 - N..].copy_from_slice(&slice[..N - 8]); + slot.as_limbs_mut()[1] = u64::from_be_bytes(dangling); + } + } else if N < 24 { + slot.as_limbs_mut()[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); + slot.as_limbs_mut()[1] = + u64::from_be_bytes(*arrayref::array_ref!(slice, N - 16, 8)); + if N != 16 { + dangling[8 * 3 - N..].copy_from_slice(&slice[..N - 16]); + slot.as_limbs_mut()[2] = u64::from_be_bytes(dangling); + } + } else { + // M<32 + slot.as_limbs_mut()[0] = u64::from_be_bytes(*arrayref::array_ref!(slice, N - 8, 8)); + slot.as_limbs_mut()[1] = + u64::from_be_bytes(*arrayref::array_ref!(slice, N - 16, 8)); + slot.as_limbs_mut()[2] = + u64::from_be_bytes(*arrayref::array_ref!(slice, N - 24, 8)); + if N == 32 { + slot.as_limbs_mut()[3] = u64::from_be_bytes(*arrayref::array_ref!(slice, 0, 8)); + } else if N != 24 { + dangling[8 * 4 - N..].copy_from_slice(&slice[..N - 24]); + slot.as_limbs_mut()[3] = u64::from_be_bytes(dangling); + } } } Return::Continue diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index 76d8203860..ff5cc74691 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -2,7 +2,8 @@ use crate::{interpreter::bytecode::Bytecode, models::SelfDestructResult, Return, use alloc::{vec, vec::Vec}; use core::mem::{self}; use hashbrown::{hash_map::Entry, HashMap as Map}; -use primitive_types::{H160, U256}; +use primitive_types::H160; +use ruint::aliases::U256; use crate::{db::Database, AccountInfo, Log}; @@ -467,7 +468,7 @@ impl JournaledState { }); Ok(SelfDestructResult { - had_value: !balance.is_zero(), + had_value: balance != U256::ZERO, is_cold, target_exists, previously_destroyed, @@ -551,7 +552,7 @@ impl JournaledState { Entry::Vacant(vac) => { // if storage was cleared, we dont need to ping db. let value = if account.storage_cleared { - U256::zero() + U256::ZERO } else { db.storage(address, key)? }; @@ -627,48 +628,43 @@ mod test { #[test] fn test_is_precompile() { - assert_eq!( - is_precompile( + assert!( + !is_precompile( H160([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), 3 ), - false, "Zero is not precompile" ); - assert_eq!( - is_precompile( + assert!( + !is_precompile( H160([1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9]), 3 ), - false, "0x100..0 is not precompile" ); - assert_eq!( - is_precompile( + assert!( + !is_precompile( H160([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4]), 3 ), - false, "0x000..4 is not precompile" ); - assert_eq!( + assert!( is_precompile( H160([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), 3 ), - true, "0x00..01 is precompile" ); - assert_eq!( + assert!( is_precompile( H160([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3]), 3 ), - true, "0x000..3 is precompile" ); } diff --git a/crates/revm/src/models.rs b/crates/revm/src/models.rs index fa447c4493..4af158a111 100644 --- a/crates/revm/src/models.rs +++ b/crates/revm/src/models.rs @@ -2,7 +2,8 @@ use core::cmp::min; use crate::{alloc::vec::Vec, interpreter::bytecode::Bytecode, Return, SpecId}; use bytes::Bytes; -use primitive_types::{H160, H256, U256}; +use primitive_types::{H160, H256}; +use ruint::aliases::U256; pub const KECCAK_EMPTY: H256 = H256([ 0xc5, 0xd2, 0x46, 0x01, 0x86, 0xf7, 0x23, 0x3c, 0x92, 0x7e, 0x7d, 0xb2, 0xdc, 0xc7, 0x03, 0xc0, @@ -27,7 +28,7 @@ pub struct AccountInfo { impl Default for AccountInfo { fn default() -> Self { Self { - balance: U256::zero(), + balance: U256::ZERO, code_hash: KECCAK_EMPTY, code: Some(Bytecode::new()), nonce: 0, @@ -56,7 +57,7 @@ impl AccountInfo { pub fn is_empty(&self) -> bool { let code_empty = self.code_hash == KECCAK_EMPTY || self.code_hash.is_zero(); - self.balance.is_zero() && self.nonce == 0 && code_empty + self.balance == U256::ZERO && self.nonce == 0 && code_empty } pub fn exists(&self) -> bool { @@ -254,7 +255,7 @@ pub enum AnalysisKind { impl Default for CfgEnv { fn default() -> CfgEnv { CfgEnv { - chain_id: 1.into(), + chain_id: U256::from(1), spec_id: SpecId::LATEST, perf_all_precompiles_have_balance: false, perf_analyse_created_bytecodes: Default::default(), @@ -269,11 +270,11 @@ impl Default for BlockEnv { fn default() -> BlockEnv { BlockEnv { gas_limit: U256::MAX, - number: 0.into(), + number: U256::ZERO, coinbase: H160::zero(), - timestamp: U256::one(), - difficulty: U256::zero(), - basefee: U256::zero(), + timestamp: U256::from(1), + difficulty: U256::ZERO, + basefee: U256::ZERO, } } } @@ -283,10 +284,10 @@ impl Default for TxEnv { TxEnv { caller: H160::zero(), gas_limit: u64::MAX, - gas_price: U256::zero(), + gas_price: U256::ZERO, gas_priority_fee: None, transact_to: TransactTo::Call(H160::zero()), //will do nothing - value: U256::zero(), + value: U256::ZERO, data: Bytes::new(), chain_id: None, nonce: None, diff --git a/crates/revm_precompiles/Cargo.toml b/crates/revm_precompiles/Cargo.toml index 82700f7749..ee247843bd 100644 --- a/crates/revm_precompiles/Cargo.toml +++ b/crates/revm_precompiles/Cargo.toml @@ -17,6 +17,7 @@ num = { version = "0.4.0", default-features = false, features = ["alloc"] } once_cell = "1.14" primitive-types = { version = "0.11", default-features = false, features = ["rlp"] } ripemd = { version = "0.1", default-features = false } +ruint = "1.4.1" secp256k1 = { version = "0.24.0", default-features = false, features = ["alloc", "recovery"], optional = true } sha2 = { version = "0.10.5", default-features = false } sha3 = { version = "0.10.4", default-features = false } diff --git a/crates/revm_precompiles/src/bn128.rs b/crates/revm_precompiles/src/bn128.rs index 4f3cf88938..01afb4e016 100644 --- a/crates/revm_precompiles/src/bn128.rs +++ b/crates/revm_precompiles/src/bn128.rs @@ -1,7 +1,8 @@ use crate::{gas_query, Precompile, PrecompileOutput, PrecompileResult, Return}; use alloc::{borrow::Cow, vec::Vec}; -use primitive_types::{H160 as Address, U256}; +use primitive_types::H160 as Address; +use ruint::aliases::U256; pub mod add { use super::*; @@ -170,7 +171,7 @@ fn run_pair( } let output = if input.is_empty() { - U256::one() + U256::from(1) } else { let elements = input.len() / PAIR_ELEMENT_LEN; let mut vals = Vec::with_capacity(elements); @@ -238,16 +239,16 @@ fn run_pair( .fold(Gt::one(), |s, (a, b)| s * bn::pairing(a, b)); if mul == Gt::one() { - U256::one() + U256::from(1) } else { - U256::zero() + U256::ZERO } }; - let mut buf = [0u8; 32]; - output.to_big_endian(&mut buf); - - Ok(PrecompileOutput::without_logs(cost, buf.to_vec())) + Ok(PrecompileOutput::without_logs( + cost, + output.to_be_bytes_vec(), + )) } /* diff --git a/crates/revm_precompiles/src/lib.rs b/crates/revm_precompiles/src/lib.rs index 8f4692cb3b..c0d1fe2b30 100644 --- a/crates/revm_precompiles/src/lib.rs +++ b/crates/revm_precompiles/src/lib.rs @@ -2,7 +2,7 @@ use bytes::Bytes; use once_cell::sync::OnceCell; -use primitive_types::{H160 as Address, H256, U256}; +use primitive_types::{H160 as Address, H256}; mod blake2; mod bn128; @@ -239,10 +239,3 @@ const fn make_address(x: u32, y: u128) -> Address { y_bytes[15], ]) } - -//use for test -pub fn u256_to_arr(value: &U256) -> [u8; 32] { - let mut result = [0u8; 32]; - value.to_big_endian(&mut result); - result -} diff --git a/crates/revm_precompiles/src/modexp.rs b/crates/revm_precompiles/src/modexp.rs index dd13d19e65..b7c6d6455b 100644 --- a/crates/revm_precompiles/src/modexp.rs +++ b/crates/revm_precompiles/src/modexp.rs @@ -6,7 +6,8 @@ use core::{ mem::size_of, }; use num::{BigUint, One, Zero}; -use primitive_types::{H160 as Address, U256}; +use primitive_types::H160 as Address; +use ruint::aliases::U256; pub const BYZANTIUM: (Address, Precompile) = ( super::make_address(0, 5), @@ -159,10 +160,10 @@ fn byzantium_gas_calc(base_len: u64, exp_len: u64, mod_len: u64, exp_highp: &Big // mul * iter_count bounded by 2^195 < 2^256 (no overflow) let gas = (mul * iter_count) / U256::from(20); - if gas.bits() > 64 { + if gas.bit_len() > 64 { u64::MAX } else { - gas.as_u64() + u128::try_from(gas).unwrap() as u64 } } @@ -181,11 +182,11 @@ fn berlin_gas_calc(base_length: u64, exp_length: u64, mod_length: u64, exp_highp let multiplication_complexity = calculate_multiplication_complexity(base_length, mod_length); let iteration_count = calculate_iteration_count(exp_length, exp_highp); - let gas = (multiplication_complexity * U256::from(iteration_count)) / 3; + let gas = (multiplication_complexity * U256::from(iteration_count)) / U256::from(3); if gas > U256::from(u64::MAX) { u64::MAX } else { - max(200, gas.as_u64()) + max(200, u128::try_from(gas).unwrap() as u64) } } @@ -372,10 +373,10 @@ mod tests { #[test] fn test_byzantium_modexp_gas() { for (test, &test_gas) in TESTS.iter().zip(BYZANTIUM_GAS.iter()) { - let input = hex::decode(&test.input).unwrap(); + let input = hex::decode(test.input).unwrap(); let res = byzantium_run(&input, 100_000_000).unwrap(); - let expected = hex::decode(&test.expected).unwrap(); + let expected = hex::decode(test.expected).unwrap(); assert_eq!( res.cost, test_gas, "used gas not maching for test: {}", @@ -388,9 +389,9 @@ mod tests { #[test] fn test_berlin_modexp_gas() { for (test, &test_gas) in TESTS.iter().zip(BERLIN_GAS.iter()) { - let input = hex::decode(&test.input).unwrap(); + let input = hex::decode(test.input).unwrap(); let res = berlin_run(&input, 100_000_000).unwrap(); - let expected = hex::decode(&test.expected).unwrap(); + let expected = hex::decode(test.expected).unwrap(); assert_eq!( res.cost, test_gas, "used gas not maching for test: {}", diff --git a/crates/revmjs/Cargo.toml b/crates/revmjs/Cargo.toml index ee67d81d70..4a8159a103 100644 --- a/crates/revmjs/Cargo.toml +++ b/crates/revmjs/Cargo.toml @@ -17,6 +17,7 @@ bytes = "1.2" getrandom = { version = "0.2", features = ["js"] } hex = "0.4" js-sys = "0.3" -primitive-types = { version = "0.11", default-features = false, features = ["rlp", "rustc-hex"] } +primitive-types = { version = "0.11", default-features = false } revm = { path = "../revm", version = "2.0", default-features = false, features = ["k256"] } +ruint = { version = "1.6.0", features = ["primitive-types", "bn-rs"] } wasm-bindgen = "0.2" diff --git a/crates/revmjs/src/lib.rs b/crates/revmjs/src/lib.rs index c3ffea368d..63d179a013 100644 --- a/crates/revmjs/src/lib.rs +++ b/crates/revmjs/src/lib.rs @@ -2,11 +2,12 @@ use core::convert::TryInto; use bn_rs::BN; use bytes::Bytes; -use primitive_types::{H160, U256}; +use primitive_types::H160; use revm::{ AccountInfo, Bytecode, DatabaseCommit, ExecutionResult, InMemoryDB, SpecId, TransactTo, EVM as rEVM, }; +use ruint::aliases::U256; use wasm_bindgen::prelude::*; #[wasm_bindgen] @@ -39,6 +40,7 @@ impl Default for EVM { } } +#[wasm_bindgen] impl EVM { pub fn new() -> EVM { console_log!("EVM created"); @@ -161,16 +163,17 @@ pub struct AccessedAccount { slots: Vec, } -impl From for (H160, Vec) { +impl From for (primitive_types::H160, Vec) { fn from(from: AccessedAccount) -> Self { (from.account, from.slots) } } +#[wasm_bindgen] impl AccessedAccount { pub fn new(account: BN) -> Self { Self { - account: account.try_into().unwrap(), + account: H160::try_from(account).unwrap(), slots: Vec::new(), } }