ZIP: 311
Title: Zcash Payment Disclosures
Owners: Jack Grigg <jack@electriccoin.co>
Status: Draft
Category: Standards / RPC / Wallet
Discussions-To: <https://github.com/zcash/zips/issues/387>

Abstract

This ZIP describes a mechanism and format for disclosing information about shielded spends and outputs within a transaction. In the typical case, this means enabling a sender to present a proof that they transferred funds to a recipient's shielded address.

Motivation

There are various situations where a proof-of-payment may be desired. For example:

When a transaction involves only transparent addresses, proof-of-payment is simple: The sender provides the transaction ID, and the recipient examines the blockchain to confirm that the transaction was mined. A third party can also perform this verification if they know the transparent addresses of the involved parties.

However, if the transaction involves shielded addresses, the blockchain by itself does not contain enough information to allow a record of the payment to be reconstructed and verified:

Source Destination Sender Recipient Amount Payment dislosure?
Transparent Transparent πŸ” πŸ” πŸ” Not required
Transparent Shielded πŸ” πŸ” πŸ”* Required
Shielded Transparent πŸ”’ πŸ” πŸ” Required
Shielded Shielded πŸ”’ πŸ” πŸ” Required

Enabling proof-of-payment for all of these transaction variants (where it is possible to do so) is the subject of this ZIP.

Use cases

Managing contributions for an event

Alice runs an event on behalf of Bob and Carol, who both agree to split the cost equally. Alice receives a single payment for half the amount, and wants proof of who it came from (so she knows which person to follow up with for the remaining amount). Carol can provide a payment disclosure that reveals to Alice:

  • The correct amount was sent to the Alice's recipient address in the given transaction.
  • Carol was the sender of that transaction (more precisely, Carol controls the spend authority used in that transaction).

and does not reveal:

  • Carol's payment address.
  • Any of Carol's other diversified payment addresses.
  • Any of Carol's other transactions.

For this use case, it is not necessary (and not necessarily intended) that the payment disclosure be publically verifiable.

Donation drive

Diana is a well-known individual with a public shielded payment address (for receiving donations). She runs a matching donation drive to the non-profit Totally Legit Bunnies, and wants to prove to her followers that she correctly matched their donations. Diana can create a payment disclosure, and post it to her social media account, that reveals:

  • The correct amount was sent to the Totally Legit Bunnies' recipient address in the given transaction.
  • The sender of the transaction is the payment address that is associated with Diana.

and does not reveal:

  • Any of Diana's other diversified payment addresses.
  • Any of Diana's other transactions.

Merchant dispute

Edward goes to CarsRFast to buy a Lamborghini, and sends funds from his shielded address to CarsRFast's transparent address. They can see a payment has been made, but claim that they have not received a payment from Edward. He can create a payment disclosure that reveals:

  • Edward was the sender of the given transaction.

and does not reveal:

  • Edward's payment address.
  • Any of Edward's other diversified payment addresses.
  • Any of Edward's other transactions.

Shielded withdrawals from an exchange

CorpBux is an exchange with a transparent hot wallet, and enables customers to withdraw their funds to shielded addresses. They can create a payment disclosure, that they can give to their customers, that reveals:

  • The correct amount was sent to the customer's shielded recipient address in the given transaction.
  • CorpBux was the sender of the given transaction.

Requirements

Conventions

The following functions used in this ZIP are defined in the Zcash protocol specification: 3

We reproduce some notation and functions from 3 here for convenience:

We also define the following notation here:

Specification

Payment disclosure data structure

