This page is the Simplified Technical English version of ZIP 244. The source ZIP is the normative text. Read the writing rules to understand the marked words.
ZIP 244: Transaction Identifier Non-Malleability
ZIP: 244
Title: Transaction Identifier Non-Malleability
Owners: Kris Nuttycombe <kris@nutty.land>
Daira-Emma Hopwood <daira@jacaranda.org>
Jack Grigg <thestr4d@gmail.com>
Status: Final
Category: Consensus
Created: 2021-01-06
License: MIT
Discussions-To: <https://github.com/zcash/zips/issues/411>
Terminology
On this page, STE words are in the place of the BCP 14 key words of the source. Refer to the key word table.
In this document, these terms have the meaning in ZIP 200 [zip-0200]:
- "consensus branch"
- "epoch"
- "network upgrade"
The term "field encoding" is the binary serialized form of a Zcash transaction field. The specification of this form is in section 7.1 of the Zcash protocol specification [protocol-txnencoding].
Abstract
This ZIP contains a new transaction digest algorithm that applies from the NU5 network upgrade. The purpose is non-malleable transaction identifiers. These identifiers are a commitment to all transaction data, with the exception of attestations to transaction validity.
This ZIP also contains a new transaction digest algorithm for signature validation. In this algorithm, all available structure from the calculation of transaction identifiers is shared. The purpose is to decrease redundant data hashing in validation to a minimum.
This ZIP also contains a new name and new semantics for the hashLightClientRoot field of the block header. With this change, additional commitments can be represented in this hash. The change also includes a mechanism to extend the set of represented commitments in the future.
Motivation
We recommend that attestations to spend authority or to the included outputs become invalid after any change to the transaction that is not explicitly approved (for example, through anyone-can-spend inputs). This applies in all cases. It is particularly important for the use of transactions in higher-level protocols. After the activation of this change, transaction identifiers are stable, independent of any possible malleation of "witness data". Examples of witness data are proofs and transaction signatures.
Also, this ZIP contains a transaction identifier and signature algorithm that is independent of the serialized format of the complete transaction. As a result, the wire format of transactions is no longer consensus-critical.
Requirements
- Continue to support the existing functionality of the protocol (multisig, and signing modes for transparent inputs).
- Make it possible to use transaction identifiers, and pairs of the form (transaction identifier, output index), as stable identifiers.
- A sender must be able to recognize their own transaction, even with the approved forms of malleability. An example of such a form is the recalculation of transaction signatures.
- For transparent inputs, we recommend that it is possible to create a transaction (B) that spends the outputs from a previous transaction (A), even before (A) is mined. We recommend that this is also possible if the creator of (B) does not wait for confirmations of (A). That is, we recommend that (B) stays valid if any variant of (A) is eventually mined.
- We recommend that it is not possible for an adversary to malleate a transaction so that the transaction is interpreted as a double-spend.
- We recommend that it is possible in the future to upgrade the protocol so that only non-malleable transactions are accepted.
- We recommend that it is possible to use the unchanged transaction identifier as the value that is used to produce a signature hash. This applies if the transaction contains no transparent inputs.
Non-requirements
Some parts of the ecosystem do not use the non-malleable transaction format yet. For backward compatibility with these parts, it is not an initial requirement that all transactions are non-malleable.
It is not a requirement that non-malleable transaction identifiers can be calculated for legacy transaction formats (Sapling V4 and earlier). But these formats can continue to be accepted by the network after the NU5 network upgrade.
Specification
Digests
All digests are personalized BLAKE2b-256 hashes. Sometimes no elements are available for hashing (for example, if there are no transparent transaction inputs or no Orchard actions). In these cases, a personalized hash of the empty byte array is used. Thus, because of the personalization string, the hashes of empty data fields also have domain separation.
The notation BLAKE2b-256(personalization_string, []) is for hashes that are calculated in this way.
TxId Digest
A new transaction digest algorithm is defined. With this algorithm, the identifier for a transaction is calculated from a tree of hashes. Each branch of the tree of hashes is for a specific subset of transaction data. The overall structure of the hash follows. Each name in this tree is described in detail below.
txid_digest
├── header_digest
├── transparent_digest
│ ├── prevouts_digest
│ ├── sequence_digest
│ └── outputs_digest
├── sapling_digest
│ ├── sapling_spends_digest
│ │ ├── sapling_spends_compact_digest
│ │ └── sapling_spends_noncompact_digest
│ ├── sapling_outputs_digest
│ │ ├── sapling_outputs_compact_digest
│ │ ├── sapling_outputs_memos_digest
│ │ └── sapling_outputs_noncompact_digest
│ └── valueBalance
└── orchard_digest
├── orchard_actions_compact_digest
├── orchard_actions_memos_digest
├── orchard_actions_noncompact_digest
├── flagsOrchard
├── valueBalanceOrchard
└── anchorOrchard
In this tree, each node in snake_case is a BLAKE2b-256 hash of its children. This hash is initialized with a personalization string that is specific to that branch of the tree. Nodes that are not digests are in camelCase. In the specification below, the nodes of the tree are in depth-first order.
txid_digest
This is a BLAKE2b-256 hash of these values:
T.1: header_digest (32-byte hash output) T.2: transparent_digest (32-byte hash output) T.3: sapling_digest (32-byte hash output) T.4: orchard_digest (32-byte hash output)
The personalization field of this hash is set to:
"ZcashTxHash_" || CONSENSUS_BRANCH_ID
ZcashTxHash_ has 1 underscore character.
CONSENSUS_BRANCH_ID has the same definition as in ZIP 143 [zip-0143]. It is the 4-byte little-endian encoding of the consensus branch ID for the epoch of the block that contains the transaction. The transaction identifier hash has domain separation across parallel consensus branches. The result of this domain separation is replay protection: transactions that are targeted for one consensus branch do not have the same transaction identifier on other consensus branches.
Relative to ZcashSigHash in ZIP 143, this signature hash has a changed personalization prefix. The reason for the change is the new role of this hash. The hash is now a transaction identifier, and not a commitment that is used only for signature purposes. The previous calculation of the transaction identifier was a SHA256d hash of the serialized transaction contents. This hash was not personalized.
T.1: header_digest
This is a BLAKE2b-256 hash of these values:
T.1a: version (4-byte little-endian version identifier including overwinter flag) T.1b: version_group_id (4-byte little-endian version group identifier) T.1c: consensus_branch_id (4-byte little-endian consensus branch id) T.1d: lock_time (4-byte little-endian nLockTime value) T.1e: expiry_height (4-byte little-endian block height)
The personalization field of this hash is set to:
"ZTxIdHeadersHash"
T.2: transparent_digest
If transparent inputs or outputs are present, the transparent digest is a BLAKE2b-256 hash of these values:
T.2a: prevouts_digest (32-byte hash) T.2b: sequence_digest (32-byte hash) T.2c: outputs_digest (32-byte hash)
The personalization field of this hash is set to:
"ZTxIdTranspaHash"
If the transaction has no transparent components, transparent_digest is:
BLAKE2b-256("ZTxIdTranspaHash", [])
T.2a: prevouts_digest
This is a BLAKE2b-256 hash of the field encoding of all outpoint field values of transparent inputs to the transaction.
The personalization field of this hash is set to:
"ZTxIdPrevoutHash"
If the transaction has transparent outputs but no transparent inputs, prevouts_digest is:
BLAKE2b-256("ZTxIdPrevoutHash", [])
T.2b: sequence_digest
This is a BLAKE2b-256 hash of the 32-bit little-endian representation of all nSequence field values of transparent inputs to the transaction.
The personalization field of this hash is set to:
"ZTxIdSequencHash"
If the transaction has transparent outputs but no transparent inputs, sequence_digest is:
BLAKE2b-256("ZTxIdSequencHash", [])
T.2c: outputs_digest
This is a BLAKE2b-256 hash of the concatenated field encodings of all transparent output values of the transaction. The field encoding of such an output is the encoded output amount (8-byte little endian), and then the scriptPubKey byte array (serialized as Bitcoin script).
The personalization field of this hash is set to:
"ZTxIdOutputsHash"
If the transaction has transparent inputs but no transparent outputs, outputs_digest is:
BLAKE2b-256("ZTxIdOutputsHash", [])
T.3: sapling_digest
If Sapling spends or outputs are present, the digest of the Sapling components has two subtrees. These subtrees are organized for easy interoperability with the CompactBlock representation of Sapling data in the ZIP 307 Light Client Protocol [zip-0307].
This digest is a BLAKE2b-256 hash of these values:
T.3a: sapling_spends_digest (32-byte hash) T.3b: sapling_outputs_digest (32-byte hash) T.3c: valueBalance (64-bit signed little-endian)
The personalization field of this hash is set to:
"ZTxIdSaplingHash"
If the transaction has no Sapling spends or outputs, sapling_digest is:
BLAKE2b-256("ZTxIdSaplingHash", [])
T.3a: sapling_spends_digest
If Sapling spends are present, this digest is a BLAKE2b-256 hash of these values:
T.3a.i: sapling_spends_compact_digest (32-byte hash) T.3a.ii: sapling_spends_noncompact_digest (32-byte hash)
The personalization field of this hash is set to:
"ZTxIdSSpendsHash"
If the transaction has Sapling outputs but no Sapling spends, sapling_spends_digest is:
BLAKE2b-256("ZTxIdSSpendsHash", [])
T.3a.i: sapling_spends_compact_digest
This is a BLAKE2b-256 hash of the field encoding of all nullifier field values of the Sapling shielded spends of the transaction.
The personalization field of this hash is set to:
"ZTxIdSSpendCHash"
T.3a.ii: sapling_spends_noncompact_digest
This is a BLAKE2b-256 hash of the non-nullifier information for all Sapling shielded spends of the transaction. The zkproof data and the spend authorization signature(s) are not in this hash. For each spend, the hash includes these elements:
T.3a.ii.1: cv (field encoding bytes) T.3a.ii.2: anchor (field encoding bytes) T.3a.ii.3: rk (field encoding bytes)
In transaction version 5, Sapling Spends have a shared anchor. This anchor is hashed into the sapling_spends_noncompact_digest for each Spend.
The personalization field of this hash is set to:
"ZTxIdSSpendNHash"
T.3b: sapling_outputs_digest
If Sapling outputs are present, this digest is a BLAKE2b-256 hash of these values:
T.3b.i: sapling_outputs_compact_digest (32-byte hash) T.3b.ii: sapling_outputs_memos_digest (32-byte hash) T.3b.iii: sapling_outputs_noncompact_digest (32-byte hash)
The personalization field of this hash is set to:
"ZTxIdSOutputHash"
If the transaction has Sapling spends but no Sapling outputs, sapling_outputs_digest is:
BLAKE2b-256("ZTxIdSOutputHash", [])
T.3b.i: sapling_outputs_compact_digest
This is a BLAKE2b-256 hash of a subset of the Sapling output information, for all Sapling shielded outputs of the transaction. This subset is the information that is in the ZIP-307 [zip-0307] CompactBlock format. For each output, the hash includes these elements:
T.3b.i.1: cmu (field encoding bytes) T.3b.i.2: ephemeral_key (field encoding bytes) T.3b.i.3: enc_ciphertext[..52] (First 52 bytes of field encoding)
The personalization field of this hash is set to:
"ZTxIdSOutC__Hash" (2 underscore characters)
T.3b.ii: sapling_outputs_memos_digest
This is a BLAKE2b-256 hash of the subset of Sapling shielded memo field data, for all Sapling shielded outputs of the transaction. For each output, the hash includes this element:
T.3b.ii.1: enc_ciphertext[52..564] (contents of the encrypted memo field)
The personalization field of this hash is set to:
"ZTxIdSOutM__Hash" (2 underscore characters)
T.3b.iii: sapling_outputs_noncompact_digest
This is a BLAKE2b-256 hash of the remaining subset of the Sapling output information, for all Sapling shielded outputs of the transaction. This subset is the information that is not in the ZIP 307 [zip-0307] CompactBlock format. The zkproof data is also not in this hash. For each output, the hash includes these elements:
T.3b.iii.1: cv (field encoding bytes) T.3b.iii.2: enc_ciphertext[564..] (post-memo Poly1305 AEAD tag of field encoding) T.3b.iii.3: out_ciphertext (field encoding bytes)
The personalization field of this hash is set to:
"ZTxIdSOutN__Hash" (2 underscore characters)
T.4: orchard_digest
If Orchard actions are present in the transaction, this digest is a BLAKE2b-256 hash of these values:
T.4a: orchard_actions_compact_digest (32-byte hash output) T.4b: orchard_actions_memos_digest (32-byte hash output) T.4c: orchard_actions_noncompact_digest (32-byte hash output) T.4d: flagsOrchard (1 byte) T.4e: valueBalanceOrchard (64-bit signed little-endian) T.4f: anchorOrchard (32 bytes)
The personalization field of this hash is set to:
"ZTxIdOrchardHash"
If the transaction has no Orchard actions, orchard_digest is:
BLAKE2b-256("ZTxIdOrchardHash", [])
T.4a: orchard_actions_compact_digest
This is a BLAKE2b-256 hash of a subset of the Orchard Action information, for all Orchard Actions of the transaction. This subset is the information that is intended for an updated version of the ZIP-307 [zip-0307] CompactBlock format. For each Action, the hash includes these elements:
T.4a.i : nullifier (field encoding bytes) T.4a.ii : cmx (field encoding bytes) T.4a.iii: ephemeralKey (field encoding bytes) T.4a.iv : encCiphertext[..52] (First 52 bytes of field encoding)
The personalization field of this hash is set to:
"ZTxIdOrcActCHash"
T.4b: orchard_actions_memos_digest
This is a BLAKE2b-256 hash of the subset of Orchard shielded memo field data, for all Orchard Actions of the transaction. For each Action, the hash includes this element:
T.4b.i: encCiphertext[52..564] (contents of the encrypted memo field)
The personalization field of this hash is set to:
"ZTxIdOrcActMHash"
T.4c: orchard_actions_noncompact_digest
This is a BLAKE2b-256 hash of the remaining subset of the Orchard Action information, for all Orchard Actions of the transaction. This subset is the information that is not intended for an updated version of the ZIP 307 [zip-0307] CompactBlock format. For each Action, the hash includes these elements:
T.4c.i : cv (field encoding bytes) T.4c.ii : rk (field encoding bytes) T.4c.iii: encCiphertext[564..] (post-memo suffix of field encoding) T.4c.iv : outCiphertext (field encoding bytes)
The personalization field of this hash is set to:
"ZTxIdOrcActNHash"
Signature Digest
A new per-input transaction digest algorithm is defined. A transaction creator can sign the hash from this algorithm, as a commitment to the effects of the transaction. A signature digest is produced for each of these items:
- Each transparent input.
- Each Sapling input.
- Each Orchard action.
This algorithm is closely based on the algorithms from ZIP 143 [zip-0143] and ZIP 243 [zip-0243]. For transactions without transparent inputs, the output of this algorithm is exactly the same as the output of the transaction digest algorithm. Thus the transaction identifier can be signed directly.
The overall structure of the hash follows. Each name in this tree is described in detail below.
signature_digest ├── header_digest ├── transparent_sig_digest ├── sapling_digest └── orchard_digest
signature_digest
This is a BLAKE2b-256 hash of these values:
S.1: header_digest (32-byte hash output) S.2: transparent_sig_digest (32-byte hash output) S.3: sapling_digest (32-byte hash output) S.4: orchard_digest (32-byte hash output)
The personalization field of this hash is set to:
"ZcashTxHash_" || CONSENSUS_BRANCH_ID
ZcashTxHash_ has 1 underscore character.
This value has the same personalization as the top hash of the transaction identifier digest tree. The purpose is that, if there are no transparent inputs, the signed data is just the transaction identifier.
S.1: header_digest
This value is identical to the value that is specified for the transaction identifier.
S.2: transparent_sig_digest
The hash can be for a coinbase transaction, or for a non-coinbase transaction that has no transparent inputs. In these cases, the value of transparent_sig_digest is identical to the value in section T.2.
If the hash is for a non-coinbase transaction that has transparent inputs, transparent_sig_digest depends on the value of a hash_type flag, as follows.
The calculation of each component below depends on the values of the hash_type flag bits. Each component is described separately.
This digest is a BLAKE2b-256 hash of these values:
S.2a: hash_type (1 byte) S.2b: prevouts_sig_digest (32-byte hash) S.2c: amounts_sig_digest (32-byte hash) S.2d: scriptpubkeys_sig_digest (32-byte hash) S.2e: sequence_sig_digest (32-byte hash) S.2f: outputs_sig_digest (32-byte hash) S.2g: txin_sig_digest (32-byte hash)
The personalization field of this hash is set to:
"ZTxIdTranspaHash"
S.2a: hash_type
This is an 8-bit unsigned value. The SIGHASH encodings from the legacy script system are used again. The value is one of these encodings, with or without the SIGHASH_ANYONECANPAY flag (0x80):
SIGHASH_ALL(0x01)SIGHASH_NONE(0x02)SIGHASH_SINGLE(0x03)
These restrictions apply. A violation of a restriction is a validation failure:
- The use of any undefined
hash_type. Ahash_typeis undefined if it is not one of these values:- 0x01
- 0x02
- 0x03
- 0x81
- 0x82
- 0x83
- The use of
SIGHASH_SINGLEwithout a "corresponding output" (an output with the same index as the input that is verified).
For the signature over a transparent input, the value of hash_type comes from the scriptSig of the input, as encoded in the transaction. If the hash is for the signature over a Sapling Spend or an Orchard Action, hash_type is set to SIGHASH_ALL.
S.2b: prevouts_sig_digest
This is a BLAKE2b-256 hash that is initialized with the personalization field value ZTxIdPrevoutHash.
If the SIGHASH_ANYONECANPAY flag is not set, the value is identical to the value of prevouts_digest for the transaction identifier in section T.2a.
If the flag is set, the value is:
BLAKE2b-256("ZTxIdPrevoutHash", [])
S.2c: amounts_sig_digest
If the SIGHASH_ANYONECANPAY flag is not set, the value of amounts_sig_digest is a BLAKE2b-256 hash of a concatenation. This concatenation contains the 8-byte signed little-endian representations of all value fields [bdr-txout] for the coins that are spent by the transparent inputs to the transaction.
The personalization field of this hash is set to:
"ZTxTrAmountsHash"
If the SIGHASH_ANYONECANPAY flag is set, amounts_sig_digest is:
BLAKE2b-256("ZTxTrAmountsHash", [])
S.2d: scriptpubkeys_sig_digest
If the SIGHASH_ANYONECANPAY flag is not set, the value of scriptpubkeys_sig_digest is a BLAKE2b-256 hash of a concatenation. This concatenation contains the field encodings of all pk_script fields [bdr-txout] for the coins that are spent by the transparent inputs to the transaction. Each field encoding includes a leading CompactSize.
The personalization field of this hash is set to:
"ZTxTrScriptsHash"
If the SIGHASH_ANYONECANPAY flag is set, scriptpubkeys_sig_digest is:
BLAKE2b-256("ZTxTrScriptsHash", [])
S.2e: sequence_sig_digest
This is a BLAKE2b-256 hash that is initialized with the personalization field value ZTxIdSequencHash.
If the SIGHASH_ANYONECANPAY flag is not set, the value is identical to the value of sequence_digest for the transaction identifier in section T.2b.
If the flag is set, the value is:
BLAKE2b-256("ZTxIdSequencHash", [])
S.2f: outputs_sig_digest
This is a BLAKE2b-256 hash that is initialized with the personalization field value ZTxIdOutputsHash.
If the sighash type is neither SIGHASH_SINGLE nor SIGHASH_NONE, the value is identical to the value of outputs_digest for the transaction identifier in section T.2c.
The value is a hash over the transaction serialized form of the transparent output at a particular index, if all these conditions are true:
- The sighash type is
SIGHASH_SINGLE. - The signature hash is calculated for the transparent input at that index.
- A transparent output is in the transaction at that index.
In all other cases, the value is:
BLAKE2b-256("ZTxIdOutputsHash", [])
S.2g: txin_sig_digest
If the hash is for the signature over a transparent input, txin_sig_digest is a BLAKE2b-256 hash of these properties of the signed transparent input:
S.2g.i: prevout (field encoding) S.2g.ii: value (8-byte signed little-endian) S.2g.iii: scriptPubKey (field encoding) S.2g.iv: nSequence (4-byte unsigned little-endian)
This hash is initialized with the personalization field value Zcash___TxInHash (3 underscores).
Notes:
- In the consensus rules,
valueis defined as a nonnegative value that is less than or equal toMAX_MONEY. But all existing implementations parse this value as signed, and enforce the nonnegative constraint as a consensus check. Here,valueis defined as signed for consistency with these existing implementations. scriptPubKeyis the field encoding (including a leadingCompactSize) of thepk_scriptfield [bdr-txout] for the coin that is spent by the transparent input. For P2SH coins, this is different from theredeemScriptthat is committed to in ZIP 243 [zip-0243].
If the hash is for the signature over a Sapling Spend or an Orchard Action, txin_sig_digest is:
BLAKE2b-256("Zcash___TxInHash", [])
S.3: sapling_digest
This value is identical to the value that is specified for the transaction identifier.
S.4: orchard_digest
This value is identical to the value that is specified for the transaction identifier.
Block Header Changes
The non-malleable transaction identifier of this ZIP is used in the place of the earlier malleable transaction identifier. This change applies to the Merkle tree that is committed to by the hashMerkleRoot value. But, because of this change, hashMerkleRoot is not sufficient as a full commitment to the transaction data in the block, including witnesses.
As a result, it is necessary to add a new commitment to the block header. This commitment is the root of a Merkle tree. The leaves of this tree are transaction authorizing data commitments, as produced in Authorizing Data Commitment. The insertion order for this Merkle tree must be identical to the insertion order of transaction identifiers into the Merkle tree for hashMerkleRoot. Thus, in this Merkle tree and in the tree with the root hashMerkleRoot, the same path is a path to the same transaction.
This new commitment has the name hashAuthDataRoot. It is the root of a binary Merkle tree of transaction authorizing data commitments. The height of this tree is \(\mathsf{ceil(log_2(tx\_count))}\). The tree is padded with leaves that have the "null" hash value [0u8; 32]. Each non-leaf hash in this tree is a BLAKE2b-256 hash with the personalization string "ZcashAuthDatHash".
Note: \(\mathsf{log_2(tx\_count)}\) is well-defined, because \(\mathsf{tx\_count} > 0\). This is true because each block has a coinbase transaction.
A change to the block header format to make space for an additional commitment is somewhat invasive. Instead, the name and the meaning of the hashLightClientRoot field are changed. This field is described in ZIP 221 [zip-0221].
The name hashLightClientRoot changes to hashBlockCommitments. The value of this hash is the BLAKE2b-256 hash of these elements, with the personalization string "ZcashBlockCommit":
hashLightClientRoot (as described in ZIP 221) hashAuthDataRoot (as described below) terminator [0u8;32]
In this representation, the hashBlockCommitments value is a linked list of hashes. The list ends with arbitrary data. For a network upgrade, it can be necessary to include additional commitments in the block header. For such an upgrade, it is possible to replace this terminator with the hash of a newly defined structure. That structure ends in a similar terminator. Fully validating nodes must always use the entire structure that is defined by the latest activated protocol version that they support.
The purpose of the linked structure of this hash is extensibility for light clients. A light client can be connected to a third-party server that supports a later protocol version. We recommend that such a third party supplies a value to use in the place of the all-zeros terminator. With this value, the light client can validate the parts of the structure that are necessary for it.
The change to hashBlockCommitments occurs in the activation block of this ZIP. This is different from the hashLightClientRoot change.
The block header byte format and version stay the same in this ZIP.
Rationale
In S.2, we use the same personalization strings for fields that have matching fields in T.2. The purpose is easier reuse of their digests. In particular, the "no transparent inputs or outputs" case of S.2 is identical to the equivalent case in T.2. Thus, for fully shielded transactions, signature_digest is equal to txid_digest.
Several changes in this ZIP (relative to ZIP 243 [zip-0243]) were made for alignment with BIP 341 [bip-0341]:
- Because of a new consensus rule, the
hash_typefield is now restricted to one of a specific set of sighash type encodings. The rationale for this change comes from BIP 341 [bip-0341-hash_type].- Note: we do not define
SIGHASH_DEFAULT, because it is equivalent toSIGHASH_ALLand we prefer canonical encodings.
- Note: we do not define
- Two new commitments (
amounts_sig_digestandscriptpubkeys_sig_digest) were added. The purpose is to solve difficulties for a hardware wallet that signs transparent inputs. Withscriptpubkeys_sig_digest, the hardware wallet can find the subset of inputs that belong to it [bip-0341-scriptPubKey]. Withamounts_sig_digest, the transaction creator cannot lie to the hardware wallet about the transaction fee [bip-0341-amount]. Without these commitments, it is necessary to send to the hardware wallet each transaction that contains an outpoint that the signed transaction refers to. - The semantics of
sequence_sig_digestwere changed. Now it is a commitment tonSequence, also ifSIGHASH_SINGLEorSIGHASH_NONEis set. The rationale for this change comes from BIP 341 [bip-0341-nSequence]. - The semantics of
outputs_sig_digestwere changed with a new consensus rule. Because of this rule, a transparent input is rejected ifSIGHASH_SINGLEis set for it without a corresponding transparent output at the same index. There is no rationale for this change in BIP 341. But without this change, these inputs effectively usedSIGHASH_NONE, and this is silently misleading. - The semantics of
txin_sig_digestwere changed. Now it is always a commitment to thescriptPubKeyfield of the transparent coin that is spent. Before the change, it was a commitment to the script that was actually in execution at the time of thesignature_digestcalculation.- Thus the signature is a commitment to the entire committed script. In Taproot, it is thus possible to prove to a hardware wallet what (unused) execution paths exist [bip-0341-scriptPubKey]. There are no alternative execution paths for P2PKH (where the executed script is
scriptPubKey) or P2SH (wherescriptPubKeyis fully executed beforeredeemScript). For P2SH, we thus commit to the Hash160 digest of
redeemScript, in the place of the actual script. Note: the Bitcoin P2SH design depends entirely on the preimage resistance of Hash160. Without this property, anyone can spend the P2SH UTXO of another person with a preimage.It is also necessary to make sure that a collision attack is not possible. This property is true for the following reason. Even if an adversary can find a Hash160 collision, the adversary can use it only to change the
scriptSigfield of the input. A change to this field has no effect on the effecting data of the transaction. By definition, the transaction thus has the same effect under consensus. That is, the same inputs are spent and the same outputs are produced.
- Thus the signature is a commitment to the entire committed script. In Taproot, it is thus possible to prove to a hardware wallet what (unused) execution paths exist [bip-0341-scriptPubKey]. There are no alternative execution paths for P2PKH (where the executed script is
In a transaction that contains transparent inputs, signatures over Sapling Spends or Orchard Actions are commitments to the same data as for the transparent inputs. This data includes all the transparent input values. Without this commitment, a hardware wallet that signs only shielded inputs can have a similar difficulty. This occurs when the transaction also contains transparent inputs from a malicious other party. That party can lie about the values of its coins.
By contrast, binding signatures for shielded coinbase transactions continue to be over the transaction identifier, as for non-coinbase transactions without transparent inputs. This is necessary because coinbase transactions have a single "dummy" transparent input element. This element has no corresponding previous output for a commitment. This is also sufficient, because the data in that transparent input is of one of these two types:
- Data that is already bound elsewhere, that is, the block height. From NU5 activation, the block height is in
expiry_height. - Data that does not have to be bound to the shielded outputs (for example, miner-identifying information).
Reference implementation
Source errata
The source has these typos. This page has the repaired form.
- Line 548:
BLAKE2b-256(``ZTxIdPrevoutHash``, [])has reStructuredText literal marks in a literal block. The repaired form has quotation marks, as in section T.2a of the source. - Line 593:
BLAKE2b-256(``ZTxIdSequencHash``, [])has the same typo. The repaired form is in section T.2b of the source. - Line 614:
BLAKE2b-256(``ZTxIdOutputsHash``, [])has the same typo. The repaired form is in section T.2c of the source.
References
- [BCP14]
- Information on BCP 14 — "RFC 2119: Key words for use in RFCs to Indicate Requirement Levels" and "RFC 8174: Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words"
- [protocol-txnencoding]
- Zcash Protocol Specification, Version 2021.2.16 [NU5 proposal]. Section 7.1: Transaction Encoding and Consensus
- [zip-0200]
- ZIP 200: Network Upgrade Mechanism
- [zip-0221]
- ZIP 221: FlyClient - Consensus Layer Changes
- [zip-0076]
- ZIP 76: Transaction Signature Validation before Overwinter
- [zip-0143]
- ZIP 143: Transaction Signature Validation for Overwinter
- [zip-0243]
- ZIP 243: Transaction Signature Validation for Sapling
- [zip-0307]
- ZIP 307: Light Client Protocol for Payment Detection
- [bip-0341]
- BIP 341: Taproot: SegWit version 1 spending rules
- [bip-0341-hash_type]
- Why reject unknown hash_type values?
- [bip-0341-scriptPubKey]
- Why does the signature message commit to the scriptPubKey?
- [bip-0341-amount]
- Why does the signature message commit to the amounts of all transaction inputs?
- [bip-0341-nSequence]
- Why does the signature message commit to all input nSequence if SIGHASH_SINGLE or SIGHASH_NONE are set?
- [bdr-txout]
- Bitcoin Developer Reference. TxOut: A Transaction Output