mirror of https://github.com/zcash/zips.git
340 lines
18 KiB
HTML
340 lines
18 KiB
HTML
<!DOCTYPE html>
|
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="generator" content="pandoc" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
|
<title>ZIP 202: Version 3 Transaction Format for Overwinter</title>
|
|
<style type="text/css">
|
|
code{white-space: pre-wrap;}
|
|
span.smallcaps{font-variant: small-caps;}
|
|
span.underline{text-decoration: underline;}
|
|
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
|
</style>
|
|
<link rel="stylesheet" href="css/zip-style.css"><link rel="stylesheet" href="assets/css/style.css"></head>
|
|
<body>
|
|
<pre><code>ZIP: 202
|
|
Title: Version 3 Transaction Format for Overwinter
|
|
Owners: Daira Hopwood <daira@electriccoin.co>
|
|
Original-Authors: Simon Liu <simon@bitcartel.com>
|
|
Status: Final
|
|
Category: Consensus
|
|
Created: 2018-01-10
|
|
License: MIT</code></pre>
|
|
<h1 id="terminology">Terminology</h1>
|
|
<p>The key words "MUST", "MUST NOT", and "MAY" in this document are to be interpreted as described in RFC 2119.<a href="#fn1" class="footnote-ref" id="fnref1"><sup>1</sup></a></p>
|
|
<p>The terms "branch", "network upgrade", and "consensus rule change" in this document are to be interpreted as described in ZIP 200.<a href="#fn2" class="footnote-ref" id="fnref2"><sup>2</sup></a></p>
|
|
<p>The term "Overwinter" in this document is to be interpreted as described in ZIP 201.<a href="#fn3" class="footnote-ref" id="fnref3"><sup>3</sup></a></p>
|
|
<h1 id="abstract">Abstract</h1>
|
|
<p>This proposal defines a new transaction format required for Network Upgrade Activation Mechanism<a href="#fn4" class="footnote-ref" id="fnref4"><sup>4</sup></a> and Transaction Expiry<a href="#fn5" class="footnote-ref" id="fnref5"><sup>5</sup></a>.</p>
|
|
<h1 id="motivation">Motivation</h1>
|
|
<p>Zcash launched with support for upstream Bitcoin version 1 transactions and defined a new version 2 transaction format which added fields required for shielded transactions.</p>
|
|
<table>
|
|
<thead>
|
|
<tr class="header">
|
|
<th>Version</th>
|
|
<th>Field</th>
|
|
<th>Description</th>
|
|
<th>Type</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>version</code></td>
|
|
<td>positive value</td>
|
|
<td><code>int32</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 1</td>
|
|
<td><code>tx_in_count</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>tx_in</code></td>
|
|
<td>list of inputs</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 1</td>
|
|
<td><code>tx_out_count</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>tx_out</code></td>
|
|
<td>list of outputs</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 1</td>
|
|
<td><code>lock_time</code></td>
|
|
<td>block height or timestamp</td>
|
|
<td><code>uint32</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 2</td>
|
|
<td><code>nJoinSplit</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 2</td>
|
|
<td><code>vJoinSplit</code></td>
|
|
<td>list of joinsplits</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 2</td>
|
|
<td><code>joinSplitPubKey</code></td>
|
|
<td>joinsplit_sig public key</td>
|
|
<td>32 bytes</td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 2</td>
|
|
<td><code>joinSplitSig</code></td>
|
|
<td>signature</td>
|
|
<td>64 bytes</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<p>A new transaction format is required to:</p>
|
|
<ul>
|
|
<li>support safe network upgrades as specified in Network Upgrade Activation Mechanism<a href="#fn6" class="footnote-ref" id="fnref6"><sup>6</sup></a>;</li>
|
|
<li>provide replay protection between pre-Overwinter and Overwinter branches during upgrades;</li>
|
|
<li>provide replay protection between different branches post-Overwinter;</li>
|
|
<li>enable a branch to support multiple transaction version formats;</li>
|
|
<li>ensure transaction formats are parsed uniquely across parallel branches;</li>
|
|
<li>support transaction expiry<a href="#fn7" class="footnote-ref" id="fnref7"><sup>7</sup></a>.</li>
|
|
</ul>
|
|
<h1 id="specification">Specification</h1>
|
|
<h2 id="transaction-format-version-3">Transaction format version 3</h2>
|
|
<p>A new version 3 transaction format will be introduced for Overwinter.</p>
|
|
<p>The version 3 format differs from the version 2 format in the following ways:</p>
|
|
<ul>
|
|
<li>header (first four bytes, little-endian encoded)
|
|
<ul>
|
|
<li><code>fOverwintered</code> flag : bit 31, must be set</li>
|
|
<li><code>nVersion</code> : bits 30-0, positive integer</li>
|
|
</ul></li>
|
|
<li><code>nVersionGroupId</code></li>
|
|
<li><code>nExpiryHeight</code></li>
|
|
</ul>
|
|
<table>
|
|
<thead>
|
|
<tr class="header">
|
|
<th>Version</th>
|
|
<th>Field</th>
|
|
<th>Description</th>
|
|
<th>Type</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr class="odd">
|
|
<td><p>>= 3</p></td>
|
|
<td><p>header</p></td>
|
|
<td><p>contains:</p>
|
|
<ul>
|
|
<li><code>fOverwintered</code> flag (bit 31, always set)</li>
|
|
<li><code>nVersion</code> (bits 30-0)</li>
|
|
</ul></td>
|
|
<td><p><code>uint32</code></p></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 3</td>
|
|
<td><code>nVersionGroupId</code></td>
|
|
<td>version group id (not zero)</td>
|
|
<td><code>uint32</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>tx_in_count</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 1</td>
|
|
<td><code>tx_in</code></td>
|
|
<td>list of inputs</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>tx_out_count</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 1</td>
|
|
<td><code>tx_out</code></td>
|
|
<td>list of outputs</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 1</td>
|
|
<td><code>lock_time</code></td>
|
|
<td>block height or timestamp</td>
|
|
<td><code>uint32</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 3</td>
|
|
<td><code>expiryHeight</code></td>
|
|
<td>block height</td>
|
|
<td><code>uint32</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 2</td>
|
|
<td><code>nJoinSplit</code></td>
|
|
<td>variable-length integer</td>
|
|
<td><code>compactSize</code></td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 2</td>
|
|
<td><code>vJoinSplit</code></td>
|
|
<td>list of joinsplits</td>
|
|
<td><code>vector</code></td>
|
|
</tr>
|
|
<tr class="odd">
|
|
<td>>= 2</td>
|
|
<td><code>joinSplitPubKey</code></td>
|
|
<td>joinsplit_sig public key</td>
|
|
<td>32 bytes</td>
|
|
</tr>
|
|
<tr class="even">
|
|
<td>>= 2</td>
|
|
<td><code>joinSplitSig</code></td>
|
|
<td>signature</td>
|
|
<td>64 bytes</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<h2 id="header-field">Header Field</h2>
|
|
<p>The first four bytes of pre-Overwinter and Overwinter transactions are little-endian encoded.</p>
|
|
<p>Version 1 transaction (txid 5c6ba844e1ca1c8083cd53e29971bd82f1f9eea1f86c1763a22dd4ca183ae061 <a href="https://zcash.blockexplorer.com/tx/5c6ba844e1ca1c8083cd53e29971bd82f1f9eea1f86c1763a22dd4ca183ae061" class="uri">https://zcash.blockexplorer.com/tx/5c6ba844e1ca1c8083cd53e29971bd82f1f9eea1f86c1763a22dd4ca183ae061</a>)</p>
|
|
<ul>
|
|
<li>begins with little-endian byte sequence [0x01, 0x00, 0x00, 0x00];</li>
|
|
<li>deserialized as 32-bit signed integer with decimal value of 1.</li>
|
|
</ul>
|
|
<p>Version 2 transaction (txid 4435bf8064e74f01262cb1725fd9b53e600fa285950163fd961bed3a64260d8b <a href="https://zcash.blockexplorer.com/tx/4435bf8064e74f01262cb1725fd9b53e600fa285950163fd961bed3a64260d8b" class="uri">https://zcash.blockexplorer.com/tx/4435bf8064e74f01262cb1725fd9b53e600fa285950163fd961bed3a64260d8b</a>)</p>
|
|
<ul>
|
|
<li>begins with little-endian byte sequence [0x02, 0x00, 0x00, 0x00];</li>
|
|
<li>deserialized as 32-bit signed integer with decimal value of 2.</li>
|
|
</ul>
|
|
<p>Transaction parsers for versions of Zcash prior to Overwinter, and for most other Bitcoin forks, require the transaction version number to be positive.</p>
|
|
<p>With the version 3 transaction format, the first four bytes of a serialized transaction, the 32-bit header, are made up of two fields as shown in the table above:</p>
|
|
<ul>
|
|
<li>1-bit <code>fOverwintered</code> flag, must be set;</li>
|
|
<li>31-bit unsigned int for the version.</li>
|
|
</ul>
|
|
<p>Pre-Overwinter parsers will deserialize these four bytes as a 32-bit signed integer. With two's complement integers, the most significant bit indicates whether an integer is positive or negative. With the Overwinter flag set, the transaction version will be negative, resulting in pre-Overwinter parsers rejecting the transaction as invalid. This provides transaction replay protection between pre-Overwinter and Overwinter software.</p>
|
|
<p>Consider the following example of a serialized version 3 transaction.</p>
|
|
<p>Pre-Overwinter parser:</p>
|
|
<ul>
|
|
<li>data begins with little-endian byte sequence: [0x03, 0x00, 0x00, 0x80];</li>
|
|
<li>deserialized as 32-bit signed integer.
|
|
<ul>
|
|
<li>with hexadecimal value of 0x80000003 (most significant bit is set);</li>
|
|
<li>decimal value of -2147483645.</li>
|
|
</ul></li>
|
|
</ul>
|
|
<p>Legacy parsers will expect the version to be a positive value, such as 1 or 2, and will thus reject the Overwinter transaction as invalid.</p>
|
|
<p>Overwinter parser:</p>
|
|
<ul>
|
|
<li>data begins with little-endian byte sequence: [0x03, 0x00, 0x00, 0x80];</li>
|
|
<li>deserialized as 32-bit unsigned integer
|
|
<ul>
|
|
<li>with binary value of 0b10000000000000000000000000000011;</li>
|
|
</ul></li>
|
|
<li>the 32-bits are decomposed into two fields:
|
|
<ul>
|
|
<li><code>fOverwintered</code> flag (bit 31) as a boolean, expected to be set;</li>
|
|
<li>version (bits 30 - bit 0) as an unsigned integer, expected to have a decimal value of 3.</li>
|
|
</ul></li>
|
|
</ul>
|
|
<p>Overwinter parsers will accept the transaction as valid as the most significant bit of the header has been set. By masking off (unsetting) the most significant bit, the parser can retrieve the transaction version number:</p>
|
|
<pre><code>0x80000003 & 0x7FFFFFFF = 0x00000003 = 3</code></pre>
|
|
<h2 id="version-group-id">Version Group Id</h2>
|
|
<p>The version group id is a non-zero, random and unique identifier, of type <code>uint32</code>, assigned to a transaction format version, or a group of soft-forking transaction format versions. The version group id helps nodes disambiguate between branches using the same version number.</p>
|
|
<p>That is, it prevents a client on one branch of the network from attempting to parse transactions intended for another branch, in the situation where the transactions share the same format version number but are actually specified differently. For example, Zcash and a clone of Zcash might both define their own custom v3 transaction formats, but each will have its own unique version group id, so that they can reject v3 transactions with unknown version group ids.</p>
|
|
<p>The combination of transaction version and version group id, <code>nVersion || nVersionGroupId</code>, uniquely defines the transaction format, thus enabling parsers to reject transactions from outside the client's chain which cannot be parsed.</p>
|
|
<p>By convention, it is expected that when introducing a new transaction version requiring a network upgrade, a new unique version group id will be assigned to that transaction version.</p>
|
|
<p>However, if a new transaction version can be correctly parsed according to the format of a preceding version (that is, it only restricts the format, or defines fields that were previously reserved and which old parsers can safely ignore), then the same version group id MAY be re-used.</p>
|
|
<h2 id="expiry-height">Expiry Height</h2>
|
|
<p>The expiry height field, as defined in the Transaction Expiry ZIP<a href="#fn8" class="footnote-ref" id="fnref8"><sup>8</sup></a>, stores the block height after which a transaction can no longer be mined.</p>
|
|
<h1 id="transaction-validation">Transaction Validation</h1>
|
|
<p>A valid Overwinter transaction intended for Zcash MUST have:</p>
|
|
<ul>
|
|
<li>version number 3; and</li>
|
|
<li>version group id 0x03C48270<a href="#fn9" class="footnote-ref" id="fnref9"><sup>9</sup></a>; and</li>
|
|
<li><code>fOverwintered</code> flag set.</li>
|
|
</ul>
|
|
<p>Overwinter validators MUST reject transactions for violating consensus rules if:</p>
|
|
<ul>
|
|
<li>the <code>fOverwintered</code> flag is not set; or</li>
|
|
<li>the version group id is unknown; or</li>
|
|
<li>the version number is unknown.</li>
|
|
</ul>
|
|
<p>Validation of version 3 transactions MUST use the signature verification process detailed in the Transaction Signature Verification for Overwinter ZIP<a href="#fn10" class="footnote-ref" id="fnref10"><sup>10</sup></a>.</p>
|
|
<h1 id="implementation">Implementation</h1>
|
|
<p>The comments and code samples in this section apply to the reference C++ implementation of Zcash. Other implementations may vary.</p>
|
|
<h2 id="transaction-version">Transaction Version</h2>
|
|
<p>Transaction version remains a positive value. The main Zcash chain will follow convention and continue to order transaction versions in an ascending order.</p>
|
|
<p>Tests can continue to check for the existence of forwards-compatible transaction fields by checking the transaction version using comparison operators:</p>
|
|
<pre><code>if (tx.nVersion >= 2) {
|
|
for (int js = 0; js < joinsplits; js++) {
|
|
...
|
|
}
|
|
}</code></pre>
|
|
<p>When (de)serializing v3 transactions, the version group id must also be checked in case the transaction is intended for a branch which has a different format for its version 3 transaction:</p>
|
|
<pre><code>if (tx.nVersion == 3 && tx.nVersionGroupId == OVERWINTER_VERSION_GROUP_ID) {
|
|
auto expiryHeight = tx.nExpiryHeight;
|
|
}</code></pre>
|
|
<p>Tests can continue to set the version to zero as an error condition:</p>
|
|
<pre><code>mtx.nVersion = 0</code></pre>
|
|
<h2 id="overwinter-validation">Overwinter Validation</h2>
|
|
<p>To test if the format of an Overwinter transaction is v3 or not:</p>
|
|
<pre><code>if (tx.fOverwintered && tx.nVersion == 3) {
|
|
// Valid v3 format transaction
|
|
}</code></pre>
|
|
<p>This only tests that the format of the transaction matches the v3 specification described above.</p>
|
|
<p>To test if the format of an Overwinter transaction is both v3 and the transaction itself is intended for the client's chain:</p>
|
|
<pre><code>if (tx.fOverwintered &&
|
|
tx.nVersionGroupId == OVERWINTER_VERSION_GROUP_ID) &&
|
|
tx.nVersion == 3) {
|
|
// Valid v3 format transaction intended for this client's chain
|
|
}</code></pre>
|
|
<p>It is expected that this test involving <code>nVersionGroupId</code> is only required when a transaction is being constructed or deserialized e.g. when an external transaction enters the system.</p>
|
|
<p>However, it's possible that a clone of Zcash is using the same version group id and passes the conditional.</p>
|
|
<p>Ultimately, a client can determine if a transaction is truly intended for the client's chain or not by following the signature verification process detailed in the Transaction Signature Verification for Overwinter ZIP<a href="#fn11" class="footnote-ref" id="fnref11"><sup>11</sup></a>.</p>
|
|
<h1 id="deployment">Deployment</h1>
|
|
<p>This proposal will be deployed with the Overwinter network upgrade. The activation block height proposal is in<a href="#fn12" class="footnote-ref" id="fnref12"><sup>12</sup></a>.</p>
|
|
<h1 id="backwards-compatibility">Backwards compatibility</h1>
|
|
<p>This proposal intentionally creates what is known as a "bilateral consensus rule change"<a href="#fn13" class="footnote-ref" id="fnref13"><sup>13</sup></a> between pre-Overwinter software and Overwinter-compatible software. Use of this new transaction format requires that all network participants upgrade their software to a compatible version within the upgrade window. Pre-Overwinter software will treat Overwinter transactions as invalid.</p>
|
|
<p>Once Overwinter has activated, Overwinter-compatible software will reject version 1 and version 2 transactions, and will only accept transactions based upon supported transaction version numbers and recognized version group ids.</p>
|
|
<h1 id="reference-implementation">Reference Implementation</h1>
|
|
<p><a href="https://github.com/zcash/zcash/pull/2925" class="uri">https://github.com/zcash/zcash/pull/2925</a></p>
|
|
<h1 id="references">References</h1>
|
|
<section class="footnotes">
|
|
<hr />
|
|
<ol>
|
|
<li id="fn1"><p><a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a><a href="#fnref1" class="footnote-back">↩</a></p></li>
|
|
<li id="fn2"><p><a href="https://github.com/zcash/zips/blob/master/zip-0200.rst">ZIP 200: Network Upgrade Activation Mechanism</a><a href="#fnref2" class="footnote-back">↩</a></p></li>
|
|
<li id="fn3"><p><a href="https://github.com/zcash/zips/blob/master/zip-0201.rst">ZIP 201: Network Handshaking for Overwinter</a><a href="#fnref3" class="footnote-back">↩</a></p></li>
|
|
<li id="fn4"><p><a href="https://github.com/zcash/zips/blob/master/zip-0200.rst">ZIP 200: Network Upgrade Activation Mechanism</a><a href="#fnref4" class="footnote-back">↩</a></p></li>
|
|
<li id="fn5"><p><a href="https://github.com/zcash/zips/blob/master/zip-0203.rst">ZIP 203: Transaction Expiry</a><a href="#fnref5" class="footnote-back">↩</a></p></li>
|
|
<li id="fn6"><p><a href="https://github.com/zcash/zips/blob/master/zip-0200.rst">ZIP 200: Network Upgrade Activation Mechanism</a><a href="#fnref6" class="footnote-back">↩</a></p></li>
|
|
<li id="fn7"><p><a href="https://github.com/zcash/zips/blob/master/zip-0203.rst">ZIP 203: Transaction Expiry</a><a href="#fnref7" class="footnote-back">↩</a></p></li>
|
|
<li id="fn8"><p><a href="https://github.com/zcash/zips/blob/master/zip-0203.rst">ZIP 203: Transaction Expiry</a><a href="#fnref8" class="footnote-back">↩</a></p></li>
|
|
<li id="fn9"><p><a href="https://github.com/zcash/zcash/pull/2925/files#diff-5cb8d9decaa15620a8f98b0c6c44da9bR311">OVERWINTER_VERSION_GROUP_ID</a><a href="#fnref9" class="footnote-back">↩</a></p></li>
|
|
<li id="fn10"><p><a href="https://github.com/zcash/zips/blob/master/zip-0143.rst">ZIP 143: Transaction Signature Verification for Overwinter</a><a href="#fnref10" class="footnote-back">↩</a></p></li>
|
|
<li id="fn11"><p><a href="https://github.com/zcash/zips/blob/master/zip-0143.rst">ZIP 143: Transaction Signature Verification for Overwinter</a><a href="#fnref11" class="footnote-back">↩</a></p></li>
|
|
<li id="fn12"><p><a href="https://github.com/zcash/zips/blob/master/zip-0201.rst">ZIP 201: Network Handshaking for Overwinter</a><a href="#fnref12" class="footnote-back">↩</a></p></li>
|
|
<li id="fn13"><p><a href="https://github.com/zcash/zips/blob/master/zip-0200.rst">ZIP 200: Network Upgrade Activation Mechanism</a><a href="#fnref13" class="footnote-back">↩</a></p></li>
|
|
</ol>
|
|
</section>
|
|
</body>
|
|
</html>
|