Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: validate received ENR response in discv4 #8407

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/net/discv4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use discv5::{
use enr::Enr;
use parking_lot::Mutex;
use proto::{EnrRequest, EnrResponse};
use reth_network_types::PeerId;
use reth_network_types::{pk2id, PeerId};
use reth_primitives::{bytes::Bytes, hex, ForkId, B256};
use secp256k1::SecretKey;
use std::{
Expand Down Expand Up @@ -1238,6 +1238,12 @@ impl Discv4Service {
fn on_enr_response(&mut self, msg: EnrResponse, remote_addr: SocketAddr, id: PeerId) {
trace!(target: "discv4", ?remote_addr, ?msg, "received ENR response");
if let Some(resp) = self.pending_enr_requests.remove(&id) {
// ensure the ENR's public key matches the expected node id
let enr_id = pk2id(&msg.enr.public_key());
if id != enr_id {
return
}

if resp.echo_hash == msg.request_hash {
let key = kad_key(id);
let fork_id = msg.eth_fork_id();
Expand Down
Loading