Commit 1fc7f36
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
721 | 721 | | |
722 | 722 | | |
723 | 723 | | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
724 | 735 | | |
725 | 736 | | |
726 | 737 | | |
| |||
0 commit comments