From eb00e2d63b4e1011ec155638bd05e8307a2d08ba Mon Sep 17 00:00:00 2001
From: Daira Hopwood The key word "MUST" in this document is to be interpreted as described in RFC 2119. 1 The term "network upgrade" in this document is to be interpreted as described in ZIP 200. 12 The term "network upgrade" in this document is to be interpreted as described in ZIP 200. 17 The terms "settled" and "full validator" in this document are to be interpreted as described in 3. The terms "Mainnet" and "Testnet" in this document are to be interpreted as described in 4. This ZIP fixes an oversight in the implementation of the Sapling consensus rules, by rejecting all non-canonical representations of Jubjub points. The Sapling specification was originally written with the intent that all values, including Jubjub points, are strongly typed with canonical representations. 6 This has significant advantages for security analysis, because it allows the protocol to be modelled with just the abstract types. The intention of the Jubjub implementation (both in the jubjub crate 15 and its prior implementations) was to ensure that only canonical point encodings would be accepted by the decoding logic. However, an oversight in the implementation allowed an edge case to slip through: for each point on the curve where the
+ The Sapling specification was originally written with the intent that all values, including Jubjub points, are strongly typed with canonical representations. 9 This has significant advantages for security analysis, because it allows the protocol to be modelled with just the abstract types. The intention of the Jubjub implementation (both in the jubjub crate 20 and its prior implementations) was to ensure that only canonical point encodings would be accepted by the decoding logic. However, an oversight in the implementation allowed an edge case to slip through: for each point on the curve where the
\(u\!\)
-coordinate is zero, there are two encodings that will be accepted:Terminology
Abstract
Motivation
- // Fix the sign of `u` if necessary
@@ -58,7 +60,7 @@
\(\mathsf{repr}_{\mathbb{J}}\)
, and
\(q_{\mathbb{J}}\)
- be as defined in 6.
Define a non-canonical compressed encoding of a Jubjub point to be a sequence of \(256\) bits, @@ -80,7 +82,7 @@ \(\mathtt{0x80}\) byte.
Once this ZIP activates, the following places within the Sapling consensus protocol where Jubjub points occur MUST reject non-canonical Jubjub point encodings.
-In Sapling Spend descriptions 3:
+In Sapling Spend descriptions 6:
-
- the @@ -92,7 +94,7 @@ RedDSA signature.
In transactions 10:
+In transactions 13:
- the @@ -106,7 +108,7 @@
In the plaintext obtained by decrypting the \(\mathsf{C^{out}}\) - field of a Sapling transmitted note ciphertext 5:
+ field of a Sapling transmitted note ciphertext 8:
- @@ -116,7 +118,7 @@
(This affects decryption of \(\mathsf{C^{out}}\) - in all cases, but is consensus-critical only in the case of a shielded coinbase output. 10)
+ in all cases, but is consensus-critical only in the case of a shielded coinbase output. 14)There are some additional fields in the consensus protocol that encode Jubjub points, but where non-canonical encodings MUST already be rejected as a side-effect of existing consensus rules.
In Sapling Spend descriptions:
@@ -129,7 +131,7 @@-
In Sapling Output descriptions 4:
+In Sapling Output descriptions 7:
- @@ -145,7 +147,7 @@
In addition, Sapling addresses and full viewing keys MUST be considered invalid when imported if they contain non-canonical Jubjub point encodings, or encodings of points that are not in the prime-order subgroup \(\mathbb{J}^{(r)}\) . These requirements MAY be enforced in advance of NU5 activation.
-In Sapling addresses 8:
+In Sapling addresses 11:
-
- the encoding of @@ -153,23 +155,51 @@ .
In Sapling full viewing keys 9 and extended full viewing keys 11:
+In Sapling full viewing keys 12 and extended full viewing keys 16:
-
- the encoding of \(\mathsf{ak}\) +
+- the encoding of + \(\mathsf{nk}\!\) .
( +
+ \(\mathsf{pk_d}\) + and \(\mathsf{ak}\) also MUST NOT encode the zero point - \(\mathcal{O}_{\mathbb{J}}\) - .)
+ \(\mathcal{O}_{\mathbb{J}}\!\) + . +(Some versions of the Zcash protocol specification mistakenly allowed + \(\mathsf{pk_d}\) + to be the zero point. This was corrected in version 2023.4.0 15 23 to match the implementation in librustzcash as of 22, which has been used in zcashd since zcashd v2.1.2.)
The above is intended to be a complete list of the places where compressed encodings of Jubjub points occur in the Zcash consensus protocol and in plaintext, address, or key formats.
+Retroactive applicability
+As originally specified, this ZIP required that the new validity rules be applied only after NU5 activation. This was necessary because a transaction containing a non-canonical Jubjub point encoding could have been included in any block before NU5 activation.
+However, now that NU5 is a settled upgrade on the Zcash Mainnet and Testnet chains 3 4, it can be observed that there were no such non-canonical encodings in publically visible transaction fields before the Mainnet and Testnet NU5 activations. Therefore, a full validator MAY enforce the above specification retroactively.
+It remains possible that there could be non-canonical + \(\mathsf{pk}\star_{\mathsf{d}}\) + encodings in plaintexts obtained by decrypting the + \(\mathsf{C^{out}}\) + field of a Sapling transmitted note ciphertext. Such encodings MUST be rejected by the decryption procedure in 8 after NU5 activation. An implementation MAY also reject them before NU5 activation. Doing so cannot lead to loss of funds sent to a Sapling address that has been correctly generated as specified in 5, because such an address cannot have + \(\mathsf{ivk} = 0\!\) + , which is the only case in which + \(\mathsf{pk}\star_{\mathsf{d}}\) + could be non-canonical.
+Note: There are no such non-canonical + \(\mathsf{pk}\star_{\mathsf{d}}\) + encodings in the + \(\mathsf{C^{out}}\) + components of shielded coinbase outputs (which are required by consensus to be decryptable by an all-zero + \(\mathsf{ovk}\) + 14).
+Rationale
-Zcash previously had a similar issue with non-canonical representations of points in Ed25519 public keys and signatures. In that case, given the prevalence of Ed25519 signatures in the wider ecosystem, the decision was made in ZIP 215 13 (which activated with the Canopy network upgrade 14) to allow non-canonical representations of points.
+Zcash previously had a similar issue with non-canonical representations of points in Ed25519 public keys and signatures. In that case, given the prevalence of Ed25519 signatures in the wider ecosystem, the decision was made in ZIP 215 18 (which activated with the Canopy network upgrade 19) to allow non-canonical representations of points.
In Sapling, we are motivated instead to reject these non-canonical points:
- The chance of the identity occurring anywhere within the Sapling components of transactions from implementations following the standard protocol is cryptographically negligible.
@@ -197,13 +227,14 @@ , and BLS12-381 \(\mathbb{G}_2\) are not affected. -Encodings of elliptic curve points on the Pallas and Vesta curves in the NU5 proposal 7 are also not affected.
+Encodings of elliptic curve points on the Pallas and Vesta curves in the NU5 proposal 10 are also not affected.
Security and Privacy Considerations
-This ZIP eliminates a potential source of consensus divergence between differing full node implementations. At the time of writing (February 2021), no such divergence exists for any production implementation of Zcash, but the alpha-stage zebrad node implementation would be susceptible to this issue.
+This ZIP eliminates a potential source of consensus divergence between differing full node implementations. At the time of writing (February 2021), no such divergence exists for any production implementation of Zcash, but an early alpha version of the zebrad node implementation would have been susceptible to this issue.
Deployment
-This ZIP is proposed to activate with Network Upgrade 5. Requirements on points encoded in payment addresses and full viewing keys MAY be enforced in advance of NU5 activation.
+This ZIP activated with Network Upgrade 5. Requirements on points encoded in payment addresses and full viewing keys MAY be enforced in advance of NU5 activation.
+zcashd PR #6399 21 retroactively enforces canonical encoding of Jubjub points for the entire chain history, as described in the Retroactive applicability section.
References
@@ -218,78 +249,118 @@
-2 -Zcash Protocol Specification, Version 2021.2.16 or later [NU5 proposal] +Zcash Protocol Specification, Version 2023.4.0 or later