Zcash in Simplified Technical English

This page is the Simplified Technical English version of ZIP 212. The source ZIP is the normative text. Read the writing rules to understand the marked words.

ZIP 212: Allow Recipient to Derive Ephemeral Secret from Note Plaintext

ZIP: 212
Title: Allow Recipient to Derive Ephemeral Secret from Note Plaintext
Owners: Sean Bowe <ewillbefull@gmail.com>
        Daira-Emma Hopwood <daira@jacaranda.org>
Status: Final
Category: Consensus
Created: 2019-03-31
License: MIT

Terminology

On this page, STE words are in the place of the BCP 14 key words of the source. Refer to the key word table.

The definitions of these functions are in the Zcash Protocol Specification [protocol]. For each function, the definition to use depends on the type (Sapling or Orchard) of the note plaintext that is processed:

Abstract

Note: This ZIP contains the changes to the encryption of notes for the Canopy network upgrade. It does not include the later changes in ZIP 2005 [zip-2005].

The proposal in this ZIP is a new note plaintext format for Sapling Outputs in transactions. (The format was later extended to include Orchard Actions.) With the new format, a recipient can verify that the sender of an Output or Action knows a private key. This private key is the key that corresponds to the ephemeral Diffie–Hellman key. The purpose of the format is that the prevention of diversified address linkability does not depend on an assumption of zk-SNARK soundness.

Motivation

The Sapling and Orchard payment protocols have a feature with the name "diversified addresses". With this feature, a user can receive payments on a very large number of payment addresses with one incoming viewing key. These payment addresses are different and unlinkable. Thus users can keep many payment addresses with no additional overhead during block chain scanning.

With this feature, a payment address is a tuple \((\mathsf{pk_d}, \mathsf{d})\). The tuple contains a public key \(\mathsf{pk_d}\) and an \(88\)-bit diversifier \(\mathsf{d}\). These values are such that \(\mathsf{pk_d} = [\mathsf{ivk}]\, \mathsf{DiversifyHash}(\mathsf{d})\) for some incoming viewing key \(\mathsf{ivk}\). The hash function \(\mathsf{DiversifyHash}(\mathsf{d})\) is a map from a diversifier to prime-order elements of the Jubjub or Pallas elliptic curve. A user can select many \(\mathsf{d}\) values to make several different and unlinkable payment addresses of this form.

To make a payment to a Sapling or Orchard address, the sender samples an ephemeral secret \(\mathsf{esk}\). The Output or Action description includes an ephemeral public key \(\mathsf{epk} = [\mathsf{esk}]\, \mathsf{DiversifyHash}(\mathsf{d})\). Then, the sender calculates a shared Diffie-Hellman secret as \(\mathsf{KA.Agree}(\mathsf{esk}, \mathsf{pk_d})\). The recipient can calculate \(\mathsf{KA.Agree}(\mathsf{ivk}, \mathsf{epk})\) to recover this shared secret, and knowledge of the particular \(\mathsf{d}\) is not necessary. This shared secret is then used as part of note decryption.

In the naïve case, the recipient cannot know the \((\mathsf{pk_d}, \mathsf{d})\) that the sender used to calculate the shared secret. But the sender is asked to include \(\mathsf{d}\) in the note plaintext for the reconstruction of the note. But if the recipient has more than one known address, an adversary can use a different payment address to do the secret exchange. The adversary then monitors the behavior of the recipient, and thus can link the two diversified addresses together. (Brian Warner found this adversary strategy earlier in the design of the Sapling protocol.)

To prevent this attack before the activation of this ZIP, the protocol had a requirement. It was necessary for the sender to prove knowledge of the discrete logarithm of \(\mathsf{epk}\). This is the discrete logarithm with respect to the \(\mathsf{g_d} = \mathsf{DiversifyHash}(\mathsf{d})\) that is included in the note commitment. This \(\mathsf{g_d}\) is determined by \(\mathsf{d}\) and is calculated again during note decryption. Thus either the note decryption fails, or the sender cannot make the proof. That proof is possible only with knowledge of the discrete logarithm.

But that proof was part of the Sapling Output statement. Thus it depended on the soundness of the underlying Groth16 zk-SNARK. Thus it also depended on relatively strong cryptographic assumptions and a trusted setup.

