Coldstorage

離線簽署比特幣交易失敗

  • September 2, 2020

我知道這個話題已經討論了很多,但是在尋找這個工作幾天后,我放棄了。

我想在連接到網際網路並同步的僅查看錢包上創建交易,然後在具有私鑰的“冷”離線機器上簽署此交易,然後在僅查看錢包上發送此交易。

僅供查看的錢包將是 [VOW]

離線冷錢包將是[OCW]

其他一些比特幣錢包將是 [SOW](在另一台機器上,它將播放對等)

首先讓我們模擬節點,每台機器上都有一個節點:

[VOW] bitcoind -regtest -wallet=/path/daemon1.dat -datadir=/path/.bitcoin1 -rpcport=18334 -port=18434 -addnode=127.0.0.1:18435
[SOW] bitcoind -regtest -wallet=/path/daemon2.dat -datadir=/path/.bitcoin2 -rpcport=18335 -port=18435 -addnode=127.0.0.1:18434
[OCW] bitcoind -regtest  -datadir=/path2/.bitcoin -wallet=/path2/wallet -rpcport=18336 -port=18436

使用這些別名呼叫 bitcoin-cli:

alias BITVOW='bitcoin-cli -regtest -datadir=/path/.bitcoin1 -rpcport=18334'
alias BITSOW='bitcoin-cli -regtest -datadir=/path/.bitcoin2 -rpcport=18335'
alias BITOCW='bitcoin-cli -regtest -rpcport=18336'

所以這兩個 [VOW] 和 [SCW] 相互連接,這沒有問題(它們形成了一個小的 2 節點網路)。

在離線機器上,我這樣做:

$ BITOCW getnewaddress
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITOCW dumpprivkey
2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj

我想將 500 BTC 發送到2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL,所以我向“其他”錢包生成資金,以支付我的錢包,並生成驗證交易:

$ BITSOW generate X
$ BITSOW getbalance
550.00000000
$ BITSOW sendtoaddress 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL 500
33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1
$ BITSOW generate 1
$ BITSOW getnewaddress
2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM

我將使用這個地址2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM從我的主錢包中通過離線簽名接收資金。

我在錢包視圖錢包上導入比特幣地址,並檢查餘額:

$ BITVOW importaddress  2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL
$ BITVOW getbalance "*" 0 true
500.00000000

完美的。現在是我想使用離線交易簽名將這些 500 發送回2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM的部分。

首先讓我們確定可以使用的TX:

$ BITVOW listunspent 1 99999999 '["2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"]'
[
 {
   "txid": 
   "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
   "vout": 0,
   "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
   "label": "",
   "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
   "amount": 500.00000000,
   "confirmations": 1,
   "spendable": false,
   "solvable": false,
   "safe": true
 }
]
$ BITVOW createrawtransaction '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499.9999}'

這將作為原始交易(例如,我放入 $RAW_TRANSACTION ):

0200000001F1B52DBE4F385D471A1BFAA669FD2BA2CB8418F627B728BE149B7DFD3E0AF333000000000000FFFFFFFF01F04C3BA40B0000000013A9144B​​17C1384DED51B51A609155FA56BE6CC7D0021208700000000

然後,在離線機器上,我想使用私鑰對此進行簽名:

$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION
{
   "hex": "0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000",
   "complete": false,
   "errors": [
  {
  "txid": "33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1",
 "vout": 0,
 "witness": [
 ],
 "scriptSig": "",
 "sequence": 4294967295,
 "error": "Input not found or already spent"
}
]
}

非常感謝您的幫助!

[編輯]:我也試過這個:

$ BITOCW signrawtransactionwithwallet $RAW_TRANSACTION '[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"a9144b17c1384ded51b51a60915fa56be6cc7d00212087"}]'
error code: -3
error message:
Missing amount for CTxOut(nValue=21000000.00000000, scriptPubKey=a9144b17c1384ded51b51a60915fa5)

[編輯]

以下是我嘗試使用Pieter Wuille提供的解決方案 (2) 和 (3) 的方法:

(2) 我在離線系統 [OCW] 上嘗試了這個,以獲得用於簽名過程的 RedeemScript:

BITOCW getaddressinfo 2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL{
 "address": "2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL",
 "scriptPubKey": "a9144b17c1384ded51b51a60915fa56be6cc7d00212087",
 "ismine": true,
 "iswatchonly": false,
 "isscript": true,
 "iswitness": false,
 "script": "witness_v0_keyhash",
 "hex": "0014dd296fa290135a7c18c3002c41cf020324538d5f",
 "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
 "embedded": {
   "isscript": false,
   "iswitness": true,
   "witness_version": 0,
   "witness_program": "dd296fa290135a7c18c3002c41cf020324538d5f",
   "pubkey": "02ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b6",
   "address": "bcrt1qm55klg5szdd8cxxrqqkyrnczqvj98r2l8m5l0f",
   "scriptPubKey": "0014dd296fa290135a7c18c3002c41cf020324538d5f"
 },
 "label": "",
 "timestamp": 1540018166,
 "hdkeypath": "m/0'/0'/4'",
 "hdseedid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
 "hdmasterkeyid": "fc9ec97f45384df39d95fc424d5a5349951d5bde",
 "labels": [
   {
     "name": "",
     "purpose": "receive"
   }
 ]
}

