Merge rust-bitcoin/rust-bitcoin#2546: Fix CJDNS marker byte check

ec67456172 Fix CJDNS marker byte check (Ava Chow)

Pull request description:

  Only the first byte of a CJDNS address is 0xfc, the second byte should be ignored.

  See https://github.com/hyperboria/peers for examples of CJDNS addresses.

ACKs for top commit:
  apoelstra:
    ACK ec67456172
  sanket1729:
    urACK ec67456172.
  Kixunil:
    ACK ec67456172

Tree-SHA512: 0da1054a8e997b6bf6e0aaedc40943edb6a6c7b23f660c92b34dc9395e6153e7e10b0268335a77fbcb5bb635352e1ed92839b350188fd6d33dabe558e88c00bb
This commit is contained in:
Andrew Poelstra 2024-03-07 14:37:08 +00:00
commit 1ac7c292b1
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 3 additions and 3 deletions

View File

@ -226,7 +226,7 @@ impl Decodable for AddrV2 {
} }
let addr: [u16; 8] = read_be_address(r)?; let addr: [u16; 8] = read_be_address(r)?;
// check the first byte for the CJDNS marker // check the first byte for the CJDNS marker
if addr[0] != u16::from_be_bytes([0xFC, 0x00]) { if addr[0] >> 8 != 0xFC{
return Err(encode::Error::ParseFailed("Invalid CJDNS address")); return Err(encode::Error::ParseFailed("Invalid CJDNS address"));
} }
AddrV2::Cjdns(Ipv6Addr::new( AddrV2::Cjdns(Ipv6Addr::new(
@ -425,8 +425,8 @@ mod test {
hex!("0520a2894dabaec08c0051a481a6dac88b64f98232ae42d4b6fd2fa81952dfe36a87") hex!("0520a2894dabaec08c0051a481a6dac88b64f98232ae42d4b6fd2fa81952dfe36a87")
); );
let ip = AddrV2::Cjdns(Ipv6Addr::from_str("fc00:1:2:3:4:5:6:7").unwrap()); let ip = AddrV2::Cjdns(Ipv6Addr::from_str("fc01:1:2:3:4:5:6:7").unwrap());
assert_eq!(serialize(&ip), hex!("0610fc000001000200030004000500060007")); assert_eq!(serialize(&ip), hex!("0610fc010001000200030004000500060007"));
let ip = AddrV2::Unknown(170, hex!("01020304")); let ip = AddrV2::Unknown(170, hex!("01020304"));
assert_eq!(serialize(&ip), hex!("aa0401020304")); assert_eq!(serialize(&ip), hex!("aa0401020304"));