Skip to content

Commit 789d4b9

Browse files
committed
Disallow output witness data in coinbase transactions
1 parent e64324e commit 789d4b9

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/validation.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,6 +3560,16 @@ static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, c
35603560
}
35613561
}
35623562

3563+
// Coinbase transaction can not have input witness data which is not covered
3564+
// (or committed to) by the witness or regular merkle tree
3565+
for (const auto& inwit : block.vtx[0]->witness.vtxinwit) {
3566+
if (!inwit.vchIssuanceAmountRangeproof.empty() ||
3567+
!inwit.vchInflationKeysRangeproof.empty() ||
3568+
!inwit.m_pegin_witness.IsNull()) {
3569+
return state.DoS(100, false, REJECT_INVALID, "bad-cb-witness", true, "Coinbase has invalid input witness data.");
3570+
}
3571+
}
3572+
35633573
// Validation for witness commitments.
35643574
// * We compute the witness hash (which is the hash including witnesses) of all the block's transactions, except the
35653575
// coinbase (where 0x0000....0000 is used instead).

test/functional/feature_txwitness.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ def WitToHex(obj):
143143
# Add extra witness that isn't covered by witness merkle root, make sure blocks are still valid
144144
block_witness_stuffed = copy.deepcopy(block_struct)
145145
block_witness_stuffed.vtx[0].wit.vtxinwit[0].vchIssuanceAmountRangeproof = b'\x00'
146-
self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed))
146+
assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed))
147147
block_witness_stuffed = copy.deepcopy(block_struct)
148148
block_witness_stuffed.vtx[0].wit.vtxinwit[0].vchInflationKeysRangeproof = b'\x00'
149-
self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed))
149+
assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed))
150150
block_witness_stuffed = copy.deepcopy(block_struct)
151151
block_witness_stuffed.vtx[0].wit.vtxinwit[0].peginWitness.stack = [b'\x00']
152-
self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed))
152+
assert_raises_rpc_error(-25, "bad-cb-witness", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed))
153153
block_witness_stuffed = copy.deepcopy(block_struct)
154154

155155
# Add extra witness data that is covered by witness merkle root, make sure invalid until

0 commit comments

Comments
 (0)