-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add BIP324 encrypted p2p transport de-/serializer (only used in tests) #18242
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
Conversation
d425adb
to
73db845
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Concept ACK. |
Concept: Concept ACK - thanks for working on this! Implementation: Some comments after first read-through of the implementation: 1. Uninitialized read in case of invalid command name In the "Invalid command name" case then a read (and use) of the uninitialized variable Lines 802 to 808 in 73db845
Shameless plug: For those interested in killing the uninitialised read bug class, consider reviewing:
2. Use of a locale dependent formatting function
Lines 819 to 823 in 73db845
Shameless plug: For those interested in permanently killing the locale dependency bug class, consider reviewing:
3. A question: I notice that It is somewhat related to another deserialization-exception anomaly I mailed you about back in October last year:
These deviations from the expected |
Very nice to see that the A small comment regarding the fuzzer: I think the assertion …
… in the fuzzing harness is guaranteed to hold for Could that be the case? :) |
Add "Waiting for author" tag? :) |
493c68c
to
07821e1
Compare
Thanks @practicalswift for the review. I tried to fix the exception handling as well as uninitialised read. I also fixed the invalid fuzzing assertion (for V2). I'm unsure about the locale dependent formatting. What would you recommend instead of |
I recommend |
07821e1
to
818b197
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.
Very glad to see BIP324 still moving forward! Concept ACK, I have some formatting suggestions, otherwise I didn't see any problems
@PastaPastaPasta Worth mentioning for future reviews: we use |
818b197
to
074e28b
Compare
Thanks @PastaPastaPasta and @practicalswift. Applied clang-format now. |
5e8ab4a
to
129545b
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.
129545b compiled and unit tests passed locally.
-
May I suggest to adapt the BIP324 and this PR to the fact that
REJECT
command has been removed from the Bitcoin Core code (#15437, #17004, #18609), i.e., shift command codes 34..38 -> 33..37? -
Rekeying code seems duplicated, therefore refactoring could be a good followup.
-
In 786ec9b mind not adding the following lines:
int readHeader(const char* pch, unsigned int nBytes);
int readData(const char* pch, unsigned int nBytes);
that are removed in 1b2f52a ?
return 0; //no short command | ||
} | ||
|
||
bool GetCommandFromShortCommandID(uint8_t shortID, std::string& cmd) |
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.
Please replace occurrences of "command" with something like "msg_type" at least in new code. See also #18533
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'd like to keep it to be consistent with BIP324 (and other bips). Changing it might make it more confusing.
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 see @MarcoFalke's point. A P2P protocol has no commands, just messages and message ids. But yea it's unfortunate that was not caught in the BIP.
76ce46f
to
61f6685
Compare
61f6685
to
4e3148b
Compare
# Conflicts: # src/test/net_tests.cpp
In order to conform to the TransportDeserializer protocol, we need to reduce the header from the messge size # Conflicts: # src/net.cpp
4e3148b
to
9e81bc4
Compare
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
FUZZ_TARGET_INIT(p2p_transport_deserializer, initialize_p2p_transport_deserializer) | ||
{ | ||
// Construct deserializer, with a dummy NodeId | ||
std::unique_ptr<TransportDeserializer> v1_deserializer = MakeUnique<V1TransportDeserializer>(Params(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION); |
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.
Please use std::make_unique
in new code.
return copy_bytes; | ||
} | ||
|
||
Optional<CNetMessage> V2TransportDeserializer::GetMessage(std::chrono::microseconds time, uint32_t& out_err_raw_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.
Please use std::optional
in new code.
…tests Summary: af2a145e575f23c64909e6cf1fb323c603bda7ca Refactor resource exhaustion test (Troy Giorshev) 5c4648d17ba18e4194959963994cc6b37053f127 Fix "invalid message size" test (Troy Giorshev) ff1e7b884447a5ba10553b2d964625f94e255bdc Move size limits to module-global (Troy Giorshev) 57890abf2c7919eddfec36178b1136cd44ffe883 Remove two unneeded tests (Troy Giorshev) Pull request description: This PR touches only the p2p_invalid_messages.py functional test module. There are two main goals accomplished here. First, it fixes the "invalid message size" test, which previously made a message that was invalid for multiple reasons. Second, it refactors the file into a single consistent style. This file appears to have originally had two authors, with different styles and some test duplication. It should now be easier and quicker to understand this module, anticipating the upcoming [BIP324](bitcoin/bitcoin#18242) and [AltNet](bitcoin/bitcoin#18989) changes. This should probably go in ahead of #19107, but the two are not strictly related. --- Depends on D9511 Backport of [[bitcoin/bitcoin#19177 | core#19177]] Test Plan: ninja all && ./test/functional/test_runner.py p2p_invalid_messages Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Subscribers: PiRK Differential Revision: https://reviews.bitcoinabc.org/D9519
My understanding is that someone else is helping with / taking over these changes, and that the BIP is still being overhauled. |
FWIW, I reviewed this repeatedly, hosted a review club meeting on BIP324 (https://bitcoincore.reviews/16202), and proposed a few times to @jonasschnelli to help move this forward. The reply was that help wasn't needed. So I am curious when that changed and who is helping with it, as little seems to be happening? |
The BIP overhaul has been ongoing for a long time, and recently @dhruv has taken it over in https://gist.github.com/dhruv/5b1275751bc98f3b64bcafce7876b489. |
Thanks for the update, @fanquake. |
This PR is superseded by #23233 which is ready for review. I've tried to go over the comment history here and address anything that's wasn't previously. |
BIP324 is here (not submitted to the BIP repository since it's still under work).
This PR adds a message transport de-/serializer for encrypted message after BIP324.
Includes:
Excludes (to keep it reviewable):
CKey
implementation)The code is exclusively used in the tests
This is based on #20962 (please review first)