比特币(BSV)知识库:比特币协议-签名标识(SIGHASH flags)

BSV知识库 专栏收录该内容
77 篇文章 3 订阅

特别提示:

比特币(BSV)知识库-Bitcoin wiki-目前为全英文内容,暂无中文译文,并且仍在持续编写和补充中。欢迎中国的开发者在文章底部评论,进行阐述和探讨。

SIGHASH flags

A SIGHASH flag is used to indicate which part of the transaction is signed by the ECDSA signature. The mechanism provides a flexibility in constructing transactions. There are in total 6 different flag combinations that can be added to a digital signature in a transaction. Note that different inputs can use different SIGHASH flags enabling complex compositions of spending conditions.

NOTE: Currently all BitcoinSV transactions require an additional SIGHASH flag called SIGHASH_FORKID which is 0x00000040

FlagValue including SIGHASH_FORKIDValue excluding SIGHASH_FORKIDFunctional Meaning
SIGHASH_ALL0x000000410x00000001Sign all inputs and outputs
SIGHASH_NONE0x000000420x00000002Sign all inputs and no output
SIGHASH_SINGLE0x000000430x00000003Sign all inputs and the output with the same index
SIGHASH_ALL | ANYONECANPAY0x000000C10x00000081Sign its own input and all outputs
SIGHASH_NONE | ANYONECANPAY0x000000C20x00000082Sign its own input and no output
SIGHASH_SINGLE | ANYONECANPAY0x000000C30x00000083Sign its own input and the output with the same index


The tables below illustrate what is signed and what is not signed in an ECDSA siganture depending on the SIGHASH type used.

Items that are always signed

The signature on any input always signs the TXID and VOUT that comprise the Outpoint being spent as well as the version of the protocol that the transaction is being evaluated under and the locktime being applied to the transaction.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

Items that are never signed

Unlocking scripts are never signed

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_ALL

SIGHASH_ALL signs all inputs and outputs used to build the transaction. Once an input signed with SIGHASH_ALL is added to a transaction, the transaction's details cannot be changed without that signature being invalidated.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_SINGLE

SIGHASH_SINGLE signs all inputs and the output that shares the same index as the input being signed. If that output or any inputs are changed that signature becomes invalidated.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_NONE

SIGHASH_NONE signs all inputs and no outputs. Any output can be changed without invalidating the signature however if any inputs are changed that signature becomes invalidated.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_ALL|ANYONECANPAY

`Once an input signed with SIGHASH_ALL|ANYONECANPAY is added to a transaction outputs cannot be changed or added without that signature being invalidated.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_SINGLE|ANYONECANPAY

SIGHASH_SINGLE|ANYONECANPAY signs the input being signed and the output that shares the same index. If that output is changed that signature becomes invalidated.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

SIGHASH_NONE|ANYONECANPAY

SIGHASH_NONE|ANYONECANPAY signs a single inputs and no outputs. This type of signature can be used to easily assign funds to a person or smart-contract without creating an on-chain action.

TxID
Version
Locktime
InputsOutputs
 Unlocking Script Locking Script
Outpoint A.....Sig Pa, Tx.....Xa BSV[ChecksigP1]
Outpoint B.....Sig Pb, Tx.....Xb BSV[ChecksigP2]
............
Outpoint N.....Sig PN, Tx.....XN BSV[ChecksigPm]

Use cases

SIGHASH flags are useful when constructing smart contracts and negotiable transactions in payment channels.

 

Use Case 1 - Crowdfunding

Using ALL | ANYONECANPAY allows a transaction to have a fixed output or fixed outputs while keeping the input list open. That is, anyone can add their input with their signature to the transaction without invalidating all existing signatures.

 

Use Case 2 - Blank Check

Using NONE allows anyone to add their desired outputs to the transaction to claim the funds in the input.

 

Use Case 3 - Modular Transaction

Using SINGLE | ANYONECANPAY modularises a transaction. Any number of these transactions can be combined into one transaction.

References

https://github.com/bitcoin-sv/bitcoin-sv/blob/master/src/script/sighashtype.h

声明:

比特币(BSV)知识库项目由比特币协会(Bitcoin Association)发起并支持,更多信息请参见知识库官网:https://wiki.bitcoinsv.io/


  • 对比特币区块链开发感兴趣的朋友可以通过CSDN站内私信联系我们,申请加入BSV开发者交流群。
  • 同时,您也可以扫描下方二维码,关注比特币协会官方微信公众号——BA资讯,了解更多区块链领域的实时资讯。

 

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 扫一扫,分享海报

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值