Skip to content

wire: ignore torv2 addresses in addrv2 messages - #2684

Open
raus7n wants to merge 1 commit into
btcsuite:masterfrom
raus7n:wire-ignore-torv2-addrv2
Open

raus7n wants to merge 1 commit into
btcsuite:masterfrom
raus7n:wire-ignore-torv2-addrv2

Conversation

@raus7n

@raus7n raus7n commented Nov 13, 2026

Copy link
Copy Markdown

Change Description

Fixes #2683.

BIP155 says Tor v2 addresses MUST be ignored on receive. readNetAddressV2
still decoded torv2 entries and returned ErrInvalidAddressSize when the
address was not 10 bytes long, so the whole addrv2 message was rejected,
including any valid addresses in it.

This change handles torv2 the same way as an unknown network ID: the address
and port are read and discarded, and ErrSkippedNetworkID is returned. Sizes
above maxAddrV2Size are still rejected. This matches Bitcoin Core and
rust-bitcoin.

Steps to Test

cd wire
go test -run 'TestReadNetAddressV2|TestAddrV2Decode' -v .

The two existing torv2 cases in TestReadNetAddressV2 now expect
ErrSkippedNetworkID, for both a wrong-size and a correct-size address.
The wrong-size case fails with invalid address size without this change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

BIP155 says Tor v2 addresses MUST be ignored on receive. Before this
change, readNetAddressV2 still decoded torv2 entries and returned
ErrInvalidAddressSize when the address was not 10 bytes long, which
made the whole addrv2 message fail to decode, valid addresses included.

Handle torv2 the same way as an unknown network ID: read and discard
the address and port, and return ErrSkippedNetworkID. This matches
Bitcoin Core and rust-bitcoin.

Fixes btcsuite#2683

@allocz allocz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already handled by #2663

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.

[bug]: wire: addrv2 message is rejected when a TorV2 entry has an unexpected length

2 participants