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

Improve asmap checks and add sanity check #18512

Merged
merged 7 commits into from May 6, 2020

Conversation

sipa
Copy link
Member

@sipa sipa commented Apr 3, 2020

This improves/documents the failure cases inside the asmap interpreter. None of the changes are bug fixes (they only change behavior for corrupted asmap files), but they may make things easier to follow.

In a second step, a sanity checker is added that effectively executes every potential code path through the asmap file, checking the same failure cases as the interpreter, and more. It takes around 30 ms to run for me for a 1.2 MB asmap file.

I've verified that this accepts asmap files constructed by https://github.com/sipa/asmap/blob/master/buildmap.py with a large dataset, and no longer accepts it with 1 bit changed in it.

@sipa
Copy link
Member Author

sipa commented Apr 3, 2020

cc @naumenkogs.

@sipa
Copy link
Member Author

sipa commented Apr 3, 2020

@practicalswift There may be opportunity to fuzz here: if SanityCheckASMap succeeds, then no input to Interpret should return 0.

EDIT: Oh no, 0 can mean no match or error; it's still possible to reach no match.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 3, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko
Copy link
Member

maflcko commented Apr 3, 2020

Would be nice to have the new code covered by some tests. Maybe the fuzzers?

diff --git a/src/test/fuzz/asmap.cpp b/src/test/fuzz/asmap.cpp
index 7f3eef79a1..1ab5459b12 100644
--- a/src/test/fuzz/asmap.cpp
+++ b/src/test/fuzz/asmap.cpp
@@ -25,4 +25,5 @@ void test_one_input(const std::vector<uint8_t>& buffer)
         }
     }
     (void)net_addr.GetMappedAS(asmap);
+    (void)SanityCheckASMap(asmap);
 }

@naumenkogs
Copy link
Member

Code review ACK 4719223
Tested: did some bit-flipping and saw that sanity check does not pass anymore.

Thank you for working on this.

@sipa
Copy link
Member Author

sipa commented Apr 3, 2020

