比特幣 解鎖腳本signature script 包含了那些東西?
使用 UTXO 需要私鑰簽名,私鑰到底都簽了什么東西呢?一直比較好奇.
比特幣的私鑰簽名總共有五中類型,具體見 btcd 代碼,如下:
// SigHashType represents hash type bits at the end of a signature.
type SigHashType uint32
// Hash type bits from the end of a signature.
const (
SigHashOld SigHashType = 0x0
SigHashAll SigHashType = 0x1
SigHashNone SigHashType = 0x2
SigHashSingle SigHashType = 0x3
SigHashAnyOneCanPay SigHashType = 0x80
// sigHashMask defines the number of bits of the hash type which is used
// to identify which outputs are signed.
sigHashMask = 0x1f
)
SigHashOld 和 SigHashAll
從代碼看,兩者是一樣的.具體簽名內容見圖.
主要內容:
所有的 TxIn,所有的 TxOut, 但是不包含簽名本身(這個是不可能做到包含自身的).
這是目前主要的簽名用法.

SigHashNone
主要內容:
所有TxIn, 但是不包含 TxOut
我不知道這種簽名用在什么地方, TxOut可以讓別人隨便改.

SigHashSingle
對所有的 TxIn和某個 TxOut 進行簽名
不清楚用途

SigHashAnyOneCanPay
對當前TxIn 和所有 TxOut 進行簽名
這個可以保證輸入輸出的安全,但是因為沒有包含TxIn 之間的順序關系. 所有這個 Tx 的 ID 是可以被修改的.

