ZIP: 231
Title: Memo Bundles
Owners: Jack Grigg <jack@electriccoin.co>
        Kris Nuttycombe <kris@electriccoin.co>
        Daira-Emma Hopwood <daira@electriccoin.co>
        Arya Solhi <arya@zfnd.org>
Credits: Sean Bowe
         Nate Wilcox
Status: Draft
Category: Consensus / Wallet
Created: 2024-04-26
License: MIT
Discussions-To: <https://github.com/zcash/zips/issues/627>

Terminology

The key words “MUST”, “MUST NOT”, “SHOULD”, and “MAY” in this document are to be interpreted as described in BCP 14 1 when, and only when, they appear in all capitals.

The term “network upgrade” in this document is to be interpreted as described in ZIP 200. 2

The character § is used when referring to sections of the Zcash Protocol Specification. 3

The terms “Mainnet” and “Testnet” are to be interpreted as described in § 3.12 ‘Mainnet and Testnet’. 4

Abstract

Currently, the memo sent in a shielded output is limited to at most 512 bytes. This ZIP proposes to allow larger memos, and to enable memo data to be shared between multiple recipients of a transaction.

Motivation

In Zcash transaction versions v2 to v5 inclusive, each Sapling or Orchard shielded output contains a ciphertext comprised of a 52-byte note plaintext, and a corresponding 512-byte memo field. 5 Recipients can only decrypt the outputs sent to them, and thus can also only observe the memo fields included with the outputs they can decrypt.

The shielded transaction protocol hides the sender(s) (that is, the addresses corresponding to the keys used to spend the input notes) from all of the recipients. For certain kinds of transactions, it is desirable to make one or more sender addresses available to one or more recipients (for example, a reply address). In such circumstances it is important to authenticate the sender addresses, to give the recipient a guarantee that the address is controlled by a sender of the transaction; failure to authenticate this address can enable phishing attacks. These Authenticated Reply Addresses require zero-knowledge proofs, and for the Orchard protocol these proofs are too large to fit into a 512-byte memo field.

It is also desirable, for clients with more stringent bandwidth constraints, to be able to transmit encrypted notes to the client without including the encrypted memo data. In the current light client protocol 6, this is done by truncating the note ciphertext to just the part that encrypts the memo. However, that has the effect of truncating the authentication tag, and so the resulting decryption algorithm does not meet standard security notions for an authenticated encryption scheme. It is a goal of this proposal to rectify this, simplifying the security argument.

Instead of the memo data, this ZIP proposes that it is possible to indicate whether a memo is present for the recipient. When using the light client protocol, a recipient need not download full transaction information if this indication tells them that they have not received any memo in the transaction.

At present, it is not possible to transmit the same memo data to multiple transaction recipients without redundantly encoding that data, and sending memo data greater than 512 bytes requires sending multiple outputs; the problem is compounded when attempting to send more than 512 bytes to each recipient. By separating memo data from the decryption capability for those memos, it admits a greater variety of applications that utilize memo data, while decreasing the amount of data that needs to be stored on-chain overall.

Requirements

Non-requirements

Specification

Since this proposal is defined only for v6 and later transactions, it is not necessary to consider Sprout JoinSplit outputs. The following sections apply to both Sapling and Orchard outputs.

Memo bundle

A memo bundle consists of a sequence of 256-byte memo chunks, each individually encrypted. These memo chunks represent zero or more encrypted memos.

Each transaction may contain a single memo bundle, and a memo bundle may contain at most memo_chunk_limit memo chunks. This limits the total amount of memo data that can be conveyed within a single transaction to memo_chunk_limit * 256 bytes.

memo_chunk_limit is a parameter to this specification, to be decided upon by the community. The authors of this ZIP propose a maximum of 64 chunks, resulting in a maximum total memo data length of 16 KiB.

Memo bundles are encoded in transactions in a prunable manner: each memo chunk can be replaced by its representative digest.

Memo encryption

During transaction construction, each output with memo data is assigned a 32-byte memo key \(\mathsf{K^{memo}}\). These keys SHOULD be generated randomly, and MUST NOT be used to encrypt more than one memo within a single transaction. If an output has no memo data, it is assigned the memo key consisting of 32 \(\mathtt{0xFF}\) bytes.

In note plaintexts of v6-onward transactions, the 512-byte memo field is replaced by \(\mathsf{K^{memo}}\).

The transaction builder generates a 32-byte salt value \(\mathsf{salt}\) from a CSPRNG. A new salt MUST be generated for each memo bundle.

The symmetric encryption key for a memo is derived from its \(\mathsf{K^{memo}}\) as follows:

\(\hspace{2em}\mathsf{encryption\_key} = \mathsf{PRF^{expand}_{K^{memo}}}([\mathtt{0xE0}] \,||\, \mathsf{salt})\)

The first byte \(\mathtt{0xE0}\) should be added to the documentation of inputs to \(\mathsf{PRF^{expand}}\) in § 4.1.2 ‘Pseudo Random Functions’ 7.

