<p>The key words "MUST" and "MAY" in this document are to be interpreted as described in RFC 2119. <aid="id1"class="footnote_reference"href="#rfc2119">1</a></p>
<p>This proposal defines an update to the Zcash peer-to-peer transaction format to include support for data elements required to support the Orchard protocol <aid="id2"class="footnote_reference"href="#protocol-orchard">2</a>. The new transaction format defines well-bounded regions of the serialized form to serve each of the existing pools of funds, and adds and describes a new region containing Orchard-specific elements.</p>
<p>This ZIP also depends upon and defines modifications to the computation of the values <strong>TxId Digest</strong>, <strong>Signature Digest</strong>, and <strong>Authorizing Data Commitment</strong> defined by ZIP 244 <aid="id3"class="footnote_reference"href="#zip-0244">7</a>.</p>
<p>The new Orchard shielded pool requires serialized data elements that are distinct from any previous Zcash transaction. In addition, with the activation of ZIP 244, the serialized transaction format will no longer be consensus-critical. It makes sense at this point to define a format that can readily accommodate future extension in a systematic fashion, where elements required for support for a given pool are kept separate.</p>
<p>The new format must fully support the Orchard protocol.</p>
<p>The new format should lend itself to future extension or pruning to add or remove value pools.</p>
<p>The computation of the non-malleable transaction identifier hash must include all newly incorporated elements except those that attest to transaction validity.</p>
<p>The computation of the commitment to authorizing data for a transaction must include all newly incorporated elements that attest to transaction validity.</p>
<p>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.</p>
<td>A sequence of Orchard Action descriptions, encoded per §7.5 ‘Action Description Encoding and Consensus’.</td>
</tr>
<tr>
<td><code>1</code></td>
<td><code>flagsOrchard</code></td>
<td><code>byte</code></td>
<td>
<dl>
<dt>An 8-bit value representing a set of flags. Ordered from LSB to MSB:</dt>
<dd>
<ul>
<li><code>spendsEnabledOrchard</code></li>
<li><code>outputsEnabledOrchard</code></li>
<li>The remaining bits are set to <code>0</code>.</li>
</ul>
</dd>
</dl>
</td>
</tr>
<tr>
<td><code>8</code></td>
<td><code>valueBalanceOrchard</code></td>
<td><code>int64</code></td>
<td>The net value of Orchard spends minus outputs.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>anchorOrchard</code></td>
<td><code>byte[32]</code></td>
<td>A root of the Orchard note commitment tree at some block height in the past.</td>
</tr>
<tr>
<td><code>varies</code></td>
<td><code>sizeProofsOrchard</code></td>
<td><code>compactSize</code></td>
<td>Length in bytes of <code>proofsOrchard</code>.</td>
</tr>
<tr>
<td><code>sizeProofsOrchard</code></td>
<td><code>proofsOrchard</code></td>
<td><code>byte[sizeProofsOrchard]</code></td>
<td>Encoding of aggregated zk-SNARK proofs for Orchard Actions.</td>
</tr>
<tr>
<td><code>64 * nActionsOrchard</code></td>
<td><code>vSpendAuthSigsOrchard</code></td>
<td><code>byte[64 * nActionsOrchard]</code></td>
<td>Authorizing signatures for each Orchard Action.</td>
</tr>
<tr>
<td><code>64</code></td>
<td><code>bindingSigOrchard</code></td>
<td><code>byte[64]</code></td>
<td>An Orchard binding signature on the SIGHASH transaction hash.</td>
</tr>
</tbody>
</table>
<ul>
<li>The <code>valueBalanceSapling</code>, <code>anchorSapling</code>, and <code>bindingSigSapling</code> fields are present if and only if <code>nSpendsSapling + nOutputsSapling > 0</code>. If <code>valueBalanceSapling</code> is not present, then <code>valueBalanceSapling</code> is defined to be 0.</li>
<li>The <code>valueBalanceOrchard</code>, <code>anchorOrchard</code>, and <code>bindingSigOrchard</code> fields are present if and only if <code>nActionsOrchard > 0</code>. If <code>valueBalanceOrchard</code> is not present, then <code>valueBalanceOrchard</code> is defined to be 0.</li>
<li>The elements of <code>vSpendProofsSapling</code> and <code>vSpendAuthSigsSapling</code> have a 1:1 correspondence to the elements of <code>vSpendsSapling</code> and MUST be ordered such that the proof or signature at a given index corresponds to the <code>SpendDescriptionV5</code> at the same index.</li>
<li>The elements of <code>vOutputProofsSapling</code> have a 1:1 correspondence to the elements of <code>vOutputsSapling</code> and MUST be ordered such that the proof at a given index corresponds to the <code>OutputDescriptionV5</code> at the same index.</li>
<li>The proofs aggregated in <code>proofsOrchard</code>, and the elements of <code>vSpendAuthSigsOrchard</code>, each have a 1:1 correspondence to the elements of <code>vActionsOrchard</code> and MUST be ordered such that the proof or signature at a given index corresponds to the <code>OrchardAction</code> at the same index.</li>
<li>For coinbase transactions, the <code>spendsEnabledOrchard</code> bit MUST be set to <code>0</code>.</li>
<p>The encodings of <code>tx_in</code>, and <code>tx_out</code> are as in a version 4 transaction (i.e. unchanged from Canopy). The encodings of <code>SpendDescriptionV5</code>, <code>OutputDescriptionV5</code> and <code>OrchardAction</code> 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.</p>
<td>A value commitment to the net value of the input note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>nullifier</code></td>
<td><code>byte[32]</code></td>
<td>The nullifier of the input note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>rk</code></td>
<td><code>byte[32]</code></td>
<td>The randomized validating key for the element of spendAuthSigsSapling corresponding to this Spend.</td>
</tr>
</tbody>
</table>
<p>The encodings of each of these elements are defined in §7.3 ‘Spend Description Encoding and Consensus’ of the Zcash Protocol Specification <aid="id4"class="footnote_reference"href="#protocol-spenddesc">3</a>.</p>
<td>A value commitment to the net value of the output note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>cmu</code></td>
<td><code>byte[32]</code></td>
<td>The u-coordinate of the note commitment for the output note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>ephemeralKey</code></td>
<td><code>byte[32]</code></td>
<td>An encoding of an ephemeral Jubjub public key.</td>
</tr>
<tr>
<td><code>580</code></td>
<td><code>encCiphertext</code></td>
<td><code>byte[580]</code></td>
<td>The encrypted contents of the note plaintext.</td>
</tr>
<tr>
<td><code>80</code></td>
<td><code>outCiphertext</code></td>
<td><code>byte[580]</code></td>
<td>The encrypted contents of the byte string created by concatenation of the transmission key with the ephemeral secret key.</td>
</tr>
</tbody>
</table>
<p>The encodings of each of these elements are defined in §7.4 ‘Output Description Encoding and Consensus’ of the Zcash Protocol Specification <aid="id5"class="footnote_reference"href="#protocol-outputdesc">4</a>.</p>
<td>A value commitment to the net value of the input note minus the output note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>nullifier</code></td>
<td><code>byte[32]</code></td>
<td>The nullifier of the input note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>rk</code></td>
<td><code>byte[32]</code></td>
<td>The randomized validating key for the element of spendAuthSigsOrchard corresponding to this Action.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>cmx</code></td>
<td><code>byte[32]</code></td>
<td>The x-coordinate of the note commitment for the output note.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>ephemeralKey</code></td>
<td><code>byte[32]</code></td>
<td>An encoding of an ephemeral Pallas public key</td>
</tr>
<tr>
<td><code>580</code></td>
<td><code>encCiphertext</code></td>
<td><code>byte[580]</code></td>
<td>The encrypted contents of the note plaintext.</td>
</tr>
<tr>
<td><code>80</code></td>
<td><code>outCiphertext</code></td>
<td><code>byte[580]</code></td>
<td>The encrypted contents of the byte string created by concatenation of the transmission key with the ephemeral secret key.</td>
</tr>
</tbody>
</table>
<p>The encodings of each of these elements are defined in §7.5 ‘Action Description Encoding and Consensus’ of the Zcash Protocol Specification <aid="id6"class="footnote_reference"href="#protocol-actiondesc">5</a>.</p>
</section>
<sectionid="modifications-to-zip-244"><h3><spanclass="section-heading">Modifications to ZIP 244</span><spanclass="section-anchor"><arel="bookmark"href="#modifications-to-zip-244"><imgwidth="24"height="24"src="assets/images/section-anchor.png"alt=""></a></span></h3>
<p>The tree of hashes defined by ZIP 244 <aid="id7"class="footnote_reference"href="#zip-0244">7</a> is re-structured to include a new branch for Orchard hashes. The <code>orchard_digest</code> branch is the only new addition to the tree; <code>header_digest</code>, <code>transparent_digest</code>, <code>sprout_digest</code>, and <code>sapling_digest</code> are as in ZIP 244:</p>
<p>A BLAKE2b-256 hash of the subset of Orchard Action information intended to be included in an updated version of the ZIP-307 <aid="id9"class="footnote_reference"href="#zip-0307">8</a><code>CompactBlock</code> format for all Orchard Actions belonging to the transaction. For each Action, the following elements are included in the hash:</p>
<pre>T.4b.i : nullifier (field encoding bytes)
T.4b.ii : cmx (field encoding bytes)
T.4b.iii: ephemeralKey (field encoding bytes)
T.4b.iv : encCiphertext[..52] (First 52 bytes of field encoding)</pre>
<p>A BLAKE2b-256 hash of the subset of Orchard shielded memo field data for all Orchard Actions belonging to the transaction. For each Action, the following elements are included in the hash:</p>
<p>A BLAKE2b-256 hash of the remaining subset of Orchard Action information <strong>not</strong> intended for inclusion in an updated version of the the ZIP 307 <aid="id10"class="footnote_reference"href="#zip-0307">8</a><code>CompactBlock</code> format, for all Orchard Actions belonging to the transaction. For each Action, the following elements are included in the hash:</p>
<pre>T.4d.i : cv (field encoding bytes)
T.4d.ii : rk (field encoding bytes)
T.4d.iii: encCiphertext[564..] (post-memo suffix of field encoding)
<p>The signature digest creation algorithm defined by ZIP 244 <aid="id11"class="footnote_reference"href="#zip-0244">7</a> is modified to include a new branch for Orchard hashes. The <code>orchard_digest</code> branch is the only new addition to the tree; <code>header_digest</code>, <code>transparent_digest</code>, <code>sprout_digest</code>, and <code>sapling_digest</code> are as in ZIP 244:</p>
<p>Identical to that specified for the transaction identifier.</p>
</section>
</section>
<sectionid="authorizing-data-commitment"><h4><spanclass="section-heading">Authorizing Data Commitment</span><spanclass="section-anchor"><arel="bookmark"href="#authorizing-data-commitment"><imgwidth="24"height="24"src="assets/images/section-anchor.png"alt=""></a></span></h4>
<p>The tree of hashes defined by ZIP 244 <aid="id13"class="footnote_reference"href="#zip-0244">7</a> for authorizing data commitments is re-structured to include a new branch for Orchard Actions. The <code>orchard_digest</code> branch is the only new addition to the tree; <code>transparent_digest</code>, and <code>sprout_digest</code><code>sapling_digest</code> are as in ZIP 244:</p>
<p>The tree of hashes defined by ZIP 244 <aid="id14"class="footnote_reference"href="#zip-0244">7</a> for authorizing data commitments is re-structured to include a new branch for Orchard authorizing data. The <code>orchard_auth_digest</code> branch is the only new addition to the tree; <code>transparent_auth_digest</code>, <code>sprout_auth_digest</code>, and <code>sapling_auth_digest</code> are as in ZIP 244:</p>
<p>A BLAKE2b-256 hash of the field encoding of the <code>zkProofsOrchard</code>, <code>spendAuthSigsOrchard</code>, and <code>bindingSigOrchard</code> fields of the transaction:</p>
<p>The original version of ZIP-225 included Sprout-related fields <code>nJoinSplit</code>, <code>vJoinSplit</code>, <code>joinSplitPubKey</code>, and <code>joinSplitSig</code> in the V5 transaction format. The Electric Coin Company and Zcash Foundation teams have elected to remove these fields from the V5 transaction format as part of the continuing process of deprecation of the Sprout shielded pool. As a consequence of these fields being removed:</p>
<li>This effectively prohibits migration transactions that would directly move funds from the Sprout pool to the Orchard pool. Sprout -> Transparent and Sprout -> Sapling migration transactions will still be supported when using the V4 transaction format.</li>
<li>V5 parsing and serialization code does not need to take these fields into account.</li>
<li>ZIP 244 <aid="id15"class="footnote_reference"href="#zip-0244">7</a> transaction identifier, signature hash, and authorizing data commitment computations are simplified by excluding consideration of these fields.</li>
</ul>
<p>Removal of these fields means that that in the future, removing the support for the V4 transaction format will also effectively end support for Sprout transactions on the Zcash network, though it might be possible to restore limited support for migration via a future ZIP 222 <aid="id16"class="footnote_reference"href="#zip-0222">6</a> extension or by other means not yet determined.</p>
<td>A sequence of JoinSplit descrptions using Groth16 proofs, encoded per §7.2 ‘JoinSplit Description Encoding and Consensus’.</td>
</tr>
<tr>
<td><code>32</code></td>
<td><code>joinSplitPubKey</code></td>
<td><code>byte[32]</code></td>
<td>An encoding of a JoinSplitSig public validating key.</td>
</tr>
<tr>
<td><code>64</code></td>
<td><code>joinSplitSig</code></td>
<td><code>byte[64]</code></td>
<td>A signature on a prefix of the transaction encoding, to be verfied using joinSplitPubKey as specified in §4.11 ‘Non-malleability (Sprout)’.</td>
</tr>
</tbody>
</table>
<ul>
<li>The <code>joinSplitPubKey</code> and <code>joinSplitSig</code> fields were specified to be present if and only if <code>nJoinSplit > 0</code>.</li>