A payment disclosure has the following fields:

  • txid: Transaction id for the transaction tx being disclosed.
  • msg: A message field, which could contain a challenge value from the party to whom the payment disclosure is directed.
  • \(\mathsf{transparentInputs}\!\) : A sequence of the transparent inputs for which we are proving spend authority \([0..\mathsf{length}(\mathsf{tx.vin})]\)
    • \(\mathsf{index}\!\) : An index into \(\mathsf{tx.vin}\!\) .
    • \(\mathsf{sig}\!\) : A BIP 322 signature. 9
      • TODO: zcashd currently only supports the legacy format defined in BIP 322. We may want to backport full BIP 322 support before having transparent input support in this ZIP, to ensure it does what we need.
      • TODO: BIP 322 specifies consensus rule checks as part of the signature verification process. We will likely need to migrate it over to an equivalent ZIP that specifies these for Zcash (which has a different set of script validation consensus rules).
  • \(\mathsf{saplingSpends}\!\) : A sequence of the Sapling Spends for which we are proving spend authority \([0..\mathsf{length}(\mathsf{tx.shieldedSpends})]\)
    • \(\mathsf{index}\!\) : An index into \(\mathsf{tx.shieldedSpends}\!\) .
    • \(\mathsf{cv}\!\) : A value commitment to the spent note.
    • \(\mathsf{rk}\!\) : A randomized public key linked to the spent note.
    • \(\mathsf{zkproof_{spend}}\!\) : A Sapling spend proof.
    • [Optional] A payment address proof addr_proof:
      • Any \((\mathsf{d, pk_d})\) such that \(\mathsf{pk_d} = [\mathsf{ivk}] \mathsf{DiversifyHash}(\mathsf{d})\)
      • \(\mathsf{nullifier_{addr}}\!\) : A nullifier for a ZIP 304 fake note. 11
      • \(\mathsf{zkproof_{addr}}\!\) : A Sapling spend proof.
    • \(\mathsf{spendAuthSig}\)
  • \(\mathsf{saplingOutputs}\!\) : A sequence of the Sapling Outputs that we are disclosing \([0..\mathsf{length}(\mathsf{tx.shieldedOutputs})]\)
    • \(\mathsf{index}\!\) : An index into \(\mathsf{tx.shieldedOutputs}\!\) .
    • \(\mathsf{ock}\!\) : The outgoing cipher key that allows this output to be recovered. 5

TODO: Add support for Orchard.

TODO: Decide on payment disclosure versioning.

TODO: Define encodings for unsigned and signed payment disclosures.

Creating a payment disclosure

The inputs to a payment disclosure are:

  • The transaction.
  • The SLIP-44 10 coin type.
  • The message \(msg\) to be included (which may be empty).
  • A sequence of \((\mathsf{outputIndex}, \mathsf{ock})\) tuples (which may be empty).
  • A sequence of Sapling spend tuples (which may be empty) containing:
    • A Sapling spend index.
    • Its corresponding expanded spending key \((\mathsf{ask}, \mathsf{nsk}, \mathsf{ovk})\!\) .
    • [Optional] An associated payment address \((\mathsf{d}, \mathsf{pk_d})\!\) .
  • A sequence of transparent input tuples (which may be empty) containing:
    • \(\mathsf{index}\!\) : An index into \(\mathsf{tx.vin}\!\) .
    • The inputs to a BIP 322 signature (excluding message_data).

The caller MUST provide at least one input tuple of any type (either a Sapling spend tuple or a transparent input tuple).

The payment disclosure is created as follows:

  • For each Sapling spend index:
    • Create a Sapling spend proof for the note that was spent in \(\mathsf{tx.shieldedSpends[index]}\!\) , using the same anchor, to obtain \((\mathsf{cv}, \mathsf{rk}, \mathsf{zkproof_{spend}})\) as well as the random \(\alpha\) that was generated internally.
    • [Optional] If an associated payment address was provided for this spend index, create a ZIP 304 signature proof for that payment address, 11 using \(\alpha\) and \(\mathsf{rk}\) from the previous step. We obtain \((\mathsf{nullifier_{addr}}, \mathsf{zkproof_{addr}})\) from this step.
  • For each transparent input index:
    • TODO: Prepare BIP 322 signature inputs using msg as the message_data.
  • Construct an unsigned payment disclosure from the disclosed Sapling outputs, and the above data for the Sapling spends and transparent inputs. Define the encoding of this as \(unsignedPaymentDisclosure\!\) .
  • For each Sapling spend index:
    • Let \(\mathsf{rsk} = \mathsf{SpendAuthSig.RandomizePrivate}(\alpha, \mathsf{ask})\!\) .
    • Let \(coinType\) be the 4-byte little-endian encoding of the SLIP 44 coin type in its index form, not its hardened form (i.e. 133 for mainnet Zcash).
    • Let \(digest = \mathsf{BLAKE2b}\text{-}\mathsf{256}(\texttt{β€œZIP311Signed”}\,||\,coinType, unsignedPaymentDisclosure)\!\) .
    • Let \(spendAuthSig = \mathsf{SpendAuthSig.Sign}(\mathsf{rsk}, digest)\!\) .
  • For each transparent input index:
    • TODO: Create a BIP 322 signature using msg as the message_data.
  • Return the payment disclosure as the combination of the unsigned payment disclosure and the set of spendAuthSig and transparent signature values.

