From 9860a224afbd67b5002887cebfe1f394d6590c3d Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:31:46 +0200 Subject: [PATCH] chore(deps): bump enr, discv5, secp256k1; remove ethers from dev-dependencies --- Cargo.lock | 594 +++++++++++------- Cargo.toml | 17 +- .../interfaces/src/test_utils/generators.rs | 14 +- crates/net/discv4/Cargo.toml | 1 - crates/net/discv4/src/lib.rs | 4 +- crates/net/discv4/src/proto.rs | 183 ++---- crates/net/discv5/Cargo.toml | 1 - crates/net/discv5/src/enr.rs | 15 +- crates/net/dns/src/lib.rs | 4 +- crates/net/dns/src/tree.rs | 2 +- crates/net/ecies/src/algorithm.rs | 6 +- crates/net/network/Cargo.toml | 15 +- crates/net/network/tests/it/connect.rs | 35 +- crates/primitives/src/genesis.rs | 24 +- crates/primitives/src/transaction/mod.rs | 4 +- crates/primitives/src/transaction/util.rs | 4 +- 16 files changed, 487 insertions(+), 436 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9c3c04eddb1..618db12e9a06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,6 +209,17 @@ dependencies = [ "serde_json", ] +[[package]] +name = "alloy-json-rpc" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +dependencies = [ + "alloy-primitives", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "alloy-node-bindings" version = "0.1.0" @@ -273,6 +284,26 @@ dependencies = [ "syn 2.0.57", ] +[[package]] +name = "alloy-rpc-client" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +dependencies = [ + "alloy-json-rpc", + "alloy-transport", + "alloy-transport-http", + "futures", + "pin-project", + "reqwest 0.12.2", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower", + "tracing", + "url", +] + [[package]] name = "alloy-rpc-engine-types" version = "0.1.0" @@ -370,6 +401,37 @@ dependencies = [ "serde", ] +[[package]] +name = "alloy-transport" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +dependencies = [ + "alloy-json-rpc", + "base64 0.22.0", + "futures-util", + "futures-utils-wasm", + "serde", + "serde_json", + "thiserror", + "tokio", + "tower", + "url", + "wasm-bindgen-futures", +] + +[[package]] +name = "alloy-transport-http" +version = "0.1.0" +source = "git+https://github.com/alloy-rs/alloy?rev=7e39c85#7e39c85f9f51e6449a8b661f54df0ac213f18639" +dependencies = [ + "alloy-json-rpc", + "alloy-transport", + "reqwest 0.12.2", + "serde_json", + "tower", + "url", +] + [[package]] name = "alloy-trie" version = "0.3.0" @@ -719,24 +781,13 @@ dependencies = [ "syn 2.0.57", ] -[[package]] -name = "async_io_stream" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d7b9decdf35d8908a7e3ef02f64c5e9b1695e230154c0e8de3969142d9b94c" -dependencies = [ - "futures", - "pharos", - "rustc_version 0.4.0", -] - [[package]] name = "attohttpc" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d9a9bf8b79a749ee0b911b91b671cc2b6c670bdbc7e3dfd537576ddc94bb2a2" dependencies = [ - "http", + "http 0.2.12", "log", "url", ] @@ -819,6 +870,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "base64ct" version = "1.6.0" @@ -2180,10 +2237,11 @@ dependencies = [ [[package]] name = "discv5" version = "0.4.1" -source = "git+https://github.com/sigp/discv5?rev=04ac004#04ac0042a345a9edf93b090007e5d31c008261ed" +source = "git+https://github.com/sigp/discv5#6707bcf3da350ff273208bb38dc29acc4cc4850c" dependencies = [ "aes 0.7.5", "aes-gcm", + "alloy-rlp", "arrayvec", "delay_map", "enr", @@ -2198,7 +2256,6 @@ dependencies = [ "more-asserts", "parking_lot 0.11.2", "rand 0.8.5", - "rlp", "smallvec", "socket2 0.4.10", "tokio", @@ -2373,10 +2430,10 @@ checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" [[package]] name = "enr" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a3d8dc56e02f954cac8eb489772c552c473346fc34f67412bb6244fd647f7e4" +version = "0.11.0" +source = "git+https://github.com/danipopes/enr?branch=advance-decode-buffer#e48bff60e7f751ed842b992e79e2a37cb9e04ea7" dependencies = [ + "alloy-rlp", "base64 0.21.7", "bytes", "ed25519-dalek", @@ -2384,8 +2441,7 @@ dependencies = [ "k256", "log", "rand 0.8.5", - "rlp", - "secp256k1 0.27.0", + "secp256k1", "serde", "sha3", "zeroize", @@ -2553,44 +2609,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "ethers-providers" -version = "2.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6434c9a33891f1effc9c75472e12666db2fa5a0fec4b29af6221680a6fe83ab2" -dependencies = [ - "async-trait", - "auto_impl", - "base64 0.21.7", - "bytes", - "const-hex", - "enr", - "ethers-core", - "futures-channel", - "futures-core", - "futures-timer", - "futures-util", - "hashers", - "http", - "instant", - "jsonwebtoken", - "once_cell", - "pin-project", - "reqwest", - "serde", - "serde_json", - "thiserror", - "tokio", - "tokio-tungstenite", - "tracing", - "tracing-futures", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "ws_stream_wasm", -] - [[package]] name = "event-listener" version = "2.5.3" @@ -2729,6 +2747,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2861,7 +2894,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" dependencies = [ "gloo-timers", - "send_wrapper 0.4.0", + "send_wrapper", ] [[package]] @@ -2883,13 +2916,10 @@ dependencies = [ ] [[package]] -name = "fxhash" -version = "0.2.1" +name = "futures-utils-wasm" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] +checksum = "42012b0f064e01aa58b545fe3727f90f7dd4020f4a3ea735b50344965f5a57e9" [[package]] name = "generic-array" @@ -2956,7 +2986,7 @@ dependencies = [ "futures-core", "futures-sink", "gloo-utils", - "http", + "http 0.2.12", "js-sys", "pin-project", "serde", @@ -3014,7 +3044,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51ee2dd2e4f378392eeff5d51618cd9a63166a2513846bbc55f21cfacd9199d4" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http 1.1.0", "indexmap 2.2.6", "slab", "tokio", @@ -3064,15 +3113,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hashers" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bca93b15ea5a746f220e56587f71e73c6165eab783df9e26590069953e3c30" -dependencies = [ - "fxhash", -] - [[package]] name = "hashlink" version = "0.8.4" @@ -3186,6 +3226,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -3193,7 +3244,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http 1.1.0", + "http-body 1.0.0", "pin-project-lite", ] @@ -3267,9 +3341,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.25", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -3281,6 +3355,26 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186548d73ac615b32a73aafe38fb4f56c0d340e110e5a200bcadbaf2e199263a" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.3", + "http 1.1.0", + "http-body 1.0.0", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -3288,8 +3382,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "log", "rustls", "rustls-native-certs", @@ -3305,12 +3399,48 @@ checksum = "6eea26c5d0b6ab9d72219f65000af310f042a740926f7b2fa3553e774036e2e7" dependencies = [ "derive_builder", "dns-lookup", - "hyper", + "hyper 0.14.28", "tokio", "tower-service", "tracing", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.2.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.0", + "hyper 1.2.0", + "pin-project-lite", + "socket2 0.5.6", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iai" version = "0.1.1" @@ -3505,8 +3635,8 @@ dependencies = [ "attohttpc", "bytes", "futures", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "log", "rand 0.8.5", "tokio", @@ -3765,7 +3895,7 @@ dependencies = [ "futures-channel", "futures-util", "gloo-net", - "http", + "http 0.2.12", "jsonrpsee-core", "pin-project", "rustls-native-certs", @@ -3791,7 +3921,7 @@ dependencies = [ "beef", "futures-timer", "futures-util", - "hyper", + "hyper 0.14.28", "jsonrpsee-types", "parking_lot 0.12.1", "rand 0.8.5", @@ -3812,7 +3942,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f80c17f62c7653ce767e3d7288b793dfec920f97067ceb189ebdd3570f2bc20" dependencies = [ "async-trait", - "hyper", + "hyper 0.14.28", "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", @@ -3845,8 +3975,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "82c39a00449c9ef3f50b84fc00fc4acba20ef8f559f07902244abf4c15c5ab9c" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "jsonrpsee-core", "jsonrpsee-types", "route-recognizer", @@ -3892,7 +4022,7 @@ version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bca9cb3933ccae417eb6b08c3448eb1cb46e39834e5b503e395e5e5bd08546c0" dependencies = [ - "http", + "http 0.2.12", "jsonrpsee-client-transport", "jsonrpsee-core", "jsonrpsee-types", @@ -4276,7 +4406,7 @@ dependencies = [ "reth-eth-wire", "reth-network", "reth-primitives", - "secp256k1 0.27.0", + "secp256k1", "tokio", ] @@ -4352,7 +4482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d4fa7ce7c4862db464a37b0b31d89bca874562f034bd7993895572783d02950" dependencies = [ "base64 0.21.7", - "hyper", + "hyper 0.14.28", "indexmap 1.9.3", "ipnet", "metrics", @@ -4420,7 +4550,7 @@ dependencies = [ "futures-util", "http-types", "pin-project-lite", - "reqwest", + "reqwest 0.11.27", "serde", "serde_json", "thiserror", @@ -4579,6 +4709,24 @@ dependencies = [ "unsigned-varint 0.7.2", ] +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nibble_vec" version = "0.1.0" @@ -4611,7 +4759,7 @@ dependencies = [ "reth-node-ethereum", "reth-primitives", "reth-tracing", - "secp256k1 0.27.0", + "secp256k1", "serde_json", "tokio", ] @@ -4835,12 +4983,50 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.57", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-sys" +version = "0.9.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "option-ext" version = "0.2.0" @@ -5012,16 +5198,6 @@ dependencies = [ "wyhash", ] -[[package]] -name = "pharos" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9567389417feee6ce15dd6527a8a1ecac205ef62c2932bcf3d9f6fc5b78b414" -dependencies = [ - "futures", - "rustc_version 0.4.0", -] - [[package]] name = "phf" version = "0.11.2" @@ -5170,7 +5346,7 @@ dependencies = [ "reth-primitives", "reth-provider", "reth-tracing", - "secp256k1 0.27.0", + "secp256k1", "serde_json", "tokio", "tokio-stream", @@ -5405,8 +5581,8 @@ dependencies = [ "dns-lookup", "futures-core", "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.28", "hyper-system-resolver", "pin-project-lite", "thiserror", @@ -5704,10 +5880,10 @@ dependencies = [ "encoding_rs", "futures-core", "futures-util", - "h2", - "http", - "http-body", - "hyper", + "h2 0.3.25", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", "hyper-rustls", "ipnet", "js-sys", @@ -5736,6 +5912,48 @@ dependencies = [ "winreg", ] +[[package]] +name = "reqwest" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d66674f2b6fb864665eea7a3c1ac4e3dfacd2fda83cf6f935a612e01b0e3338" +dependencies = [ + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.4.3", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.2.0", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "resolv-conf" version = "0.7.0" @@ -5964,7 +6182,7 @@ dependencies = [ "reth-net-nat", "reth-network", "reth-primitives", - "secp256k1 0.27.0", + "secp256k1", "serde", "tempfile", "toml", @@ -6031,8 +6249,7 @@ dependencies = [ "reth-net-nat", "reth-primitives", "reth-tracing", - "rlp", - "secp256k1 0.27.0", + "secp256k1", "serde", "thiserror", "tokio", @@ -6057,8 +6274,7 @@ dependencies = [ "reth-metrics", "reth-primitives", "reth-tracing", - "rlp", - "secp256k1 0.27.0", + "secp256k1", "thiserror", "tokio", "tracing", @@ -6078,7 +6294,7 @@ dependencies = [ "reth-primitives", "reth-tracing", "schnellru", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_with", "thiserror", @@ -6136,7 +6352,7 @@ dependencies = [ "rand 0.8.5", "reth-net-common", "reth-primitives", - "secp256k1 0.27.0", + "secp256k1", "sha2 0.10.8", "sha3", "thiserror", @@ -6171,7 +6387,7 @@ dependencies = [ "reth-net-common", "reth-primitives", "reth-tracing", - "secp256k1 0.27.0", + "secp256k1", "serde", "snap", "test-fuzz", @@ -6199,7 +6415,7 @@ dependencies = [ "reth-net-common", "reth-primitives", "reth-tracing", - "secp256k1 0.27.0", + "secp256k1", "serde", "test-fuzz", "thiserror", @@ -6267,7 +6483,7 @@ dependencies = [ "reth-network-api", "reth-primitives", "reth-rpc-types", - "secp256k1 0.27.0", + "secp256k1", "thiserror", "tokio", "tracing", @@ -6377,14 +6593,14 @@ version = "0.2.0-beta.5" dependencies = [ "alloy-node-bindings", "alloy-rlp", + "alloy-rpc-client", + "alloy-transport-http", "aquamarine", "auto_impl", "criterion", "derive_more", "discv5", "enr", - "ethers-core", - "ethers-providers", "fnv", "futures", "futures-test", @@ -6396,6 +6612,7 @@ dependencies = [ "pin-project", "pprof", "rand 0.8.5", + "reqwest 0.12.2", "reth-discv4", "reth-discv5", "reth-dns-discovery", @@ -6414,7 +6631,7 @@ dependencies = [ "reth-tracing", "reth-transaction-pool", "schnellru", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_json", "serial_test", @@ -6522,7 +6739,7 @@ dependencies = [ "eyre", "futures", "humantime", - "hyper", + "hyper 0.14.28", "jsonrpsee", "metrics", "metrics-exporter-prometheus", @@ -6562,7 +6779,7 @@ dependencies = [ "reth-tasks", "reth-tracing", "reth-transaction-pool", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_json", "shellexpand", @@ -6713,7 +6930,7 @@ dependencies = [ "revm", "revm-primitives", "roaring", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_json", "serde_with", @@ -6810,16 +7027,16 @@ dependencies = [ "derive_more", "dyn-clone", "futures", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.28", "jsonrpsee", "jsonwebtoken", "metrics", "parking_lot 0.12.1", "pin-project", "rand 0.8.5", - "reqwest", + "reqwest 0.11.27", "reth-consensus-common", "reth-interfaces", "reth-metrics", @@ -6841,7 +7058,7 @@ dependencies = [ "revm-inspectors", "revm-primitives", "schnellru", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_json", "tempfile", @@ -6882,7 +7099,7 @@ dependencies = [ name = "reth-rpc-builder" version = "0.2.0-beta.5" dependencies = [ - "hyper", + "hyper 0.14.28", "jsonrpsee", "metrics", "reth-beacon-consensus", @@ -6961,7 +7178,7 @@ dependencies = [ "proptest", "proptest-derive", "rand 0.8.5", - "secp256k1 0.27.0", + "secp256k1", "serde", "serde_json", "serde_with", @@ -7225,7 +7442,7 @@ dependencies = [ "once_cell", "revm-primitives", "ripemd", - "secp256k1 0.28.2", + "secp256k1", "sha2 0.10.8", "substrate-bn", ] @@ -7626,17 +7843,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "secp256k1" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" -dependencies = [ - "rand 0.8.5", - "secp256k1-sys 0.8.1", - "serde", -] - [[package]] name = "secp256k1" version = "0.28.2" @@ -7644,16 +7850,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ "rand 0.8.5", - "secp256k1-sys 0.9.2", -] - -[[package]] -name = "secp256k1-sys" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a129b9e9efbfb223753b9163c4ab3b13cff7fd9c7f010fbac25ab4099fa07e" -dependencies = [ - "cc", + "secp256k1-sys", + "serde", ] [[package]] @@ -7721,12 +7919,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" -[[package]] -name = "send_wrapper" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" - [[package]] name = "serde" version = "1.0.197" @@ -8085,7 +8277,7 @@ dependencies = [ "base64 0.13.1", "bytes", "futures", - "http", + "http 0.2.12", "httparse", "log", "rand 0.8.5", @@ -8602,6 +8794,16 @@ dependencies = [ "syn 2.0.57", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.24.1" @@ -8624,18 +8826,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "tokio-tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d5dcb2a1ce06d81107c3d0ffa3121fe974b73f068c8282cb1c32328113b6c" -dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", -] - [[package]] name = "tokio-util" version = "0.7.10" @@ -8752,8 +8942,8 @@ dependencies = [ "bytes", "futures-core", "futures-util", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "http-range-header", "httpdate", "iri-string", @@ -9036,25 +9226,6 @@ dependencies = [ "toml", ] -[[package]] -name = "tungstenite" -version = "0.20.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e3dac10fd62eaf6617d3a904ae222845979aec67c615d1c842b4002c7666fb9" -dependencies = [ - "byteorder", - "bytes", - "data-encoding", - "http", - "httparse", - "log", - "rand 0.8.5", - "sha1", - "thiserror", - "url", - "utf-8", -] - [[package]] name = "typenum" version = "1.17.0" @@ -9180,12 +9351,6 @@ dependencies = [ "serde", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "utf16_iter" version = "1.0.5" @@ -9219,6 +9384,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "vergen" version = "8.3.1" @@ -9614,25 +9785,6 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dad7bb64b8ef9c0aa27b6da38b452b0ee9fd82beaf276a87dd796fb55cbae14e" -[[package]] -name = "ws_stream_wasm" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7999f5f4217fe3818726b66257a4475f71e74ffd190776ad053fa159e50737f5" -dependencies = [ - "async_io_stream", - "futures", - "js-sys", - "log", - "pharos", - "rustc_version 0.4.0", - "send_wrapper 0.6.0", - "thiserror", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", -] - [[package]] name = "wyhash" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 5393b2a5f8df..7da3ebbc6609 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -266,12 +266,10 @@ alloy-rpc-trace-types = { git = "https://github.com/alloy-rs/alloy", rev = "7e39 alloy-rpc-engine-types = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } alloy-genesis = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } alloy-node-bindings = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } +alloy-rpc-client = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } +alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } alloy-eips = { git = "https://github.com/alloy-rs/alloy", rev = "7e39c85" } -# TODO: Remove -ethers-core = { version = "2.0.14", default-features = false } -ethers-providers = { version = "2.0.14", default-features = false } - # misc aquamarine = "0.5" bytes = "1.5" @@ -320,9 +318,10 @@ futures-util = "0.3.25" hyper = "0.14.25" tower = "0.4" tower-http = "0.4" +reqwest = "0.12" # p2p -discv5 = { git = "https://github.com/sigp/discv5", rev = "04ac004" } +discv5 = "0.4.1" igd-next = "0.14.3" # rpc @@ -331,11 +330,11 @@ jsonrpsee-core = "0.20" jsonrpsee-types = "0.20" # crypto -secp256k1 = { version = "0.27.0", default-features = false, features = [ +secp256k1 = { version = "0.28", default-features = false, features = [ "global-context", "recovery", ] } -enr = { version = "=0.10.0", default-features = false, features = ["k256"] } +enr = { version = "0.11", default-features = false, features = ["k256"] } # for eip-4844 c-kzg = "1.0.0" @@ -355,3 +354,7 @@ proptest-derive = "0.4" serial_test = "3" similar-asserts = "1.5.0" test-fuzz = "5" + +[patch.crates-io] +discv5 = { git = "https://github.com/sigp/discv5" } +enr = { git = "https://github.com/danipopes/enr", branch = "advance-decode-buffer" } diff --git a/crates/interfaces/src/test_utils/generators.rs b/crates/interfaces/src/test_utils/generators.rs index fc201758effc..d9f7544fb758 100644 --- a/crates/interfaces/src/test_utils/generators.rs +++ b/crates/interfaces/src/test_utils/generators.rs @@ -7,7 +7,7 @@ use reth_primitives::{ SealedHeader, StorageEntry, Transaction, TransactionKind, TransactionSigned, TxLegacy, B256, U256, }; -use secp256k1::{KeyPair, Secp256k1}; +use secp256k1::{Keypair, Secp256k1}; use std::{ cmp::{max, min}, collections::{hash_map::DefaultHasher, BTreeMap}, @@ -92,22 +92,22 @@ pub fn random_tx(rng: &mut R) -> Transaction { /// - There is no guarantee that the nonce is not used twice for the same account pub fn random_signed_tx(rng: &mut R) -> TransactionSigned { let secp = Secp256k1::new(); - let key_pair = KeyPair::new(&secp, rng); + let key_pair = Keypair::new(&secp, rng); let tx = random_tx(rng); sign_tx_with_key_pair(key_pair, tx) } /// Signs the [Transaction] with the given key pair. -pub fn sign_tx_with_key_pair(key_pair: KeyPair, tx: Transaction) -> TransactionSigned { +pub fn sign_tx_with_key_pair(key_pair: Keypair, tx: Transaction) -> TransactionSigned { let signature = sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap(); TransactionSigned::from_transaction_and_signature(tx, signature) } -/// Generates a set of [KeyPair]s based on the desired count. -pub fn generate_keys(rng: &mut R, count: usize) -> Vec { +/// Generates a set of [Keypair]s based on the desired count. +pub fn generate_keys(rng: &mut R, count: usize) -> Vec { let secp = Secp256k1::new(); - (0..count).map(|_| KeyPair::new(&secp, rng)).collect() + (0..count).map(|_| Keypair::new(&secp, rng)).collect() } /// Generate a random block filled with signed transactions (generated using @@ -405,7 +405,7 @@ mod tests { let signature_hash = tx.signature_hash(); for _ in 0..100 { - let key_pair = KeyPair::new(&secp, &mut rand::thread_rng()); + let key_pair = Keypair::new(&secp, &mut rand::thread_rng()); let signature = sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), signature_hash) diff --git a/crates/net/discv4/Cargo.toml b/crates/net/discv4/Cargo.toml index fa0e284ff2c1..c43b7ce82713 100644 --- a/crates/net/discv4/Cargo.toml +++ b/crates/net/discv4/Cargo.toml @@ -22,7 +22,6 @@ alloy-rlp = { workspace = true, features = ["derive"] } discv5.workspace = true secp256k1 = { workspace = true, features = ["global-context", "rand-std", "recovery", "serde"] } enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] } -rlp = "0.5" # needed for enr # async/futures tokio = { workspace = true, features = ["io-util", "net", "time"] } tokio-stream.workspace = true diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index b919c8277b9e..ce67eaffce2f 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -39,7 +39,7 @@ use discv5::{ }; use enr::Enr; use parking_lot::Mutex; -use proto::{EnrRequest, EnrResponse, EnrWrapper}; +use proto::{EnrRequest, EnrResponse}; use reth_primitives::{bytes::Bytes, hex, ForkId, PeerId, B256}; use secp256k1::SecretKey; use std::{ @@ -1279,7 +1279,7 @@ impl Discv4Service { self.send_packet( Message::EnrResponse(EnrResponse { request_hash, - enr: EnrWrapper::new(self.local_eip_868_enr.clone()), + enr: self.local_eip_868_enr.clone(), }), remote_addr, ); diff --git a/crates/net/discv4/src/proto.rs b/crates/net/discv4/src/proto.rs index 8bbb84b62964..bdca3bfb4de8 100644 --- a/crates/net/discv4/src/proto.rs +++ b/crates/net/discv4/src/proto.rs @@ -1,10 +1,8 @@ //! Discovery v4 protocol implementation. use crate::{error::DecodePacketError, EnrForkIdEntry, PeerId, MAX_PACKET_SIZE, MIN_PACKET_SIZE}; -use alloy_rlp::{ - length_of_length, Decodable, Encodable, Error as RlpError, Header, RlpDecodable, RlpEncodable, -}; -use enr::{Enr, EnrKey}; +use alloy_rlp::{Decodable, Encodable, Error as RlpError, Header, RlpDecodable, RlpEncodable}; +use enr::Enr; use reth_primitives::{ bytes::{Buf, BufMut, Bytes, BytesMut}, keccak256, pk2id, ForkId, NodeRecord, B256, @@ -112,8 +110,7 @@ impl Message { // Sign the payload with the secret key using recoverable ECDSA let signature: RecoverableSignature = SECP256K1.sign_ecdsa_recoverable( - &secp256k1::Message::from_slice(keccak256(&payload).as_ref()) - .expect("B256.len() == MESSAGE_SIZE"), + &secp256k1::Message::from_digest(keccak256(&payload).0), secret_key, ); @@ -158,7 +155,7 @@ impl Message { let recoverable_sig = RecoverableSignature::from_compact(signature, recovery_id)?; // recover the public key - let msg = secp256k1::Message::from_slice(keccak256(&packet[97..]).as_slice())?; + let msg = secp256k1::Message::from_digest(keccak256(&packet[97..]).0); let pk = SECP256K1.recover_ecdsa(&msg, &recoverable_sig)?; let node_id = pk2id(&pk); @@ -234,85 +231,6 @@ pub struct Neighbours { pub expire: u64, } -/// Passthrough newtype to [`Enr`]. -/// -/// We need to wrap the ENR type because of Rust's orphan rules not allowing -/// implementing a foreign trait on a foreign type. -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct EnrWrapper(Enr); - -impl EnrWrapper { - /// Creates a new instance of [`EnrWrapper`]. - pub fn new(enr: Enr) -> Self { - EnrWrapper(enr) - } -} - -impl Encodable for EnrWrapper -where - K: EnrKey, -{ - fn encode(&self, out: &mut dyn BufMut) { - let payload_length = self.0.signature().length() + - self.0.seq().length() + - self.0.iter().fold(0, |acc, (k, v)| acc + k.as_slice().length() + v.len()); - - let header = Header { list: true, payload_length }; - header.encode(out); - - self.0.signature().encode(out); - self.0.seq().encode(out); - - for (k, v) in self.0.iter() { - // Keys are byte data - k.as_slice().encode(out); - // Values are raw RLP encoded data - out.put_slice(v); - } - } - - fn length(&self) -> usize { - let payload_length = self.0.signature().length() + - self.0.seq().length() + - self.0.iter().fold(0, |acc, (k, v)| acc + k.as_slice().length() + v.len()); - payload_length + length_of_length(payload_length) - } -} - -fn to_alloy_rlp_error(e: rlp::DecoderError) -> RlpError { - match e { - rlp::DecoderError::RlpIsTooShort => RlpError::InputTooShort, - rlp::DecoderError::RlpInvalidLength => RlpError::Overflow, - rlp::DecoderError::RlpExpectedToBeList => RlpError::UnexpectedString, - rlp::DecoderError::RlpExpectedToBeData => RlpError::UnexpectedList, - rlp::DecoderError::RlpDataLenWithZeroPrefix | - rlp::DecoderError::RlpListLenWithZeroPrefix => RlpError::LeadingZero, - rlp::DecoderError::RlpInvalidIndirection => RlpError::NonCanonicalSize, - rlp::DecoderError::RlpIncorrectListLen => { - RlpError::Custom("incorrect list length when decoding rlp") - } - rlp::DecoderError::RlpIsTooBig => RlpError::Custom("rlp is too big"), - rlp::DecoderError::RlpInconsistentLengthAndData => { - RlpError::Custom("inconsistent length and data when decoding rlp") - } - rlp::DecoderError::Custom(s) => RlpError::Custom(s), - } -} - -impl Decodable for EnrWrapper { - fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let enr = as rlp::Decodable>::decode(&rlp::Rlp::new(buf)) - .map_err(to_alloy_rlp_error) - .map(EnrWrapper::new); - if enr.is_ok() { - // Decode was successful, advance buffer - let header = Header::decode(buf)?; - buf.advance(header.payload_length); - } - enr - } -} - /// A [ENRRequest packet](https://github.com/ethereum/devp2p/blob/master/discv4.md#enrrequest-packet-0x05). /// /// This packet is used to request the current version of a node's Ethereum Node Record (ENR). @@ -327,12 +245,12 @@ pub struct EnrRequest { /// /// This packet is used to respond to an ENRRequest packet and includes the requested ENR along with /// the hash of the original request. -#[derive(Clone, Debug, Eq, PartialEq, RlpEncodable)] +#[derive(Clone, Debug, Eq, PartialEq, RlpEncodable, RlpDecodable)] pub struct EnrResponse { /// The hash of the ENRRequest packet being replied to. pub request_hash: B256, /// The ENR (Ethereum Node Record) for the responding node. - pub enr: EnrWrapper, + pub enr: Enr, } // === impl EnrResponse === @@ -342,37 +260,11 @@ impl EnrResponse { /// /// See also pub fn eth_fork_id(&self) -> Option { - let mut maybe_fork_id = self.enr.0.get_raw_rlp(b"eth")?; + let mut maybe_fork_id = self.enr.get_raw_rlp(b"eth")?; EnrForkIdEntry::decode(&mut maybe_fork_id).ok().map(|entry| entry.fork_id) } } -impl Decodable for EnrResponse { - fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let b = &mut &**buf; - let rlp_head = Header::decode(b)?; - if !rlp_head.list { - return Err(RlpError::UnexpectedString) - } - // let started_len = b.len(); - let this = Self { - request_hash: alloy_rlp::Decodable::decode(b)?, - enr: EnrWrapper::::decode(b)?, - }; - // TODO: `Decodable` can be derived once we have native alloy_rlp decoding for ENR: - // Skipping the size check here is fine since the `buf` is the UDP datagram - // let consumed = started_len - b.len(); - // if consumed != rlp_head.payload_length { - // return Err(alloy_rlp::Error::ListLengthMismatch { - // expected: rlp_head.payload_length, - // got: consumed, - // }) - // } - *buf = *b; - Ok(this) - } -} - /// Represents a Ping packet. /// /// A [Ping packet](https://github.com/ethereum/devp2p/blob/master/discv4.md#ping-packet-0x01). @@ -750,7 +642,6 @@ mod tests { #[test] fn encode_decode_enr_msg() { - use self::EnrWrapper; use alloy_rlp::Decodable; use enr::secp256k1::SecretKey; use std::net::Ipv4Addr; @@ -770,7 +661,7 @@ mod tests { let forkentry = EnrForkIdEntry { fork_id }; forkentry.encode(&mut buf); builder.add_value_rlp("eth", buf.into()); - EnrWrapper::new(builder.build(&key).unwrap()) + builder.build(&key).unwrap() }; let enr_response = EnrResponse { request_hash: rng.gen(), enr }; @@ -789,30 +680,25 @@ mod tests { #[test] fn encode_known_rlp_enr() { - use self::EnrWrapper; use alloy_rlp::Decodable; use enr::{secp256k1::SecretKey, EnrPublicKey}; use std::net::Ipv4Addr; - let valid_record = - hex!("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f" - ); - let signature = - hex!("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c" - ); + let valid_record = hex!("f884b8407098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c01826964827634826970847f00000189736563703235366b31a103ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd31388375647082765f"); + let signature = hex!("7098ad865b00a582051940cb9cf36836572411a47278783077011599ed5cd16b76f2635f4e234738f30813a89eb9137e3e3df5266e3a1f11df72ecf1145ccb9c"); let expected_pubkey = hex!("03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138"); - let enr = EnrWrapper::::decode(&mut &valid_record[..]).unwrap(); - let pubkey = enr.0.public_key().encode(); + let enr = Enr::::decode(&mut &valid_record[..]).unwrap(); + let pubkey = enr.public_key().encode(); - assert_eq!(enr.0.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); - assert_eq!(enr.0.id(), Some(String::from("v4"))); - assert_eq!(enr.0.udp4(), Some(DEFAULT_DISCOVERY_PORT)); - assert_eq!(enr.0.tcp4(), None); - assert_eq!(enr.0.signature(), &signature[..]); + assert_eq!(enr.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); + assert_eq!(enr.id(), Some(String::from("v4"))); + assert_eq!(enr.udp4(), Some(DEFAULT_DISCOVERY_PORT)); + assert_eq!(enr.tcp4(), None); + assert_eq!(enr.signature(), &signature[..]); assert_eq!(pubkey.to_vec(), expected_pubkey); - assert!(enr.0.verify()); + assert!(enr.verify()); assert_eq!(&alloy_rlp::encode(&enr)[..], &valid_record[..]); @@ -833,19 +719,19 @@ mod tests { hex!("03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138"); let mut valid_record_buf = valid_record.as_slice(); - let enr = EnrWrapper::::decode(&mut valid_record_buf).unwrap(); - let pubkey = enr.0.public_key().encode(); + let enr = Enr::::decode(&mut valid_record_buf).unwrap(); + let pubkey = enr.public_key().encode(); // Byte array must be consumed after enr has finished decoding assert!(valid_record_buf.is_empty()); - assert_eq!(enr.0.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); - assert_eq!(enr.0.id(), Some(String::from("v4"))); - assert_eq!(enr.0.udp4(), Some(DEFAULT_DISCOVERY_PORT)); - assert_eq!(enr.0.tcp4(), None); - assert_eq!(enr.0.signature(), &signature[..]); + assert_eq!(enr.ip4(), Some(Ipv4Addr::new(127, 0, 0, 1))); + assert_eq!(enr.id(), Some(String::from("v4"))); + assert_eq!(enr.udp4(), Some(DEFAULT_DISCOVERY_PORT)); + assert_eq!(enr.tcp4(), None); + assert_eq!(enr.signature(), &signature[..]); assert_eq!(pubkey.to_vec(), expected_pubkey); - assert!(enr.0.verify()); + assert!(enr.verify()); } // test vector from the enr library rlp encoding tests @@ -863,20 +749,23 @@ mod tests { let mut builder = Enr::builder(); builder.ip(ip.into()); builder.tcp4(tcp); - EnrWrapper::new(builder.build(&key).unwrap()) + builder.build(&key).unwrap() }; let mut encoded_bytes = &alloy_rlp::encode(&enr)[..]; - let decoded_enr = EnrWrapper::::decode(&mut encoded_bytes).unwrap(); + let decoded_enr = Enr::::decode(&mut encoded_bytes).unwrap(); // Byte array must be consumed after enr has finished decoding assert!(encoded_bytes.is_empty()); assert_eq!(decoded_enr, enr); - assert_eq!(decoded_enr.0.id(), Some("v4".into())); - assert_eq!(decoded_enr.0.ip4(), Some(ip)); - assert_eq!(decoded_enr.0.tcp4(), Some(tcp)); - assert_eq!(decoded_enr.0.public_key().encode(), key.public().encode()); - assert!(decoded_enr.0.verify()); + assert_eq!(decoded_enr.id(), Some("v4".into())); + assert_eq!(decoded_enr.ip4(), Some(ip)); + assert_eq!(decoded_enr.tcp4(), Some(tcp)); + assert_eq!( + decoded_enr.public_key().encode(), + key.public_key(secp256k1::SECP256K1).encode() + ); + assert!(decoded_enr.verify()); } } diff --git a/crates/net/discv5/Cargo.toml b/crates/net/discv5/Cargo.toml index 03b856be9a00..a18bc9b6fbb4 100644 --- a/crates/net/discv5/Cargo.toml +++ b/crates/net/discv5/Cargo.toml @@ -18,7 +18,6 @@ reth-metrics.workspace = true # ethereum alloy-rlp.workspace = true -rlp = "0.5.2" discv5 = { workspace = true, features = ["libp2p"] } enr = { workspace = true, default-features = false, features = ["rust-secp256k1"] } multiaddr = { version = "0.18", default-features = false } diff --git a/crates/net/discv5/src/enr.rs b/crates/net/discv5/src/enr.rs index 502233794248..0f1e05815088 100644 --- a/crates/net/discv5/src/enr.rs +++ b/crates/net/discv5/src/enr.rs @@ -40,30 +40,25 @@ pub struct EnrCombinedKeyWrapper(pub discv5::Enr); impl From> for EnrCombinedKeyWrapper { fn from(value: Enr) -> Self { - let encoded_enr = rlp::encode(&value); - let enr = rlp::decode::(&encoded_enr).unwrap(); - - Self(enr) + let encoded_enr = alloy_rlp::encode(&value); + Self(alloy_rlp::Decodable::decode(&mut &encoded_enr[..]).unwrap()) } } impl From for Enr { fn from(val: EnrCombinedKeyWrapper) -> Self { - let EnrCombinedKeyWrapper(enr) = val; - let encoded_enr = rlp::encode(&enr); - - rlp::decode::>(&encoded_enr).unwrap() + let encoded_enr = alloy_rlp::encode(&val.0); + alloy_rlp::Decodable::decode(&mut &encoded_enr[..]).unwrap() } } #[cfg(test)] mod tests { + use super::*; use alloy_rlp::Encodable; use discv5::enr::{CombinedKey, EnrKey}; use reth_primitives::{Hardfork, NodeRecord, MAINNET}; - use super::*; - #[test] fn discv5_discv4_id_conversion() { let discv5_pk = CombinedKey::generate_secp256k1().public(); diff --git a/crates/net/dns/src/lib.rs b/crates/net/dns/src/lib.rs index d5ca9da32c65..f317eaa2bc61 100644 --- a/crates/net/dns/src/lib.rs +++ b/crates/net/dns/src/lib.rs @@ -402,8 +402,8 @@ fn convert_enr_node_record(enr: &Enr) -> Option } .into_ipv4_mapped(); - let mut maybe_fork_id = enr.get(b"eth")?; - let fork_id = ForkId::decode(&mut maybe_fork_id).ok(); + let maybe_fork_id = enr.get(b"eth")?; + let fork_id = ForkId::decode(&mut &maybe_fork_id[..]).ok(); Some(DnsNodeRecordUpdate { node_record, fork_id, enr: enr.clone() }) } diff --git a/crates/net/dns/src/tree.rs b/crates/net/dns/src/tree.rs index 53220f694e52..614d5f1d23ba 100644 --- a/crates/net/dns/src/tree.rs +++ b/crates/net/dns/src/tree.rs @@ -22,7 +22,7 @@ use crate::error::{ ParseEntryResult, }; use data_encoding::{BASE32_NOPAD, BASE64URL_NOPAD}; -use enr::{Enr, EnrError, EnrKey, EnrKeyUnambiguous, EnrPublicKey}; +use enr::{Enr, EnrKey, EnrKeyUnambiguous, EnrPublicKey, Error as EnrError}; use reth_primitives::{hex, Bytes}; use secp256k1::SecretKey; #[cfg(feature = "serde")] diff --git a/crates/net/ecies/src/algorithm.rs b/crates/net/ecies/src/algorithm.rs index 5dce7fee6902..bd1eb1d328f8 100644 --- a/crates/net/ecies/src/algorithm.rs +++ b/crates/net/ecies/src/algorithm.rs @@ -399,7 +399,7 @@ impl ECIES { let msg = x ^ self.nonce; let (rec_id, sig) = SECP256K1 .sign_ecdsa_recoverable( - &secp256k1::Message::from_slice(msg.as_slice()).unwrap(), + &secp256k1::Message::from_digest(msg.0), &self.ephemeral_secret_key, ) .serialize_compact(); @@ -473,7 +473,7 @@ impl ECIES { let x = ecdh_x(&self.remote_public_key.unwrap(), &self.secret_key); self.remote_ephemeral_public_key = Some(SECP256K1.recover_ecdsa( - &secp256k1::Message::from_slice((x ^ self.remote_nonce.unwrap()).as_ref()).unwrap(), + &secp256k1::Message::from_digest((x ^ self.remote_nonce.unwrap()).0), &signature, )?); self.ephemeral_shared_secret = @@ -631,7 +631,7 @@ impl ECIES { let tag = self.egress_mac.as_mut().unwrap().digest(); out.reserve(ECIES::header_len()); - out.extend_from_slice(&header); + out.extend_from_slice(&header[..]); out.extend_from_slice(tag.as_slice()); } diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 1df8067649b8..ca2875388113 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -80,12 +80,13 @@ reth-provider = { workspace = true, features = ["test-utils"] } reth-tracing.workspace = true reth-transaction-pool = { workspace = true, features = ["test-utils"] } -alloy-node-bindings.workspace = true -ethers-core = { workspace = true, default-features = false } -ethers-providers = { workspace = true, default-features = false, features = ["ws"] } - enr = { workspace = true, features = ["serde", "rust-secp256k1"] } +alloy-node-bindings.workspace = true +alloy-rpc-client.workspace = true +alloy-transport-http = { workspace = true, features = ["reqwest"] } +reqwest = { workspace = true, features = ["json"] } + # misc serial_test.workspace = true tempfile.workspace = true @@ -104,11 +105,7 @@ test-utils = [ "reth-transaction-pool/test-utils", ] geth-tests = [] -optimism = [ - "reth-primitives/optimism", - "reth-provider/optimism", - "reth-network-api/optimism", -] +optimism = ["reth-primitives/optimism", "reth-provider/optimism", "reth-network-api/optimism"] [[bench]] name = "bench" diff --git a/crates/net/network/tests/it/connect.rs b/crates/net/network/tests/it/connect.rs index 67e71909d12d..d20c38011f79 100644 --- a/crates/net/network/tests/it/connect.rs +++ b/crates/net/network/tests/it/connect.rs @@ -1,7 +1,6 @@ //! Connection tests use alloy_node_bindings::Geth; -use ethers_providers::{Http, Middleware, Provider}; use futures::StreamExt; use reth_discv4::Discv4Config; use reth_eth_wire::DisconnectReason; @@ -319,10 +318,10 @@ async fn test_incoming_node_id_blacklist() { let temp_dir = tempfile::tempdir().unwrap().into_path(); let geth = Geth::new().data_dir(temp_dir).disable_discovery().authrpc_port(0).spawn(); let geth_endpoint = SocketAddr::new([127, 0, 0, 1].into(), geth.port()); - let provider = Provider::::try_from(format!("http://{geth_endpoint}")).unwrap(); + let provider = Provider::new(&format!("http://{geth_endpoint}")); // get the peer id we should be expecting - let geth_peer_id = enr_to_peer_id(provider.node_info().await.unwrap().enr); + let geth_peer_id = provider.peer_id().await.unwrap(); let ban_list = BanList::new(vec![geth_peer_id], HashSet::new()); let peer_config = PeersConfig::default().with_ban_list(ban_list); @@ -371,10 +370,10 @@ async fn test_incoming_connect_with_single_geth() { let temp_dir = tempfile::tempdir().unwrap().into_path(); let geth = Geth::new().data_dir(temp_dir).disable_discovery().authrpc_port(0).spawn(); let geth_endpoint = SocketAddr::new([127, 0, 0, 1].into(), geth.port()); - let provider = Provider::::try_from(format!("http://{geth_endpoint}")).unwrap(); + let provider = Provider::new(&format!("http://{geth_endpoint}")); // get the peer id we should be expecting - let geth_peer_id = enr_to_peer_id(provider.node_info().await.unwrap().enr); + let geth_peer_id = provider.peer_id().await.unwrap(); let config = NetworkConfigBuilder::new(secret_key) .listener_port(0) @@ -431,10 +430,10 @@ async fn test_outgoing_connect_with_single_geth() { let geth_socket = SocketAddr::new([127, 0, 0, 1].into(), geth_p2p_port); let geth_endpoint = SocketAddr::new([127, 0, 0, 1].into(), geth.port()).to_string(); - let provider = Provider::::try_from(format!("http://{geth_endpoint}")).unwrap(); + let provider = Provider::new(&format!("http://{geth_endpoint}")); // get the peer id we should be expecting - let geth_peer_id: PeerId = enr_to_peer_id(provider.node_info().await.unwrap().enr); + let geth_peer_id = provider.peer_id().await.unwrap(); // add geth as a peer then wait for a `SessionEstablished` event handle.add_peer(geth_peer_id, geth_socket); @@ -475,10 +474,10 @@ async fn test_geth_disconnect() { let geth_socket = SocketAddr::new([127, 0, 0, 1].into(), geth_p2p_port); let geth_endpoint = SocketAddr::new([127, 0, 0, 1].into(), geth.port()).to_string(); - let provider = Provider::::try_from(format!("http://{geth_endpoint}")).unwrap(); + let provider = Provider::new(&format!("http://{geth_endpoint}")); // get the peer id we should be expecting - let geth_peer_id: PeerId = enr_to_peer_id(provider.node_info().await.unwrap().enr); + let geth_peer_id = provider.peer_id().await.unwrap(); // add geth as a peer then wait for `PeerAdded` and `SessionEstablished` events. handle.add_peer(geth_peer_id, geth_socket); @@ -699,3 +698,21 @@ async fn test_connect_many() { assert_eq!(peer.network().num_connected_peers(), 4); } } + +struct Provider(alloy_rpc_client::RpcClient>); + +impl Provider { + fn new(url: &str) -> Self { + Self(alloy_rpc_client::RpcClient::new_http(url.parse().unwrap())) + } + + async fn peer_id(&self) -> Result> { + let req: serde_json::Value = self.0.request("admin_nodeInfo", ()).await?; + let enr = req.get("enr").ok_or("no .enr")?.as_str().ok_or(".enr not a string")?.parse()?; + Ok(enr_to_peer_id(enr)) + } + + async fn add_peer(&self, enode: String) -> Result<(), impl std::error::Error> { + self.0.request("admin_addPeer", (enode,)).await + } +} diff --git a/crates/primitives/src/genesis.rs b/crates/primitives/src/genesis.rs index 52b24facbf79..991b01bd7e65 100644 --- a/crates/primitives/src/genesis.rs +++ b/crates/primitives/src/genesis.rs @@ -13,7 +13,7 @@ mod allocator { use alloy_genesis::GenesisAccount; use secp256k1::{ rand::{thread_rng, RngCore}, - KeyPair, Secp256k1, + Keypair, Secp256k1, }; use std::collections::{hash_map::Entry, BTreeMap, HashMap}; @@ -73,9 +73,9 @@ mod allocator { /// Add a funded account to the genesis alloc. /// /// Returns the key pair for the account and the account's address. - pub fn new_funded_account(&mut self, balance: U256) -> (KeyPair, Address) { + pub fn new_funded_account(&mut self, balance: U256) -> (Keypair, Address) { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert(address, GenesisAccount::default().with_balance(balance)); @@ -90,9 +90,9 @@ mod allocator { &mut self, balance: U256, code: Bytes, - ) -> (KeyPair, Address) { + ) -> (Keypair, Address) { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert( @@ -110,9 +110,9 @@ mod allocator { &mut self, balance: U256, storage: BTreeMap, - ) -> (KeyPair, Address) { + ) -> (Keypair, Address) { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert( @@ -130,9 +130,9 @@ mod allocator { &mut self, code: Bytes, storage: BTreeMap, - ) -> (KeyPair, Address) { + ) -> (Keypair, Address) { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert( @@ -146,9 +146,9 @@ mod allocator { /// Adds an account with code to the genesis alloc. /// /// Returns the key pair for the account and the account's address. - pub fn new_account_with_code(&mut self, code: Bytes) -> (KeyPair, Address) { + pub fn new_account_with_code(&mut self, code: Bytes) -> (Keypair, Address) { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert(address, GenesisAccount::default().with_code(Some(code))); @@ -169,7 +169,7 @@ mod allocator { /// Returns the key pair for the account and the account's address. pub fn add_account(&mut self, account: GenesisAccount) -> Address { let secp = Secp256k1::new(); - let pair = KeyPair::new(&secp, &mut self.rng); + let pair = Keypair::new(&secp, &mut self.rng); let address = public_key_to_address(pair.public_key()); self.alloc.insert(address, account); diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 817271ae3393..c6648c3d9c2c 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1703,7 +1703,7 @@ mod tests { use alloy_primitives::{address, b256, bytes}; use alloy_rlp::{Decodable, Encodable, Error as RlpError}; use reth_codecs::Compact; - use secp256k1::{KeyPair, Secp256k1}; + use secp256k1::{Keypair, Secp256k1}; use std::str::FromStr; #[test] @@ -1996,7 +1996,7 @@ mod tests { tx.set_chain_id(chain_id % (u64::MAX / 2 - 36)); } - let key_pair = KeyPair::new(&secp, &mut rng); + let key_pair = Keypair::new(&secp, &mut rng); let signature = sign_message(B256::from_slice(&key_pair.secret_bytes()[..]), tx.signature_hash()).unwrap(); diff --git a/crates/primitives/src/transaction/util.rs b/crates/primitives/src/transaction/util.rs index 638064c12f10..b4a2db7f6b52 100644 --- a/crates/primitives/src/transaction/util.rs +++ b/crates/primitives/src/transaction/util.rs @@ -18,7 +18,7 @@ pub(crate) mod secp256k1 { let sig = RecoverableSignature::from_compact(&sig[0..64], RecoveryId::from_i32(sig[64] as i32)?)?; - let public = SECP256K1.recover_ecdsa(&Message::from_slice(&msg[..32])?, &sig)?; + let public = SECP256K1.recover_ecdsa(&Message::from_digest(*msg), &sig)?; Ok(public_key_to_address(public)) } @@ -26,7 +26,7 @@ pub(crate) mod secp256k1 { /// Returns the corresponding signature. pub fn sign_message(secret: B256, message: B256) -> Result { let sec = SecretKey::from_slice(secret.as_ref())?; - let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_slice(&message[..])?, &sec); + let s = SECP256K1.sign_ecdsa_recoverable(&Message::from_digest(message.0), &sec); let (rec_id, data) = s.serialize_compact(); let signature = Signature {