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:
- A sender may need to prove that their payment was sent to a recipient, and available to be received (following the Zcash protocol in-band).
- A third party may need to verify that a payment between a given sender and recipient was executed successfully.
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 |
- 🔍 = Visible on the block chain.
- 🔐 = Cannot be confirmed without information that is not visible on the block chain.
- 🔐* = Information is revealed, but not enough to confirm the amount paid (due to change).
- 🔒 = Requires either an interactive payment disclosure, or a non-interactive payment disclosure that reveals the sender's address.
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
- The payment disclosure may disclose the contents of zero or more shielded outputs within a single transaction. (Zero outputs is useful for z2t transactions.)
- Payment disclosures can only be created by a sender of the transaction, and are non-malleable (that is, no-one else can take one or more payment disclosures and construct a new one that they would not have been able to make independently).
- A payment disclosure may be tied to a challenge, creating an interactive proof.
- Senders with a shielded address may choose to provably reveal that address as part of the payment disclosure.
- Senders are not required to remember any ephemeral data from the creation of a transaction in order to produce a payment disclosure for that transaction. (Performance may be improved if they do cache witness data for spent notes.)
- The payment disclosure can be created without requiring another trusted setup.
Conventions
The following functions used in this ZIP are defined in the Zcash protocol specification:
-
\(\mathsf{DiversifyHash}(\mathsf{d})\)
-
\(\mathsf{SpendAuthSig.RandomizePrivate}(α, \mathsf{sk})\)
,
\(\mathsf{SpendAuthSig.Sign}(\mathsf{sk}, m)\)
, and
\(\mathsf{SpendAuthSig.Verify}(\mathsf{vk}, m, σ)\)
We reproduce some notation and functions from here for convenience:
-
\([k] P\)
means scalar multiplication of the elliptic curve point
\(P\)
by the scalar
\(k\)
.
-
\(\mathsf{BLAKE2b}\text{-}\mathsf{256}(p, x)\)
refers to unkeyed BLAKE2b-256 in sequential mode, with an output digest length of 32 bytes, 16-byte personalization string
\(p\)
, and input
\(x\)
.
We also define the following notation here:
-
\([a..b]\)
means the sequence of values inclusive of
\(a\)
and exclusive of
\(b\)
.
-
\(\mathsf{length}(a)\)
means the length of the sequence
\(a\)
.
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.
- 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.
-
\(\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.
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 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, 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}\)
:
- 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 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:
- The anchor is already encoded in the transaction, so can be omitted from the payment disclosure encoding.
- It is necessary to have a witness for each spent note that is being included in the payment disclosure. Using the same anchor means that the same witness can be used for the transaction spend and the payment disclosure, which in turn means that wallets that support payment disclosures only need to remember that witness, and do not need to continually update witnesses for spent notes in the off-chance that they might be used in a payment disclosure.
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