也許我遺漏了一些東西,但我找不到合適的 RedeemScript 進行簽名。

(3) 首先,我不知道自己不選幣也能做這樣的事情。如果是這樣,我寧願讓“僅線上觀看”錢包自動選擇硬幣,這樣我就不必以程式方式選擇合適的輸入。

然後,按照你的建議,這是我迄今為止在線上系統上嘗試過的,在與上面相同的createrawtransaction之後:

BITVOW converttopsbt 0200000001f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a9144b17c1384ded51b51a60915fa56be6cc7d0021208700000000
cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==

和:

BITVOW walletprocesspsbt cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAAAAA==
{
 "psbt": "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG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s7u49wDR127cFd1vLU3bk3vifQH+////XTiaFEkYHocUhIg+XmbMi3nnpSw1qgKYKbZh1oS7dlsAAAAASEcwRAIgc/2/mN/evEi/hBA4JtTw/82mndVSuISAeTcqDQ5yyfQCIADnr/yfLKbOVj3hbqjUwewVu44xRSoBeHt3ptEwB02BAf7///87CVHCCJ4KsgaiAtMhT2h38YkXIqFy9cYDmU/IthPSmgAAAABIRzBEAiAfkNsXRjf7sPjyknV38nY1WLQ4K7oV8iqP+nhI8/jV5gIgDpJCo3VPg2M4GT9uSuDKlp4w6BqDnJsIyGdZ6XRj0SUB/v///wIAdDukCwAAABepFEsXwThN7VG1GmCRX6Vr5sx9ACEghxyLBSoBAAAAF6kULDnWiZNlc9lyYG7jv4tHeqBx1H6HbwAAAAAA",
 "complete": false
}

然後我在離線系統上導出了這個並做了:

BITOCW  walletprocesspsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbt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CP4Yg5870w8Zz0QCcK6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA=",
 "complete": true
}

當我看到 complete = true 時我很高興,但後來發生了這樣的事情:

BITOCW finalizepsbt "cHNidP8BAFMCAAAAAfG1Lb5POF1HGhv6pmn9K6LLhBj2J7covhSbff0+CvMzAAAAAAD/////AfBMO6QLAAAAF6kUSxfBOE3tUbUaYJFfpWvmzH0AISCHAAAAAAABAP0lBQIAAAALfARlDuNzSr0JSrElwpd+izM03irULESrdcQzBmKw8CQAAAAASEcwRAIgKRmcygxX+LVIzMLYpwHVPbTSNYYQjZaMXUyQCBIDBLICIFFntYpDI+G0yUH+yL7b/4YIrYjDUk08q/4A+I/2hh84Af7///+n2vDIPJrmbmA2RRL2RMtbVp+Sf4AU/JUUm53K1JOoJwAAAABIRzBEAiBOLc842GEgXdiq0gagWZ5Vvni5e6DiFGZYG+m6xGrA0QIgf1mtao/3/dGA3u6LvgI2s7bLMtDAr+cxCU/lNJ1PC8cB/v///6ePR81CkwFcpxZub36mqRIemlMGNfvWhNxlDPPZW5LyAAAAAEhHMEQCIEEl9vU7Ezn4zApn1bgUS7DR3Wvz3J9YMEzvVKgmbRaXAiA3Xv8Q5bDbLKEJ/tHn+Adr1u+EUsaKdp8LnWM8cLajHwH+////unzoFharwYU9mElHKsCWwwmoqvbtEbzL8i2dzUFq8RcAAAAASEcwRAIgVoSlc5RumxBU/O4gDzrFdXcxuCBDt30DczglDmuvSegCIFkZIqu1OS5UNncEThnNS8th+38lFf71PDa9Og2n3TKFAf7////Zq7QRMc7AhtcyGYE/HdvSAR146Dv659BXuzrHycdrcQAAAABIRzBEAiBctxeVGCoN8zlKnG19Tgs4GKnQ1r/Ge6Hjr/kIX0LJSQIgNHhYFpt2aabQEWA06apQpTcscoBH1hkDO9b9P3kNBKsB/v///0dInKhhB5SbX3zsU4+I8irL8UFXYDWqM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K6yHaQdaZWRpsWy5ASEC/103Cng0bT+6yXUDdaPXc6rJodqt+HC4h3EtN8Ii0rYAAQAWABTdKW+ikBNafBjDACxBzwIDJFONXwA="
error code: -22
error message:
TX decode failed PSBT is not sane.: iostream error

我發現 github 比特幣項目上的問題 #14473 似乎與此有關,但我不確定(<https://github.com/bitcoin/bitcoin/issues/14473>)。

[編輯]

關於**(2):我按照建議在*嵌入欄位中得到了scriptPubKey*,即0014dd296fa290135a7c18c3002c41cf020324538d5f,以及金額,因為它不在原始交易中(正如彼得所建議的那樣):