A few changes:

  • I've split out the changes into more commits
  • Made it an error to reach EOF without a RETURN instruction
  • Made the sanity checker slightly more tolerant (it now supports multiple jumps to the same location, a potential optimization that buildmap.py doesn't currently use).
  • Added a commit that makes failures in the Interpreter assertion failures, and adds a fuzz tester that verifies this does not happen with asmaps that pass SanityCheckASMap.

I've verified that the fuzzer actually finds asmaps that pass the sanity check, and the Interpreter is run on it (by adding an early assertion failure in Interpreter). I'll try to share my corpus.

@naumenkogs
Copy link
Member

Using gcc 9.2.1, AFL 2.5.2, got this at compilation for fuzzing:

libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::~UniqueLock()':
/home/gleb/bitcoin/src/./sync.h:169: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::TryEnter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:139: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
/home/gleb/bitcoin/src/./sync.h:142: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::Enter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:126: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:7281: recipe for target 'test/fuzz/addrman_deserialize' failed
make[2]: *** [test/fuzz/addrman_deserialize] Error 1
make[2]: *** Waiting for unfinished jobs....
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::~UniqueLock()':
/home/gleb/bitcoin/src/./sync.h:169: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::TryEnter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:139: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
/home/gleb/bitcoin/src/./sync.h:142: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::Enter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:126: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:7329: recipe for target 'test/fuzz/block' failed
make[2]: *** [test/fuzz/block] Error 1
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::~UniqueLock()':
/home/gleb/bitcoin/src/./sync.h:169: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::TryEnter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:139: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
/home/gleb/bitcoin/src/./sync.h:142: undefined reference to `LeaveCritical()'
libbitcoin_util.a(libbitcoin_util_a-threadinterrupt.o): In function `UniqueLock<AnnotatedMixin<std::mutex>, std::unique_lock<std::mutex> >::Enter(char const*, char const*, int)':
/home/gleb/bitcoin/src/./sync.h:126: undefined reference to `EnterCritical(char const*, char const*, int, void*, bool)'
collect2: error: ld returned 1 exit status
Makefile:7369: recipe for target 'test/fuzz/block_header_and_short_txids_deserialize' failed
make[2]: *** [test/fuzz/block_header_and_short_txids_deserialize] Error 1
make[2]: Leaving directory '/home/gleb/bitcoin/src'
Makefile:18893: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/gleb/bitcoin/src'
Makefile:783: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

cc: @practicalswift

@maflcko
Copy link
Member

maflcko commented Apr 4, 2020

@naumenkogs have you run make distclean?

@practicalswift
Copy link
Contributor

Concept ACK

Thanks a lot for adding a fuzzing harness!

@naumenkogs
Copy link
Member

@MarcoFalke
This helped.

@sipa
With the latest code, the map I generated with truncate -s 1M wrong_asmap seems to be valid. I don't think that's correct behavior?

@sipa
Copy link
Member Author

sipa commented Apr 4, 2020

@naumenkogs Nice catch. DecodeBits wasn't returning failure when EOF occurred in the mantissa bits. Should be fixed now. I believe it should be impossible to take a valid asmap and truncate it, and having it still be acceptable.

@naumenkogs
Copy link
Member

ACK 906e031

@sipa sipa force-pushed the 202003_asmap_checks branch 2 times, most recently from 81e2fb7 to a48a4a7 Compare April 6, 2020 21:02
@sipa
Copy link
Member Author

sipa commented Apr 6, 2020

Now added an extra check that verifies that no truncation of a valid asmap remains valid.

@laanwj laanwj added this to Blockers in High-priority for review Apr 16, 2020
@hebasto
Copy link
Member

hebasto commented Apr 17, 2020

@sipa
Mind addressing a compiler warning issue on ARM 32-bit platforms: d0b10ed from #18686 ?

@practicalswift
Copy link
Contributor

ACK 7489776 modulo feedback below.

@sipa, would it be possible to make it so that the existing coverage-increasing inputs to src/test/fuzz/asmap are not invalidated by the merge of this PR? The qa-assets inputs achieve very comprehensive coverage for asmap thanks to previous fuzzing efforts. It would be nice to keep those inputs. Perhaps your src/test/fuzz/asmap.cpp changes can be moved to a separate new fuzzing harness file? :)

Copy link
Contributor

@jonatack jonatack 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 adding sanity checks and fuzzing.

ACK 7489776 code review, regular build/tests/ran bitcoin with -asmap, fuzz build/ran both fuzzers overnight.

fuzz/asmap_direct

#900803874	REDUCE cov: 730 ft: 3838 corp: 210/19Kb exec/s: 19950 rss: 562Mb L: 78/2049 MS: 1 EraseBytes-
#906401851	REDUCE cov: 730 ft: 3838 corp: 210/19Kb exec/s: 19899 rss: 562Mb L: 249/2049 MS: 2 InsertRepeatedBytes-EraseBytes-
#906756962	REDUCE cov: 730 ft: 3838 corp: 210/19Kb exec/s: 19895 rss: 562Mb L: 247/2049 MS: 1 EraseBytes-

fuzz/asmap

#183578499	REDUCE cov: 1226 ft: 3413 corp: 222/7168b exec/s: 3930 rss: 421Mb L: 39/147 MS: 1 EraseBytes-
#184582017	REDUCE cov: 1226 ft: 3413 corp: 222/7165b exec/s: 3928 rss: 421Mb L: 116/147 MS: 2 EraseBytes-ChangeByte-
#185253963	REDUCE cov: 1226 ft: 3413 corp: 222/7164b exec/s: 3928 rss: 421Mb L: 115/147 MS: 1 EraseBytes-

A few non-blocking ideas for your consideration below.

if (opcode == 0) {
return DecodeASN(pos, endpos);
} else if (opcode == 1) {
if (opcode == Instruction::RETURN) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Perhaps use a switch statement for the opcode conditionals, here and in SanityCheckASMap, to make explicit the nature of the operation (testing a single value against a set of scoped enumerations) and possibly generate better code with a jump table instead of repeatedly checking individual values.

while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) asmap_prefix.pop_back();
while (!asmap_prefix.empty()) {
asmap_prefix.pop_back();
assert(!SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos));
Copy link
Contributor

@jonatack jonatack Apr 26, 2020

Choose a reason for hiding this comment

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

nit suggestion:

+    size_t bits = buffer.size() - sep_pos - 1;
-    if (buffer.size() - sep_pos - 1 > 128) return; // At most 128 bits in IP address
+    if (bits > 128) return; // At most 128 bits in IP address
 
     // Checks on asmap
     std::vector<bool> asmap(buffer.begin(), buffer.begin() + sep_pos);
-    if (SanityCheckASMap(asmap, buffer.size() - 1 - sep_pos)) {
+    if (SanityCheckASMap(asmap, bits)) {
         // Verify that for valid asmaps, no prefix (except up to 7 zero padding bits) is valid.
         std::vector<bool> asmap_prefix = asmap;
         while (!asmap_prefix.empty() && asmap_prefix.size() + 7 > asmap.size() && asmap_prefix.back() == false) asmap_prefix.pop_back();
         while (!asmap_prefix.empty()) {
             asmap_prefix.pop_back();
-            assert(!SanityCheckASMap(asmap_prefix, buffer.size() - 1 - sep_pos));
+            assert(!SanityCheckASMap(asmap_prefix, bits));

return;
}
}
if (!have_sep) return; // Needs exactly 1 separator
Copy link
Contributor

Choose a reason for hiding this comment

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

nit suggestion:

-    bool have_sep = false;
+    int separators{0};
     size_t sep_pos;
     for (size_t pos = 0; pos < buffer.size(); ++pos) {
         uint8_t x = buffer[pos];
         if ((x & 0xFE) == 0) continue;
         if (x == 0xFF) {
-            if (have_sep) return;
-            have_sep = true;
+            if (separators != 0) return;
+            separators += 1;
             sep_pos = pos;
         } else {
             return;
         }
     }
-    if (!have_sep) return; // Needs exactly 1 separator
+    if (separators != 1) return; // Needs exactly 1 separator

Copy link
Contributor

Choose a reason for hiding this comment

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

@jonatack Even in your code the only values the variable can have is 0 and 1. Why would you want to use an int instead of a bool then?

Copy link
Contributor

Choose a reason for hiding this comment

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

My thoughts were (a) a sanity check is better than just eyeballing code, not only for now but also future changes, and (b) a check for exactly one is more strongly verified when a state of more than one is also tested.

Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

ACK 7489776

Reviewed code and tested asmap and asmap_direct fuzzers. Confirmed that bitcoind starts with a correct map and Sanity checker catches a corrupt file.

@@ -118,3 +119,56 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
// Reached EOF without RETURN, or aborted (see any of the breaks above).
return 0; // 0 is not a valid ASN
}

bool SanityCheckASMap(const std::vector<bool>& asmap, int bits)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: It's a bit inconsistent that this function has ASMap in it while DecodeAsmap for example has Asmap.

@laanwj laanwj merged commit f763283 into bitcoin:master May 6, 2020
@laanwj laanwj removed this from Blockers in High-priority for review May 7, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 12, 2020
7489776 Add asmap_direct fuzzer that tests Interpreter directly (Pieter Wuille)
7cf97fd Make asmap Interpreter errors fatal and fuzz test it (Pieter Wuille)
c81aefc Add additional effiency checks to sanity checker (Pieter Wuille)
fffd8dc Add asmap sanity checker (Pieter Wuille)
5feefbe Improve asmap Interpret checks and document failures (Pieter Wuille)
2b3dbfa Deal with decoding failures explicitly in asmap Interpret (Pieter Wuille)
1479007 Introduce Instruction enum in asmap (Pieter Wuille)

Pull request description:

  This improves/documents the failure cases inside the asmap interpreter. None of the changes are bug fixes (they only change behavior for corrupted asmap files), but they may make things easier to follow.

  In a second step, a sanity checker is added that effectively executes every potential code path through the asmap file, checking the same failure cases as the interpreter, and more. It takes around 30 ms to run for me for a 1.2 MB asmap file.

  I've verified that this accepts asmap files constructed by https://github.com/sipa/asmap/blob/master/buildmap.py with a large dataset, and no longer accepts it with 1 bit changed in it.

ACKs for top commit:
  practicalswift:
    ACK 7489776 modulo feedback below.
  jonatack:
    ACK 7489776 code review, regular build/tests/ran bitcoin with -asmap, fuzz build/ran both fuzzers overnight.
  fjahr:
    ACK 7489776

Tree-SHA512: d876df3859735795c857c83e7155ba6851ce839bdfa10c18ce2698022cc493ce024b5578c1828e2a94bcdf2552c2f46c392a251ed086691b41959e62a6970821
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 25, 2021
Summary:
```
This improves/documents the failure cases inside the asmap interpreter. None of the changes are bug fixes (they only change behavior for corrupted asmap files), but they may make things easier to follow.

In a second step, a sanity checker is added that effectively executes every potential code path through the asmap file, checking the same failure cases as the interpreter, and more. It takes around 30 ms to run for me for a 1.2 MB asmap file.

I've verified that this accepts asmap files constructed by https://github.com/sipa/asmap/blob/master/buildmap.py with a large dataset, and no longer accepts it with 1 bit changed in it.
```

Backport of core [[bitcoin/bitcoin#18512 | PR18512]].

Test Plan:
  ninja all check-all
  ninja bitcoin-fuzzers
  ./test/fuzz/test_runner.py <path_to_corpus>

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D9055
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 10, 2021
Summary:
test: Fix outstanding -Wsign-compare errors
refactor: Rework asmap Interpret to avoid ptrdiff_t

This is a backport of Core [[bitcoin/bitcoin#18216 | PR18216]]

It also includes a change in asmap.cpp that was missed in D9055 ([[bitcoin/bitcoin#18512 | PR18512]])

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D9197
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jul 30, 2021
16791f2 CMakeLists tests: add raw files generation. (furszy)
672d9a2 init: move asmap code earlier in init process (Jon Atack)
65cd143 net: extract conditional to bool CNetAddr::IsHeNet (Jon Atack)
2fc1f37 logging: asmap logging and #include fixups (Jon Atack)
0c9efb8 test: add functional test for an empty, unparsable asmap (Jon Atack)
6545656 config: separate the asmap finding and parsing checks (Jon Atack)
618b8d1 config: enable passing -asmap an absolute file path (Jon Atack)
8c7bdbe config: use default value in -asmap config (Jon Atack)
de39fab test: add feature_asmap functional tests (Jon Atack)
4290d3f Make asmap Interpret tolerant of malicious map data (Pieter Wuille)
e527e04 Use ASNs for mapped IPv4 addresses correctly (Pieter Wuille)
9a28bc0 Mark asmap const in statistics code (Pieter Wuille)
868a6ed Avoid asmap copies in initialization (Pieter Wuille)
cb698fb Add extra logging of asmap use and bucketing (Gleb Naumenko)
2fe5a05 Return mapped AS in RPC call getpeerinfo (Gleb Naumenko)
ce7aa15 scripted-diff: Replace NET_TOR with NET_ONION (wodry)
4c3ae7d Integrate ASN bucketing in Addrman and add tests (Gleb Naumenko)
718f1df CAddrManTest: remove redundant MakeDeterministic call. (furszy)
fd51941 Tests: address placement should be deterministic by default (René Nyffenegger)
8d01cbd  Add asmap utility which queries a mapping (Gleb Naumenko)
e986ed0 CAddrMan::Deserialize handle corrupt serializations better. (Patrick Strateman)
d2a8baf addrman.h: CAddrInfo inline members default values, plus several typos corrected. (furszy)
a7b9fd9 refactor: Use uint16_t instead of unsigned short (furszy)

Pull request description:

  Decoupled from #2411, built on top of #2479. Probably the last decouple from the "road to Tor" work.

  Focused on porting the ASN nodes bucketing functionality. The hearth of this work is bitcoin#16702.

  Providing an asmap file that contains the IP->ASN mapping, nodes will be bucketed by AS they belong to, in order to make impossible for a node to connect to several nodes hosted in a single AS.
  This is done in response to Erebus attack, but also to generally diversify the connections every node creates, especially useful when a large fraction of nodes operate under a couple of cloud providers.

  #### List of PRs:
  * bitcoin#7932
  * bitcoin#10765
  * bitcoin#13532
  * bitcoin#13575
  * bitcoin#16702
  * bitcoin#17812
  * bitcoin#18023
  * bitcoin#19314

  PRs for a follow up PR:
  * bitcoin#18029
  * bitcoin#18512

ACKs for top commit:
  random-zebra:
    re-utACK 16791f2
  Fuzzbawls:
    ACK 16791f2

Tree-SHA512: 1452af87d693526d3359822845bbd6211578b5c7c69d740d19c8c3ee25c66fd6e130f4421066a8f5384d62f65a2754423c633f90d7e3d809f4f1cc00c3c956ba
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 11, 2021
ecde04a [Consensus] Bump Active Protocol version to 70923 for v5.3 (random-zebra)
b63e4f5 Consensus: Add v5.3 enforcement height for testnet. (furszy)
f44be94 Only relay IPv4, IPv6, Tor addresses (Pieter Wuille)
015298c fix: tor: Call event_base_loopbreak from the event's callback (furszy)
34ff7a8 Consensus: Add mnb ADDRv2 guard. (furszy)
b4515dc GUI: Present v3 onion addresses properly in MNs list. (furszy)
337d43d tests: don't export in6addr_loopback (Vasil Dimov)
2cde8e0 GUI: Do not show the tor v3 onion address in the topbar. (furszy)
0b5f406 Doc: update tor.md with latest upstream information. (furszy)
89df7f2 addrman: ensure old versions don't parse peers.dat (Vasil Dimov)
bb90c5c test: add getnetworkinfo network name regression tests (Jon Atack)
d8e01b5 rpc: update GetNetworksInfo() to not return unsupported networks (Jon Atack)
57fc7b0 net: update GetNetworkName() with all enum Network cases (Jon Atack)
647d60b tests: Modify rpc_bind to conform to bitcoin#14532 behaviour. (Carl Dong)
d4d6729 Allow running rpc_bind.py --nonloopback test without IPv6 (Kristaps Kaupe)
4a034d8 test: Add rpc_bind test to default-run tests (Wladimir J. van der Laan)
61a08af [tests] bind functional test nodes to 127.0.0.1  Prevents OSX firewall (Sjors Provoost)
6a4f1e0 test: Add basic addr relay test (furszy)
78aa61c net: Make addr relay mockable (furszy)
ba954ca Send and require SENDADDRV2 before VERACK (Pieter Wuille)
61c2ed4 Bump net protocol version + don't send 'sendaddrv2' to pre-70923 software (furszy)
ccd508a tor: make a TORv3 hidden service instead of TORv2 (Vasil Dimov)
6da9a14 net: advertise support for ADDRv2 via new message (furszy)
e58d5d0 Migrate to test_large_inv() to Misbehaving logging. (furszy)
d496b64 [QA] fix mininode CAddress ser/deser (Jonas Schnelli)
cec9567 net: CAddress & CAddrMan: (un)serialize as ADDRv2 Change the serialization of `CAddrMan` to serialize its addresses in ADDRv2/BIP155 format by default. Introduce a new `CAddrMan` format version (3). (furszy)
b8c1dda streams update: get rid of nType and nVersion. (furszy)
3eaa273 Support bypassing range check in ReadCompactSize (Pieter Wuille)
a237ba4 net: recognize TORv3/I2P/CJDNS networks (Vasil Dimov)
8e50853 util: make EncodeBase32 consume Spans (Sebastian Falbesoner)
1f67e30 net: CNetAddr: add support to (un)serialize as ADDRv2 (Vasil Dimov)
2455420 test: move HasReason so it can be reused (furszy)
d41adb4 util: move HasPrefix() so it can be reused (Vasil Dimov)
f6f86af Unroll Keccak-f implementation (Pieter Wuille)
45222e6 Implement keccak-f[1600] and SHA3-256 (Pieter Wuille)
08ad06d net: change CNetAddr::ip to have flexible size (furszy)
3337219 net: improve encapsulation of CNetAddr. (furszy)
910d5c4 test: Do not instantiate CAddrDB for static call (Hennadii Stepanov)
6b607ef Drop IsLimited in favor of IsReachable (Ben Woosley)
a40711b IsReachable is the inverse of IsLimited (DRY). Includes unit tests (marcaiaf)
8839828 net: don't accept non-left-contiguous netmasks (Vasil Dimov)
5d7f864 rpcbind: Warn about exposing RPC to untrusted networks (Luke Dashjr)
2a6abd8 CNetAddr: Add IsBindAny method to check for INADDR_ANY (Luke Dashjr)
4fdfa45 net: Always default rpcbind to localhost, never "all interfaces" (Luke Dashjr)
31064a8 net: Minor accumulated cleanups (furszy)
9f9c871 tests: Avoid using C-style NUL-terminated strings as arguments (practicalswift)
f6c52a3 tests: Add tests to make sure lookup methods fail on std::string parameters with embedded NUL characters (practicalswift)
a751b9b net: Avoid using C-style NUL-terminated strings as arguments in the netbase interface (furszy)
f30869d test: add IsRFC2544 tests (Mark Tyneway)
ed5abe1 Net: Proper CService deserialization + GetIn6Addr return false if addr isn't an IPv6 addr (furszy)
86d73fb net: save the network type explicitly in CNetAddr (Vasil Dimov)
ad57dfc net: document `enum Network` (Vasil Dimov)
cb160de netaddress: Update CNetAddr for ORCHIDv2 (Carl Dong)
c3c04e4 net: Better misbehaving logging (furszy)
3660487 net: Use C++11 member initialization in protocol (Marco)
082baa3 refactor: Drop unused CBufferedFile::Seek() (Hennadii Stepanov)
e2d776a util: CBufferedFile fixes (Larry Ruane)
6921f42 streams: backport OverrideStream class (furszy)

Pull request description:

  Conjunction of a large number of back ports, updates and refactorings that made with the final goal of implementing v3 Onion addresses support (BIP155 https://github.com/bitcoin/bips/blob/master/bip-0155.mediawiki) before the tor v2 addresses EOL, scheduled, by the Tor project, for (1) July 15th: v2 addr support removal from the code base, and (2) October 15th: v2 addr network disable, where **every peer in our network running under Tor will loose the connection and drop the network**.

  As BIP155 describes, this is introducing a new P2P message to gossip longer node addresses over the P2P network. This is required to support new-generation Onion addresses, I2P, and potentially other networks that have longer endpoint addresses than fit in the 128 bits of the current addr message.

  In order to achieve the end goal, had to:
  1.  Create Span class and push it up to latest Bitcoin implementation.
  2.  Update the whole serialization framework and every object using it up to latest Bitcoin implementation (3-4 years ahead of what we currently are in master).
  3.  Update the address manager implementing ASN-based bucketing of the network nodes.
  4.  Update and refactor the netAddress and address manager tests to latest Bitcoin implementation (4 years ahead of what we currently are in master).
  5.  Several util string, vector, encodings, parsing, hashing backports and more..

  Important note:
  This PR it is not meant to be merged as a standalone PR, will decouple smaller ones moving on. Adding on each sub-PR its own description isolated from this big monster.

  Second note:
  This is still a **work-in-progress**, not ready for testing yet. I'm probably missing to mention few PRs that have already adapted to our sources. Just making it public so can decouple the changes, we can start merging them and i can continue working a bit more confortable (rebase a +170 commits separate branch is not fun..).

  ### List of back ported and adapted PRs:

  Span and Serialization:
  ----------------
  *  bitcoin#12886.
  *  bitcoin#12916.
  *  bitcoin#13558.
  *  bitcoin#13697. (Only Span's commit 29943a9)
  *  bitcoin#17850.
  *  bitcoin#17896.
  *  bitcoin#12752.
  *  bitcoin#16577.
  *  bitcoin#16670. (without faebf62)
  *  bitcoin#17957.
  *  bitcoin#18021.
  *  bitcoin#18087.
  *  bitcoin#18112 (only from 353f376 that we don't support).
  *  bitcoin#18167.
  *  bitcoin#18317.
  *  bitcoin#18591 (only Span's commit 0fbde48)
  *  bitcoin#18468.
  *  bitcoin#19020.
  *  bitcoin#19032.
  *  bitcoin#19367.
  *  bitcoin#19387.

  Net, NetAddress and AddrMan:
  ----------------

  *  bitcoin#7932.
  *  bitcoin#10756.
  *  bitcoin#10765.
  *  bitcoin#12218.
  *  bitcoin#12855.
  *  bitcoin#13532.
  *  bitcoin#13575.
  *  bitcoin#13815.
  *  bitcoin#14532.
  *  bitcoin#15051.
  *  bitcoin#15138.
  *  bitcoin#15689.
  *  bitcoin#16702.
  *  bitcoin#17243.
  *  bitcoin#17345.
  *  bitcoin#17754.
  *  bitcoin#17758.
  *  bitcoin#17812.
  *  bitcoin#18023.
  *  bitcoin#18454.
  *  bitcoin#18512.
  *  bitcoin#19314.
  *  bitcoin#19687

  Keys and Addresses encoding:
  ----------------
  * bitcoin#11372.
  * bitcoin#17511.
  * bitcoin#17721.

  Util:
  ----------------
  * bitcoin#9140.
  * bitcoin#16577.
  * bitcoin#16889.
  * bitcoin#19593.

  Bench:
  ----------------
  * bitcoin#16299.

  BIP155:
  ----------------
  *  bitcoin#19351.
  *  bitcoin#19360.
  *  bitcoin#19534.
  *  bitcoin#19628.
  *  bitcoin#19841.
  *  bitcoin#19845.
  *  bitcoin#19954.
  *  bitcoin#19991 (pending).
  *  bitcoin#19845.
  *  bitcoin#20000 (pending).
  *  bitcoin#20120.
  *  bitcoin#20284.
  *  bitcoin#20564.
  *  bitcoin#21157 (pending).
  *  bitcoin#21564 (pending).
  *  Fully removed v2 onion addr support.
  *  Add hardcoded seeds.
  *  Add release-notes, changes to files.md and every needed documentation.

  I'm currently working on the PRs marked as "pending", this isn't over, but I'm pretty pretty close :). What a long road..

ACKs for top commit:
  random-zebra:
    utACK ecde04a
  Fuzzbawls:
    ACK ecde04a

Tree-SHA512: 82c95fbda76fce63f96d8a9af7fa9a89cb1e1b302b7891e27118a6103af0be23606bf202c7332fa61908205e6b6351764e2ec23d753f1e2484028f57c2e8b51a
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants