From d4a3bf1b23e3972fb82e085c0e29fe2c4647ed5c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 31 Jul 2025 12:13:36 +0200 Subject: [PATCH] cmd/devp2p/internal/v4test: add test for ENRRequest (#32303) This adds a cross-client protocol test for a recently discovered bug in Nethermind. --- cmd/devp2p/internal/v4test/discv4tests.go | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/devp2p/internal/v4test/discv4tests.go b/cmd/devp2p/internal/v4test/discv4tests.go index 963df6cdbc..de97d7a276 100644 --- a/cmd/devp2p/internal/v4test/discv4tests.go +++ b/cmd/devp2p/internal/v4test/discv4tests.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/internal/utesting" "github.com/ethereum/go-ethereum/p2p/discover/v4wire" + "github.com/ethereum/go-ethereum/p2p/enode" ) const ( @@ -501,6 +502,36 @@ func FindnodeAmplificationWrongIP(t *utesting.T) { } } +func ENRRequest(t *utesting.T) { + t.Log(`This test sends an ENRRequest packet and expects a response containing a valid ENR.`) + + te := newTestEnv(Remote, Listen1, Listen2) + defer te.close() + bond(t, te) + + req := &v4wire.ENRRequest{Expiration: futureExpiration()} + hash := te.send(te.l1, req) + + response, _, err := te.read(te.l1) + if err != nil { + t.Fatal("read error:", err) + } + enrResp, ok := response.(*v4wire.ENRResponse) + if !ok { + t.Fatalf("expected ENRResponse packet, got %T", response) + } + if !bytes.Equal(enrResp.ReplyTok, hash) { + t.Errorf("wrong hash in response packet: got %x, want %x", enrResp.ReplyTok, hash) + } + node, err := enode.New(enode.ValidSchemes, &enrResp.Record) + if err != nil { + t.Errorf("invalid record in response: %v", err) + } + if node.ID() != te.remote.ID() { + t.Errorf("wrong node ID in response: got %v, want %v", node.ID(), te.remote.ID()) + } +} + var AllTests = []utesting.Test{ {Name: "Ping/Basic", Fn: BasicPing}, {Name: "Ping/WrongTo", Fn: PingWrongTo}, @@ -510,6 +541,7 @@ var AllTests = []utesting.Test{ {Name: "Ping/PastExpiration", Fn: PingPastExpiration}, {Name: "Ping/WrongPacketType", Fn: WrongPacketType}, {Name: "Ping/BondThenPingWithWrongFrom", Fn: BondThenPingWithWrongFrom}, + {Name: "ENRRequest", Fn: ENRRequest}, {Name: "Findnode/WithoutEndpointProof", Fn: FindnodeWithoutEndpointProof}, {Name: "Findnode/BasicFindnode", Fn: BasicFindnode}, {Name: "Findnode/UnsolicitedNeighbors", Fn: UnsolicitedNeighbors},