Skip to content

Commit

Permalink
transparent: Fix bugs in AccountPubKey::derive_pubkey_at_bip32_path
Browse files Browse the repository at this point in the history
- A typo in a panic guard condition instead exposed the panic.
- The match logic wasn't correctly handling the first element of the
  path.
  • Loading branch information
str4d committed Dec 17, 2024
1 parent fedb8cc commit 36a374b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions zcash_transparent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions zcash_transparent/src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,17 @@ impl AccountPubKey {
expected_account_index: AccountId,
path: &[ChildNumber],
) -> Result<secp256k1::PublicKey, bip32::Error> {
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()
Expand Down

0 comments on commit 36a374b

Please sign in to comment.