Skip to content

fix: resend original WHOAREYOU during handshake retransmissions#219

Open
Gabriel-Trintinalia wants to merge 3 commits intoConsensys:masterfrom
Gabriel-Trintinalia:fix/resend-who-are-you
Open

fix: resend original WHOAREYOU during handshake retransmissions#219
Gabriel-Trintinalia wants to merge 3 commits intoConsensys:masterfrom
Gabriel-Trintinalia:fix/resend-who-are-you

Conversation

@Gabriel-Trintinalia
Copy link
Copy Markdown
Contributor

@Gabriel-Trintinalia Gabriel-Trintinalia commented Apr 22, 2026

When a session is in WHOAREYOU_SENT and another unauthorised packet arrives (e.g. a retransmission), we were generating a new WHOAREYOU with a fresh nonce.

That breaks the handshake: the initiator has already signed against the original challenge, so the next HANDSHAKE gets rejected.

This change reuses the original WHOAREYOU instead of creating a new one, keeping the challenge stable and the handshake valid.

The spec requires this behaviour:

▎ If the recipient has already sent a WHOAREYOU for the node, it should re-send the same WHOAREYOU packet.

  • Fix HandshakeResend hive test

Note

Medium Risk
Touches session-handshake state and packet emission behavior; incorrect handling could break peer session establishment or cause stuck handshakes under packet loss/retransmit scenarios.

Overview
Ensures UnauthorizedMessagePacketHandler does not generate a new WHOAREYOU when the session is already in WHOAREYOU_SENT, and instead triggers a resend of the original challenge.

Adds NodeSession tracking for the last outbound WhoAreYouPacket plus a resendOutgoingWhoAreYou() path that reuses the original masking IV/challenge bytes, and clears the pending packet when the handshake state is reset. Updates/extends tests to cover the resend behavior and challenge stability.

Reviewed by Cursor Bugbot for commit eac42de. Bugbot is set up for automated code reviews on this repo. Configure here.

@Gabriel-Trintinalia Gabriel-Trintinalia requested a review from a team as a code owner April 22, 2026 21:33
@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as draft April 22, 2026 22:17
@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as draft April 22, 2026 22:17
Copy link
Copy Markdown

@macfarla macfarla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Gabriel-Trintinalia Gabriel-Trintinalia marked this pull request as ready for review April 23, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants