Disallow output witness data in coinbase transactions

This commit is contained in:
Gregory Sanders 2019-03-25 09:34:24 -04:00
parent e64324e3ec
commit 789d4b97f7
2 changed files with 13 additions and 3 deletions

View file

@ -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).

View file

@ -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