P2sh

p2sh 檢查失敗

  • November 11, 2015

我正在嘗試驗證來自實時比特幣區塊鏈的 p2sh 交易,但是它沒有通過檢查。我正在使用pybitcointools進行檢查,並且我已經成功驗證了許多其他 txhash/pubkey/signature 集,所以我認為問題不在於 ECDSA 庫。

我想我一定是錯誤地評估了 p2sh。請有人告訴我哪裡出錯了:

tx hash7edb32d4ffd7a385b763c7a8e56b6358bcd729e747290624e18acdbe6209fc45花費 txout 中索引為 0 的 tx hash 40eee3ae1760e3a8532263678cdf64569e6ad06abc133af64f735e52562bccc8

首先我評估腳本:

OP_FALSE
OP_PUSHDATA0(72)
3045022100ad0851c69dd756b45190b5a8e97cb4ac3c2b0fa2f2aae23aed6ca97ab33bf88302200b248593abc1259512793e7dea61036c601775ebb23640a0120b0dba2c34b79001
OP_PUSHDATA0(69)
5141042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf51ae

這使堆棧像這樣:

0 - 00
1 - 3045022100ad0851c69dd756b45190b5a8e97cb4ac3c2b0fa2f2aae23aed6ca97ab33bf88302200b248593abc1259512793e7dea61036c601775ebb23640a0120b0dba2c34b79001
2 - 5141042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf51ae    

我將其備份為stack_copy.

然後我評估 scriptpubkey:

OP_HASH160
OP_PUSHDATA0(20)
e9c3dd0c07aac76179ebc76a6c78d4d67c6c160a
OP_EQUAL

這很好。

最後我評估 p2sh - 我恢復stack_copy並從堆棧中彈出最後一項 (2)。我反序列化它以獲得以下腳本:

OP_TRUE
OP_PUSHDATA0(65)
042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf
OP_TRUE
OP_CHECKMULTISIG

然後使用stack_copy(沒有剛剛彈出的元素 2)對此進行評估。檢查簽名評估的數據是:

serial tx: 0100000001c8cc2b56525e734ff63a13bc6ad06a9e5664df8c67632253a8e36017aee3ee4000000000455141042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf51aefeffffff0120f40e00000000001976a9141d30342095961d951d306845ef98ac08474b36a088ac0000000001000000
txhash: 8fcf56ee75816930fb141fdc19b2aa1bc721b124d2a76d5f0c1be17bcd21ccdc
pubkey: 042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf
signature: 3045022100ad0851c69dd756b45190b5a8e97cb4ac3c2b0fa2f2aae23aed6ca97ab33bf88302200b248593abc1259512793e7dea61036c601775ebb23640a0120b0dba2c34b790

然而這是失敗的!如果您需要更多資訊,請告訴我,我可以提供。

locktime將支出交易的欄位意外設置為0實際上是272295針對此交易的。

{
   "hash": "7edb32d4ffd7a385b763c7a8e56b6358bcd729e747290624e18acdbe6209fc45",
   "num_inputs": 1,
   "input": {
       "0": {
           "funds": 990000,
           "hash": "40eee3ae1760e3a8532263678cdf64569e6ad06abc133af64f735e52562bccc8",
           "index": 0,
           "parsed_script": "OP_FALSE OP_PUSHDATA0(72) 3045022100ad0851c69dd756b45190b5a8e97cb4ac3c2b0fa2f2aae23aed6ca97ab33bf88302200b248593abc1259512793e7dea61036c601775ebb23640a0120b0dba2c34b79001 OP_PUSHDATA0(69) 5141042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf51ae",  
           "script_length": 144,
           "sequence_num": 4294967294
       }
   },
   "lock_time": 272295,
   "num_outputs": 1,
   "output": {
       "0": {
           "addresses": [
               "13fLLox43yXYvfoZadXpGbkTUXkW8bhqut"
           ],
           "funds": 980000,
           "parsed_script": "OP_DUP OP_HASH160 OP_PUSHDATA0(20) 1d30342095961d951d306845ef98ac08474b36a0 OP_EQUALVERIFY OP_CHECKSIG",
           "script_length": 25
       }
   },
   "size": 229,
   "version": 1
}

並且將帶有 txin 0 腳本的序列化 tx 替換為以下腳本:

OP_TRUE
OP_PUSHDATA0(65)
042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf
OP_TRUE
OP_CHECKMULTISIG

實際上應該是:

0100000001c8cc2b56525e734ff63a13bc6ad06a9e5664df8c67632253a8e36017aee3ee4000000000455141042f90074d7a5bf30c72cf3a8dfd1381bdbd30407010e878f3a11269d5f74a58788505cdca22ea6eab7cfb40dc0e07aba200424ab0d79122a653ad0c7ec9896bdf51aefeffffff0120f40e00000000001976a9141d30342095961d951d306845ef98ac08474b36a088aca727040001000000

只有包含鎖定時間的最後 8 個字節與以前不同:a727040001000000

新的串列 tx 具有雜湊:

607789be41392e6b12735a79bc9ea94573b4e39948badef18ca48e85ee15196d

並且之前的簽名和公鑰已經正確。這些現在在 pybitcointools 中正確評估,如下所示:

pybitcointools.ecdsa_raw_verify(tx_hash, pybitcointools.der_decode_sig(bin2hex(signature)), bin2hex(pubkey))

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