From 24421925193cc2b702829dc92a3367ca28fe568e Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Mon, 3 Jan 2022 22:32:57 +0000
Subject: [PATCH 01/13] ZIP 244: Change semantics of `sequence_sig_digest`
Co-authored-by: Daira Hopwood
---
zip-0244.rst | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/zip-0244.rst b/zip-0244.rst
index f210c98e1..230cc1b9f 100644
--- a/zip-0244.rst
+++ b/zip-0244.rst
@@ -531,8 +531,7 @@ S.2b: sequence_sig_digest
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdSequencHash``.
-If the ``SIGHASH_ANYONECANPAY`` flag is not set, and the sighash type is neither
-``SIGHASH_SINGLE`` nor ``SIGHASH_NONE``::
+If the ``SIGHASH_ANYONECANPAY`` flag is not set::
identical to the value of ``sequence_digest`` as specified for the
transaction identifier in section T.2b.
@@ -736,6 +735,17 @@ happens in the block that activates this ZIP.
The block header byte format and version are not altered by this ZIP.
+=========
+Rationale
+=========
+
+Several changes in this ZIP (relative to ZIP 243 [#zip-0243]_) were made to
+align with BIP 341 [#bip-0341]_:
+
+- The semantics of ``sequence_sig_digest`` were changed, to commit to ``nSequence``
+ even if ``SIGHASH_SINGLE`` or ``SIGHASH_NONE`` is set. The rationale for this
+ change is inherited from BIP 341 [#bip-0341-nSequence]_.
+
========================
Reference implementation
========================
@@ -754,3 +764,5 @@ References
.. [#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-nSequence] `Why does the signature message commit to all input nSequence if SIGHASH_SINGLE or SIGHASH_NONE are set? `_
From daac926497146038cd69ac0cb206462a36188c26 Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Mon, 3 Jan 2022 23:30:55 +0000
Subject: [PATCH 02/13] ZIP 244: Add new S.2 commitments to input amounts and
scriptCodes
Co-authored-by: Daira Hopwood
---
zip-0244.rst | 65 +++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 54 insertions(+), 11 deletions(-)
diff --git a/zip-0244.rst b/zip-0244.rst
index 230cc1b9f..9a3e04ca0 100644
--- a/zip-0244.rst
+++ b/zip-0244.rst
@@ -503,10 +503,12 @@ The construction of each component below depends upon the values of the
This digest is a BLAKE2b-256 hash of the following values ::
- S.2a: prevouts_sig_digest (32-byte hash)
- S.2b: sequence_sig_digest (32-byte hash)
- S.2c: outputs_sig_digest (32-byte hash)
- S.2d: txin_sig_digest (32-byte hash)
+ S.2a: prevouts_sig_digest (32-byte hash)
+ S.2b: amounts_sig_digest (32-byte hash)
+ S.2c: script_codes_sig_digest (32-byte hash)
+ S.2d: sequence_sig_digest (32-byte hash)
+ S.2e: outputs_sig_digest (32-byte hash)
+ S.2f: txin_sig_digest (32-byte hash)
The personalization field of this hash is set to::
@@ -526,7 +528,37 @@ otherwise::
BLAKE2b-256(``ZTxIdPrevoutHash``, [])
-S.2b: sequence_sig_digest
+S.2b: amounts_sig_digest
+''''''''''''''''''''''''
+If the ``SIGHASH_ANYONECANPAY`` flag is not set, the value of
+``amounts_sig_digest`` is a BLAKE2b-256 hash of the concatenation of the 8-byte
+signed little-endian representations of all ``value`` fields [#bdr-txout]_ for
+the coins 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.2c: script_codes_sig_digest
+'''''''''''''''''''''''''''''
+If the ``SIGHASH_ANYONECANPAY`` flag is not set, the value of
+``script_codes_sig_digest`` is a BLAKE2b-256 hash of the concatenation of the
+field encodings (including leading ``CompactSize``) of all ``pk_script`` fields
+[#bdr-txout]_ for the coins spent by the transparent inputs to the transaction.
+
+The personalization field of this hash is set to::
+
+ "ZTxTrScriptsHash"
+
+If the ``SIGHASH_ANYONECANPAY`` flag is set, ``script_codes_sig_digest`` is::
+
+ BLAKE2b-256("ZTxTrScriptsHash", [])
+
+S.2d: sequence_sig_digest
'''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdSequencHash``.
@@ -540,7 +572,7 @@ otherwise::
BLAKE2b-256(``ZTxIdSequencHash``, [])
-S.2c: outputs_sig_digest
+S.2e: outputs_sig_digest
''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdOutputsHash``.
@@ -561,16 +593,16 @@ otherwise::
BLAKE2b-256(``ZTxIdOutputsHash``, [])
-S.2d: txin_sig_digest
+S.2f: txin_sig_digest
'''''''''''''''''''''
This is a BLAKE2b-256 hash of the following properties of the transparent input being
signed, initialized with the personalization field value ``Zcash___TxInHash`` (3
underscores)::
- S.2d.i: prevout (field encoding)
- S.2d.ii: script_code (field encoding)
- S.2d.iii: value (8-byte signed little-endian)
- S.2d.iv: nSequence (4-byte unsigned little-endian)
+ S.2f.i: prevout (field encoding)
+ S.2f.ii: script_code (field encoding)
+ S.2f.iii: value (8-byte signed little-endian)
+ S.2f.iv: nSequence (4-byte unsigned little-endian)
Note: ``value`` is defined in the consensus rules to be a nonnegative value <=
``MAX_MONEY``, but all existing implementations parse this value as signed and
@@ -742,6 +774,14 @@ Rationale
Several changes in this ZIP (relative to ZIP 243 [#zip-0243]_) were made to
align with BIP 341 [#bip-0341]_:
+- Two new commitments (``amounts_sig_digest`` and ``script_codes_sig_digest``)
+ were added, to address difficulties in the case of a hardware wallet signing
+ transparent inputs. ``script_codes_sig_digest`` helps the hardware wallet to
+ determine the subset of inputs belonging to it [#bip-0341-scriptPubKey]_.
+ ``amounts_sig_digest`` prevents the transaction creator from lying to the
+ hardware wallet about the transaction fee [#bip-0341-amount]_. Without these
+ commitments, the hardware wallet would need to be sent every transaction
+ containing an outpoint referenced in the transaction being signed.
- The semantics of ``sequence_sig_digest`` were changed, to commit to ``nSequence``
even if ``SIGHASH_SINGLE`` or ``SIGHASH_NONE`` is set. The rationale for this
change is inherited from BIP 341 [#bip-0341-nSequence]_.
@@ -765,4 +805,7 @@ References
.. [#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-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 `_
\ No newline at end of file
From c2585a4fc94329f1366b4d666af5a91380201b74 Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Mon, 3 Jan 2022 23:49:04 +0000
Subject: [PATCH 03/13] ZIP 244: Extend S.2 to be used for shielded signatures
Co-authored-by: Daira Hopwood
---
zip-0244.rst | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/zip-0244.rst b/zip-0244.rst
index 9a3e04ca0..ad33860ea 100644
--- a/zip-0244.rst
+++ b/zip-0244.rst
@@ -490,11 +490,7 @@ Identical to that specified for the transaction identifier.
S.2: transparent_sig_digest
```````````````````````````
-If we are producing a hash for the signature over a Sapling Spend or an Orchard Action,
-the value of ``transparent_sig_digest`` is identical to the value specified in section
-`T.2 <#t-2-transparent-digest>`_.
-
-If we are producing a hash for signature over a transparent input, the value of
+In the case that transparent inputs or outputs are present, the value of
``transparent_sig_digest`` depends upon the value of a ``hash_type`` flag as in ZIP 143
[#zip-0143]_.
@@ -514,6 +510,11 @@ The personalization field of this hash is set to::
"ZTxIdTranspaHash"
+In the case that the transaction has no transparent components,
+``transparent_sig_digest`` is ::
+
+ BLAKE2b-256("ZTxIdTranspaHash", [])
+
S.2a: prevouts_sig_digest
'''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
@@ -595,9 +596,10 @@ otherwise::
S.2f: txin_sig_digest
'''''''''''''''''''''
-This is a BLAKE2b-256 hash of the following properties of the transparent input being
-signed, initialized with the personalization field value ``Zcash___TxInHash`` (3
-underscores)::
+If we are producing a hash for the signature over a transparent input, the value
+of ``txin_sig_digest`` is a BLAKE2b-256 hash of the following properties of the
+transparent input being signed, initialized with the personalization field value
+``Zcash___TxInHash`` (3 underscores)::
S.2f.i: prevout (field encoding)
S.2f.ii: script_code (field encoding)
@@ -609,6 +611,11 @@ Note: ``value`` is defined in the consensus rules to be a nonnegative value <=
enforce the nonnegative constraint as a consensus check. It is defined as signed
here for consistency with those existing implementations.
+If we are producing a hash for the signature over a Sapling Spend or an Orchard
+Action, ``txin_sig_digest`` is::
+
+ BLAKE2b-256("Zcash___TxInHash", [])
+
S.3: sapling_digest
```````````````````
Identical to that specified for the transaction identifier.
@@ -771,6 +778,12 @@ The block header byte format and version are not altered by this ZIP.
Rationale
=========
+In S.2, we use the same personalization strings for fields that have matching
+fields in T.2, in order to facilitate 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 purely-shielded transactions, ``signature_digest`` is
+equal to ``txid_digest``.
+
Several changes in this ZIP (relative to ZIP 243 [#zip-0243]_) were made to
align with BIP 341 [#bip-0341]_:
@@ -786,6 +799,13 @@ align with BIP 341 [#bip-0341]_:
even if ``SIGHASH_SINGLE`` or ``SIGHASH_NONE`` is set. The rationale for this
change is inherited from BIP 341 [#bip-0341-nSequence]_.
+Signatures over Sapling Spends or Orchard Actions commit to the same data as for
+transparent inputs, in order to ensure that they commit to all transparent input
+values. Without this commitment, there is a similar difficulty in the case where
+a hardware wallet is only signing shielded inputs, in a transaction that also
+contains transparent inputs from a malicious other party (where that party lies
+about their coins' values).
+
========================
Reference implementation
========================
From 89f46c2d99199525d2ee272b3328dc615e5c6c0d Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Tue, 4 Jan 2022 00:20:49 +0000
Subject: [PATCH 04/13] ZIP 244: Add hash_type to the S.2 digest input
This was committed to by the ZIP 143 and ZIP 243 transaction digest
algorithms, but had been accidentally omitted from ZIP 244. It is not a
security issue because the encoding of each layer uses sentinel values,
meaning we were indirectly committing to hash_type (unlike BIP 341, which
conditionally omits commitments based on hash_type and therefore needs to
directly commit to it). But not committing directly to hash_type would
complicate security analysis of the digest, and including it keeps the
transparent part of ZIP 244 closer to BIP 341.
We additionally import two new consensus rules from BIP 341 that apply
to hash_type.
Co-authored-by: Daira Hopwood
Co-authored-by: Kris Nuttycom
---
zip-0244.rst | 66 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 19 deletions(-)
diff --git a/zip-0244.rst b/zip-0244.rst
index ad33860ea..e5fda9d71 100644
--- a/zip-0244.rst
+++ b/zip-0244.rst
@@ -491,20 +491,20 @@ Identical to that specified for the transaction identifier.
S.2: transparent_sig_digest
```````````````````````````
In the case that transparent inputs or outputs are present, the value of
-``transparent_sig_digest`` depends upon the value of a ``hash_type`` flag as in ZIP 143
-[#zip-0143]_.
+``transparent_sig_digest`` depends upon the value of a ``hash_type`` flag.
The construction of each component below depends upon the values of the
-``hash_type`` flag bits. Each component will be described separately
+``hash_type`` flag bits. Each component will be described separately.
This digest is a BLAKE2b-256 hash of the following values ::
- S.2a: prevouts_sig_digest (32-byte hash)
- S.2b: amounts_sig_digest (32-byte hash)
- S.2c: script_codes_sig_digest (32-byte hash)
- S.2d: sequence_sig_digest (32-byte hash)
- S.2e: outputs_sig_digest (32-byte hash)
- S.2f: txin_sig_digest (32-byte hash)
+ S.2a: hash_type (1 byte)
+ S.2b: prevouts_sig_digest (32-byte hash)
+ S.2c: amounts_sig_digest (32-byte hash)
+ S.2d: script_codes_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::
@@ -515,7 +515,22 @@ In the case that the transaction has no transparent components,
BLAKE2b-256("ZTxIdTranspaHash", [])
-S.2a: prevouts_sig_digest
+S.2a: hash_type
+'''''''''''''''
+This is an 8-bit unsigned value. The ``SIGHASH`` encodings from the legacy
+script system are reused: one of ``SIGHASH_ALL``, ``SIGHASH_NONE``, and
+``SIGHASH_SINGLE``, with or without the ``SIGHASH_ANYONECANPAY`` flag. The
+following restrictions apply, which cause validation failure if violated:
+
+- Using any undefined ``hash_type`` (not 0x01, 0x02, 0x03, 0x81, 0x82, or 0x83).
+- Using ``SIGHASH_SINGLE`` without a "corresponding output" (an output with the
+ same index as the input being verified).
+
+If we are producing a hash for the signature over a Sapling Spend or an Orchard
+Action, ``hash_type`` is set to ``SIGHASH_ALL``, and is not encoded anywhere in
+the transaction's authorizing data.
+
+S.2b: prevouts_sig_digest
'''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdPrevoutHash``.
@@ -529,7 +544,7 @@ otherwise::
BLAKE2b-256(``ZTxIdPrevoutHash``, [])
-S.2b: amounts_sig_digest
+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 the concatenation of the 8-byte
@@ -544,7 +559,7 @@ If the ``SIGHASH_ANYONECANPAY`` flag is set, ``amounts_sig_digest`` is::
BLAKE2b-256("ZTxTrAmountsHash", [])
-S.2c: script_codes_sig_digest
+S.2d: script_codes_sig_digest
'''''''''''''''''''''''''''''
If the ``SIGHASH_ANYONECANPAY`` flag is not set, the value of
``script_codes_sig_digest`` is a BLAKE2b-256 hash of the concatenation of the
@@ -559,7 +574,7 @@ If the ``SIGHASH_ANYONECANPAY`` flag is set, ``script_codes_sig_digest`` is::
BLAKE2b-256("ZTxTrScriptsHash", [])
-S.2d: sequence_sig_digest
+S.2e: sequence_sig_digest
'''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdSequencHash``.
@@ -573,7 +588,7 @@ otherwise::
BLAKE2b-256(``ZTxIdSequencHash``, [])
-S.2e: outputs_sig_digest
+S.2f: outputs_sig_digest
''''''''''''''''''''''''
This is a BLAKE2b-256 hash initialized with the personalization field value
``ZTxIdOutputsHash``.
@@ -594,17 +609,17 @@ otherwise::
BLAKE2b-256(``ZTxIdOutputsHash``, [])
-S.2f: txin_sig_digest
+S.2g: txin_sig_digest
'''''''''''''''''''''
If we are producing a hash for the signature over a transparent input, the value
of ``txin_sig_digest`` is a BLAKE2b-256 hash of the following properties of the
transparent input being signed, initialized with the personalization field value
``Zcash___TxInHash`` (3 underscores)::
- S.2f.i: prevout (field encoding)
- S.2f.ii: script_code (field encoding)
- S.2f.iii: value (8-byte signed little-endian)
- S.2f.iv: nSequence (4-byte unsigned little-endian)
+ S.2g.i: prevout (field encoding)
+ S.2g.ii: script_code (field encoding)
+ S.2g.iii: value (8-byte signed little-endian)
+ S.2g.iv: nSequence (4-byte unsigned little-endian)
Note: ``value`` is defined in the consensus rules to be a nonnegative value <=
``MAX_MONEY``, but all existing implementations parse this value as signed and
@@ -787,6 +802,13 @@ equal to ``txid_digest``.
Several changes in this ZIP (relative to ZIP 243 [#zip-0243]_) were made to
align with BIP 341 [#bip-0341]_:
+- The ``hash_type`` field is now restricted via a new consensus rule to be one
+ of a specific set of sighash type encodings. The rationale for this change is
+ inherited from BIP 341 [#bip-0341-hash_type]_.
+
+ - Note however that we do not define ``SIGHASH_DEFAULT``, as it is equivalent
+ to ``SIGHASH_ALL``, and we prefer the encodings to be canonical.
+
- Two new commitments (``amounts_sig_digest`` and ``script_codes_sig_digest``)
were added, to address difficulties in the case of a hardware wallet signing
transparent inputs. ``script_codes_sig_digest`` helps the hardware wallet to
@@ -798,6 +820,11 @@ align with BIP 341 [#bip-0341]_:
- The semantics of ``sequence_sig_digest`` were changed, to commit to ``nSequence``
even if ``SIGHASH_SINGLE`` or ``SIGHASH_NONE`` is set. The rationale for this
change is inherited from BIP 341 [#bip-0341-nSequence]_.
+- The semantics of ``outputs_sig_digest`` were changed, via a new consensus rule
+ that rejects transparent inputs for which ``SIGHASH_SINGLE`` is set without a
+ corresponding transparent output at the same index. BIP 341 does not give a
+ rationale for this change, but without it these inputs were effectively using
+ ``SIGHASH_NONE``, which is silently misleading.
Signatures over Sapling Spends or Orchard Actions commit to the same data as for
transparent inputs, in order to ensure that they commit to all transparent input
@@ -825,6 +852,7 @@ References
.. [#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? `_
From 68b6147c02bc5412948b9411cb38e0ab4d5f5ffc Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Tue, 4 Jan 2022 00:52:07 +0000
Subject: [PATCH 05/13] ZIP 244: Reverse order of value and script_code in
txin_sig_digest
This matches the order in which they are committed to in BIP 341 (and
also at the transaction level in S.2).
---
zip-0244.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/zip-0244.rst b/zip-0244.rst
index e5fda9d71..59612be3a 100644
--- a/zip-0244.rst
+++ b/zip-0244.rst
@@ -617,8 +617,8 @@ transparent input being signed, initialized with the personalization field value
``Zcash___TxInHash`` (3 underscores)::
S.2g.i: prevout (field encoding)
- S.2g.ii: script_code (field encoding)
- S.2g.iii: value (8-byte signed little-endian)
+ S.2g.ii: value (8-byte signed little-endian)
+ S.2g.iii: script_code (field encoding)
S.2g.iv: nSequence (4-byte unsigned little-endian)
Note: ``value`` is defined in the consensus rules to be a nonnegative value <=
From 2671741042bd2d2fca57ffa0db267385d9de729a Mon Sep 17 00:00:00 2001
From: Jack Grigg
Date: Tue, 4 Jan 2022 00:54:16 +0000
Subject: [PATCH 06/13] ZIP 244: Regenerate HTML
---
zip-0244.html | 127 +++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 109 insertions(+), 18 deletions(-)
diff --git a/zip-0244.html b/zip-0244.html
index c0c297b99..90d82ee29 100644
--- a/zip-0244.html
+++ b/zip-0244.html
@@ -254,17 +254,29 @@
Identical to that specified for the transaction identifier.
S.2: transparent_sig_digest
- If we are producing a hash for the signature over a Sapling Spend or an Orchard Action, the value of transparent_sig_digest
is identical to the value specified in section T.2.
- If we are producing a hash for signature over a transparent input, the value of transparent_sig_digest
depends upon the value of a hash_type
flag as in ZIP 143 .
- The construction of each component below depends upon the values of the hash_type
flag bits. Each component will be described separately
+ In the case that transparent inputs or outputs are present, the value of transparent_sig_digest
depends upon the value of a hash_type
flag.
+ The construction of each component below depends upon the values of the hash_type
flag bits. Each component will be described separately.
This digest is a BLAKE2b-256 hash of the following values
- S.2a: prevouts_sig_digest (32-byte hash)
-S.2b: sequence_sig_digest (32-byte hash)
-S.2c: outputs_sig_digest (32-byte hash)
-S.2d: txin_sig_digest (32-byte hash)
+ S.2a: hash_type (1 byte)
+S.2b: prevouts_sig_digest (32-byte hash)
+S.2c: amounts_sig_digest (32-byte hash)
+S.2d: script_codes_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: prevouts_sig_digest
+ In the case that the transaction has no transparent components, transparent_sig_digest
is
+ BLAKE2b-256("ZTxIdTranspaHash", [])
+ S.2a: hash_type
+ This is an 8-bit unsigned value. The SIGHASH
encodings from the legacy script system are reused: one of SIGHASH_ALL
, SIGHASH_NONE
, and SIGHASH_SINGLE
, with or without the SIGHASH_ANYONECANPAY
flag. The following restrictions apply, which cause validation failure if violated:
+
+ - Using any undefined
hash_type
(not 0x01, 0x02, 0x03, 0x81, 0x82, or 0x83).
+ - Using
SIGHASH_SINGLE
without a "corresponding output" (an output with the same index as the input being verified).
+
+ If we are producing a hash for the signature over a Sapling Spend or an Orchard Action, hash_type
is set to SIGHASH_ALL
, and is not encoded anywhere in the transaction's authorizing data.
+
+ S.2b: prevouts_sig_digest
This is a BLAKE2b-256 hash initialized with the personalization field value ZTxIdPrevoutHash
.
If the SIGHASH_ANYONECANPAY
flag is not set:
identical to the value of ``prevouts_digest`` as specified for the
@@ -272,15 +284,29 @@
otherwise:
BLAKE2b-256(``ZTxIdPrevoutHash``, [])
- S.2b: sequence_sig_digest
+ 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 the concatenation of the 8-byte signed little-endian representations of all value
fields for the coins 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: script_codes_sig_digest
+ If the SIGHASH_ANYONECANPAY
flag is not set, the value of script_codes_sig_digest
is a BLAKE2b-256 hash of the concatenation of the field encodings (including leading CompactSize
) of all pk_script
fields for the coins spent by the transparent inputs to the transaction.
+ The personalization field of this hash is set to:
+ "ZTxTrScriptsHash"
+ If the SIGHASH_ANYONECANPAY
flag is set, script_codes_sig_digest
is:
+ BLAKE2b-256("ZTxTrScriptsHash", [])
+
+ S.2e: sequence_sig_digest
This is a BLAKE2b-256 hash initialized with the personalization field value ZTxIdSequencHash
.
- If the SIGHASH_ANYONECANPAY
flag is not set, and the sighash type is neither SIGHASH_SINGLE
nor SIGHASH_NONE
:
+ If the SIGHASH_ANYONECANPAY
flag is not set:
identical to the value of ``sequence_digest`` as specified for the
transaction identifier in section T.2b.
otherwise:
BLAKE2b-256(``ZTxIdSequencHash``, [])
- S.2c: outputs_sig_digest
+ S.2f: outputs_sig_digest
This is a BLAKE2b-256 hash initialized with the personalization field value ZTxIdOutputsHash
.
If the sighash type is neither SIGHASH_SINGLE
nor SIGHASH_NONE
:
identical to the value of ``outputs_digest`` as specified for the
@@ -291,13 +317,15 @@
otherwise:
BLAKE2b-256(``ZTxIdOutputsHash``, [])
- S.2d: txin_sig_digest
- This is a BLAKE2b-256 hash of the following properties of the transparent input being signed, initialized with the personalization field value Zcash___TxInHash
(3 underscores):
- S.2d.i: prevout (field encoding)
-S.2d.ii: script_code (field encoding)
-S.2d.iii: value (8-byte signed little-endian)
-S.2d.iv: nSequence (4-byte unsigned little-endian)
+ S.2g: txin_sig_digest
+ If we are producing a hash for the signature over a transparent input, the value of txin_sig_digest
is a BLAKE2b-256 hash of the following properties of the transparent input being signed, initialized with the personalization field value Zcash___TxInHash
(3 underscores):
+ S.2g.i: prevout (field encoding)
+S.2g.ii: value (8-byte signed little-endian)
+S.2g.iii: script_code (field encoding)
+S.2g.iv: nSequence (4-byte unsigned little-endian)
Note: value
is defined in the consensus rules to be a nonnegative value <= MAX_MONEY
, but all existing implementations parse this value as signed and enforce the nonnegative constraint as a consensus check. It is defined as signed here for consistency with those existing implementations.
+ If we are producing a hash for the signature over a Sapling Spend or an Orchard Action, txin_sig_digest
is:
+ BLAKE2b-256("Zcash___TxInHash", [])
S.3: sapling_digest
@@ -366,7 +394,7 @@
is well-defined because
\(\mathsf{tx\_count} > 0\)
, due to the coinbase transaction in each block. Non-leaf hashes in this tree are BLAKE2b-256 hashes personalized by the string "ZcashAuthDatHash"
.
- Changing the block header format to allow space for an additional commitment is somewhat invasive. Instead, the name and meaning of the hashLightClientRoot
field, described in ZIP 221 , is changed.
+ Changing the block header format to allow space for an additional commitment is somewhat invasive. Instead, the name and meaning of the hashLightClientRoot
field, described in ZIP 221 , is changed.
hashLightClientRoot
is renamed to hashBlockCommitments
. The value of this hash is the BLAKE2b-256 hash personalized by the string "ZcashBlockCommit"
of the following elements:
hashLightClientRoot (as described in ZIP 221)
hashAuthDataRoot (as described below)
@@ -377,6 +405,21 @@
The block header byte format and version are not altered by this ZIP.
+ Rationale
+ In S.2, we use the same personalization strings for fields that have matching fields in T.2, in order to facilitate 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 purely-shielded transactions, signature_digest
is equal to txid_digest
.
+ Several changes in this ZIP (relative to ZIP 243 ) were made to align with BIP 341 :
+
+ - The
hash_type
field is now restricted via a new consensus rule to be one of a specific set of sighash type encodings. The rationale for this change is inherited from BIP 341 .
+
+ - Note however that we do not define
SIGHASH_DEFAULT
, as it is equivalent to SIGHASH_ALL
, and we prefer the encodings to be canonical.
+
+
+ - Two new commitments (
amounts_sig_digest
and script_codes_sig_digest
) were added, to address difficulties in the case of a hardware wallet signing transparent inputs. script_codes_sig_digest
helps the hardware wallet to determine the subset of inputs belonging to it . amounts_sig_digest
prevents the transaction creator from lying to the hardware wallet about the transaction fee . Without these commitments, the hardware wallet would need to be sent every transaction containing an outpoint referenced in the transaction being signed.
+ - The semantics of
sequence_sig_digest
were changed, to commit to nSequence
even if SIGHASH_SINGLE
or SIGHASH_NONE
is set. The rationale for this change is inherited from BIP 341 .
+ - The semantics of
outputs_sig_digest
were changed, via a new consensus rule that rejects transparent inputs for which SIGHASH_SINGLE
is set without a corresponding transparent output at the same index. BIP 341 does not give a rationale for this change, but without it these inputs were effectively using SIGHASH_NONE
, which is silently misleading.
+
+ Signatures over Sapling Spends or Orchard Actions commit to the same data as for transparent inputs, in order to ensure that they commit to all transparent input values. Without this commitment, there is a similar difficulty in the case where a hardware wallet is only signing shielded inputs, in a transaction that also contains transparent inputs from a malicious other party (where that party lies about their coins' values).
+
Reference implementation