ZIP: 32 Title: Shielded Hierarchical Deterministic Wallets Owners: Jack Grigg <str4d@electriccoin.co> Daira-Emma Hopwood <daira-emma@electriccoin.co> Credits: Sean Bowe Kris Nuttycombe Ying Tong Lai Pieter Wuille Marek Palatinus Pavol Rusnak Status: Final Category: Standards / Wallet Created: 2018-05-22 License: MIT
The key words "MUST", "MUST NOT", and "MAY" in this document are to be interpreted as described in BCP 14 1 when, and only when, they appear in all capitals.
"Jubjub" refers to the elliptic curve defined in 15.
A "chain code" is a cryptovalue that is needed, in addition to a spending key, in order to derive descendant keys and addresses of that key.
The terms "Testnet" and "Mainnet" are to be interpreted as described in section 3.12 of the Zcash Protocol Specification 10.
This proposal defines a mechanism for extending hierarchical deterministic wallets, as described in BIP 32 2, to support Zcash's shielded addresses.
The initial parts of the specification define (mostly) equivalent, but independent, systems for deriving a tree of key components from a single seed, for the following shielded pools (which have different internal key structures):
Previous versions of this document also defined a similar derivation system for the Sprout shielded pool. This has been removed since it was never used, and is unlikely to be used given that zcashd no longer generates Sprout addresses (and neither Zebra nor the mobile SDKs have ever done so).
The last part shows how to use these trees in the context of existing BIP 44 5 wallets.
This specification complements the existing use by some Zcash wallets of BIP 32 and BIP 44 for transparent Zcash addresses, and is not intended to deprecate that usage (privacy risks of using transparent addresses notwithstanding).
BIP 32 2 is the standard mechanism by which wallets for Bitcoin and its derivatives (including Zcash's transparent addresses 6) generate keys and addresses deterministically. This has several advantages over random generation:
At present, no such equivalent exists for Zcash's shielded addresses. This is of particular concern for hardware wallets; all currently-marketed devices only store a seed internally, and have trained their users to only backup that seed. Given that the Sapling upgrade will make it feasible to use hardware wallets with shielded addresses, it is desirable to have a standard mechanism for deriving them.
Most of the notation and functions used in this ZIP are defined in the Zcash protocol specification 9. They are reproduced here for convenience:
The following algorithm standardized in 22 is used:
We also define the following conversion function:
Implementors should note that this ZIP is consistently little-endian (in keeping with the Sapling and Orchard specifications), which is the opposite of BIP 32.
We adapt the path notation of BIP 32 2 to describe shielded HD paths, using prime marks (
BIP 32 defines a method to derive a number of child keys from a parent key. In order to prevent these from depending solely on the parent key itself, both the private and public keys are extended with a 32-byte chain code. We similarly extend Sapling keys with a chain code here. However, the concepts of "private" and "public" keys in BIP 32 do not map cleanly to Sapling's key components. We take the following approach:
We represent a Sapling extended spending key as
We represent a Sapling extended full viewing key as
Define
Let
Note that the master extended key is invalid if
As in BIP 32, the method for deriving a child extended key, given a parent extended key and an index
Note that the child extended key is invalid if
Let
Note that the child extended key is invalid if
The above derivation mechanisms produce external addresses suitable for giving out to senders. We also want to be able to produce another address derived from a given external address, for use by wallets for internal operations such as change and auto-shielding. Unlike BIP 44 that allows deriving a stream of external and internal addresses in the same hierarchical derivation tree 5, for any external full viewing key we only need to be able to derive a single internal full viewing key that has viewing authority for just internal transfers. We also need to be able to derive the corresponding internal spending key if we have the external spending key.
Let
Note that the child extended key is invalid if
Let
Let
This design uses the same technique as non-hardened derivation to obtain a full viewing key with the same spend authority (the private key corresponding to
The values of
(For simplicity, the proof authorizing key is not shown.)
This method of deriving internal keys is applied to external keys that are children of the Account level. It was implemented in zcashd as part of support for ZIP 316 8.
Note that the internal extended key is invalid if
The 88-bit diversifiers for a Sapling extended key are derived from its diversifier key
A valid diversifier
The default diversifier for a Sapling extended key is defined to be
The derivation mechanism for Sapling addresses specified above incurs significant complexity to support non-hardened derivation. In the several years since Sapling was deployed, we have seen no use cases for non-hardened derivation appear. With that in mind, we only support hardened key derivation for Orchard.
We represent an Orchard extended spending key as
Let
Note that the resulting child spending key may produce an invalid external FVK, as specified in 12, with small probability. The corresponding internal FVK derived as specified in the next section may also be invalid with small probability.
As in the case of Sapling, for a given external address, we want to produce another address for use by wallets for internal operations such as change and auto-shielding. That is, for any external full viewing key we need to be able to derive a single internal full viewing key that has viewing authority for just internal transfers. We also need to be able to derive the corresponding internal spending key if we have the external spending key.
Let
Define
The result of applying
Unlike Sapling internal key derivation, we do not base this internal key derivation procedure on non-hardened derivation, which is not defined for Orchard. We can obtain the desired separation of viewing authority by modifying only the
This method of deriving internal keys is applied to external keys that are children of the Account level. It was implemented in zcashd as part of support for ZIP 316 8.
Note that the resulting FVK may be invalid, as specified in 12.
As with Sapling, we define a mechanism for deterministically deriving a sequence of diversifiers, without leaking how many diversified addresses have already been generated for an account. Unlike Sapling, we do so by deriving a diversifier key directly from the full viewing key, instead of as part of the extended spending key. This means that the full viewing key provides the capability to determine the position of a diversifier within the sequence, which matches the capabilities of a Sapling extended full viewing key but simplifies the key structure.
Given an Orchard extended spending key
Note that unlike Sapling, all Orchard diversifiers are valid, and thus all possible values of
The default diversifier for
Existing Zcash-supporting HD wallets all use BIP 44 5 to organize their derived keys. In order to more easily mesh with existing user experiences, we broadly follow BIP 44's design here. However, we have altered the design where it makes sense to leverage features of shielded addresses.
Sapling and Orchard key paths have the following three path levels at the top, all of which use hardened derivation:
Unlike BIP 44, none of the shielded key paths have a
Sapling provides a mechanism to allow the efficient creation of diversified payment addresses with the same spending authority. A group of such addresses shares the same full viewing key and incoming viewing key, and so creating as many unlinkable addresses as needed does not increase the cost of scanning the block chain for relevant transactions.
The above key path levels include an account identifier, which in all user interfaces is represented as a "bucket of funds" under the control of a single spending authority. Therefore, wallets implementing Sapling ZIP 32 derivation MUST support the following path for any account in range
Furthermore, wallets MUST support generating the default payment address (corresponding to the default diversifier as defined above) for any account they support. They MAY also support generating a stream of payment addresses for a given account, if they wish to maintain the user experience of giving a unique address to each recipient.
Note that a given account can have a maximum of approximately
If in certain circumstances a wallet needs to derive independent spend authorities within a single account, they MAY additionally support a non-hardened
zcashd version 4.6.0 and later uses this to derive "legacy" Sapling addresses from a mnemonic seed phrase under account
Orchard supports diversified addresses with the same spending authority (like Sapling). A group of such addresses shares the same full viewing key and incoming viewing key, and so creating as many unlinkable addresses as needed does not increase the cost of scanning the block chain for relevant transactions.
The above key path levels include an account identifier, which in all user interfaces is represented as a "bucket of funds" under the control of a single spending authority. Therefore, wallets implementing Orchard ZIP 32 derivation MUST support the following path for any account in range
Furthermore, wallets MUST support generating the default payment address (corresponding to the default diversifier for Orchard) for any account they support. They MAY also support generating a stream of diversified payment addresses for a given account, if they wish to enable users to give a unique address to each recipient.
Note that a given account can have a maximum of
The following encodings are analogous to the xprv
and xpub
encodings defined in BIP 32 for transparent keys and addresses. Each key type has a raw representation and a Bech32 7 encoding.
A Sapling extended spending key
For the master extended spending key,
When encoded as Bech32, the Human-Readable Part is secret-extended-key-main
for the production network, or secret-extended-key-test
for the test network.
A Sapling extended full viewing key
For the master extended full viewing key,
When encoded as Bech32, the Human-Readable Part is zxviews
for the production network, or zxviewtestsapling
for the test network.
An Orchard extended spending key
For the master extended spending key,
When encoded as Bech32, the Human-Readable Part is secret-orchard-extsk-main
for Mainnet, or secret-orchard-extsk-test
for Testnet.
We define this encoding for completeness, however given that it includes the capability to derive child spending keys, we expect that most wallets will only expose the regular Orchard spending key encoding to users 21.
The following values were previously used in the specification of hierarchical derivation for Sprout, and therefore SHOULD NOT be used in future Zcash-related specifications:
zxsprout
and zxtestsprout
, formerly specified for Sprout extended spending keys on Mainnet and Testnet respectively.TBC
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 | BIP 32: Hierarchical Deterministic Wallets |
---|
3 | BIP 39: Mnemonic code for generating deterministic keys |
---|
4 | BIP 43: Purpose Field for Deterministic Wallets |
---|
5 | BIP 44: Multi-Account Hierarchy for Deterministic Wallets |
---|
6 | SLIP 44: Registered coin types for BIP-0044 |
---|
7 | BIP 173: Base32 address format for native v0-16 witness outputs |
---|
8 | ZIP 316: Unified Addresses and Unified Viewing Keys |
---|
9 | Zcash Protocol Specification, Version 2022.2.19 or later [NU5 proposal] |
---|
10 | Zcash Protocol Specification, Version 2022.2.19. Section 3.12: Mainnet and Testnet |
---|
11 | Zcash Protocol Specification, Version 2022.2.19. Section 4.2.2: Sapling Key Components |
---|
12 | Zcash Protocol Specification, Version 2022.2.19. Section 4.2.3: Orchard Key Components |
---|
13 | Zcash Protocol Specification, Version 2022.2.19. Section 5.4.1.6: DiversifyHash^Sapling and DiversifyHash^Orchard Hash Functions |
---|
14 | Zcash Protocol Specification, Version 2022.2.19. Section 5.4.6.1: Spend Authorization Signature |
---|
15 | Zcash Protocol Specification, Version 2022.2.19. Section 5.4.9.3: Jubjub |
---|
16 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.2.1: Sprout Payment Addresses |
---|
17 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.2.3: Sprout Spending Keys |
---|
18 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.3.3: Sapling Full Viewing Keys |
---|
19 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.3.4: Sapling Spending Keys |
---|
20 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.4.4: Orchard Raw Full Viewing Keys |
---|
21 | Zcash Protocol Specification, Version 2022.2.19. Section 5.6.4.5: Orchard Spending Keys |
---|
22 | NIST Special Publication 800-38G — Recommendation for Block Cipher Modes of Operation: Methods for Format-Preserving Encryption |
---|