diff --git a/src/validation.cpp b/src/validation.cpp index d164752bd5..2609ad31e9 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3560,6 +3560,16 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c } } + // Coinbase transaction can not have input witness data which is not covered + // (or committed to) by the witness or regular merkle tree + for (const auto& inwit : block.vtx[0]->witness.vtxinwit) { + if (!inwit.vchIssuanceAmountRangeproof.empty() || + !inwit.vchInflationKeysRangeproof.empty() || + !inwit.m_pegin_witness.IsNull()) { + return state.DoS(100, false, REJECT_INVALID, "bad-cb-witness", true, "Coinbase has invalid input witness data."); + } + } + // Validation for witness commitments. // * We compute the witness hash (which is the hash including witnesses) of all the block's transactions, except the // coinbase (where 0x0000....0000 is used instead). diff --git a/test/functional/feature_txwitness.py b/test/functional/feature_txwitness.py index 51d875e540..51b6631cfd 100755 --- a/test/functional/feature_txwitness.py +++ b/test/functional/feature_txwitness.py @@ -143,13 +143,13 @@ class TxWitnessTest(BitcoinTestFramework): # Add extra witness that isn't covered by witness merkle root, make sure blocks are still valid block_witness_stuffed = copy.deepcopy(block_struct) block_witness_stuffed.vtx[0].wit.vtxinwit[0].vchIssuanceAmountRangeproof = b'\x00' - self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed)) + assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed)) block_witness_stuffed = copy.deepcopy(block_struct) block_witness_stuffed.vtx[0].wit.vtxinwit[0].vchInflationKeysRangeproof = b'\x00' - self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed)) + assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed)) block_witness_stuffed = copy.deepcopy(block_struct) block_witness_stuffed.vtx[0].wit.vtxinwit[0].peginWitness.stack = [b'\x00'] - self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed)) + assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed)) block_witness_stuffed = copy.deepcopy(block_struct) # Add extra witness data that is covered by witness merkle root, make sure invalid until