From 36a374b52ab6410181fbbf2059a295a7f8a490c5 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 17 Dec 2024 13:05:16 +0000 Subject: [PATCH] transparent: Fix bugs in `AccountPubKey::derive_pubkey_at_bip32_path` - A typo in a panic guard condition instead exposed the panic. - The match logic wasn't correctly handling the first element of the path. --- zcash_transparent/CHANGELOG.md | 4 ++++ zcash_transparent/src/keys.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/zcash_transparent/CHANGELOG.md b/zcash_transparent/CHANGELOG.md index 8dc130e2b..35cc8874e 100644 --- a/zcash_transparent/CHANGELOG.md +++ b/zcash_transparent/CHANGELOG.md @@ -7,6 +7,10 @@ and this library adheres to Rust's notion of ## [Unreleased] +### Fixed +- `zcash_transparent::keys::AccountPubKey::derive_pubkey_at_bip32_path` now + returns the correct result for valid paths instead of an error or panic. + ## [0.1.0] - 2024-12-16 The entries below are relative to the `zcash_primitives` crate as of the tag diff --git a/zcash_transparent/src/keys.rs b/zcash_transparent/src/keys.rs index 8941cb193..28e405fa1 100644 --- a/zcash_transparent/src/keys.rs +++ b/zcash_transparent/src/keys.rs @@ -273,17 +273,17 @@ impl AccountPubKey { expected_account_index: AccountId, path: &[ChildNumber], ) -> Result { - if path.len() > 3 { + if path.len() < 3 { Err(bip32::Error::ChildNumber) } else { match path.split_at(3) { - ( - [ChildNumber(44 | ChildNumber::HARDENED_FLAG), coin_type, account_index], - sub_path, - ) if coin_type.is_hardened() - && coin_type.index() == params.network_type().coin_type() - && account_index.is_hardened() - && account_index.index() == expected_account_index.into() => + ([purpose, coin_type, account_index], sub_path) + if purpose.is_hardened() + && purpose.index() == 44 + && coin_type.is_hardened() + && coin_type.index() == params.network_type().coin_type() + && account_index.is_hardened() + && account_index.index() == expected_account_index.into() => { sub_path .iter()