Bitcoin-Core

我在嘗試進行 BTC 轉賬時遇到 Signature is found in scriptCode 異常

  • January 11, 2021

當我將 0.001 BTC 從 轉移miBEA6o6nZcaLZebR1dsDv4AMHRwJk1mbi到 時miV1sbmLM9fptRfWD5o8hs5L6ucUeJzmp5,出現以下錯誤:mandatory-script-verify-flag-failed (Signature is found in scriptCode) (code 16)

這是我的廣播數據:

01000000020e920885bc349b3ef0fcecb0acc04c74c59bdfc67d76242fc934f7f9d7d5c915010000006b483045022100dc4681014ce850d2808c82978d92b94f4940ef5ef9c63e3c9f248a0cdf9266df02203cf0344dfbe933d5335ab06da1040cf373d866efe156824e9938ba633bd54591012103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98effffffff33c8ba1adb1b885e553610e9431bbdbfe14078a1de8ef60d9e29316ea759e8df010000006b483045022100a4cb81427b8613276d458df994d1c9b02aad66fa69be5aef10e71a392a9df10402205b8b919147543aa6c11b12b8b2c44edf498973c6539021cb349ecff674df3f93012103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98effffffff02a0860100000000001976a914208a8852a3cec93382c8bebbbd6c9ef4676f512088ac8041100000000000232103a5be350852bb09e24edc83f8e02070a74597a8b775af46e8efbef394ae4fa98eac00000000`

我執行的測試方法:https ://github.com/lingting/VirtualCurrency/blob/0.3.1/src/test/java/live/lingting/virtual/currency/omni/Transfer.java#L130

轉賬操作,簽名程式碼:https ://github.com/lingting/VirtualCurrency/blob/0.3.1/src/main/java/live/lingting/virtual/currency/service/impl/BtcOmniServiceImpl.java#L248

簽名位於:https ://github.com/lingting/VirtualCurrency/blob/0.3.1/src/main/java/live/lingting/virtual/currency/service/impl/BtcOmniServiceImpl.java#L335

簽名碼:

       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);
       }
   }

我想問一下我的程式碼有什麼問題。在我這次送出的<https://github.com/lingting/VirtualCurrency/commit/0ea9b090d6fe2e4821afc10b5725436d56f2909d#diff-25a6634263c1b1f6fc4697a04e2b9904ea4b042a89f59dc848a>中。我仍然可以正常送出程式碼。,我當時也測試過,我生成的測試地址裡有好幾次轉賬證明,但是為什麼現在不行了?

  • 參考的輸出是 P2PK
  • createOutputScript(fromAddress)暗示 P2PKH
  • P2PKH scriptSig 與 P2PK pubkeyscript 不匹配

用於編寫此三行答案的資源:

  • 編譯核心
  • 使用 30 GB 頻寬下載區塊鏈
  • 兩三個小時的時間

但如果這還不夠,我很樂意提供更多幫助。

引用自:https://bitcoin.stackexchange.com/questions/101347