If the generated key is 32 \(\mathtt{0xFF}\) bytes, the transaction constructor MAY repeat this procedure with a different salt, in order to avoid the recipient misinterpreting the output as having no memo data. Since that has negligible probability, it alternatively MAY omit this check.

Each memo is padded to a multiple of 256 bytes with zeroes, and split into 256-byte chunks. Each memo chunk is encrypted with ChaCha20Poly1305 8 as follows:

\(\hspace{2em}\mathsf{IETF\_AEAD\_CHACHA20\_POLY1305}(\mathsf{encryption\_key}, \mathsf{nonce}, \mathsf{memo\_chunk})\)

where \(\mathsf{nonce} = \mathsf{I2BEOSP}_{88}(\mathsf{counter}) \,||\, [\mathsf{final\_chunk}]\).

This is a variant of the STREAM construction 9.

Finally, the encrypted memo chunks for all memos are combined into a single sequence using an order-preserving shuffle. Memo chunks from different memos MAY be interleaved in any order, but memo chunks from the same memo MUST have the same relative order. The following diagram shows an example shuffle of three memos:

[
    (memo_a, 0),
    (memo_b, 0),
    (memo_a, 1),
    (memo_c, 0),
    (memo_c, 1),
    (memo_a, 2),
]

Memo decryption

When a recipient decrypts a shielded output, they obtain a memo key \(\mathsf{K^{memo}}\). From this they derive encryption_key as above, and then proceed as follows:

If any chunk of the memo encrypted to memo_key has been pruned, the decryption process above returns nothing (as final_chunk will be set to 0x01 with the wrong counter value), ensuring that a malformed memo is not returned.

Encoding in transactions

Bytes Name Data Type Description
1 fAllPruned uint8 1 if all chunks have been pruned, otherwise 0.
32 nonceOrHash byte[32] The nonce for deriving encryption keys, or the overall hash.
† varies nMemoChunks compactSize The number of memo chunks.
† varies pruned byte[\(\mathsf{ceiling}(\mathtt{nMemoChunks}/8)\)] Bitflags indicating the type of each entry in vMemoChunks.
† varies vMemoChunks MemoChunk[nMemoChunks] A sequence of encrypted memo chunks.

† These fields are present if and only if fAllPruned == 0.

If fAllPruned == 0, then:

If fAllPruned == 1, then:

Transaction sighash

memo_chunk_digest = H(AEAD(MemoChunk, memo_key))
memo_bundle_digest = H(concat(memo_chunk_digests))

The memo bundle digest structure is a performance optimization for the case where all memo chunks in a transaction have been pruned.

TODO: finish this to be a modification to the equivalent of ZIP 244 for transaction v6.

Transaction fees

(This section will become a modification to ZIP 317.)

A memo bundle may contain two free chunks if there are any shielded outputs in the transaction. Otherwise, each memo chunk requires marginal_fee as defined in ZIP 317 10.

Network protocol

Nodes must reject GetData responses having an fAllPruned value that is nonzero, or any byte of pruned that is nonzero.

Changes to the Zcash Protocol Specification

The following changes affecting the definitions of note plaintexts and note ciphertexts, and the algorithms for encryption and decryption.

In § 3.2.1 ‘Note Plaintexts and Memo Fields’:

In § 5.5 ‘Encodings of Note Plaintexts and Memo Fields’ 11:

In § 4.7.2 ‘Sending Notes (Sapling)’ 12 and § 4.7.3 ‘Sending Notes (Orchard)’ 13:

In § 4.20.1 ‘Encryption (Sapling and Orchard)’ 14:

In § 4.20.2 ‘Decryption using an Incoming Viewing Key (Sapling and Orchard)’ 15 and § 4.20.3 ‘Decryption using a Full Viewing Key (Sapling and Orchard)’ 16:

Applicability

All of these changes apply identically to Mainnet and Testnet.

Open issues

Limit on the number of memo chunks

memo_chunk_limit == 64 is recommended. This results in a maximum of 16 KiB of memo data per transaction.

Interaction with ZIP 302 17

TBD

Rationale

Memo bundle size restriction

Restricting the total amount of memo data in a bundle, for example to 16 KiB, limits the rate at which the chain size can grow cheaply (from a computational perspective; memo bundles are much easier to produce than proofs or signatures).

The current behaviour for previous transaction versions (no limit on the number of memos) is not altered by this ZIP, because memos in those transactions are tied to individual shielded outputs (incurring their computational cost), and are not natively aggregatable.

Memo chunk size

TODO: this table needs to be recalculated with a 16 KiB limit.

With 10 KiB limit on amount of memo data as the constant in this table, the maximum number of unique memos you can create, and the cost in bytes of that memo data plus auth when using a 32-byte memo key, is:

