Disallow coinbase output witness data, since outputs are explicit anyways

This commit is contained in:
Gregory Sanders 2019-03-25 09:55:32 -04:00
parent 8b2e8859d6
commit 2cb47d1705
2 changed files with 10 additions and 3 deletions

View file

@ -406,6 +406,14 @@ bool VerifyAmounts(const std::vector<CTxOut>& inputs, const CTransaction& tx, st
bool VerifyCoinbaseAmount(const CTransaction& tx, const CAmountMap& mapFees) { bool VerifyCoinbaseAmount(const CTransaction& tx, const CAmountMap& mapFees) {
assert(tx.IsCoinBase()); assert(tx.IsCoinBase());
// Miner shouldn't be stuffing witness data
for (const auto& outwit : tx.witness.vtxoutwit) {
if (!outwit.IsNull()) {
return false;
}
}
CAmountMap remaining = mapFees; CAmountMap remaining = mapFees;
for (unsigned int i = 0; i < tx.vout.size(); i++) { for (unsigned int i = 0; i < tx.vout.size(); i++) {
const CTxOut& out = tx.vout[i]; const CTxOut& out = tx.vout[i];

View file

@ -167,8 +167,7 @@ class TxWitnessTest(BitcoinTestFramework):
block_witness_stuffed = copy.deepcopy(block_struct) block_witness_stuffed = copy.deepcopy(block_struct)
# Add extra witness data that is covered by witness merkle root, make sure invalid until # Add extra witness data that is covered by witness merkle root, make sure invalid
# witness merkle root is recalculated
assert_equal(block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchSurjectionproof, b'') assert_equal(block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchSurjectionproof, b'')
assert_equal(block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchRangeproof, b'') assert_equal(block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchRangeproof, b'')
block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchRangeproof = b'\x00'*100000 block_witness_stuffed.vtx[0].wit.vtxoutwit[0].vchRangeproof = b'\x00'*100000
@ -180,7 +179,7 @@ class TxWitnessTest(BitcoinTestFramework):
block_witness_stuffed.vtx[0].rehash() block_witness_stuffed.vtx[0].rehash()
block_witness_stuffed.hashMerkleRoot = block_witness_stuffed.calc_merkle_root() block_witness_stuffed.hashMerkleRoot = block_witness_stuffed.calc_merkle_root()
block_witness_stuffed.rehash() block_witness_stuffed.rehash()
self.nodes[0].testproposedblock(WitToHex(block_witness_stuffed)) assert_raises_rpc_error(-25, "bad-cb-amount", self.nodes[0].testproposedblock, WitToHex(block_witness_stuffed))
assert_greater_than(len(WitToHex(block_witness_stuffed)), 100000*4) # Make sure the witness data is actually serialized assert_greater_than(len(WitToHex(block_witness_stuffed)), 100000*4) # Make sure the witness data is actually serialized
# Test that issuance inputs in coinbase don't survive a serialization round-trip # Test that issuance inputs in coinbase don't survive a serialization round-trip