Merge pull request #5543 from nuttycom/feature/wallet_unified_addresses-address_review

Rename sapling-specific zip32 FFI methods.
This commit is contained in:
Kris Nuttycombe 2022-02-13 07:35:08 -07:00 committed by GitHub
commit 96f34b9bbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 49 deletions

View File

@ -7,14 +7,14 @@ Notable changes
Mnemonic Recovery Phrases
-------------------------
The zcashd wallet has been modified to support ZIP 339 (to be compatible with BIP 39)
which describes how to derive the wallet's HD seed from a mnemonic phrase.
The mnemonic phrase will be generated on load of the wallet, or the first time
the wallet is unlocked, and is available via the `z_exportwallet` RPC call. All
new addresses produced by the wallet are now derived from this seed using the
HD wallet functionality described in ZIP 32 and ZIP 316. For users upgrading an
existing Zcashd wallet, it is recommended that the wallet be backed up prior to
upgrading to the 4.5.2 Zcashd release.
The zcashd wallet has been modified to support BIP 39, which describes how to
derive the wallet's HD seed from a mnemonic phrase. The mnemonic phrase will
be generated on load of the wallet, or the first time the wallet is unlocked,
and is available via the `z_exportwallet` RPC call. All new addresses produced
by the wallet are now derived from this seed using the HD wallet functionality
described in ZIP 32 and ZIP 316. For users upgrading an existing Zcashd wallet,
it is recommended that the wallet be backed up prior to upgrading to the 4.5.2
Zcashd release.
Following the upgrade to 4.5.2, Zcashd will require that the user confirm that
they have backed up their new emergency recovery phrase, which may be obtained

View File

@ -30,32 +30,18 @@ class WalletAccountsTest(BitcoinTestFramework):
# Check we only have balances in the expected pools.
# Remember that empty pools are omitted from the output.
def check_account_balance(self, account, expected, minconf=None):
if minconf is None:
actual = self.nodes[0].z_getbalanceforaccount(account)
else:
actual = self.nodes[0].z_getbalanceforaccount(account, minconf)
def _check_balance_for_rpc(self, rpcmethod, node, account, expected, minconf):
rpc = getattr(self.nodes[node], rpcmethod)
actual = rpc(account) if minconf is None else rpc(account, minconf)
assert_equal(set(expected), set(actual['pools']))
for pool in expected:
assert_equal(expected[pool] * COIN, actual['pools'][pool]['valueZat'])
assert_equal(actual['minimum_confirmations'], 1 if minconf is None else minconf)
# Check we only have balances in the expected pools.
# Remember that empty pools are omitted from the output.
def check_address_balance(self, address, expected, minconf=None):
fvk = self.nodes[0].z_exportviewingkey(address)
if minconf is None:
actual = self.nodes[0].z_getbalanceforviewingkey(fvk)
else:
actual = self.nodes[0].z_getbalanceforviewingkey(fvk, minconf)
assert_equal(set(expected), set(actual['pools']))
for pool in expected:
assert_equal(expected[pool] * COIN, actual['pools'][pool]['valueZat'])
assert_equal(actual['minimum_confirmations'], 1 if minconf is None else minconf)
def check_balance(self, account, address, expected, minconf=None):
self.check_account_balance(account, expected, minconf)
self.check_address_balance(address, expected, minconf)
def check_balance(self, node, account, address, expected, minconf=None):
self._check_balance_for_rpc('z_getbalanceforaccount', node, account, expected, minconf)
fvk = self.nodes[node].z_exportviewingkey(address)
self._check_balance_for_rpc('z_getbalanceforviewingkey', node, fvk, expected, minconf)
def run_test(self):
# With a new wallet, the first account will be 0.
@ -96,8 +82,8 @@ class WalletAccountsTest(BitcoinTestFramework):
self.check_receiver_types(ua1, ['transparent', 'sapling'])
# The balances of the accounts are all zero.
self.check_balance(0, ua0, {})
self.check_balance(1, ua1, {})
self.check_balance(0, 0, ua0, {})
self.check_balance(0, 1, ua1, {})
# Manually send funds to one of the receivers in the UA.
recipients = [{'address': ua0, 'amount': Decimal('10')}]
@ -113,14 +99,14 @@ class WalletAccountsTest(BitcoinTestFramework):
# The new balance should not be visible with the default minconf, but should be
# visible with minconf=0.
self.sync_all()
self.check_balance(0, ua0, {})
self.check_balance(0, ua0, {'sapling': 10}, 0)
self.check_balance(0, 0, ua0, {})
self.check_balance(0, 0, ua0, {'sapling': 10}, 0)
self.nodes[2].generate(1)
self.sync_all()
# The default minconf should now detect the balance.
self.check_balance(0, ua0, {'sapling': 10})
self.check_balance(0, 0, ua0, {'sapling': 10})
# Manually send funds from the UA receiver.
node1sapling = self.nodes[1].z_getnewaddress('sapling')
@ -139,8 +125,8 @@ class WalletAccountsTest(BitcoinTestFramework):
# shown, as that transaction has been created and broadcast, and _might_ get mined
# up until the transaction expires), or 9 (if we include the unmined transaction).
self.sync_all()
self.check_balance(0, ua0, {})
self.check_balance(0, ua0, {'sapling': 9}, 0)
self.check_balance(0, 0, ua0, {})
self.check_balance(0, 0, ua0, {'sapling': 9}, 0)
if __name__ == '__main__':

View File

