Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_block.py
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.generatetoaddress(100, node.get_deterministic_priv_key().address) | node.generatetoaddress(100, node.get_deterministic_priv_key().address) | ||||
best_block = node.getblock(node.getbestblockhash()) | best_block = node.getblock(node.getbestblockhash()) | ||||
tip = int(node.getbestblockhash(), 16) | tip = int(node.getbestblockhash(), 16) | ||||
height = best_block["height"] + 1 | height = best_block["height"] + 1 | ||||
block_time = best_block["time"] + 1 | block_time = best_block["time"] + 1 | ||||
# Use merkle-root malleability to generate an invalid block with | # Use merkle-root malleability to generate an invalid block with | ||||
# same blockheader. | # same blockheader (CVE-2012-2459). | ||||
# Manufacture a block with 3 transactions (coinbase, spend of prior | # Manufacture a block with 3 transactions (coinbase, spend of prior | ||||
# coinbase, spend of that spend). Duplicate the 3rd transaction to | # coinbase, spend of that spend). Duplicate the 3rd transaction to | ||||
# leave merkle root and blockheader unchanged but invalidate the block. | # leave merkle root and blockheader unchanged but invalidate the block. | ||||
# For more information on merkle-root malleability see | |||||
# src/consensus/merkle.cpp. | |||||
self.log.info("Test merkle root malleability.") | self.log.info("Test merkle root malleability.") | ||||
block2 = create_block(tip, create_coinbase(height), block_time) | block2 = create_block(tip, create_coinbase(height), block_time) | ||||
block_time += 1 | block_time += 1 | ||||
# b'0x51' is OP_TRUE | # b'0x51' is OP_TRUE | ||||
tx1 = create_tx_with_script( | tx1 = create_tx_with_script( | ||||
block1.vtx[0], 0, script_sig=b'', amount=50 * COIN) | block1.vtx[0], 0, script_sig=b'', amount=50 * COIN) | ||||
Show All 13 Lines | def run_test(self): | ||||
block2.vtx.append(block2.vtx[2]) | block2.vtx.append(block2.vtx[2]) | ||||
assert_equal(block2.hashMerkleRoot, block2.calc_merkle_root()) | assert_equal(block2.hashMerkleRoot, block2.calc_merkle_root()) | ||||
assert_equal(orig_hash, block2.rehash()) | assert_equal(orig_hash, block2.rehash()) | ||||
assert block2_orig.vtx != block2.vtx | assert block2_orig.vtx != block2.vtx | ||||
node.p2p.send_blocks_and_test( | node.p2p.send_blocks_and_test( | ||||
[block2], node, success=False, reject_reason='bad-txns-duplicate') | [block2], node, success=False, reject_reason='bad-txns-duplicate') | ||||
# Check transactions for duplicate inputs | # Check transactions for duplicate inputs (CVE-2018-17144) | ||||
self.log.info("Test duplicate input block.") | self.log.info("Test duplicate input block.") | ||||
block2_orig.vtx[2].vin.append(block2_orig.vtx[2].vin[0]) | block2_orig.vtx[2].vin.append(block2_orig.vtx[2].vin[0]) | ||||
block2.vtx = [block2.vtx[0]] + \ | block2.vtx = [block2.vtx[0]] + \ | ||||
sorted(block2.vtx[1:], key=lambda tx: tx.get_id()) | sorted(block2.vtx[1:], key=lambda tx: tx.get_id()) | ||||
block2_orig.vtx[2].rehash() | block2_orig.vtx[2].rehash() | ||||
block2_orig.hashMerkleRoot = block2_orig.calc_merkle_root() | block2_orig.hashMerkleRoot = block2_orig.calc_merkle_root() | ||||
block2_orig.rehash() | block2_orig.rehash() | ||||
Show All 21 Lines |