It is better to make the sender transfer sufficient information in the note plaintext to derive \(\mathsf{esk}\). Then, during note decryption, the recipient can check that \(\mathsf{epk} = [\mathsf{esk}]\, \mathsf{g_d}\) for the expected \(\mathsf{g_d}\). If this equation is false, the recipient can ignore the payment as invalid. For Sapling, this is a line of defense if the soundness of the zk-SNARK does not hold. For Orchard, this check is necessary, because \(\mathsf{epk} = [\mathsf{esk}]\, \mathsf{g_d}\) is not checked in the Action statement (for efficiency and simplicity).

A simple alternative is to send \(\mathsf{esk}\) to the recipient in the note plaintext. But for that alternative, a larger note plaintext is necessary. With that alternative, the proof of IND-CCA2 security for in-band secret distribution is also compromised. To prevent these two problems, we use a key derivation to get both \(\mathsf{esk}\) and \(\mathsf{rcm}\).

Specification

Note: The intent is that the specification in this ZIP agrees with version 2023.4.0 or later of the Zcash Protocol Specification [protocol]. The intent is also that it agrees with the deployed implementations in librustzcash and the orchard crate.

Earlier versions of the protocol specification (2022.3.8 and earlier) did not agree with this ZIP. The difference was in the domain separators for \(\mathsf{PRF^{expand}}\) that are used to derive \(\mathsf{rcm}\) and \(\mathsf{esk}\). For Sapling, the protocol specification was different from the deployed implementations. For Orchard, this ZIP was different from the deployed implementations before December 2023.

The definition of pseudo random functions (PRFs) is in section 4.1.2 of the Zcash Protocol Specification [protocol-abstractprfs]. We adapt \(\mathsf{PRF^{expand}}\) for the purposes of this ZIP. This function is keyed by a 256-bit key \(\mathsf{sk}\). Its input is a byte sequence of arbitrary length, and its output is a \(64\)-byte sequence.

Changes to Sapling and Orchard Note plaintexts

The specification of note plaintext encodings is in section 5.5 of the Zcash Protocol Specification [protocol-notept]. Before the activation of this ZIP, the encoding of a Sapling note plaintext had this requirement: the first byte has the form \(\mathtt{0x01}\). This byte is the version of the note plaintext. Also, the note plaintext and its encoding contain a \(256\)-bit \(\mathsf{rcm}\) field.

After the activation of this ZIP, senders must use this note plaintext format for Sapling or Orchard notes:

  • The first byte of the encoding must have the form \(\mathtt{0x02}\) (the new note plaintext version).
  • The field \(\mathsf{rcm}\) of the encoding has the new name \(\mathsf{rseed}\). The type of this field \(\mathsf{rseed}\) of the Sapling or Orchard note plaintext is no longer \(\mathsf{NoteCommit.Trapdoor}\) (the type that it had for Sapling). The field is now a \(32\)-byte sequence.

One requirement is removed from the descriptions of note plaintexts in the Zcash Protocol Specification. That requirement was that the former \(\mathsf{rcm}\) field, interpreted as a little endian integer, is a scalar of the Jubjub elliptic curve.

Changes to the process of sending Sapling or Orchard notes

The process to send notes is described in section 4.7.2 of the Zcash Protocol Specification for Sapling [protocol-saplingsend]. For Orchard, it is described in section 4.7.3 [protocol-orchardsend]. Also, the process to encrypt a note is described in section 4.20.1 of the Zcash Protocol Specification [protocol-saplingandorchardencrypt]. Before the activation of this ZIP, the sender sampled \(\mathsf{rcm^{new}}\) and the ephemeral private key \(\mathsf{esk}\) uniformly at random during this process.

After the activation of this ZIP, the sender must instead sample a uniformly random \(32\)-byte sequence \(\mathsf{rseed}\). The note plaintext contains \(\mathsf{rseed}\) in the place of \(\mathsf{rcm^{new}}\).

For Sapling:

  • \(\mathsf{rcm^{new}}\) must be derived as the output of \(\mathsf{ToScalar}(\mathsf{PRF^{expand}_{rseed}}([4]))\).
  • \(\mathsf{esk}\) must be derived as the output of \(\mathsf{ToScalar}(\mathsf{PRF^{expand}_{rseed}}([5]))\).

For Orchard:

  • \(\mathsf{rcm^{new}}\) must be derived as the output of \(\mathsf{ToScalar}(\mathsf{PRF^{expand}_{rseed}}([5] \,||\, \underline{\text{ρ}}))\).
  • \(\mathsf{esk}\) must be derived as the output of \(\mathsf{ToScalar}(\mathsf{PRF^{expand}_{rseed}}([4] \,||\, \underline{\text{ρ}}))\).
  • \(\text{φ}\) must be derived as the output of \(\mathsf{ToScalar}(\mathsf{PRF^{expand}_{rseed}}([9] \,||\, \underline{\text{ρ}}))\).

