Check CJDNS address is valid #20616

pull lontivero wants to merge 1 commits into bitcoin:master from lontivero:validate-cjdns-addresses changing 2 files +15 −0
  1. lontivero commented at 5:33 PM on December 10, 2020: contributor

    CJDNS addresses start with 0xFC and for that reason if a netaddr was unserialized with network type cjdns but its address prefix is not 0xFC then that netaddr should be considered invalid.

  2. lontivero force-pushed on Dec 10, 2020
  3. lontivero force-pushed on Dec 10, 2020
  4. DrahtBot added the label P2P on Dec 10, 2020
  5. laanwj commented at 12:00 PM on December 11, 2020: member

    Concept ACK, CJDNS addresses do and will always start with 0xFC (we could even have used this to save a byte in the wire representation) this is a simple sanity check.

  6. practicalswift commented at 3:24 PM on December 11, 2020: contributor

    Concept ACK

    Nice contribution. Thanks for adding a test too!

  7. in src/netaddress.cpp:444 in 96b98ad92c outdated
     436 | @@ -437,6 +437,9 @@ bool CNetAddr::IsValid() const
     437 |          return false;
     438 |      }
     439 |  
     440 | +    if (IsCJDNS() && (m_addr[0] != 0xFC))
     441 | +        return false;
     442 | +
    


    jonatack commented at 3:34 PM on December 11, 2020:

    nit, same line or use braces for new code, per doc/developer-notes.md

    If an `if` only has a single-statement `then`-clause, it can appear
    on the same line as the `if`, without braces. In every other case,
    braces are required, and the `then` and `else` clauses must appear
    correctly indented on a new line.

    lontivero commented at 7:03 PM on December 11, 2020:

    I wanted to follow the same style that the rest of the if statements had in the method. Should I change it anyway?


    sipa commented at 7:04 PM on December 11, 2020:

    Yes, absolutely. The developer notes explicitly state you should not try to mimick surrounding style when writing new code.


    lontivero commented at 3:27 PM on December 14, 2020:

    Done

  8. jonatack commented at 3:35 PM on December 11, 2020: member

    Concept ACK

  9. lontivero force-pushed on Dec 11, 2020
  10. lontivero force-pushed on Dec 14, 2020
  11. in src/netaddress.cpp:440 in fbd400db10 outdated
     436 | @@ -437,6 +437,11 @@ bool CNetAddr::IsValid() const
     437 |          return false;
     438 |      }
     439 |  
     440 | +    // cjdns addresses always start with 0xfc
    


    jonatack commented at 4:31 PM on December 14, 2020:

    suggestion, if you retouch:

        // CJDNS addresses always start with 0xfc
    

    as everywhere else in the file and in net_tests.cpp refers to CJDNS

  12. in src/test/net_tests.cpp:614 in fbd400db10 outdated
     608 | +    s << MakeSpan(ParseHex("06"                               // network type (CJDNS)
     609 | +                           "10"                               // address length
     610 | +                           "aa000001000200030004000500060007" // address
     611 | +                           ));
     612 | +    s >> addr;
     613 | +    BOOST_CHECK(!addr.IsValid());
    


    jonatack commented at 4:38 PM on December 14, 2020:

    perhaps assert IsCJDNS() before the invalidity check

         s >> addr;
    +    BOOST_CHECK(addr.IsCJDNS());
         BOOST_CHECK(!addr.IsValid());
    
  13. jonatack commented at 4:39 PM on December 14, 2020: member

    ACK fbd400db1084d983ea676725fa912336e8612a87

    A couple of minor suggestions below, happy to re-ACK if you update

  14. Check if Cjdns address is valid f7264fff0a
  15. lontivero force-pushed on Dec 14, 2020
  16. jonatack commented at 7:04 PM on December 14, 2020: member

    ACK f7264fff0a098f8b6354c7373b8790791c25dd07

  17. practicalswift commented at 7:41 PM on December 14, 2020: contributor

    cr ACK f7264fff0a098f8b6354c7373b8790791c25dd07: patch looks correct

  18. theStack approved
  19. theStack commented at 9:31 AM on December 15, 2020: member

    ACK f7264fff0a098f8b6354c7373b8790791c25dd07 ✔️ Verified that Cjdns addresses always start with 0xfc by reading https://gathman.org/meshdoc/Cjdns%20-%20Wikipedia.html#Address_generation and https://www.systutorials.com/docs/linux/man/5-cjdroute.conf/

  20. laanwj commented at 4:50 PM on December 15, 2020: member
  21. laanwj merged this on Dec 15, 2020
  22. laanwj closed this on Dec 15, 2020

  23. sipa commented at 5:43 PM on December 15, 2020: member

    Posthumous utACK f7264fff0a098f8b6354c7373b8790791c25dd07

    I think this check makes sense because it is so simple and easily observable, but we probably don't want to go much further with similar sanity checks (e.g. we could go check if relayed torv3 contain an actual ed25519 pubkey, which IMO would lead us too far).

  24. sidhujag referenced this in commit 28852243b6 on Dec 15, 2020
  25. PastaPastaPasta referenced this in commit 4561d8af49 on Jun 27, 2021
  26. PastaPastaPasta referenced this in commit 80d712c5ad on Jun 28, 2021
  27. PastaPastaPasta referenced this in commit 366c69839d on Jun 29, 2021
  28. PastaPastaPasta referenced this in commit ba0e274bc6 on Jul 1, 2021
  29. PastaPastaPasta referenced this in commit cc0dc3d7e2 on Jul 1, 2021
  30. PastaPastaPasta referenced this in commit 43b948da43 on Jul 15, 2021
  31. PastaPastaPasta referenced this in commit 5ff3dd1b34 on Jul 16, 2021
  32. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 00:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me