|
37 | 37 | keys_to_multisig_script,
|
38 | 38 | MIN_PADDING,
|
39 | 39 | MIN_STANDARD_TX_NONWITNESS_SIZE,
|
| 40 | + PAY_TO_ANCHOR, |
40 | 41 | script_to_p2sh_script,
|
41 | 42 | script_to_p2wsh_script,
|
42 | 43 | )
|
@@ -389,6 +390,56 @@ def run_test(self):
|
389 | 390 | maxfeerate=0,
|
390 | 391 | )
|
391 | 392 |
|
| 393 | + self.log.info('OP_1 <0x4e73> is able to be created and spent') |
| 394 | + anchor_value = 10000 |
| 395 | + create_anchor_tx = self.wallet.send_to(from_node=node, scriptPubKey=PAY_TO_ANCHOR, amount=anchor_value) |
| 396 | + self.generate(node, 1) |
| 397 | + |
| 398 | + # First spend has non-empty witness, will be rejected to prevent third party wtxid malleability |
| 399 | + anchor_nonempty_wit_spend = CTransaction() |
| 400 | + anchor_nonempty_wit_spend.vin.append(CTxIn(COutPoint(int(create_anchor_tx["txid"], 16), create_anchor_tx["sent_vout"]), b"")) |
| 401 | + anchor_nonempty_wit_spend.vout.append(CTxOut(anchor_value - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE])))) |
| 402 | + anchor_nonempty_wit_spend.wit.vtxinwit.append(CTxInWitness()) |
| 403 | + anchor_nonempty_wit_spend.wit.vtxinwit[0].scriptWitness.stack.append(b"f") |
| 404 | + anchor_nonempty_wit_spend.rehash() |
| 405 | + |
| 406 | + self.check_mempool_result( |
| 407 | + result_expected=[{'txid': anchor_nonempty_wit_spend.rehash(), 'allowed': False, 'reject-reason': 'bad-witness-nonstandard'}], |
| 408 | + rawtxs=[anchor_nonempty_wit_spend.serialize().hex()], |
| 409 | + maxfeerate=0, |
| 410 | + ) |
| 411 | + |
| 412 | + # Clear witness stuffing |
| 413 | + anchor_spend = anchor_nonempty_wit_spend |
| 414 | + anchor_spend.wit.vtxinwit[0].scriptWitness.stack = [] |
| 415 | + anchor_spend.rehash() |
| 416 | + |
| 417 | + self.check_mempool_result( |
| 418 | + result_expected=[{'txid': anchor_spend.rehash(), 'allowed': True, 'vsize': anchor_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}], |
| 419 | + rawtxs=[anchor_spend.serialize().hex()], |
| 420 | + maxfeerate=0, |
| 421 | + ) |
| 422 | + |
| 423 | + self.log.info('But cannot be spent if nested sh()') |
| 424 | + nested_anchor_tx = self.wallet.create_self_transfer(sequence=SEQUENCE_FINAL)['tx'] |
| 425 | + nested_anchor_tx.vout[0].scriptPubKey = script_to_p2sh_script(PAY_TO_ANCHOR) |
| 426 | + nested_anchor_tx.rehash() |
| 427 | + self.generateblock(node, self.wallet.get_address(), [nested_anchor_tx.serialize().hex()]) |
| 428 | + |
| 429 | + nested_anchor_spend = CTransaction() |
| 430 | + nested_anchor_spend.vin.append(CTxIn(COutPoint(nested_anchor_tx.sha256, 0), b"")) |
| 431 | + nested_anchor_spend.vin[0].scriptSig = CScript([bytes(PAY_TO_ANCHOR)]) |
| 432 | + nested_anchor_spend.vout.append(CTxOut(nested_anchor_tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE])))) |
| 433 | + nested_anchor_spend.rehash() |
| 434 | + |
| 435 | + self.check_mempool_result( |
| 436 | + result_expected=[{'txid': nested_anchor_spend.rehash(), 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Witness version reserved for soft-fork upgrades)'}], |
| 437 | + rawtxs=[nested_anchor_spend.serialize().hex()], |
| 438 | + maxfeerate=0, |
| 439 | + ) |
| 440 | + # but is consensus-legal |
| 441 | + self.generateblock(node, self.wallet.get_address(), [nested_anchor_spend.serialize().hex()]) |
| 442 | + |
392 | 443 | self.log.info('Spending a confirmed bare multisig is okay')
|
393 | 444 | address = self.wallet.get_address()
|
394 | 445 | tx = tx_from_hex(raw_tx_reference)
|
|
0 commit comments