Skip to content

Commit

Permalink
Merge pull request #919 from daira/draft-ecc-explicit-fees
Browse files Browse the repository at this point in the history
Add draft ZIP for Explicit Fees
  • Loading branch information
nuttycom authored Oct 29, 2024
2 parents 1d0b4ef + 1157a5f commit bce4585
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ be deleted.

<embed><table>
<tr> <th>Title</th> </tr>
<tr> <td class="left"><a href="zips/draft-ecc-explicit-fees.rst">Explicit Fees</a></td>
<tr> <td class="left"><a href="zips/draft-noamchom67-manufacturing-consent.rst">Manufacturing Consent; Re-Establishing a Dev Fund for ECC, ZF, ZCG, Qedit, FPF, and ZecHub</a></td>
<tr> <td class="left"><a href="zips/draft-nuttycom-funding-allocation.rst">Block Reward Allocation for Non-Direct Development Funding</a></td>
<tr> <td class="left"><a href="zips/draft-zf-community-dev-fund-2-proposal.rst">Establishing a Hybrid Dev Fund for ZF, ZCG and a Dev Fund Reserve</a></td>
Expand Down
169 changes: 169 additions & 0 deletions rendered/draft-ecc-explicit-fees.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<!DOCTYPE html>
<html>
<head>
<title>Draft ecc-explicit-fees: Explicit Fees</title>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=TeX-AMS-MML_HTMLorMML"></script>
<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="css/style.css"></head>
<body>
<section>
<pre>ZIP: Unassigned
Title: Explicit Fees
Owners: Daira-Emma Hopwood &lt;daira-emma@electriccoin.co&gt;
Kris Nuttycombe &lt;kris@electriccoin.co&gt;
Jack Grigg &lt;jack@electriccoin.co&gt;
Credits: Simon Liu
Status: Draft
Category: Consensus
License: MIT
Discussions-To: &lt;<a href="https://github.com/zcash/zips/issues/803">https://github.com/zcash/zips/issues/803</a>&gt;
Pull-Request: &lt;<a href="https://github.com/zcash/zips/pull/919">https://github.com/zcash/zips/pull/919</a>&gt;</pre>
<section id="terminology"><h2><span class="section-heading">Terminology</span><span class="section-anchor"> <a rel="bookmark" href="#terminology"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<p>The key word "MUST" in this document is to be interpreted as described in BCP 14 <a id="footnote-reference-1" class="footnote_reference" href="#bcp14">1</a> when, and only when, it appears in all capitals.</p>
<p>The character § is used when referring to sections of the Zcash Protocol Specification <a id="footnote-reference-2" class="footnote_reference" href="#protocol">2</a>.</p>
</section>
<section id="abstract"><h2><span class="section-heading">Abstract</span><span class="section-anchor"> <a rel="bookmark" href="#abstract"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<p>This proposal adds an explicit <code>fee</code> field to the v6 transaction format. Instead of fees being implicit in the difference between the input value and output value of the transaction, all value transfers, including fee transfers to miners, will be explicit and committed to via the txid.</p>
</section>
<section id="motivation"><h2><span class="section-heading">Motivation</span><span class="section-anchor"> <a rel="bookmark" href="#motivation"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<p>When it comes to fee selection, it should be very hard to make mistakes. The current transparent fee computation (inherited from Bitcoin) — input value less output value — is prone to user error. It is very easy to forget to add an output for a change address, make a calculation error <a id="footnote-reference-3" class="footnote_reference" href="#bitcointalk-fee-error">5</a>, mix up units etc.</p>
<p>In addition, when signing a transaction with a hardware wallet, using an implicit fee means that the hardware wallet must recompute the fee on its own and cannot simply display the value being committed to.</p>
<p>Finally, this change will make it possible for light clients to determine the fee paid by a transaction without needing to download and inspect transparent inputs to the transaction.</p>
</section>
<section id="requirements"><h2><span class="section-heading">Requirements</span><span class="section-anchor"> <a rel="bookmark" href="#requirements"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<p>There must not be any potentially error-prone calculations needed to compute the fee for a given transaction. That is, the fee must be obvious from the encoding of the transaction.</p>
</section>
<section id="specification"><h2><span class="section-heading">Specification</span><span class="section-anchor"> <a rel="bookmark" href="#specification"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<section id="transaction-format"><h3><span class="section-heading">Transaction Format</span><span class="section-anchor"> <a rel="bookmark" href="#transaction-format"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h3>
<p>The following field is added to the v6 transaction format <a id="footnote-reference-4" class="footnote_reference" href="#zip-0230-transaction-format">6</a>.</p>
<table>
<thead>
<tr>
<th>Bytes</th>
<th>Name</th>
<th>Data Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>8</td>
<td><code>fee</code></td>
<td><code>uint64</code></td>
<td>The fee to be paid by this transaction, in zatoshis.</td>
</tr>
</tbody>
</table>
</section>
<section id="consensus-rules"><h3><span class="section-heading">Consensus Rules</span><span class="section-anchor"> <a rel="bookmark" href="#consensus-rules"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h3>
<p>The following changes are to be made to the Zcash Protocol Specification <a id="footnote-reference-5" class="footnote_reference" href="#protocol">2</a>.</p>
<p>In § 3.4 ‘Transactions and Treestates’ <a id="footnote-reference-6" class="footnote_reference" href="#protocol-transactions">3</a> (last modified by ZIP 236 <a id="footnote-reference-7" class="footnote_reference" href="#zip-0236">7</a>), add the following consensus rule and note:</p>
<blockquote>
<ul>
<li>[NU7 onward] For v6 and later transactions, the remaining value in the transparent transaction value pool, in zatoshis, MUST be equal to the value of the transaction’s <code>fee</code> field.</li>
</ul>
<p>Non-normative note: The effect of these rules is that the <code>fee</code> field of v6 and later coinbase transactions will always be zero.</p>
</blockquote>
<p>In § 7.1 ‘Transaction Encoding and Consensus’ <a id="footnote-reference-8" class="footnote_reference" href="#protocol-txnconsensus">4</a>, add:</p>
<blockquote>
<p>[NU7 onward] <code>fee</code> MUST be in the range
<span class="math">\(\{ 0 .. \mathsf{MAX\_MONEY} \}\)</span>
.</p>
</blockquote>
</section>
<section id="signature-hash"><h3><span class="section-heading">Signature Hash</span><span class="section-anchor"> <a rel="bookmark" href="#signature-hash"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h3>
<p>The transaction signature hashing algorithm defined in ZIP 244 is to be modified for v6 transactions as follows:</p>
<p>Section T.1: <cite>header_digest</cite> <a id="footnote-reference-9" class="footnote_reference" href="#zip-0244-header-digest">8</a> is specified in <cite>draft-txv6-sighash</cite> <a id="footnote-reference-10" class="footnote_reference" href="#draft-txv6-sighash">9</a> to read:</p>
<blockquote>
<p>A BLAKE2b-256 hash of the following values</p>
<pre>T.1a: version (4-byte little-endian version identifier including ``fOverwintered`` 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)
T.1f: fee (8-byte little-endian fee value)</pre>
<p>The personalization field of this hash is set to:</p>
<pre>"ZTxIdHeadersHash"</pre>
</blockquote>
</section>
</section>
<section id="reference-implementation"><h2><span class="section-heading">Reference implementation</span><span class="section-anchor"> <a rel="bookmark" href="#reference-implementation"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<p>TBD</p>
</section>
<section id="references"><h2><span class="section-heading">References</span><span class="section-anchor"> <a rel="bookmark" href="#references"><img width="24" height="24" class="section-anchor" src="assets/images/section-anchor.png" alt=""></a></span></h2>
<table id="bcp14" class="footnote">
<tbody>
<tr>
<th>1</th>
<td><a href="https://www.rfc-editor.org/info/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"</a></td>
</tr>
</tbody>
</table>
<table id="protocol" class="footnote">
<tbody>
<tr>
<th>2</th>
<td><a href="protocol/protocol.pdf">Zcash Protocol Specification, Version 2024.5.1 [NU6] or later</a></td>
</tr>
</tbody>
</table>
<table id="protocol-transactions" class="footnote">
<tbody>
<tr>
<th>3</th>
<td><a href="protocol/protocol.pdf#transactions">Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 3.4: Transactions and Treestates</a></td>
</tr>
</tbody>
</table>
<table id="protocol-txnconsensus" class="footnote">
<tbody>
<tr>
<th>4</th>
<td><a href="protocol/protocol.pdf#txnconsensus">Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 7.1.2: Transaction Consensus Rules</a></td>
</tr>
</tbody>
</table>
<table id="bitcointalk-fee-error" class="footnote">
<tbody>
<tr>
<th>5</th>
<td><a href="https://bitcointalk.org/index.php?topic=1818791.0">Bitcoin Forum post by @Voiceeeeee, March 8, 2017. "PLEASE HELP.. I sent a transaction with a 2.5 BTC transaction fee"</a></td>
</tr>
</tbody>
</table>
<table id="zip-0230-transaction-format" class="footnote">
<tbody>
<tr>
<th>6</th>
<td><a href="zip-0230">ZIP 230: Version 6 Transaction Format</a></td>
</tr>
</tbody>
</table>
<table id="zip-0236" class="footnote">
<tbody>
<tr>
<th>7</th>
<td><a href="zip-0236">ZIP 236: Blocks should balance exactly</a></td>
</tr>
</tbody>
</table>
<table id="zip-0244-header-digest" class="footnote">
<tbody>
<tr>
<th>8</th>
<td><a href="zip-0244#t-1-header-digest">ZIP 244: Transaction Identifier Non-Malleability. Section T.1: Header Digest</a></td>
</tr>
</tbody>
</table>
<table id="draft-txv6-sighash" class="footnote">
<tbody>
<tr>
<th>9</th>
<td><a href="draft-txv6-sighash">ZIP draft: Version 6 Transaction Signature Validation</a></td>
</tr>
</tbody>
</table>
</section>
</section>
</body>
</html>
1 change: 1 addition & 0 deletions rendered/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<p>These are works-in-progress, and may never be assigned ZIP numbers if their ideas become obsoleted or abandoned. Do not assume that these drafts will exist in perpetuity; instead assume that they will either move to a numbered ZIP, or be deleted.</p>
<embed><table>
<tr> <th>Title</th> </tr>
<tr> <td class="left"><a href="draft-ecc-explicit-fees">Explicit Fees</a></td>
<tr> <td class="left"><a href="draft-noamchom67-manufacturing-consent">Manufacturing Consent; Re-Establishing a Dev Fund for ECC, ZF, ZCG, Qedit, FPF, and ZecHub</a></td>
<tr> <td class="left"><a href="draft-nuttycom-funding-allocation">Block Reward Allocation for Non-Direct Development Funding</a></td>
<tr> <td class="left"><a href="draft-zf-community-dev-fund-2-proposal">Establishing a Hybrid Dev Fund for ZF, ZCG and a Dev Fund Reserve</a></td>
Expand Down
134 changes: 134 additions & 0 deletions zips/draft-ecc-explicit-fees.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
::

