diff --git a/zip-0216.html b/zip-0216.html
index 1dc50d982..5313eee47 100644
--- a/zip-0216.html
+++ b/zip-0216.html
@@ -18,14 +18,16 @@
Discussions-To: <https://github.com/zcash/zips/issues/400>
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
@@ -38,14 +40,14 @@
-coordinate zero:
Each of these has a single non-canonical encoding in which the value of the sign bit is - \(1\) + \(1\!\) .
This creates a consensus issue because (unlike other non-canonical point encodings that are rejected) either of the above encodings can be decoded, and then re-encoded to a different encoding. For example, if a non-canonical encoding appeared in a transaction field, then node implementations that store points internally as abstract curve points, and used those to derive transaction IDs, would derive different IDs than nodes which store transactions as bytes (such as zcashd).
This issue is not known to cause any security vulnerability, beyond the risk of consensus incompatibility. In fact, for some of the fields that would otherwise be affected, the issue does not occur because there are already consensus rules that prohibit small-order points, and this incidentally prohibits non-canonical encodings.
@@ -53,25 +55,25 @@Let - \(\mathsf{abst}_{\mathbb{J}}\) + \(\mathsf{abst}_{\mathbb{J}}\!\) , - \(\mathsf{repr}_{\mathbb{J}}\) + \(\mathsf{repr}_{\mathbb{J}}\!\) , and \(q_{\mathbb{J}}\) - be as defined in 6.
+ be as defined in 9.Define a non-canonical compressed encoding of a Jubjub point to be a sequence of \(256\) bits, - \(b\) + \(b\!\) , such that \(\mathsf{abst}_{\mathbb{J}}(b) \neq \bot\) and - \(\mathsf{repr_{\mathbb{J}}}\big(\mathsf{abst}_{\mathbb{J}}(b)\big) \neq b\) + \(\mathsf{repr_{\mathbb{J}}}\big(\mathsf{abst}_{\mathbb{J}}(b)\big) \neq b\!\) .
Non-normative note: There are two such bit sequences, \(\mathsf{I2LEOSP}_{\ell_{\mathbb{J}}}(2^{255} + 1)\) and - \(\mathsf{I2LEOSP}_{\ell_{\mathbb{J}}}(2^{255} + q_{\mathbb{J}} - 1)\) + \(\mathsf{I2LEOSP}_{\ell_{\mathbb{J}}}(2^{255} + q_{\mathbb{J}} - 1)\!\) . The Sapling protocol uses little-endian ordering when converting between bit and byte sequences, so the first of these sequences corresponds to a \(\mathtt{0x01}\) byte, followed by @@ -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,17 +108,17 @@
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:
- - \(\mathsf{pk}\star_{\mathsf{d}}\) + \(\mathsf{pk}\star_{\mathsf{d}}\!\) .
(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:
@@ -125,51 +127,79 @@ \(\mathtt{cv}\)-- \(\mathtt{rk}\) - + \(\mathtt{rk}\!\) + .
In Sapling Output descriptions 4:
+In Sapling Output descriptions 7:
- \(\mathtt{cv}\)
- - \(\mathtt{ephemeralKey}\) + \(\mathtt{ephemeralKey}\!\) .
These fields cannot by consensus contain small-order points. All of the points with non-canonical encodings are small-order.
Implementations MAY choose to reject non-canonical encodings of the above four fields early in decoding of a transaction. This eliminates the risk that parts of the transaction could be re-serialized from their internal representation to a different byte sequence than in the original transaction, e.g. when calculating transaction IDs.
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)}\) + \(\mathbb{J}^{(r)}\!\) . These requirements MAY be enforced in advance of NU5 activation.
-In Sapling addresses 8:
+In Sapling addresses 11:
-
- the encoding of - \(\mathsf{pk_d}\) + \(\mathsf{pk_d}\!\) .
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 24 to match the implementation in librustzcash as of 23, 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.
+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).
+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:
Encodings of elliptic curve points on Curve25519, BN-254 - \(\mathbb{G}_1\) + \(\mathbb{G}_1\!\) , BN-254 - \(\mathbb{G}_2\) + \(\mathbb{G}_2\!\) , BLS12-381 - \(\mathbb{G}_1\) + \(\mathbb{G}_1\!\) , 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.
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. As of February 2023, no known divergence of this type exists for any production implementation of Zcash, but an early alpha version of the zebrad node implementation would have been susceptible to this issue.
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 PRs #6000 21 and #6399 22 retroactively enforce canonical encoding of Jubjub points for the entire chain history, as described in the Retroactive applicability section.
2 | -Zcash Protocol Specification, Version 2021.2.16 or later [NU5 proposal] | +Zcash Protocol Specification, Version 2023.4.0 or later |
---|