zips/zip-0230.rst

353 lines
37 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

::
ZIP: 230
Title: Version 6 Transaction Format
Owners: Daira-Emma Hopwood <daira@electriccoin.co>
Jack Grigg <jack@electriccoin.co>
Sean Bowe <sean@electriccoin.co>
Kris Nuttycombe <kris@electriccoin.co>
Pablo Kogan <pablo@qed-it.com>
Vivek Arte <vivek@qed-it.com>
Original-Authors: Greg Pfeil
Deirdre Connolly
Credits: Ying Tong Lai
Status: Draft
Category: Consensus
Created: 2023-04-18
License: MIT
Discussions-To: <https://github.com/zcash/zips/issues/686>
Terminology
===========
The key words "MUST", "SHOULD", and "MAY" in this document are to be interpreted as
described in BCP 14 [#BCP14]_ when, and only when, they appear in all capitals.
The character § is used when referring to sections of the Zcash Protocol Specification
[#protocol]_.
Abstract
========
This proposal defines a new Zcash peer-to-peer transaction format, which includes
data that supports the Orchard-ZSA protocol and all operations related to Zcash
Shielded Assets (ZSAs). The new format adds and describes new fields containing
ZSA-specific elements. Like the existing v5 transaction format, it keeps well-bounded
regions of the serialized form to serve each pool of funds.
This ZIP also depends upon and defines modifications to the computation of the values
**TxId Digest**, **Signature Digest**, and **Authorizing Data Commitment** defined by
ZIP 244 [#zip-0244]_.
Motivation
==========
The Orchard-ZSA protocol requires serialized data elements that are distinct from
any previous Zcash transaction. Since ZIP 244 was activated in NU5, the
v5 and later serialized transaction formats are not consensus-critical.
Thus, this ZIP defines format that can easily accommodate future extensions,
where elements or a given pool are kept separate.
Requirements
============
The new format must fully support the Orchard-ZSA protocol.
The new format should lend itself to future extension or pruning to add or remove
value pools.
The computation of the non-malleable transaction identifier hash must include all
newly incorporated elements except those that attest to transaction validity.
The computation of the commitment to authorizing data for a transaction must include
all newly incorporated elements that attest to transaction validity.
Non-requirements
================
More general forms of extensibility, such as definining a key/value format that
allows for parsers that are unaware of some components, are not required.
Specification
=============
All fields in this specification are encoded as little-endian.
The Zcash transaction format for transaction version 6 is as follows:
Transaction Format
------------------
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+====================================+==========================+========================================+===========================================================================+
| **Common Transaction Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``4`` |``header`` |``uint32`` |Contains: |
| | | | * ``fOverwintered`` flag (bit 31, always set) |
| | | | * ``version`` (bits 30 .. 0) transaction version. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``4`` |``nVersionGroupId`` |``uint32`` |Version group ID (nonzero). |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``4`` |``nConsensusBranchId`` |``uint32`` |Consensus branch ID (nonzero). |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``4`` |``lock_time`` |``uint32`` |Unix-epoch UTC time or block height, encoded as in Bitcoin. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``4`` |``nExpiryHeight`` |``uint32`` |A block height in the range {1 .. 499999999} after which |
| | | |the transaction will expire, or 0 to disable expiry. |
| | | |[ZIP-203] |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``8`` |``fee`` |``int64`` |The fee to be paid by this transaction, in zatoshis. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| **Transparent Transaction Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``tx_in_count`` |``compactSize`` |Number of transparent inputs in ``tx_in``. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``tx_in`` |``tx_in`` |Transparent inputs, encoded as in Bitcoin. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``tx_out_count`` |``compactSize`` |Number of transparent outputs in ``tx_out``. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``tx_out`` |``tx_out`` |Transparent outputs, encoded as in Bitcoin. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| **Sapling Transaction Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``nSpendsSapling`` |``compactSize`` |Number of Sapling Spend descriptions in ``vSpendsSapling``. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``96 * nSpendsSapling`` |``vSpendsSapling`` |``SpendDescriptionV6[nSpendsSapling]`` |A sequence of Sapling Spend descriptions, encoded per |
| | | |protocol §7.3 Spend Description Encoding and Consensus. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``nOutputsSapling`` |``compactSize`` |Number of Sapling Output Decriptions in ``vOutputsSapling``. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``756 * nOutputsSapling`` |``vOutputsSapling`` |``OutputDescriptionV6[nOutputsSapling]``|A sequence of Sapling Output descriptions, encoded per |
| | | |protocol §7.4 Output Description Encoding and Consensus. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``8`` |``valueBalanceSapling`` |``int64`` |The net value of Sapling Spends minus Outputs |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``32`` |``anchorSapling`` |``byte[32]`` |A root of the Sapling note commitment tree |
| | | |at some block height in the past. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``192 * nSpendsSapling`` |``vSpendProofsSapling`` |``byte[192 * nSpendsSapling]`` |Encodings of the zk-SNARK proofs for each Sapling Spend. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``64 * nSpendsSapling`` |``vSpendAuthSigsSapling`` |``byte[64 * nSpendsSapling]`` |Authorizing signatures for each Sapling Spend. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``192 * nOutputsSapling`` |``vOutputProofsSapling`` |``byte[192 * nOutputsSapling]`` |Encodings of the zk-SNARK proofs for each Sapling Output. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``64`` |``bindingSigSapling`` |``byte[64]`` |A Sapling binding signature on the SIGHASH transaction hash. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| **Orchard-ZSA Transaction Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``nActionsOrchard`` |``compactSize`` |The number of Orchard-ZSA Action descriptions in |
| | | |``vActionsOrchard``. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``852 * nActionsOrchard`` |``vActionsOrchard`` |``OrchardZsaAction[nActionsOrchard]`` |A sequence of Orchard-ZSA Action descriptions, encoded per |
| | | |the `Orchard-ZSA Action Description Encoding`. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``1`` |``flagsOrchard`` |``byte`` |An 8-bit value representing a set of flags. Ordered from LSB to MSB: |
| | | | * ``enableSpendsOrchard`` |
| | | | * ``enableOutputsOrchard`` |
| | | | * ``enableZSAs`` |
| | | | * The remaining bits are set to :math:`0\!`. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``8`` |``valueBalanceOrchard`` |``int64`` |The net value of Orchard spends minus outputs. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``32`` |``anchorOrchard`` |``byte[32]`` |A root of the Orchard note commitment tree at some block |
| | | |height in the past. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``sizeProofsOrchardZSA`` |``compactSize`` |Length in bytes of ``proofsOrchardZSA``. Value is **(TO UPDATE)** |
| | | |:math:`2720 + 2272 \cdot \mathtt{nActionsOrchard}\!`. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``sizeProofsOrchardZSA`` |``proofsOrchardZSA`` |``byte[sizeProofsOrchardZSA]`` |Encoding of aggregated zk-SNARK proofs for Orchard-ZSA Actions. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``64 * nActionsOrchard`` |``vSpendAuthSigsOrchard`` |``byte[64 * nActionsOrchard]`` |Authorizing signatures for each Orchard-ZSA Action. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``64`` |``bindingSigOrchard`` |``byte[64]`` |An Orchard binding signature on the SIGHASH transaction hash. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| **Orchard-ZSA Burn Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| ``varies`` | ``nAssetBurn`` | ``compactSize`` | The number of Assets burnt. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| ``40 * nAssetBurn`` | ``vAssetBurn`` | ``AssetBurn[nAssetBurn]`` | A sequence of Asset Burn descriptions, |
| | | | encoded per `Orchard-ZSA Asset Burn Description`_. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
| **Orchard-ZSA Issuance Fields** |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``varies`` |``nIssueActions`` |``compactSize`` |The number of issuance actions in the bundle. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``IssueActionSize * nIssueActions`` |``vIssueActions`` |``IssueAction[nIssueActions]`` |A sequence of issuance action descriptions, where IssueActionSize is |
| | | |the size, in bytes, of an IssueAction description. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``32`` |``ik`` |``byte[32]`` |The issuance validating key of the issuer, used to validate the signature. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
|``64`` |``issueAuthSig`` |``byte[64]`` |The signature of the transaction SIGHASH, signed by the issuer, |
| | | |validated as in Issuance Authorization Signature Scheme [#zip-0227]_. |
+------------------------------------+--------------------------+----------------------------------------+---------------------------------------------------------------------------+
* The fields ``valueBalanceSapling`` and ``bindingSigSapling`` are present if and only if
:math:`\mathtt{nSpendsSapling} + \mathtt{nOutputsSapling} > 0\!`. If ``valueBalanceSapling``
is not present, then :math:`\mathsf{v^{balanceSapling}}`` is defined to be :math:`0\!`.
* The field ``anchorSapling`` is present if and only if :math:`\mathtt{nSpendsSapling} > 0\!`.
* The fields ``flagsOrchard``, ``valueBalanceOrchard``, ``anchorOrchard``,
``sizeProofsOrchardZSA``, ``proofsOrchardZSA``, and ``bindingSigOrchard`` are present if and
only if :math:`\mathtt{nActionsOrchard} > 0\!`. If ``valueBalanceOrchard`` is not present,
then :math:`\mathsf{v^{balanceOrchard}}` is defined to be :math:`0\!`.
* The elements of ``vSpendProofsSapling`` and ``vSpendAuthSigsSapling`` have a 1:1
correspondence to the elements of ``vSpendsSapling`` and MUST be ordered such that the
proof or signature at a given index corresponds to the ``SpendDescriptionV6`` at the
same index.
* The elements of ``vOutputProofsSapling`` have a 1:1 correspondence to the elements of
``vOutputsSapling`` and MUST be ordered such that the proof at a given index corresponds
to the ``OutputDescriptionV6`` at the same index.
* The proofs aggregated in ``proofsOrchardZSA``, and the elements of
``vSpendAuthSigsOrchard``, each have a 1:1 correspondence to the elements of
``vActionsOrchard`` and MUST be ordered such that the proof or signature at a given
index corresponds to the ``OrchardZsaAction`` at the same index.
* For coinbase transactions, the ``enableSpendsOrchard`` and ``enableZSAs`` bits MUST be set to :math:`0\!`.
The encodings of ``tx_in``, and ``tx_out`` are as in a version 4 transaction (i.e.
unchanged from Canopy). The encodings of ``SpendDescriptionV6``, ``OutputDescriptionV6``
, ``OrchardZsaAction``, ``AssetBurn`` and ``IssueAction`` are described below. The encoding of Sapling Spends and Outputs has
changed relative to prior versions in order to better separate data that describe the
effects of the transaction from the proofs of and commitments to those effects, and for
symmetry with this separation in the Orchard-related parts of the transaction format.
Sapling Spend Description (``SpendDescriptionV6``)
--------------------------------------------------
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=============================+==========================+======================================+============================================================+
|``32`` |``cv`` |``byte[32]`` |A value commitment to the net value of the input note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``nullifier`` |``byte[32]`` |The nullifier of the input note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``rk`` |``byte[32]`` |The randomized validating key for the element of |
| | | |spendAuthSigsSapling corresponding to this Spend. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
The encodings of each of these elements are defined in §7.3 Spend Description Encoding
and Consensus of the Zcash Protocol Specification [#protocol-spenddesc]_.
Sapling Output Description (``OutputDescriptionV6``)
----------------------------------------------------
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=============================+==========================+======================================+============================================================+
|``32`` |``cv`` |``byte[32]`` |A value commitment to the net value of the output note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``cmu`` |``byte[32]`` |The :math:`u\!`-coordinate of the note commitment for the |
| | | |output note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``ephemeralKey`` |``byte[32]`` |An encoding of an ephemeral Jubjub public key. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``580`` |``encCiphertext`` |``byte[580]`` |The encrypted contents of the note plaintext. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``80`` |``outCiphertext`` |``byte[80]`` |The encrypted contents of the byte string created by |
| | | |concatenation of the transmission key with the ephemeral |
| | | |secret key. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
The encodings of each of these elements are defined in §7.4 Output Description Encoding
and Consensus of the Zcash Protocol Specification [#protocol-outputdesc]_.
Orchard-ZSA Action Description (``OrchardZsaAction``)
-----------------------------------------------------
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=============================+==========================+======================================+============================================================+
|``32`` |``cv`` |``byte[32]`` |A value commitment to the net value of the input note minus |
| | | |the output note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``nullifier`` |``byte[32]`` |The nullifier of the input note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``rk`` |``byte[32]`` |The randomized validating key for the element of |
| | | |spendAuthSigsOrchard corresponding to this Action. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``cmx`` |``byte[32]`` |The :math:`x\!`-coordinate of the note commitment for the |
| | | |output note. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``32`` |``ephemeralKey`` |``byte[32]`` |An encoding of an ephemeral Pallas public key |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``612`` |``encCiphertext`` |``byte[580]`` |The encrypted contents of the note plaintext. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
|``80`` |``outCiphertext`` |``byte[80]`` |The encrypted contents of the byte string created by |
| | | |concatenation of the transmission key with the ephemeral |
| | | |secret key. |
+-----------------------------+--------------------------+--------------------------------------+------------------------------------------------------------+
The encodings of each of these elements are defined in §7.5 Action Description Encoding
and Consensus of the Zcash Protocol Specification [#protocol-actiondesc]_.
Orchard-ZSA Asset Burn Description
----------------------------------
An Orchard-ZSA Asset Burn description is encoded in a transaction as an instance of an ``AssetBurn`` type:
+-------+---------------+-----------------------------+--------------------------------------------------------------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=======+===============+=============================+====================================================================================================================+
| 32 | ``AssetBase`` | ``byte[32]`` | For the Orchard-based ZSA protocol, this is the encoding of the Asset Base :math:`\mathsf{AssetBase^{Orchard}}\!`. |
+-------+---------------+-----------------------------+--------------------------------------------------------------------------------------------------------------------+
| 8 | ``valueBurn`` | :math:`\{1 .. 2^{64} - 1\}` | The amount being burnt. |
+-------+---------------+-----------------------------+--------------------------------------------------------------------------------------------------------------------+
The encodings of each of these elements are defined in ZIP 226 [#zip-0226]_.
Issuance Action Description (``IssueAction``)
---------------------------------------------
An issuance action, ``IssueAction``, is the instance of issuing a specific Custom Asset, and contains the following fields:
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=============================+==========================+===========================================+=====================================================================+
|``2`` |``assetDescSize`` |``byte`` |The length of the asset description string in bytes. |
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
|``assetDescSize`` |``asset_desc`` |``byte[assetDescSize]`` |A byte sequence of length ``assetDescSize`` bytes which SHOULD be a |
| | | |well-formed UTF-8 code unit sequence according to Unicode 15.0.0 |
| | | |or later. |
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
|``varies`` |``nNotes`` |``compactSize`` |The number of notes in the issuance action. |
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
|``noteSize * nNotes`` |``vNotes`` |``Note[nNotes]`` |A sequence of note descriptions within the issuance action, |
| | | |where ``noteSize`` is the size, in bytes, of a Note. |
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
|``1`` |``flagsIssuance`` |``byte`` |An 8-bit value representing a set of flags. Ordered from LSB to MSB: |
| | | | * :math:`\mathsf{finalize}` |
| | | | * The remaining bits are set to :math:`0\!`. |
+-----------------------------+--------------------------+-------------------------------------------+---------------------------------------------------------------------+
The encodings of each of these elements are defined in ZIP 227 [#zip-0227]_.
Reference implementation
========================
TODO
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" <https://www.rfc-editor.org/info/bcp14>`_
.. [#protocol] `Zcash Protocol Specification, Version 2023.4.0 or later [NU5 proposal] <protocol/protocol.pdf>`_
.. [#protocol-spenddesc] `Zcash Protocol Specification, Version 2023.4.0 [NU5 proposal]. Section 4.4: Spend Descriptions <protocol/protocol.pdf#spenddesc>`_
.. [#protocol-outputdesc] `Zcash Protocol Specification, Version 2023.4.0 [NU5 proposal]. Section 4.5: Output Descriptions <protocol/protocol.pdf#outputdesc>`_
.. [#protocol-actiondesc] `Zcash Protocol Specification, Version 2023.4.0 [NU5 proposal]. Section 4.6: Action Descriptions <protocol/protocol.pdf#actiondesc>`_
.. [#zip-0226] `ZIP 226: Transfer and Burn of Zcash Shielded Assets <https://qed-it.github.io/zips/zip-0226>`_
.. [#zip-0227] `ZIP 227: Issuance of Zcash Shielded Assets <https://qed-it.github.io/zips/zip-0227>`_
.. [#zip-0244] `ZIP 244: Transaction Identifier Non-Malleability <zip-0244.rst>`_