ZIP: Unassigned
Title: Explicit Fees
Owners: Daira-Emma Hopwood <daira-emma@electriccoin.co>
Kris Nuttycombe <kris@electriccoin.co>
Jack Grigg <jack@electriccoin.co>
Credits: Simon Liu
Status: Draft
Category: Consensus
License: MIT
Discussions-To: <https://github.com/zcash/zips/issues/803>
Pull-Request: <https://github.com/zcash/zips/pull/919>


Terminology
===========

The key word "MUST" in this document is to be interpreted as described in BCP 14 [#BCP14]_
when, and only when, it appears in all capitals.

The character § is used when referring to sections of the Zcash Protocol Specification
[#protocol]_.


Abstract
========

This proposal adds an explicit ``fee`` field to the v6 transaction format.
Instead of fees being implicit in the difference between the input value and
output value of the transaction, all value transfers, including fee transfers to
miners, will be explicit and committed to via the txid.


Motivation
==========

When it comes to fee selection, it should be very hard to make mistakes.
The current transparent fee computation (inherited from Bitcoin) — input value
less output value — is prone to user error. It is very easy to forget to add an
output for a change address, make a calculation error [#bitcointalk-fee-error]_,
mix up units etc.

In addition, when signing a transaction with a hardware wallet, using an implicit
fee means that the hardware wallet must recompute the fee on its own and cannot
simply display the value being committed to.

Finally, this change will make it possible for light clients to determine the
fee paid by a transaction without needing to download and inspect transparent
inputs to the transaction.


Requirements
============

There must not be any potentially error-prone calculations needed to compute the
fee for a given transaction. That is, the fee must be obvious from the encoding
of the transaction.


Specification
=============

Transaction Format
------------------

The following field is added to the v6 transaction format [#zip-0230-transaction-format]_.

+-------+---------+------------+------------------------------------------------------+
| Bytes | Name | Data Type | Description |
+=======+=========+============+======================================================+
| 8 | ``fee`` | ``uint64`` | The fee to be paid by this transaction, in zatoshis. |
+-------+---------+------------+------------------------------------------------------+

Consensus Rules
---------------

The following changes are to be made to the Zcash Protocol Specification [#protocol]_.

In § 3.4 ‘Transactions and Treestates’ [#protocol-transactions]_ (last modified by
ZIP 236 [#zip-0236]_), add the following consensus rule and note:

* [NU7 onward] For v6 and later transactions, the remaining value in the
transparent transaction value pool, in zatoshis, MUST be equal to the value
of the transaction’s ``fee`` field.

Non-normative note: The effect of these rules is that the ``fee`` field of
v6 and later coinbase transactions will always be zero.

In § 7.1 ‘Transaction Encoding and Consensus’ [#protocol-txnconsensus]_, add:

[NU7 onward] ``fee`` MUST be in the range :math:`\{ 0 .. \mathsf{MAX\_MONEY} \}`.

Signature Hash
--------------

The transaction signature hashing algorithm defined in ZIP 244 is to be modified
for v6 transactions as follows:

Section T.1: `header_digest` [#zip-0244-header-digest]_ is specified in
`draft-txv6-sighash` [#draft-txv6-sighash]_ to read:

A BLAKE2b-256 hash of the following values ::
T.1a: version (4-byte little-endian version identifier including ``fOverwintered`` 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)
T.1f: fee (8-byte little-endian fee value)
The personalization field of this hash is set to::
"ZTxIdHeadersHash"


Reference implementation
========================

TBD


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 2024.5.1 [NU6] or later <protocol/protocol.pdf>`_
.. [#protocol-transactions] `Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 3.4: Transactions and Treestates <protocol/protocol.pdf#transactions>`_
.. [#protocol-txnconsensus] `Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 7.1.2: Transaction Consensus Rules <protocol/protocol.pdf#txnconsensus>`_
.. [#bitcointalk-fee-error] `Bitcoin Forum post by @Voiceeeeee, March 8, 2017. "PLEASE HELP.. I sent a transaction with a 2.5 BTC transaction fee" <https://bitcointalk.org/index.php?topic=1818791.0>`_
.. [#zip-0230-transaction-format] `ZIP 230: Version 6 Transaction Format <zip-0230.rst>`_
.. [#zip-0236] `ZIP 236: Blocks should balance exactly <zip-0236.rst>`_
.. [#zip-0244-header-digest] `ZIP 244: Transaction Identifier Non-Malleability. Section T.1: Header Digest <zip-0244#t-1-header-digest>`_
.. [#draft-txv6-sighash] `ZIP draft: Version 6 Transaction Signature Validation <draft-txv6-sighash>`_

0 comments on commit bce4585

Please sign in to comment.