BITOCW -named signrawtransactionwithkey hexstring=$RAW_TRANSACTION prevtxs='[{"txid":"33f30a3efd7d9b14be28b727f61884cba22bfd69a6fa1b1a475d384fbe2db5f1","vout":0,"scriptPubKey":"0014dd296fa290135a7c18c3002c41cf020324538d5f", "amount":499.9999}]' privkeys='["cQgMpjZKVnYon1cfKaMuSpAsNQS3rw49BKUmmWV3n3UbEc1ywcQj"]'
{
 "hex": "02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000",
 "complete": true
}

然後我可以在線上機器上廣播簽名的交易,但是:

BITVOW sendrawtransaction 02000000000101f1b52dbe4f385d471a1bfaa669fd2ba2cb8418f627b728be149b7dfd3e0af3330000000000ffffffff01f04c3ba40b00000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f56870246304302204385ab257825a678365ed1dfd9e06dd8c0f31ecf1f12ffd8058dff9cb952a98f021f7b0919da9ba57d94b0b5f24eaa27bcf6902460008e7db0f51890761e291c2b012102ff5d370a78346d3fbac9750375a3d773aac9a1daadf870b887712d37c222d2b600000000
error code: -26
error message: mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)

關於使用fundrawtransaction選擇硬幣,我創建了一個空交易並嘗試從線上“僅查看”錢包中為其註資:

$ BITVOW createrawtransaction '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":1}'02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000
$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true}'
error code: -4
error message:
Insufficient funds

includeWatching 是否足以使其將僅觀看地址考慮在內?可以肯定的是,我試過:

$ BITVOW fundrawtransaction 02000000000100e1f5050000000017a914ef9751cb4e8dbe30f6070c546cb5fa6538231f568700000000 '{"includeWatching":true, "changeAddress":"2Mz6H8BU3Gg4Nmrv1LyZPm4KcaKj8EjZXxL"}'

它使我的bitcoind因錯誤而中止:

2018-10-27T18:55:19Z 新的出站對等體已連接:版本:70015,blocks=112,peer=0 bitcoind: policy/feerate.cpp:25: CAmount CFeeRate::GetFee(size_t) const: Assertion `nBytes_ <= uint64_t(std::numeric_limits::max())’ 失敗。中止

關於使用walletcreatefundedpsbt的硬幣選擇,我給了我:

$ BITVOW walletcreatefundedpsbt '[]' '{"2NF64kzg5R4wdA3bjJAtVyvKmvgbo1FJ8SM":499}'
error code: -4
error message:
Insufficient funds

signrawtransactionwithwallet使用錢包有兩個目的:

  • 查找簽名所需的私鑰(您通過導入處理)
  • 查找正在花費的交易輸出(沒有這些資訊,您將無法建構有效的交易,並且離線錢包處於離線狀態,無法訪問記入您的交易)。

為了提高實用性,有許多解決方案:

  • 將線上系統的 wallet.dat 複製到線下系統,這樣就可以看到交易歷史了(不要轉回來,因為裡面會包含私鑰)
  • 使用signrawtransactionwithkeyRPC,它允許您在 RPC 呼叫中指定私鑰和 UTXO 資訊,因此在離線系統上不再需要導入。
  • 使用 PSBT 風格的 RPC 呼叫;在離線系統上使用,walletcreatefundedpsbt在線上系統上使用簽名,使用walletprocesspsbt提取完成的交易finalizepsbt,您可以使用廣播sendrawtransaction。PSBT 文件包含簽名所需的所有元數據,包括正在使用的舊交易(輸出)。

我有一個非常古老的 Greg Maxwell 教程來解決這個稍微老一點的問題

https://web.archive.org/web/20171124193914/https://people.xiph.org/~greg/signdemo.txt

該教程使用“bitcoind”作為該命令是因為它是在“bitcoin-cli”成為正確命令之前編寫的。除了這個細節,本教程應該仍然適用於最近的比特幣核心版本

我不確定為什麼在沒有回答所寫問題的情況下,這個討論會轉向“PSBT 做得更好”,但我不會反對“PSBT 做得更好”

這個問題現在很難理解,已經以構想的方式改變了,所以我可能錯過了什麼

問題使用’signrawtransactionwithwallet'

本教程使用’signrawtransaction'

提問者嘗試使用“getaddressinfo”查找 RedeemScript

本教程使用“decoderawtransaction”公開 RedeemScript

除非我錯誤地閱讀了建議流程,否則問題是冷錢包無法知道 RedeemScript,這就是“signrawtransactionwithwallet”無法工作的原因。‘signrawtransaction’ 接受 RedeemScript 作為參數,而 ‘decoderawtransaction’ 公開 RedeemScript

Greg Maxwell 教程中的方法我沒有嘗試過,但我希望這個小小的貢獻有助於更好地理解問題

如果我找不到更新的離線簽名教程,我會嘗試騰出一些時間來寫一個新版本

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