-
Notifications
You must be signed in to change notification settings - Fork 37.4k
BIP324 connection support #28196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BIP324 connection support #28196
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
0d56e4d
to
ffb2f0c
Compare
90291f8
to
a77b9cc
Compare
a77b9cc
to
aaa3af2
Compare
1d0a9fb
to
d539d73
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review ACK db9888f
I reviewed the code again and did a little bit of manual mutation testing (checking that the fuzz test fails if I break things).
The nits can be ignored.
* Each V2TransportTester encapsulates a V2Transport (the one being tested), and can be told to | ||
* interact with it. To do so, it also encapsulates a BIP324Cipher to act as the other side. A | ||
* second V2Transport is not used, as doing so would not permit scenarios that involve sending | ||
* invalid data, or ones scenarios using BIP324 features that are not implemented on the sending |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: either "ones" or "scenarios"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #28433.
// Only wipe the buffer when everything is sent in the READY state. In the AWAITING_KEY state | ||
// we still need the garbage that's in the send buffer to construct the garbage authentication | ||
// packet. | ||
if (m_send_state == SendState::READY && m_send_pos == m_send_buffer.size()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this shortcut works, I wonder if it would be conceptually clearer to not have this special case and instead save the garbage in a m_send_garbage
vector, similar to the existing m_recv_garbage
on the receive side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do this if I make further changes to the PR, or as a follow-up. It would also simplify something else: getting rid of the "don't send in MABE_V1 state" exception, by only putting stuff in the send buffer when leaving that state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #28433.
ACK db9888f |
Outstanding/followup comments: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK db9888f
db9888f net: detect wrong-network V1 talking to V2Transport (Pieter Wuille) 91e1ef8 test: add unit tests for V2Transport (Pieter Wuille) 297c888 net: make V2Transport preallocate receive buffer space (Pieter Wuille) 3ffa5fb net: make V2Transport send uniformly random number garbage bytes (Pieter Wuille) 0be752d net: add short message encoding/decoding support to V2Transport (Pieter Wuille) 8da8642 net: make V2Transport auto-detect incoming V1 and fall back to it (Pieter Wuille) 13a7f01 net: add V2Transport class with subset of BIP324 functionality (Pieter Wuille) dc2d7eb crypto: Spanify EllSwiftPubKey constructor (Pieter Wuille) 5f4b2c6 net: remove unused Transport::SetReceiveVersion (Pieter Wuille) c3fad1f net: add have_next_message argument to Transport::GetBytesToSend() (Pieter Wuille) Pull request description: This is part of bitcoin#27634. This implements the BIP324 v2 transport (which implements all of what the BIP calls transport layer *and* application layer), though in a non-exposed way. It is tested through an extensive fuzz test, which verifies that v2 transports can talk to v2 transports, and v1 transports can talk to v2 transports, and a unit test that exercises a number of unusual scenarios. The transport is functionally complete, including: * Autodetection of incoming V1 connections. * Garbage, both sending and receiving. * Short message type IDs, both sending and receiving. * Ignore packets (receiving only, but tested in a unit test). * Session IDs are visible in `getpeerinfo` output (for manual comparison). Things that are not included, left for future PRs, are: * Actually using the v2 transport for connections. * Support for the `NODE_P2P_V2` service flag. * Retrying downgrade to V1 when attempted outbound V2 connections immediately fail. * P2P functional and unit tests ACKs for top commit: naumenkogs: ACK db9888f theStack: re-ACK db9888f mzumsande: Code Review ACK db9888f Tree-SHA512: 8906ac1e733a99e1f31c9111055611f706d80bbfc2edf6a07fa6e47b21bb65baacd1ff17993cbbf588063b2f5ad30b3af674a50c7bc8e8ebf4671483a21bbfeb
6470438 doc: fix typos and mistakes in BIP324 code comments (Pieter Wuille) 9bde93d net: do not use send buffer to store/cache garbage (Pieter Wuille) b6934fd net: merge V2Transport constructors, move key gen (Pieter Wuille) Pull request description: This addresses a few remaining comments on #28196: * Deduplicate the `V2Transport` constructors (bitcoin/bitcoin#28196 (comment)) * Do not use the send buffer to store garbage (bitcoin/bitcoin#28196 (comment)) * Fix typo (bitcoin/bitcoin#28196 (comment)) In addition, also fix an incorrect description in `V2Transport::SendState` (it claimed garbage was sent in the `READY` state, but it's in the `AWAITING_KEY` state). ACKs for top commit: naumenkogs: ACK 6470438 theStack: Code-review ACK 6470438 Tree-SHA512: 4bf6d2fe73c8054502d0b60e9de1722f8b3dd269c2dd6bf67197c3fb6eabcf047b6360cdab3c1fd5504215c2ac4ac2890a022780efc30ff583776242c8112451
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK db9888f
3f4e1bb tests: fix incorrect assumption in v2transport_test (Pieter Wuille) Pull request description: One part of the current `v2transport_test` introduced in #28196 assumes that if a bit gets modified in a message, failure should instantly be detected after sending that message. This is not correct in case the length descriptor is modified, as that may cause the receiver to need more data first. Fix this by sending more messages until failure actually occurs. Discovered in #27495 (comment). ACKs for top commit: theStack: ACK 3f4e1bb Tree-SHA512: faa90bf91996cbaaef62d764e746cb222eaf6796316b0d0e13709e528750b7c0ef09172f7fecfe814dbb8c136c5259f65ca1ac79318e6768a0bfc4e626a63249
6470438 doc: fix typos and mistakes in BIP324 code comments (Pieter Wuille) 9bde93d net: do not use send buffer to store/cache garbage (Pieter Wuille) b6934fd net: merge V2Transport constructors, move key gen (Pieter Wuille) Pull request description: This addresses a few remaining comments on bitcoin#28196: * Deduplicate the `V2Transport` constructors (bitcoin#28196 (comment)) * Do not use the send buffer to store garbage (bitcoin#28196 (comment)) * Fix typo (bitcoin#28196 (comment)) In addition, also fix an incorrect description in `V2Transport::SendState` (it claimed garbage was sent in the `READY` state, but it's in the `AWAITING_KEY` state). ACKs for top commit: naumenkogs: ACK 6470438 theStack: Code-review ACK 6470438 Tree-SHA512: 4bf6d2fe73c8054502d0b60e9de1722f8b3dd269c2dd6bf67197c3fb6eabcf047b6360cdab3c1fd5504215c2ac4ac2890a022780efc30ff583776242c8112451
3f4e1bb tests: fix incorrect assumption in v2transport_test (Pieter Wuille) Pull request description: One part of the current `v2transport_test` introduced in bitcoin#28196 assumes that if a bit gets modified in a message, failure should instantly be detected after sending that message. This is not correct in case the length descriptor is modified, as that may cause the receiver to need more data first. Fix this by sending more messages until failure actually occurs. Discovered in bitcoin#27495 (comment). ACKs for top commit: theStack: ACK 3f4e1bb Tree-SHA512: faa90bf91996cbaaef62d764e746cb222eaf6796316b0d0e13709e528750b7c0ef09172f7fecfe814dbb8c136c5259f65ca1ac79318e6768a0bfc4e626a63249
626f8e3 fuzz: actually test garbage >64b in p2p transport test (Pieter Wuille) Pull request description: This fixes an oversight from #28196: in the `p2p_transport_bidirectional_v2` fuzz test, when the desired garbage length is over 64 bytes, the code would actually use garbage length 0. Fix this. ACKs for top commit: instagibbs: ACK 626f8e3 brunoerg: crACK 626f8e3 Tree-SHA512: f6346367adb10464b6c9d20aef43625531d2a4d8110887ad03214b8c1907b83560f2dd5b5415e2180a40b4cd276d51881b32b60c740471b5c6bb218aa19848d8
This is part of #27634.
This implements the BIP324 v2 transport (which implements all of what the BIP calls transport layer and application layer), though in a non-exposed way. It is tested through an extensive fuzz test, which verifies that v2 transports can talk to v2 transports, and v1 transports can talk to v2 transports, and a unit test that exercises a number of unusual scenarios. The transport is functionally complete, including:
getpeerinfo
output (for manual comparison).Things that are not included, left for future PRs, are:
NODE_P2P_V2
service flag.