Electrum

離線簽署交易 - 手動方式與 Electrum

  • July 2, 2020

受到執行緒的啟發(需要逐步贖回原始交易範例),我想了解字節級別的交易簽名。

所以我創建了自己的 Linux 腳本:

  • 生成密鑰對
  • 累積原始交易所需的所有必要字節
  • 利用 OpenSSL 簽署交易

我在離線電腦上處理私鑰的所有事情,同時我在不同的線上系統的螢幕上查看區塊鏈瀏覽器。

對於我的測試交易,我想贖回我在主網上控制的地址的一個 utxo,並使用 P2PKH 將一些 satoshis(略高於“灰塵”級別)發送到其他一些地址。這是我手動創建和簽名的交易:

{
   "version": 1,
   "locktime": 0,
   "ins": [
           {
                   "n": 1,
                   "script": {
                           "asm": "304402200c441b33dc180ec93e1df07df575399f74112dbf4a0a200151c9c4f1afc7c71e02200fc2fcf42847d5c504f06edef7b8fa81b092e7b8b00169d7f8868a02da6ad12401 02dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2",
                           "hex": "47304402200c441b33dc180ec93e1df07df575399f74112dbf4a0a200151c9c4f1afc7c71e02200fc2fcf42847d5c504f06edef7b8fa81b092e7b8b00169d7f8868a02da6ad124012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2"
                   },
                   "sequence": 4294967295,
                   "txid": "127ea67612d6e217f99b2b28cc9f8347eb518f99c45102f925774ad8f4958d0f",
                   "witness": []
           }
   ],
   "outs": [
           {
                   "script": {
                           "addresses": [
                                   "1HangpEdoDsSe5i3n7DQNbYie65PGGmPcq"
                           ],
                           "asm": "OP_DUP OP_HASH160 b5e5e05c83c470ffd21c3330fb99a6a0101351ad OP_EQUALVERIFY OP_CHECKSIG",
                           "hex": "76a914b5e5e05c83c470ffd21c3330fb99a6a0101351ad88ac"
                   },
                   "value": 800
           },
           {
                   "script": {
                           "addresses": [
                                   "1HaXuSmR7PXhR4GCcyvGC7USYDuDjw6FHw"
                           ],
                           "asm": "OP_DUP OP_HASH160 b5d9896cc07a30e1d739097df0c1d47181cbbe75 OP_EQUALVERIFY OP_CHECKSIG",
                           "hex": "76a914b5d9896cc07a30e1d739097df0c1d47181cbbe7588ac"
                   },
                   "value": 900
           }
   ],
   "hash": "18d7100c870deb63dec258282f5ff150ebc64e4497d107073503fb4343f4810d",
   "txid": "18d7100c870deb63dec258282f5ff150ebc64e4497d107073503fb4343f4810d"
}

…對應於十六進製表示 01000000010f8d95f4d84a7725f90251c4998f51eb47839fcc282b9bf917e2d61276a67e12010000006a47304402200c441b33dc180ec93e1df07df575399f74112dbf4a0a200151c9c4f1afc7c71e02200fc2fcf42847d5c504f06edef7b8fa81b092e7b8b00169d7f8868a02da6ad124012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2ffffffff0220030000000000001976a914b5e5e05c83c470ffd21c3330fb99a6a0101351ad88ac84030000000000001976a914b5d9896cc07a30e1d739097df0c1d47181cbbe7588ac00000000

Electrum 有一個菜單項來“通過文本載入事務”,這是我對十六進製字元串所做的。它正確地將結果顯示為*“與您的錢包無關的交易”,因為我還沒有導入私鑰。Electrum 為我提供了廣播交易的選項,但我決定這樣做 ( *),因為我想將*手動創建的交易與 Electrum 在使用他們的 UI 功能時生成的交易進行比較。

(*)我後來通過 blockchain.com 廣播了我的手動交易

因此,為了能夠進行比較,我將私鑰導入 Electrum 並創建了一個具有相同參數的交易(使用“支付給多個”功能)。這是 Electrum 創建的交易:

