Skip to content

discv5: fix WHOAREYOU pending-request correlation#43

Merged
ch4r10t33r merged 1 commit into
mainfrom
fix/discv5-whoareyou-correlation
Apr 12, 2026
Merged

discv5: fix WHOAREYOU pending-request correlation#43
ch4r10t33r merged 1 commit into
mainfrom
fix/discv5-whoareyou-correlation

Conversation

@ch4r10t33r
Copy link
Copy Markdown
Collaborator

Summary

  • Fix 5 bugs in the discv5 WHOAREYOU/Handshake path that prevented completing a full handshake exchange
  • sendWhoareyou now echoes the triggering packet's nonce and stores challenge_data for id-sig verification
  • handleWhoareyou builds and sends a real Handshake reply (ECDH, key derivation, id-sig, encrypt pending message)
  • handleHandshake uses the session's stored id_nonce and challenge_data instead of zero-padded header nonce
  • sendToNode sends a random ordinary packet when no session exists, triggering the WHOAREYOU→Handshake flow
  • Adds PendingChallenge nonce-indexed list with expiry, challenge_data field on Session, pubkey on table.Entry

Test plan

  • zig build test --summary all — all 144 tests pass (3 new: handshake roundtrip, nonce echo, pending expiry)
  • zig build simtest --summary all — passes
  • zig fmt --check . — clean

Closes #38

Fix 5 bugs preventing a complete discv5 handshake exchange:

1. sendWhoareyou now echoes the triggering packet's nonce instead of
   zeroes, enabling the initiator to correlate the challenge.

2. Add PendingChallenge nonce-indexed list to Node so inbound WHOAREYOU
   packets can be mapped back to the target peer.

3. handleWhoareyou now builds and sends a full Handshake reply (ECDH,
   key derivation, id-sig, encodeHandshake) instead of discarding the
   ephemeral keypair.

4. handleHandshake uses sess.id_nonce and sess.challenge_data from the
   awaiting_handshake session instead of zero-padding the header nonce.

5. sendToNode sends a random ordinary packet when no session exists,
   storing the plaintext for retry inside the Handshake body.

Also adds challenge_data field to Session, pubkey field to table.Entry,
and expiry for PendingChallenge entries.

Tests: handshake roundtrip, nonce echo correlation, pending expiry.

Closes #38
@ch4r10t33r ch4r10t33r merged commit f21efbb into main Apr 12, 2026
6 checks passed
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.

discovery: complete discv5 WHOAREYOU pending-request correlation

1 participant