Repository navigation
Conversation
### Context Recent discussions highlighted that many nodes which synced before Bitcoin Core v28 have their block and undo files stored effectively in the clear (zero XOR key). This patch adds a simple, resumable maintenance tool to obfuscate previously raw block files, rotate an existing key to a fresh random one, or deobfuscate (set key to zero) if consciously chosen, all without requiring resync. The operation can be cancelled and restarted safely. ### Implementation The new startup option `-reobfuscate-blocks[=VALUE]` accepts either 16 hex characters as an exact 8-byte XOR key (little-endian in-memory layout) or a boolean to generate a random 64-bit key. e.g. `-reobfuscate-blocks=0000000000000000` sets the key to zero, effectively removing obfuscation. If we detect unobfuscated blocks at start time, we suggest this new option in a warning. At startup, we iterate over all undo and block files (grouping the block and undo files for more uniform iteration), read them with the old XOR key and write them back with the new key (`<name>.reobfuscated`). The implementation actually combines the two keys and reads directly into the new obfuscated version to only do a single iteration over the data. This works if the original blocks aren't obfuscated or if the new blocks aren't or if both are. After successful write, we immediately delete the old file. Once all files are staged, we rename them back and atomically swap `xor.dat.reobfuscated` → `xor.dat` and continue operation. We log the old and new keys and print progress roughly per-percent as undo and block files complete (i.e. max 2 * 100 progress logs). ### Constraints * Reobfuscation resumes automatically (detected via `xor.dat.reobfuscated`) even without the flag. In worst-case a crash should only force us to redo previous work. * Single-threaded, processing one file at a time to keep code simple and avoid complexity of interleaving renames and key swaps across threads. * Fast in practice with sequential read/modify/write per blockfile - after recent obfuscation vectorization, this path is very quick. ### Single-threaded Performance cpu | hdd/ssd | block count | size | files | time (min) | blocks/min ---------------------|---------|-------------|---------|--------|------------|------------ Apple M4 Max laptop | SSD | ~909k | ~707 GB | 9,982 | 6.2 | 146,613 Intel Core i9 | SSD | ~909k | ~725 GB | 10,238 | 23.1 | 39,351 Raspberry Pi 5 | SSD | ~914k | ~728 GB | 10,276 | 72.78 | 12,558 Intel Core i7 | HDD | ~909k | ~720 GB | 10,156 | 208.7 | 4,356 Raspberry Pi 4B | HDD | ~915k | ~730 GB | 10,304 | 1467 | 624 ----- Similar work: bitcoin#32451 and andrewtoth/blocks-xor Co-authored-by: Andrew Toth <[email protected]> Co-authored-by: Murch <[email protected]> Co-authored-by: Anthony Towns <[email protected]>
Enable multithreaded re-obfuscation of blk*/rev* files. The number of worker threads is controlled by -par (auto/negative semantics handled at call-site). Operation remains resumable and safe. The threads don't need blocking since they access separate vector values in read-only way in a round-robin pattern. Used `std::jthread` for RAII join and a single `std::atomic_bool` to aggregates failures and interruptions. Updated help text for -reobfuscate-blocks to mention -par. Logging announces thread count when >1. Co-authored-by: Anthony Towns [email protected]
l0rinc
pushed a commit
that referenced
this pull request
Jul 22, 2026
…AFL fork faada35 fuzz: [refactor] Use 100'000 digit separator in __AFL_LOOP (MarcoFalke) fae067e fuzz: Avoid dangling prevoutfetch threads after AFL fork (MarcoFalke) Pull request description: Presumably fixes https://issues.oss-fuzz.com/issues/536943806 This is a bit confusing, because the issue was already fixed in commit f608a40, by removing the AFL forkserver. However, OSS-Fuzz doesn't go through the AFL_LOOP, but through the AFL libFuzzer driver: ``` #0 0x7e055245baab in __pthread_clockjoin_ex /build/glibc-B3wQXB/glibc-2.31/nptl/pthread_join_common.c:89:6 #1 0x5a27e904dcdd in operator() /src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:293:14 #2 0x5a27e904dcdd in Join<(lambda at /src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:292:44)> /src/llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_thread_arg_retval.h:75:9 #3 0x5a27e904dcdd in ___interceptor_pthread_join /src/llvm-project/compiler-rt/lib/asan/asan_interceptors.cpp:292:25 #4 0x5a27e90f4044 in std::__1::thread::join() #5 0x5a27e9366277 in ThreadPool::Stop() [bitcoin-core/src/util/threadpool.h:146](https://github.com/bitcoin/bitcoin/blob/7d8137c1417b61589949b3e8b081e5310fe335f3/src/util/threadpool.h#L146):53 #6 0x5a27e9365db9 in ThreadPool::~ThreadPool() [bitcoin-core/src/util/threadpool.h:94](https://github.com/bitcoin/bitcoin/blob/7d8137c1417b61589949b3e8b081e5310fe335f3/src/util/threadpool.h#L94):9 ... #32 0x5a27e95a9506 in (anonymous namespace)::ResetChainman(TestingSetup&) (.12669) [bitcoin-core/src/test/fuzz/process_messages.cpp:44](https://github.com/bitcoin/bitcoin/blob/7d8137c1417b61589949b3e8b081e5310fe335f3/src/test/fuzz/process_messages.cpp#L44):27 #33 0x5a27e95a8c60 in process_messages_fuzz_target(std::__1::span<unsigned char const, 18446744073709551615ul>) [bitcoin-core/src/test/fuzz/process_messages.cpp:141](https://github.com/bitcoin/bitcoin/blob/7d8137c1417b61589949b3e8b081e5310fe335f3/src/test/fuzz/process_messages.cpp#L141):9 ... #36 0x5a27e97b7190 in test_one_input(std::__1::span<unsigned char const, 18446744073709551615ul>) bitcoin-core/src/test/fuzz/fuzz.cpp:86:5 #37 0x5a27e97b7190 in LLVMFuzzerTestOneInput bitcoin-core/src/test/fuzz/fuzz.cpp:214:5 #38 0x5a27e90ada19 in LLVMFuzzerRunDriver /src/aflplusplus/utils/aflpp_driver/aflpp_driver.c:427:13 #39 0x5a27e90ad69b in main /src/aflplusplus/utils/aflpp_driver/aflpp_driver.c:323:10 #40 0x7e055223b082 in __libc_start_main /build/glibc-B3wQXB/glibc-2.31/csu/libc-start.c:308:16 #41 0x5a27e8fc602d in _start ``` So the correct fix would be to set `AFL_DRIVER_DONT_DEFER=1`. Ref: https://github.com/AFLplusplus/AFLplusplus/blob/ad5304010ae3be9d5cdc1ba51b09e14169c5cb87/utils/aflpp_driver/aflpp_driver.c#L161 However, I don't know how to do this on OSS-Fuzz, so just drop the threads for now, because there are dedicated fuzz targets to test the multi-threaded case anyway. ACKs for top commit: l0rinc: ACK faada35 andrewtoth: lgtm ACK faada35 sedited: ACK faada35 Tree-SHA512: c249d7267f789084968f8510531f60fc71c9fbd6b4e574a181fd6da1af19a3cb7c03ba60c3ca70244b56ce44c602293517cdb6b0e969b4a2cc9d1afaa49ab0f8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.