diff --git a/crates/networking/p2p/rlpx/connection/handshake.rs b/crates/networking/p2p/rlpx/connection/handshake.rs index 177ea98b82f..a66b442a096 100644 --- a/crates/networking/p2p/rlpx/connection/handshake.rs +++ b/crates/networking/p2p/rlpx/connection/handshake.rs @@ -214,7 +214,7 @@ async fn receive_auth( public_key: auth.public_key, nonce: auth.nonce, ephemeral_key: remote_ephemeral_key, - init_message: msg_bytes.to_owned(), + init_message: msg_bytes, }) } @@ -239,7 +239,7 @@ async fn receive_ack( public_key: remote_public_key, nonce: ack.nonce, ephemeral_key: remote_ephemeral_key, - init_message: msg_bytes.to_owned(), + init_message: msg_bytes, }) } @@ -258,15 +258,9 @@ async fn receive_handshake_msg( buf.resize(msg_size + 2, 0); // Read the rest of the message - // Guard unwrap - if buf.len() < msg_size + 2 { - return Err(PeerConnectionError::CryptographyError(String::from( - "bad buf size", - ))); - } - stream.read_exact(&mut buf[2..msg_size + 2]).await?; - let ack_bytes = &buf[..msg_size + 2]; - Ok(ack_bytes.to_vec()) + stream.read_exact(&mut buf[2..]).await?; + buf.truncate(msg_size + 2); + Ok(buf) } /// Encodes an Auth message, to start a handshake.