In these expressions, \(\underline{\text{ρ}} = \mathsf{I2LEOSP}_{256}(\mathsf{nf^{old}}\) from the same Action description \(\!)\).

Note: The domain separators \([4]\) and \([5]\) that are used in the input to \(\mathsf{PRF^{expand}_{rseed}}\) are swapped for Orchard relative to Sapling. The cause was an oversight, and there is no good reason for the difference.

The specified domain separators were corrected to agree with the deployed implementations in librustzcash and the orchard crate. This correction is in version 2023.4.0 of the Zcash Protocol Specification, and in this ZIP from December 2023.

Changes to the process of receiving Sapling or Orchard notes

The process to receive notes in Sapling or Orchard is described in sections 4.20.2 and 4.20.3 of the Zcash Protocol Specification [protocol-decryptivk] [protocol-decryptovk]. (Only Sapling was deployed at the initial activation of this ZIP, but this ZIP now applies to both Sapling and Orchard.)

There is a "grace period" of 32256 blocks that starts from the block where this ZIP activates. During the grace period, note plaintexts with lead byte \(\mathtt{0x01}\) must still be accepted.

ActivationHeight is the activation height of this ZIP. GracePeriodEndHeight is ActivationHeight + 32256.

The height of a transaction in a mined block is defined as the height of that block. An implementation can also decrypt mempool transactions. In that case, the height to use is the height of the next block at the time of the check. We recommend that an implementation does not try to decrypt mempool transactions without a best-effort view of the current block chain height.

When the recipient of a note (with an incoming viewing key or a full viewing key) can decrypt a note plaintext, it does this check on the plaintext lead byte. The check depends on the height of the transaction that contains the note plaintext:

  • If the height is less than ActivationHeight, the recipient accepts only \(\mathtt{0x01}\) as the plaintext lead byte.
  • If the height is greater than or equal to ActivationHeight and less than GracePeriodEndHeight, the recipient accepts \(\mathtt{0x01}\) or \(\mathtt{0x02}\) as the plaintext lead byte.
  • If the height is greater than or equal to GracePeriodEndHeight, the recipient accepts only \(\mathtt{0x02}\) as the plaintext lead byte.

If the plaintext lead byte is not accepted, the note must be discarded. But an exception applies if an implementation decrypted the note from a mempool transaction and the note was accepted at that time. In that case, if the transaction is later mined in a block after the end of the grace period, the note can be kept.

A note plaintext with lead byte \(\mathtt{0x02}\) contains a field \(\mathsf{rseed}\) that is a \(32\)-byte sequence. This field is in the place of a scalar value \(\mathsf{rcm}\). During decryption and in all later contexts, the recipient derives \(\mathsf{rcm}\) with \(\mathsf{PRF^{expand}_{rseed}}\) in the same way as the sender. Refer to Changes to the process of sending Sapling or Orchard notes. Also, the recipient must derive \(\mathsf{esk}\) as described in that section and check that \(\mathsf{epk} = [\mathsf{esk}]\, \mathsf{g_d}\). If this check is not satisfied, decryption must fail.

Consensus rule change for coinbase transactions

This rule applies after the activation of this ZIP, to each Sapling output of a coinbase transaction. If the output is decrypted to a note plaintext as specified in [zip-0213], the note plaintext lead byte must be equal to \(\mathtt{0x02}\).

This rule applies even during the “grace period”. It also applies to funding stream outputs [zip-0207] that are sent to shielded payment addresses, if there are any.

NU5 activates after the end of the grace period [zip-0252]. Thus for Orchard outputs, a note plaintext lead byte equal to \(\mathtt{0x02}\) is always necessary.

Rationale

The attack that is prevented here is an interactive attack. This attack is possible only if an adversary can break critical soundness properties of the underlying zk-SNARKs of Sapling. It is possibly valid to assume that this cannot occur, because of other damaging effects on the system. An example of such an effect is undetectable counterfeiting. But we tried to prevent all instances in the protocol where privacy (even against interactive attacks) depended on strong cryptographic assumptions.

A different approach here is a source of confusion for users who were told that "privacy does not depend on zk-SNARK soundness" or similar claims.

