Skip to content

Compile-time safety for handshake#121

Merged
nyonson merged 5 commits intorust-bitcoin:mainfrom
nyonson:handshake-types
Jul 3, 2025
Merged

Compile-time safety for handshake#121
nyonson merged 5 commits intorust-bitcoin:mainfrom
nyonson:handshake-types

Conversation

@nyonson
Copy link
Collaborator

@nyonson nyonson commented Jun 25, 2025

No description provided.

@nyonson nyonson force-pushed the handshake-types branch 4 times, most recently from 7412b98 to 56e5892 Compare June 26, 2025 17:54
nyonson added 3 commits June 26, 2025 15:14
Introducing the "TypeState" pattern to the handshake. This moves the
runtime error variant, HandshakeOutOfOrder, to compile time. The type
system now doesn't allow for out of order calls.
The BIP-324 protocol is packet in nature, not stream based, and the
encrypted packets are not the same size as plaintext. They get length
bits added to the front and authentication bits tacked on the back. So
encryption in place would be a huge pain. And generally decryption in
place is weird too, because there are these bytes on either end which
no longer make sense to the plaintext. However, there is a solid use
case for *decryption* in place in the handshake where packet content
is not really cared about.
Update the receive_version to take a mutable input buffer instead of
an immutable input and a mutable output buffer. During the handshake,
callers don't care about decoy packets or version packet. And they
really don't want to deal with the variable sized output buffer.
nyonson added 2 commits June 27, 2025 10:37
The real tricky part of the handshake is reading the unknown number
of garbage bytes from the remote peer. That was hard to tease apart when
combined with the authenticating the garbage with the following decoy
or version packet, so split into two steps.
@nyonson nyonson marked this pull request as ready for review July 2, 2025 22:41
@nyonson nyonson merged commit 1be2134 into rust-bitcoin:main Jul 3, 2025
10 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.

1 participant