Skip to content

Commit 1fc7f36

Browse files
authored
fix(network): handle invalid peer public key in onLibp2pPeerConnect (ChainSafe#8829)
## Description Fixes an uncaughtException crash when connecting to a peer with a malformed public key. ### Error ``` uncaughtException: Point of length 294 was invalid. Expected 33 compressed bytes or 65 uncompressed bytes at fromBytes (node_modules/@noble/curves/esm/abstract/weierstrass.js:594:23) at uncompressPublicKey (node_modules/@chainsafe/enr/lib/defaultCrypto.js:17:38) at computeNodeId (packages/beacon-node/lib/network/subnets/interface.js:12:37) at PeerManager.onLibp2pPeerConnect (packages/beacon-node/lib/network/peers/peerManager.js:117:28) ``` ### Fix Wrap `computeNodeId(remotePeer)` in a try-catch. If computing the node ID fails (due to invalid public key), log at debug level and disconnect the peer gracefully with a GOODBYE. ### Notes This is a defensive fix - we shouldn't crash the node because one peer has malformed crypto data. The peer is simply disconnected. Closes ChainSafe#8302 --- *This PR was authored with AI assistance (lodekeeper using Claude Opus 4).* --------- Co-authored-by: lodekeeper <lodekeeper@users.noreply.github.com>
1 parent af02941 commit 1fc7f36

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

packages/beacon-node/src/network/peers/peerManager.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,17 @@ export class PeerManager {
721721
// NOTE: libp2p may emit two "peer:connect" events: One for inbound, one for outbound
722722
// If that happens, it's okay. Only the "outbound" connection triggers immediate action
723723
const now = Date.now();
724+
725+
// Ethereum uses secp256k1 for node IDs, reject peers with other key types
726+
if (remotePeer.type !== "secp256k1") {
727+
this.logger.debug("Peer does not have secp256k1 key, disconnecting", {
728+
peer: remotePeerPrettyStr,
729+
type: remotePeer.type,
730+
});
731+
void this.goodbyeAndDisconnect(remotePeer, GoodByeReasonCode.IRRELEVANT_NETWORK);
732+
return;
733+
}
734+
724735
const nodeId = computeNodeId(remotePeer);
725736
const peerData: PeerData = {
726737
lastReceivedMsgUnixTsMs: direction === "outbound" ? 0 : now,

0 commit comments

Comments
 (0)