@ -286,27 +286,27 @@ extern "C" {
);
/// Derive the master ExtendedSpendingKey from a seed.
void librustzcash_zip32_xsk_master(
void librustzcash_zip32_sapling_xsk_master(
const unsigned char *seed,
size_t seedlen,
unsigned char *xsk_master
);
/// Derive a child ExtendedSpendingKey from a parent.
void librustzcash_zip32_xsk_derive(
void librustzcash_zip32_sapling_xsk_derive(
const unsigned char *xsk_parent,
uint32_t i,
unsigned char *xsk_i
);
/// Derive a internal ExtendedSpendingKey from an external key
void librustzcash_zip32_xsk_derive_internal(
void librustzcash_zip32_sapling_xsk_derive_internal(
const unsigned char *xsk_external,
unsigned char *xsk_internal
);
/// Derive a child ExtendedFullViewingKey from a parent.
bool librustzcash_zip32_xfvk_derive(
bool librustzcash_zip32_sapling_xfvk_derive(
const unsigned char *xfvk_parent,
uint32_t i,
unsigned char *xfvk_i

View File

@ -1039,7 +1039,7 @@ pub extern "C" fn librustzcash_sapling_proving_ctx_free(ctx: *mut SaplingProving
/// Derive the master ExtendedSpendingKey from a seed.
#[no_mangle]
pub extern "C" fn librustzcash_zip32_xsk_master(
pub extern "C" fn librustzcash_zip32_sapling_xsk_master(
seed: *const c_uchar,
seedlen: size_t,
xsk_master: *mut [c_uchar; 169],
@ -1054,7 +1054,7 @@ pub extern "C" fn librustzcash_zip32_xsk_master(
/// Derive a child ExtendedSpendingKey from a parent.
#[no_mangle]
pub extern "C" fn librustzcash_zip32_xsk_derive(
pub extern "C" fn librustzcash_zip32_sapling_xsk_derive(
xsk_parent: *const [c_uchar; 169],
i: u32,
xsk_i: *mut [c_uchar; 169],
@ -1072,7 +1072,7 @@ pub extern "C" fn librustzcash_zip32_xsk_derive(
/// Derive the Sapling internal spending key from the external extended
/// spending key
#[no_mangle]
pub extern "C" fn librustzcash_zip32_xsk_derive_internal(
pub extern "C" fn librustzcash_zip32_sapling_xsk_derive_internal(
xsk_external: *const [c_uchar; 169],
xsk_internal_ret: *mut [c_uchar; 169],
) {
@ -1088,7 +1088,7 @@ pub extern "C" fn librustzcash_zip32_xsk_derive_internal(
/// Derive a child ExtendedFullViewingKey from a parent.
#[no_mangle]
pub extern "C" fn librustzcash_zip32_xfvk_derive(
pub extern "C" fn librustzcash_zip32_sapling_xfvk_derive(
xfvk_parent: *const [c_uchar; 169],
i: u32,
xfvk_i: *mut [c_uchar; 169],

View File

@ -244,7 +244,7 @@ libzcash::UnifiedFullViewingKey libzcash::UnifiedFullViewingKey::FromZcashdUFVK(
libzcash::UFVKId libzcash::UnifiedFullViewingKey::GetKeyID(const KeyConstants& keyConstants) const {
// The ID of a ufvk is the blake2b hash of the serialized form of the
// ufvk with the receivers sorted in order of descending receiver type.
// ufvk with the receivers sorted in typecode order.
CBLAKE2bWriter h(SER_GETHASH, 0, ZCASH_UFVK_ID_PERSONAL);
h << Encode(keyConstants);
return libzcash::UFVKId(h.GetHash());

View File

@ -66,7 +66,7 @@ std::optional<SaplingExtendedFullViewingKey> SaplingExtendedFullViewingKey::Deri
CSerializeData p_bytes(ss_p.begin(), ss_p.end());
CSerializeData i_bytes(ZIP32_XFVK_SIZE);
if (librustzcash_zip32_xfvk_derive(
if (librustzcash_zip32_sapling_xfvk_derive(
reinterpret_cast<unsigned char*>(p_bytes.data()),
i,
reinterpret_cast<unsigned char*>(i_bytes.data())
@ -170,7 +170,7 @@ SaplingExtendedSpendingKey SaplingExtendedSpendingKey::Master(const HDSeed& seed
{
auto rawSeed = seed.RawSeed();
CSerializeData m_bytes(ZIP32_XSK_SIZE);
librustzcash_zip32_xsk_master(
librustzcash_zip32_sapling_xsk_master(
rawSeed.data(),
rawSeed.size(),
reinterpret_cast<unsigned char*>(m_bytes.data()));
@ -188,7 +188,7 @@ SaplingExtendedSpendingKey SaplingExtendedSpendingKey::Derive(uint32_t i) const
CSerializeData p_bytes(ss_p.begin(), ss_p.end());
CSerializeData i_bytes(ZIP32_XSK_SIZE);
librustzcash_zip32_xsk_derive(
librustzcash_zip32_sapling_xsk_derive(
reinterpret_cast<unsigned char*>(p_bytes.data()),
i,
reinterpret_cast<unsigned char*>(i_bytes.data()));
@ -254,7 +254,7 @@ SaplingExtendedSpendingKey SaplingExtendedSpendingKey::DeriveInternalKey() const
CSerializeData external_key_bytes(ss_p.begin(), ss_p.end());
CSerializeData internal_key_bytes(ZIP32_XSK_SIZE);
librustzcash_zip32_xsk_derive_internal(
librustzcash_zip32_sapling_xsk_derive_internal(
reinterpret_cast<unsigned char*>(external_key_bytes.data()),
reinterpret_cast<unsigned char*>(internal_key_bytes.data()));