Verifying a payment disclosure

Given a payment disclosure \(\mathsf{pd}\!\) , a transaction \(\mathsf{tx}\!\) , and the height of the block in which \(\mathsf{tx}\) was mined (which we assume was verified by the caller), the verifier proceeds as follows:

  • Perform the following structural correctness checks, returning false if any check fails:
    • \(\mathsf{pd.txid} = \mathsf{tx.txid}()\)
    • Sequence length correctness:
      • \(\mathsf{length}(\mathsf{pd.saplingOutputs}) \leq \mathsf{length}(\mathsf{tx.shieldedOutputs})\)
      • \(\mathsf{length}(\mathsf{pd.saplingSpends}) \leq \mathsf{length}(\mathsf{tx.shieldedSpends})\)
      • \(\mathsf{length}(\mathsf{pd.transparentInputs}) \leq \mathsf{length}(\mathsf{tx.vin})\)
    • Index uniqueness:
      • For every \(\mathsf{output}\) in \(\mathsf{pd.saplingOutputs}\!\) , \(\mathsf{output.index}\) only occurs once.
      • For every \(\mathsf{spend}\) in \(\mathsf{pd.saplingSpends}\!\) , \(\mathsf{spend.index}\) only occurs once.
      • For every \(\mathsf{input}\) in \(\mathsf{pd.transparentInputs}\!\) , \(\mathsf{input.index}\) only occurs once.
    • Index correctness:
      • For every \(\mathsf{output}\) in \(\mathsf{pd.saplingOutputs}\!\) , \(\mathsf{output.index} < \mathsf{length}(\mathsf{tx.shieldedOutputs})\)
      • For every \(\mathsf{spend}\) in \(\mathsf{pd.saplingSpends}\!\) , \(\mathsf{spend.index} < \mathsf{length}(\mathsf{tx.shieldedSpends})\)
      • For every \(\mathsf{input}\) in \(\mathsf{pd.transparentInputs}\!\) , \(\mathsf{input.index} < \mathsf{length}(\mathsf{tx.vin})\)
    • \(\mathsf{length}(\mathsf{pd.saplingSpends}) + \mathsf{length}(\mathsf{pd.transparentInputs}) > 0\)
  • Let \(unsignedPaymentDisclosure\) be the encoding of the payment disclosure without signatures.
  • Let \(coinType\) be the 4-byte little-endian encoding of the coin type in its index form, not its hardened form (i.e. 133 for mainnet Zcash).
  • Let \(digest = \mathsf{BLAKE2b}\text{-}\mathsf{256}(\texttt{β€œZIP311Signed”}\,||\,coinType, unsignedPaymentDisclosure)\!\) .
  • For every \(\mathsf{spend}\) in \(\mathsf{pd.saplingSpends}\!\) :
    • If \(\mathsf{SpendAuthSig.Verify}(\mathsf{spend.rk}, digest, \mathsf{spend.spendAuthSig}) = 0\!\) , return false.
    • [Optional] If a payment address proof \(\mathsf{addrProof}\) is present in \(\mathsf{spend}\!\) , verify \((\mathsf{addrProof.nullifier_{addr}}, \mathsf{spend.rk}, \mathsf{addrProof.zkproof_{addr}})\) as a ZIP 304 proof for \((\mathsf{addrProof.d}, \mathsf{addrProof.pk_d})\) 11. If verification fails, return false.
    • Decode and verify \(\mathsf{zkproof_{spend}}\) as a Sapling spend proof 4 with primary input:
      • \(\mathsf{tx.shieldedSpends[spend.index].rt}\)
      • \(\mathsf{spend.cv}\)
      • \(\mathsf{tx.shieldedSpends[spend.index].nf}\)
      • \(\mathsf{spend.rk}\)

      If verification fails, return false.

  • For every \(\mathsf{input}\) in \(\mathsf{pd.transparentInputs}\!\) :
    • TODO: BIP 322 verification.
  • For every \(\mathsf{output}\) in \(\mathsf{pd.saplingOutputs}\!\) :
    • Recover the Sapling note in \(\mathsf{tx.shieldedOutputs}[\mathsf{output.index}]\) via the process specified in 6 with inputs \((height, \mathsf{output.ock})\!\) . If recovery returns \(\bot\!\) , return false.
  • Return true.

