mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Require callers of AcceptBlockHeader() to perform anti-dos checks
In order to prevent memory DoS, we must ensure that we don't accept a new header into memory until we've performed anti-DoS checks, such as verifying that the header is part of a sufficiently high work chain. This commit adds a new argument to AcceptBlockHeader() so that we can ensure that all call-sites which might cause a new header to be accepted into memory have to grapple with the question of whether the header is safe to accept, or needs further validation. This patch also fixes two places where low-difficulty-headers could have been processed without such validation (processing an unrequested block from the network, and processing a compact block). Credit to Niklas Gögge for noticing this issue, and thanks to Sjors Provoost for test code.
This commit is contained in:
@@ -195,7 +195,7 @@ int main(int argc, char* argv[])
|
||||
bool new_block;
|
||||
auto sc = std::make_shared<submitblock_StateCatcher>(block.GetHash());
|
||||
RegisterSharedValidationInterface(sc);
|
||||
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*new_block=*/&new_block);
|
||||
bool accepted = chainman.ProcessNewBlock(blockptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&new_block);
|
||||
UnregisterSharedValidationInterface(sc);
|
||||
if (!new_block && accepted) {
|
||||
std::cerr << "duplicate" << std::endl;
|
||||
@@ -210,6 +210,9 @@ int main(int argc, char* argv[])
|
||||
case BlockValidationResult::BLOCK_RESULT_UNSET:
|
||||
std::cerr << "initial value. Block has not yet been rejected" << std::endl;
|
||||
break;
|
||||
case BlockValidationResult::BLOCK_HEADER_LOW_WORK:
|
||||
std::cerr << "the block header may be on a too-little-work chain" << std::endl;
|
||||
break;
|
||||
case BlockValidationResult::BLOCK_CONSENSUS:
|
||||
std::cerr << "invalid by consensus rules (excluding any below reasons)" << std::endl;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user