Test case for spending bare multisig? #29113

issue ajtowns opened this issue on December 19, 2023
  1. ajtowns commented at 1:27 AM on December 19, 2023: contributor

    I think the only place we currently test that spending a bare multisig utxo is okay is in AreInputsStandard in script_p2sh_tests.cpp, but this only checks that AreInputsStandard() passes, it doesn't check that there isn't some other rule preventing the spend from entering the mempool and eventually being mined.

    Adding

            self.log.info('Spending a confirmed bare multisig is okay')
            node = self.nodes[0]
            address = self.wallet.get_address()
            tx = tx_from_hex(raw_tx_reference)
            privkey, pubkey = generate_keypair()
            tx.vout[0].scriptPubKey = keys_to_multisig_script([pubkey] * 3, k=1)  # Some bare multisig script (1-of-3)
            tx.rehash()
            self.generateblock(node, address, [tx.serialize().hex()])
            tx_spend = CTransaction()
            tx_spend.vin.append(CTxIn(COutPoint(tx.sha256, 0), b""))
            tx_spend.vout.append(CTxOut(tx.vout[0].nValue - int(fee*COIN), script_to_p2wsh_script(CScript([OP_TRUE]))))
            tx_spend.rehash()
            sign_input_legacy(tx_spend, 0, tx.vout[0].scriptPubKey, privkey, sighash_type=SIGHASH_ALL)
            tx_spend.vin[0].scriptSig = bytes(CScript([OP_0])) + tx_spend.vin[0].scriptSig
            self.check_mempool_result(
                result_expected=[{'txid': tx_spend.rehash(), 'allowed': True, 'vsize': tx_spend.get_vsize(), 'fees': { 'base': Decimal('0.00000700')}}],
                rawtxs=[tx_spend.serialize().hex()],
                maxfeerate=0,
            )
    

    at the end of mempool_accept.py might therefore be a reasonable addition?

    Can add a bug to trigger test failures via:

    --- a/src/policy/policy.cpp
    +++ b/src/policy/policy.cpp
    @@ -185,6 +185,7 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs)
     
             std::vector<std::vector<unsigned char> > vSolutions;
             TxoutType whichType = Solver(prev.scriptPubKey, vSolutions);
    +        if (whichType == TxoutType::MULTISIG) return false;
             if (whichType == TxoutType::NONSTANDARD || whichType == TxoutType::WITNESS_UNKNOWN) {
                 // WITNESS_UNKNOWN failures are typically also caught with a policy
                 // flag in the script interpreter, but it can be helpful to catch
    
  2. ajtowns added the label Feature on Dec 19, 2023
  3. maflcko removed the label Feature on Dec 19, 2023
  4. maflcko added the label Tests on Dec 19, 2023
  5. maflcko commented at 8:19 AM on December 19, 2023: member

    A pull request would be welcome :)

  6. achow101 closed this on May 1, 2024

  7. achow101 referenced this in commit d73245abc7 on May 1, 2024
  8. bitcoin locked this on May 1, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-26 09:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me