One alternative was to decrease the length of the memo field and ask the sender to supply \(\mathsf{esk}\) in the existing note plaintext. With this alternative, the transaction format does not change. But this alternative is harmful to users who now expect to have a \(512\)-byte memo field available. We recommend that changes to the memo field length are considered in a wider context than changes for cryptographic purposes.

A second alternative is to transmit a signature of knowledge of a correct \(\mathsf{esk}\) in the place of \(\mathsf{esk}\) itself. But this alternative is apparently an unnecessary complication. It is also likely to be slower than to supply only \(\mathsf{esk}\).

The purpose of the grace period is to decrease the loss-of-funds risk from non-conformant wallet implementations that send notes. The intent is that, during the grace period (of approximately 4 weeks), it is possible to identify wallets that still send plaintexts that agree with the old specification. It is then possible to persuade their developers to make the necessary updates.

To be clear, such wallets are non-conformant, for this reason: it is a "must" requirement to send note plaintexts with lead byte \(\mathtt{0x02}\) immediately at the network upgrade (and to make the other changes in this specification). Note that nodes clear their mempools when the network upgrade activates. Thus nodes remove all plaintexts with lead byte \(\mathtt{0x01}\) that were sent conformantly and not mined before the network upgrade.

Historical note: In practice, some note plaintexts with lead byte \(\mathtt{0x01}\) were sent non-conformantly even after the end of the specified grace period. ZecWallet extended its implementation of the grace period by 161280 more blocks (approximately 20 weeks) to make the recovery of these funds possible [zecwallet-grace-extension].

Security and Privacy Considerations

An interactive attack is prevented by the changes in this ZIP. In that attack, an adversary who breaks only the knowledge soundness assumption of the zk-SNARK can link diversified addresses together. It is already assumed that the adversary cannot defeat the EC-DDH assumption of the Jubjub (or Pallas) elliptic curve. If the adversary can defeat that assumption, the adversary can do a linkability attack trivially.

The naïve case is a protocol change where \(\mathsf{esk}\) is supplied directly to the recipient (and not derived through \(\mathsf{rseed}\)). The result of this change is an instance of key-dependent encryption. It is difficult or possibly impossible to prove that key-dependent encryption is secure with existing security notions.

In our approach, we use a key derivation that is, in the end, a query to an oracle. Thus a proof of IND-CCA2 security can be written. In the proof, the oracle is reprogrammed to return bogus keys when necessary.

Deployment

This ZIP is deployed with the Canopy network upgrade [zip-0251].

Reference Implementation

In zcashd:

In librustzcash:

Acknowledgements

Sean Bowe and Zooko Wilcox found that diversified address unlinkability depended on the zk-SNARK knowledge assumption.

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"
[protocol]
Zcash Protocol Specification, Version 2023.4.0 or later
[protocol-abstractprfs]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.1.2: Pseudo Random Functions
[protocol-abstractcommit]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.1.8: Commitment
[protocol-saplingkeycomponents]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.2.2: Sapling Key Components
[protocol-orchardkeycomponents]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.2.3: Orchard Key Components
[protocol-saplingsend]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.7.2: Sending Notes (Sapling)
[protocol-orchardsend]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.7.3: Sending Notes (Orchard)
[protocol-saplingandorchardencrypt]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.20.1: Encryption (Sapling and Orchard)
[protocol-decryptivk]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.20.2: Decryption using an Incoming Viewing Key (Sapling and Orchard)
[protocol-decryptovk]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 4.20.3: Decryption using an Outgoing Viewing Key (Sapling and Orchard)
[protocol-concretediversifyhash]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 5.4.1.6: DiversifyHash^Sapling and DiversifyHash^Orchard Hash Functions
[protocol-concretesaplingkeyagreement]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 5.4.5.3 Sapling Key Agreement
[protocol-concreteorchardkeyagreement]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 5.4.5.5 Orchard Key Agreement
[protocol-notept]
Zcash Protocol Specification, Version 2025.6.1 [NU6.1]. Section 5.5: Encodings of Note Plaintexts and Memo Fields
[zip-0207]
ZIP 207: Funding Streams
[zip-0213]
ZIP 213: Shielded Coinbase
[zip-0251]
ZIP 251: Deployment of the Canopy Network Upgrade
[zip-0252]
ZIP 252: Deployment of the NU5 Network Upgrade
[zip-2005]
ZIP 2005: Ironwood Quantum Recoverability
[zecwallet-grace-extension]
Commit c31a04a in aditypk00/librustzcash: Move ZIP-212 grace period to end of April