mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 00:34:01 +02:00
Merge bitcoin/bitcoin#32646: p2p: Add witness mutation check inside FillBlock
28299ce776p2p: remove vestigial READ_STATUS_CHECKBLOCK_FAILED (Greg Sanders)bac9ee4830p2p: Add witness mutation check inside FillBlock (Greg Sanders) Pull request description: Since #29412, we have not allowed mutated blocks to continue being processed immediately the block is received, but this is only done for the legacy BLOCK message. Extend these checks as belt-and-suspenders to not allow similar mutation strategies to affect relay by honest peers by applying the check inside `PartiallyDownloadedBlock::FillBlock`, immediately before returning `READ_STATUS_OK`. ACKs for top commit: Crypt-iQ: ACK28299ce776achow101: ACK28299ce776stratospher: ACK28299ce7. dergoegge: Code review ACK28299ce776Tree-SHA512: 883d7c12ca096234b425e6fe12e46b0611607600916e6ac8d1c8112224aa76924b7b074754910163ac2ec15379075d618a9ece3642649ac7629cddb0d4e432ea
This commit is contained in:
@@ -36,14 +36,10 @@ void initialize_pdb()
|
||||
g_setup = testing_setup.get();
|
||||
}
|
||||
|
||||
PartiallyDownloadedBlock::CheckBlockFn FuzzedCheckBlock(std::optional<BlockValidationResult> result)
|
||||
PartiallyDownloadedBlock::IsBlockMutatedFn FuzzedIsBlockMutated(bool result)
|
||||
{
|
||||
return [result](const CBlock&, BlockValidationState& state, const Consensus::Params&, bool, bool) {
|
||||
if (result) {
|
||||
return state.Invalid(*result);
|
||||
}
|
||||
|
||||
return true;
|
||||
return [result](const CBlock& block, bool) {
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -115,35 +111,22 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
|
||||
skipped_missing |= (!pdb.IsTxAvailable(i) && skip);
|
||||
}
|
||||
|
||||
// Mock CheckBlock
|
||||
bool fail_check_block{fuzzed_data_provider.ConsumeBool()};
|
||||
auto validation_result =
|
||||
fuzzed_data_provider.PickValueInArray(
|
||||
{BlockValidationResult::BLOCK_RESULT_UNSET,
|
||||
BlockValidationResult::BLOCK_CONSENSUS,
|
||||
BlockValidationResult::BLOCK_CACHED_INVALID,
|
||||
BlockValidationResult::BLOCK_INVALID_HEADER,
|
||||
BlockValidationResult::BLOCK_MUTATED,
|
||||
BlockValidationResult::BLOCK_MISSING_PREV,
|
||||
BlockValidationResult::BLOCK_INVALID_PREV,
|
||||
BlockValidationResult::BLOCK_TIME_FUTURE,
|
||||
BlockValidationResult::BLOCK_HEADER_LOW_WORK});
|
||||
pdb.m_check_block_mock = FuzzedCheckBlock(
|
||||
fail_check_block ?
|
||||
std::optional<BlockValidationResult>{validation_result} :
|
||||
std::nullopt);
|
||||
bool segwit_active{fuzzed_data_provider.ConsumeBool()};
|
||||
|
||||
// Mock IsBlockMutated
|
||||
bool fail_block_mutated{fuzzed_data_provider.ConsumeBool()};
|
||||
pdb.m_check_block_mutated_mock = FuzzedIsBlockMutated(fail_block_mutated);
|
||||
|
||||
CBlock reconstructed_block;
|
||||
auto fill_status{pdb.FillBlock(reconstructed_block, missing)};
|
||||
auto fill_status{pdb.FillBlock(reconstructed_block, missing, segwit_active)};
|
||||
switch (fill_status) {
|
||||
case READ_STATUS_OK:
|
||||
assert(!skipped_missing);
|
||||
assert(!fail_check_block);
|
||||
assert(!fail_block_mutated);
|
||||
assert(block->GetHash() == reconstructed_block.GetHash());
|
||||
break;
|
||||
case READ_STATUS_CHECKBLOCK_FAILED: [[fallthrough]];
|
||||
case READ_STATUS_FAILED:
|
||||
assert(fail_check_block);
|
||||
assert(fail_block_mutated);
|
||||
break;
|
||||
case READ_STATUS_INVALID:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user