Skip to content

Conversation

@erickcestari
Copy link

This PR fixes two address validation issues discovered through differential fuzzing between btcd and Bitcoin Core. Both issues relate to addresses that should be rejected or treated as unroutable but were being accepted by btcd.

1. Treat RFC7343 (ORCHIDv2) addresses as unroutable

IPv6 ORCHIDv2 addresses (2001:20::/28) defined by RFC7343 are overlay routable cryptographic hash identifiers. These should not be treated as valid peer addresses, consistent with Bitcoin Core's behavior.

2. Skip IPv4-mapped IPv6 addresses in addrv2 messages

IPv4-mapped IPv6 addresses (::ffff:0:0/96, RFC 4291) sent with networkID 0x02 (IPv6) in addrv2 messages are now rejected. These addresses represent IPv4 addresses embedded in IPv6 format and should not be gossiped as IPv6 in addrv2; the canonical encoding for IPv4 addresses uses networkID 0x01 with a 4-byte address. This matches Bitcoin Core's behavior.

This issue was discovered through differential fuzzing between btcd and
Bitcoin Core.

Add detection and filtering of IPv6 ORCHIDv2 addresses as defined by
RFC7343 (2001:20::/28). These addresses are overlay routable
cryptographic hash identifiers and should not be treated as routable
peer addresses, consistent with Bitcoin Core's behavior.

Changes:
- Add rfc7343Net variable for the 2001:20::/28 address block
- Add IsRFC7343() function to detect ORCHIDv2 addresses
- Update IsRoutable() to exclude RFC7343 addresses
- Add comprehensive test coverage for RFC7343 detection
- Fix incorrect error message in TestIPTypes (IsRFC1918 -> IsRFC6145)
@Roasbeef
Copy link
Member

CI run approved.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 21297762383

Details

  • 17 of 17 (100.0%) changed or added relevant lines in 2 files are covered.
  • 86 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.1%) to 54.839%

Files with Coverage Reduction New Missed Lines %
txscript/taproot.go 2 97.74%
rpcclient/infrastructure.go 84 39.75%
Totals Coverage Status
Change from base Build 20942501138: -0.1%
Covered Lines: 31132
Relevant Lines: 56770

💛 - Coveralls

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

Change looks good, one minor nit that can save a hand full of lines in the diff.

This issue was discovered through differential fuzzing between btcd and
Bitcoin Core.

IPv4-mapped IPv6 addresses (::ffff:0:0/96, RFC 4291) sent with networkID
0x02 (IPv6) in addrv2 messages are now properly rejected. Per BIP155,
these addresses should use networkID 0x01 (IPv4) instead. This aligns
btcd's behavior with Bitcoin Core's addrv2 handling.

Changes:
- Add ipv4MappedPrefix constant for the ::ffff:0:0/96 prefix
- Add isIPv4Mapped() helper function to detect these addresses
- Update readNetAddressV2() to skip IPv4-mapped addresses with IPv6 networkID
- Add comprehensive test coverage for IPv4-mapped address detection
@erickcestari erickcestari force-pushed the fix-addrv2-address-validation branch from 011f8fa to 37d8163 Compare February 5, 2026 12:38
@erickcestari erickcestari requested a review from Roasbeef February 5, 2026 12:38
@erickcestari
Copy link
Author

Thanks for this PR!

Change looks good, one minor nit that can save a hand full of lines in the diff.

Thanks for the review Roasbeef!

It should be good now.

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