Chunk size Memo size ≤ 256 bytes Memo size = 512 bytes
Pre-231 20 @ 10240 ( 0.00%) 20 @ 10240 ( 0.00%)
512 20 @ 11220 (+ 9.57%) 20 @ 11220 (+ 9.57%)
256 40 @ 12200 (+19.14%) 20 @ 11540 (+12.70%)
256 20-out 20 @ 6100 (-40.43%)

In the “256 20-out” case you have a distinguisher compared to old transactions, in that you can tell the transaction is sending at most 256 bytes per recipient rather than 512 if it is sending the max number of memos. But that’s inherently baked into the decision to use a smaller memo chunk size (and it is still possible for the chunks to all be a single memo sent to all outputs, or anything in between).

Memo key size

If we used a 16-byte memo key instead of 32 bytes, the transaction size overhead becomes:

Chunk size Memo size ≤ 256 bytes Memo size = 512 bytes
Pre-231 20 @ 10240 ( 0.00%) 20 @ 10240 ( 0.00%)
512 20 @ 10900 (+ 6.45%) 20 @ 10900 (+ 6.45%)
256 40 @ 11560 (+12.89%) 20 @ 11220 (+ 9.57%)
256 20-out 20 @ 5780 (-43.55%)

The decrease in overhead is relatively modest in most cases, but more noticeable for small memos with a 256-byte memo chunk.

However, 128-bit keys don’t meet Zcash’s target security level of 125 bits, as argued in 18.

The benefits of 256-bit keys are:

Encryption format

Including a per-transaction \(\mathsf{salt}\) in the derivation of \(\mathsf{encryption_key}\) gives protection against accidental (or intentional) reuse of \(\mathsf{K^{memo}}\) reuse across multiple transactions. We do not protect against \(\mathsf{K^{memo}}\) reuse within a transaction; it is up to the transaction builder to ensure that the same \(\mathsf{K^{memo}}\) is not used to encrypt two different memos (and if they did so, normal clients would either never observe the second memo, or would decrypt parts of each memo and get a nonsensical and potentially insecure “spliced” memo).

We do not include commitments to the shielded outputs in the derivation of \(\mathsf{encryption_key}\) for two reasons:

Pruned encoding

The separation of memo data from note data, and the new ability to easily store variable-length memo data, opens up an attack vector against node operators for storing arbitrary data. The transaction digest commitments to the memo bundle are structured such that if a node operator is presented with a memo key (i.e. they are given the capability to decrypt a particular memo), they can identify and prune the corresponding memo chunks, while still enabling the transaction to be validated as part of its corresponding block and broadcast over the network.

The transaction encoding permits pruning at the individual chunk level in order to facilitate pruning an individual memo from a transaction without affecting the other memos. This enables node operators to be responsive to, for example, GDPR deletion requests.

Note that broadcasting a partially-pruned transaction means that the pruned chunks no longer contribute to the upper bound on memo data.

The prunable structure does not introduce a censorship axis; memo bundles do not reveal which memo chunks correspond to which memos, and therefore a network adversary cannot selectively censor individual memos. They can censor any/all chunks within specific transactions, however shielded transactions do not reveal their senders, recipients, or amounts, and thus also cannot be individually targeted for censorship.

Transaction fees

Making the fee linear in the number of chunks has the following properties:

Combined with the memo bundle size restriction, the maximum additional fee for a memo bundle over prior transactions is 0.0019 ZEC.

Deployment

This ZIP is proposed to activate with Network Upgrade 7. 20

Reference implementation

TBD

References


  1. 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”↩︎

  2. ZIP 200: Network Upgrade Mechanism↩︎

  3. Zcash Protocol Specification, Version 2024.5.1 [NU6] or later↩︎

  4. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 3.12: Mainnet and Testnet↩︎

  5. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 3.2.1: Note Plaintexts and Memo Fields↩︎

  6. ZIP 307: Light Client Protocol for Payment Detection↩︎

  7. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.1.2: Pseudo Random Functions↩︎

  8. RFC 8439: ChaCha20 and Poly1305 for IETF Protocols↩︎

  9. Online Authenticated-Encryption and its Nonce-Reuse Misuse-Resistance↩︎

  10. ZIP 317: Proportional Transfer Fee Mechanism↩︎

  11. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 5.5: Encodings of Note Plaintexts and Memo Fields↩︎

  12. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.7.2: Sending Notes (Sapling)↩︎

  13. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.7.3: Sending Notes (Orchard)↩︎

  14. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.20.1: Encryption (Sapling and Orchard)↩︎

  15. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.20.2: Decryption using an Incoming Viewing Key (Sapling and Orchard)↩︎

  16. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 4.20.3: Decryption using a Full Viewing Key (Sapling and Orchard)↩︎

  17. ZIP 302: Standardized Memo Field Format↩︎

  18. Zcash Protocol Specification, Version 2024.5.1 [NU6]. Section 8.7: In-band secret distribution↩︎

  19. zcash/zips issue #693: Standardize a protocol for creating shielded transactions offline↩︎

  20. ZIP 254: Deployment of the NU7 Network Upgrade↩︎