Skip to content
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: small improvements #1496

Merged
merged 3 commits into from
Sep 21, 2023
Merged

bip324: small improvements #1496

merged 3 commits into from
Sep 21, 2023

Conversation

sipa
Copy link
Member

@sipa sipa commented Sep 15, 2023

Contains 3 small improvements to BIP324:

  • Since (in the V1 protocol) message type strings must be followed by only 0 bytes after the first 0, the first 16 bytes of an incoming V1 connection are predictable (network magic + "version\x00\x00\x00\x00\x00"). The current BIP text states to only compare the first 12 bytes instead of 16. This is in theory a semantics change, but wouldn't be observable except with negligible probability (v2 nodes that use 12 vs 16 can communicate with each other, and each can communicate with v1). However, there are possible future extensions that could make this observable (specifically, see footnote 19), so it seems worthwhile to still switch to 16.
  • Related to the previous point, it is also possible to detect incoming v1 connections of the wrong network: if the network magic does not match, but the version message type string after it does. Without this, an incoming connection from a v1 peer will get sent key + garbage, which in turn will almost certainly cause them to disconnect immediately, and changing this should not make much of a difference, but it allows for faster disconnect in this situation.
  • Drop the BIP330 message types from the short encodings list in the BIP. It feels like it shouldn't be BIP324's goal to predict future protocol improvements.

@dhruv
Copy link
Contributor

dhruv commented Sep 20, 2023

ACK cdcb680

@kallewoof kallewoof merged commit 7004ad1 into bitcoin:master Sep 21, 2023
achow101 added a commit to bitcoin-core/gui that referenced this pull request Oct 4, 2023
ba2e5bf net: raise V1_PREFIX_LEN from 12 to 16 (Pieter Wuille)

Pull request description:

  A "version" message in the V1 protocol starts with a fixed 16 bytes:
  * The 4-byte network magic
  * The 12-byte command string: "version" plus 5 0x00 bytes

  The current code detects incoming V1 connections by just looking at the first 12 bytes (matching an [earlier version](bitcoin/bips#1496) of BIP324), but 16 bytes is more precise. This isn't an observable difference right now, as a 12 byte prefix ought to be negligible already, but it may become observable with future extensions to the protocol, so make the code match the specification.

ACKs for top commit:
  achow101:
    ACK ba2e5bf
  theStack:
    re-ACK ba2e5bf
  mzumsande:
    Code review ACK ba2e5bf

Tree-SHA512: 64876b03613bd1c5dda82f4ca1b367014365f9ae4cfa30f45c5758a563c68cbea81a98d02ba616c264674c204517aac8b7de94da10f32e77b56267a43710c651
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
ba2e5bf net: raise V1_PREFIX_LEN from 12 to 16 (Pieter Wuille)

Pull request description:

  A "version" message in the V1 protocol starts with a fixed 16 bytes:
  * The 4-byte network magic
  * The 12-byte command string: "version" plus 5 0x00 bytes

  The current code detects incoming V1 connections by just looking at the first 12 bytes (matching an [earlier version](bitcoin/bips#1496) of BIP324), but 16 bytes is more precise. This isn't an observable difference right now, as a 12 byte prefix ought to be negligible already, but it may become observable with future extensions to the protocol, so make the code match the specification.

ACKs for top commit:
  achow101:
    ACK ba2e5bf
  theStack:
    re-ACK ba2e5bf
  mzumsande:
    Code review ACK ba2e5bf

Tree-SHA512: 64876b03613bd1c5dda82f4ca1b367014365f9ae4cfa30f45c5758a563c68cbea81a98d02ba616c264674c204517aac8b7de94da10f32e77b56267a43710c651
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.

3 participants