Payment disclosure validity in UIs

TODO: Set some standards for how UIs should display payment disclosures, and how they should convey the various kinds of validity information:

  • One, but not all, of the spenders proved spend authority.
  • All spenders of a specific type proved spend authority.
  • All spenders proved spend authority.
  • These, but also including optional payment address proofs.

Rationale

If a sender elects, at transaction creation time, to use an \(\mathsf{ovk}\) of \(\bot\) for a specific Sapling output, then they are unable to subsequently create a payment disclosure that discloses that output. This maintains the semantics of \(\mathsf{ovk}\!\) , in that the sender explicitly chose to lose the capability to recover that output.

Payment disclosures that prove Sapling spend authority are not required to reveal a sender address. This is because it is impossible: we can "prove" the transaction came from any of the diversified addresses linked to the spending key. Fundamentally, the "sender" of a transaction is anyone who has access to the corresponding spend authority; in the case of Sapling, a spend authority corresponds to multiple diversified addresses. In situations where a sender address is already known to the verifier of the payment disclosure (or publically), it may still be useful to have the option of linking the payment disclosure to that address.

Security and Privacy Considerations

When spending Sapling notes normally in transactions, wallets select a recent anchor to make the anonymity set of the spent note as large as possible. By contrast, Sapling spend authority in a payment disclosure is proven using the same anchor that was used in the transaction itself, instead of a recent anchor. We do this for efficency reasons:

There is no privacy benefit to selecting a more recent anchor; the anonymity set of the note was "fixed" by the original spend (which revealed that the note existed as of that anchor's height).

We require all payment disclosures to prove spend authority for at least one input, in order to simplify the verification UX. In particular, if payment disclosures without spends were considered valid, an invalid payment disclosure with invalid signatures (that would be shown as invalid by UIs) could be mutated into a payment disclosure that would be shown as valid by UIs, by stripping off the signatures. We do not believe that this prevents any useful use cases; meanwhile if someone is intent on obtaining Sapling output disclosures regardless of the validity of their source, they will do so without a common standard.

Reference implementation

TBD

References

1 RFC 2119: Key words for use in RFCs to Indicate Requirement Levels
2 RFC 4648: The Base16, Base32, and Base64 Data Encodings
3 Zcash Protocol Specification, Version 2020.1.15 or later
4 Zcash Protocol Specification, Version 2020.1.15. Section 4.15.2: Spend Statement (Sapling)
5 Zcash Protocol Specification, Version 2020.1.15. 4.17.1: Encryption (Sapling)
6 Zcash Protocol Specification, Version 2020.1.15. 4.17.3: Decryption using a Full Viewing Key (Sapling)
7 Zcash Protocol Specification, Version 2020.1.15. Section 5.4.1.6: DiversifyHash Hash Function
8 Zcash Protocol Specification, Version 2020.1.15. Section 5.4.6.1: Spend Authorization Signature
9 BIP 322: Generic Signed Message Format
10 SLIP-0044 : Registered coin types for BIP-0044
11 ZIP 304: Sapling Address Signatures