Bitcoind

操作對目前堆棧大小無效

  • December 8, 2018

根據 bip65 <https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki>

我可以使用 IF … ELSE … ENDIF 之類的表達式這是本文件中的範例腳本:

IF
   HASH160 &lt;Hash160(encryption key)&gt; EQUALVERIFY
   &lt;publisher pubkey&gt; CHECKSIG
ELSE
   &lt;expiry time&gt; CHECKLOCKTIMEVERIFY DROP
   &lt;buyer pubkey&gt; CHECKSIG
ENDIF

但是當我嘗試使用以下腳本進行交易時:

OP_IF 
   OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
   10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF

<https://tchain.btc.com/dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374>

我得到錯誤:

bitcoin-cli -testnet sendrawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
error code: -26
error message:
mandatory-script-verify-flag-failed (Operation not valid with the current stack size) (code 16)

我的錯誤在哪裡?

附言

SHA256 從 1 -> 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a

SHA256 來自 2 -> dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986

您的事務在其腳本中只有0x51(just OP_1),OP_IF消耗1OP_SHA256然後在空堆棧上操作,導致此錯誤。

就像 arubi 說的,你的 scriptSig 只是0x51

$ bitcoin-cli decoderawtransaction 020000000174c3e24cbc6f8a0633e55f055e1747127e91f5b6e1157fc059e1b700b777f4db000000000151ffffffff01c0d401000000000023a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d9868700000000
{
 "txid": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
 "hash": "2e7c6efc9dc6104f132a10d0d64263269d1ece326b4d64cb1061fe5a81b4d53b",
 "version": 2,
 "size": 96,
 "vsize": 96,
 "weight": 384,
 "locktime": 0,
 "vin": [
   {
     "txid": "dbf477b700b7e159c07f15e1b6f5917e1247175e055fe533068a6fbc4ce2c374",
     "vout": 0,
     "scriptSig": {
       "asm": "1",
       "hex": "51"
     },
     "sequence": 4294967295
   }
 ],
 "vout": [
   {
     "value": 0.00120000,
     "n": 0,
     "scriptPubKey": {
       "asm": "OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL",
       "hex": "a820dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d98687",
       "type": "nonstandard"
     }
   }
 ]
}

這意味著如果scriptPubKey您花費的輸入是:

OP_IF 
   OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 
OP_ELSE 
   10 OP_CHECKLOCKTIMEVERIFY OP_DROP OP_SHA256 dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986 OP_EQUAL
OP_ENDIF

它將執行這個分支(因為棧頂元素為真):

OP_IF 
   OP_SHA256 4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a OP_EQUAL 

您還必須為該值提供任何散列值4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a以使其成功返回。

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