{
   "version": 2,
   "locktime": 636848,
   "ins": [
           {
                   "n": 1,
                   "script": {
                           "asm": "3045022100fa7033d292275ebcd4d8fdf38d6b76461ba4a9330df3b21cf5e72f25f08938c802207268e19442c1d3e0ff9850cd6f500985260c250e18d71976093475bd61180ebb01 02dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2",
                           "hex": "483045022100fa7033d292275ebcd4d8fdf38d6b76461ba4a9330df3b21cf5e72f25f08938c802207268e19442c1d3e0ff9850cd6f500985260c250e18d71976093475bd61180ebb012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2"
                   },
                   "sequence": 4294967294,
                   "txid": "127ea67612d6e217f99b2b28cc9f8347eb518f99c45102f925774ad8f4958d0f",
                   "witness": []
           }
   ],
   "outs": [
           {
                   "script": {
                           "addresses": [
                                   "1HangpEdoDsSe5i3n7DQNbYie65PGGmPcq"
                           ],
                           "asm": "OP_DUP OP_HASH160 b5e5e05c83c470ffd21c3330fb99a6a0101351ad OP_EQUALVERIFY OP_CHECKSIG",
                           "hex": "76a914b5e5e05c83c470ffd21c3330fb99a6a0101351ad88ac"
                   },
                   "value": 800
           },
           {
                   "script": {
                           "addresses": [
                                   "1HaXuSmR7PXhR4GCcyvGC7USYDuDjw6FHw"
                           ],
                           "asm": "OP_DUP OP_HASH160 b5d9896cc07a30e1d739097df0c1d47181cbbe75 OP_EQUALVERIFY OP_CHECKSIG",
                           "hex": "76a914b5d9896cc07a30e1d739097df0c1d47181cbbe7588ac"
                   },
                   "value": 900
           }
   ],
   "hash": "0f33ae7fc5ca788351a4b571083cf0fa8cbb37afe0206260b02c4c889c05c099",
   "txid": "0f33ae7fc5ca788351a4b571083cf0fa8cbb37afe0206260b02c4c889c05c099"
}

…對應於十六進製表示02000000010f8d95f4d84a7725f90251c4998f51eb47839fcc282b9bf917e2d61276a67e12010000006a47304402200dd93baf0a38e4a352a7029c2a37a9bb8ef06bc32ab33fabb8278c6733193e4a02203393c4f5b73345a2a76694de9dff429d65b4de77581601ccc748c642a0dac308012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2feffffff0220030000000000001976a914b5e5e05c83c470ffd21c3330fb99a6a0101351ad88ac84030000000000001976a914b5d9896cc07a30e1d739097df0c1d47181cbbe7588ace5b70900

我的問題來了:

當我比較兩個解碼的交易時,我得到以下差異:

~/$ diff tx-manual tx-electrum 
2,3c2,3
<   "version": 1,
<   "locktime": 0,
---
>   "version": 2,
>   "locktime": 636848,
8,9c8,9
<               "asm": "304402200c441b33dc180ec93e1df07df575399f74112dbf4a0a200151c9c4f1afc7c71e02200fc2fcf42847d5c504f06edef7b8fa81b092e7b8b00169d7f8868a02da6ad12401 02dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2",
<               "hex": "47304402200c441b33dc180ec93e1df07df575399f74112dbf4a0a200151c9c4f1afc7c71e02200fc2fcf42847d5c504f06edef7b8fa81b092e7b8b00169d7f8868a02da6ad124012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2"
---
>               "asm": "3045022100fa7033d292275ebcd4d8fdf38d6b76461ba4a9330df3b21cf5e72f25f08938c802207268e19442c1d3e0ff9850cd6f500985260c250e18d71976093475bd61180ebb01 02dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2",
>               "hex": "483045022100fa7033d292275ebcd4d8fdf38d6b76461ba4a9330df3b21cf5e72f25f08938c802207268e19442c1d3e0ff9850cd6f500985260c250e18d71976093475bd61180ebb012102dece727c6ddde3140abfcc554ffe50768ab29faa7439c411772fe3c7b93f7cb2"
11c11
<           "sequence": 4294967295,
---
>           "sequence": 4294967294,
38,39c38,39
<   "hash": "18d7100c870deb63dec258282f5ff150ebc64e4497d107073503fb4343f4810d",
<   "txid": "18d7100c870deb63dec258282f5ff150ebc64e4497d107073503fb4343f4810d"
---
>   "hash": "0f33ae7fc5ca788351a4b571083cf0fa8cbb37afe0206260b02c4c889c05c099",
>   "txid": "0f33ae7fc5ca788351a4b571083cf0fa8cbb37afe0206260b02c4c889c05c099"

誰能解釋我的區別(或指出適當的 BIP)以及為什麼 Electrum 使用它們?我知道簽名不是確定性的(編輯:根據@Coding Enthusiast 的評論,Electrum 的簽名是確定性的,但我的不是),因此必須不同,因此雜湊/txid 也必須不同。但是版本、鎖定時間和最後一個 scriptpubkey 之後的 e5b70900**後綴的意義如何(參見 Electrum tx 的十六進製表示)?

  • 版本號是任意的,取決於客戶端,只要選擇的數字是有效的。
  • 在現代錢包中,通常設置為目前區塊高度,這是針對比特幣中稱為“費用狙擊”nLockTime的特定問題的簡單保護,在這種情況下,孤立其他人的區塊以竊取費用收入比挖礦更經濟在以後的高度你自己的新的。
  • e5b70900nLockTime,表示塊高度為636901。請參閱協議文件。

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