Skip to content

Commit

Permalink
fix: validate received ENR response in discv4 (paradigmxyz#8407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored and mw2000 committed Jun 5, 2024
1 parent 10974b0 commit e24fe51
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit e24fe51

Please sign in to comment.