1

When I transferred a 0.001 BTC from miBEA6o6nZcaLZebR1dsDv4AMHRwJk1mbi to miV1sbmLM9fptRfWD5o8hs5L6ucUeJzmp5, the following error occurred: mandatory-script-verify-flag-failed (Signature is found in scriptCode) (code 16).

This is my broadcast data:

01000000020e920885bc349b3ef0fcecb0acc04c74c59bdfc67d76242fc934f7f9d7d5c915010000006b483045022100dc4681014ce850d2808c82978d92b94f4940ef5ef9c63e3c9f248a0cdf9266df02203cf0344dfbe933d5335ab06da1040cf373d866efe156824e9938ba633bd54591012103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98effffffff33c8ba1adb1b885e553610e9431bbdbfe14078a1de8ef60d9e29316ea759e8df010000006b483045022100a4cb81427b8613276d458df994d1c9b02aad66fa69be5aef10e71a392a9df10402205b8b919147543aa6c11b12b8b2c44edf498973c6539021cb349ecff674df3f93012103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98effffffff02a0860100000000001976a914208a8852a3cec93382c8bebbbd6c9ef4676f512088ac8041100000000000232103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98eac00000000`

The test method I performed: https://github.com/lingting/VirtualCurrency/blob/0.3.1/src/test/java/live/lingting/virtual/currency/omni/Transfer.java#L130

Transfer operation, signed code: https://github.com/lingting/VirtualCurrency/blob/0.3.1/src/main/java/live/lingting/virtual/currency/service/impl/BtcOmniServiceImpl.java#L248

The signature is at: https://github.com/lingting/VirtualCurrency/blob/0.3.1/src/main/java/live/lingting/virtual/currency/service/impl/BtcOmniServiceImpl.java#L335

Signature code:

        List<TransactionInput> inputs = tx.getInputs();
     
    for (int i = 0; i < inputs.size(); i++) {
        Script script = ScriptBuilder.createOutputScript(fromAddress);
        TransactionInput txIn = tx.getInput(i);

        Sha256Hash hash = tx.hashForSignature(i, script, SigHash.ALL, false);
        ECKey.ECDSASignature ecdsaSignature = key.sign(hash);
        TransactionSignature txSignature = new TransactionSignature(ecdsaSignature, SigHash.ALL, false);
        if (ScriptPattern.isP2PK(script)) {
            txIn.setScriptSig(ScriptBuilder.createInputScript(txSignature));
        }
        else if (ScriptPattern.isP2SH(script)) {
            txIn.setScriptSig(ScriptBuilder.createP2SHMultiSigInputScript(ListUtil.toList(txSignature), script));
        }
        else if (ScriptPattern.isP2PKH(script)) {
            txIn.setScriptSig(ScriptBuilder.createInputScript(txSignature, key));
        }
        else if (ScriptPattern.isP2WPKH(script)) {
            Script scriptCode = ScriptBuilder.createP2PKHOutputScript(key);
            TransactionSignature signature = tx.calculateWitnessSignature(i, key, scriptCode, txIn.getValue(),
                    SigHash.ALL, false);
            txIn.setScriptSig(ScriptBuilder.createEmpty());
            txIn.setWitness(TransactionWitness.redeemP2WPKH(signature, key));
        }
        else {
            throw new ScriptException(ScriptError.SCRIPT_ERR_UNKNOWN_ERROR,
                    "Unable to sign this scriptPubKey: " + script);
        }
    }

I would like to ask what is wrong with my code. In my submission this time https://github.com/lingting/VirtualCurrency/commit/0ea9b090d6fe2e4821afc10b5725436d56f2909d#diff-25a6634263c1b1f6fc4697a04e2b9904ea4b042a89f59dc848a. I can still submit the code normally. , I also tested it at the time, and there are several transfers in the test address I generated to prove it, but why is it not possible now?

0
  • The referenced outputs are P2PK
  • createOutputScript(fromAddress) implies P2PKH
  • P2PKH scriptSig doesn't match with P2PK pubkeyscript

Resources used to write this three-line answer:

  • Compile Core
  • Use 30 GB bandwidth to download the blockchain
  • Two-three hours of time

but I'm happy to help more if this isn't enough.

  • Thank you very much, the transfer was successful! – lingting Jan 12 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.