Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from hdwallet to bip32 #1421

Merged
merged 1 commit into from
Jun 17, 2024
Merged

Migrate from hdwallet to bip32 #1421

merged 1 commit into from
Jun 17, 2024

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Jun 14, 2024

As part of this, we migrate to secp256k1 0.27. This version does not bump secp256k1-sys, so remains compatible with the libsecp256k1 revision used in zcashd.

The zcash_primitives::legacy::keys::AccountPrivKey encoding also changes to preserve the transparent extended key metadata. Previously the type was documented as such, but only encoded the private key and chain code; the new encoding now matches the documentation. As a side effect, the unstable encoding of zcash_keys::keys::UnifiedSpendingKey also changes.

Closes #1407.
Closes #1408.

@str4d str4d requested a review from nuttycom June 14, 2024 22:59
Comment on lines +18 to +30
- `zcash_primitives::legacy::keys`:
- `AccountPrivKey::{from_bytes, to_bytes}` now use the byte encoding from the
inside of a `xprv` Base58 string encoding from BIP 32, excluding the prefix
bytes (i.e. starting with `depth`).
- `AccountPrivKey::from_extended_privkey` now takes
`bip32::ExtendedPrivateKey<secp256k1::SecretKey>`.
- The following methods now return `Result<_, bip32::Error>`:
- `AccountPrivKey::from_seed`
- `AccountPrivKey::derive_secret_key`
- `AccountPrivKey::derive_external_secret_key`
- `AccountPrivKey::derive_internal_secret_key`
- `AccountPubKey::derive_external_ivk`
- `AccountPubKey::derive_internal_ivk`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be a good time to move the transparent keys to zcash_keys? I think that if we did so, zcash_keys would no longer need to depend upon zcash_primitives.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I kinda see it, but also the other protocol-specific key types exist in their own crates, so zcash-keys may not be where we want this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may instead make more sense to plan a move to some zcash_transparent crate that involves not just the key material, but the transparent builder logic etc. as well.

Copy link
Contributor

@nuttycom nuttycom Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some sense bip32 is that protocol-specific key derivation crate; we just have to add some more layers for Zcash, so I think this going in zcash_keys would be reasonable.

The advantage to moving it to zcash_keys is that then the bip32 dependency can go behind the transparent-inputs feature flag, and we get some nice additional pruning of dependencies.

Copy link
Contributor Author

@str4d str4d Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving these as-is may mean that zcash_keys no longer depends on zcash_primitives, but it would mean that zcash_primitives now needs to depends on zcash_keys, because the rest of the transparent logic is still there and needs these key types. So the move would not decouple the crates, it would just invert their relationship.

As part of this, we migrate to `secp256k1 0.27`. This version does not
bump `secp256k1-sys`, so remains compatible with the `libsecp256k1`
revision used in `zcashd`.

The `zcash_primitives::legacy::keys::AccountPrivKey` encoding also
changes to preserve the transparent extended key metadata. Previously
the type was documented as such, but only encoded the private key and
chain code; the new encoding now matches the documentation. As a side
effect, the unstable encoding of `zcash_keys::keys::UnifiedSpendingKey`
also changes.

Closes #1407.
Closes #1408.
Copy link

codecov bot commented Jun 15, 2024

Codecov Report

Attention: Patch coverage is 88.88889% with 7 lines in your changes missing coverage. Please review.

Project coverage is 63.16%. Comparing base (5a2a670) to head (f54ee4a).

Files Patch % Lines
zcash_client_sqlite/src/error.rs 0.00% 3 Missing ⚠️
zcash_client_sqlite/src/wallet/init.rs 0.00% 2 Missing ⚠️
zcash_keys/src/keys.rs 66.66% 1 Missing ⚠️
zcash_primitives/src/legacy/keys.rs 98.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1421      +/-   ##
==========================================
+ Coverage   63.14%   63.16%   +0.01%     
==========================================
  Files         126      126              
  Lines       14719    14729      +10     
==========================================
+ Hits         9294     9303       +9     
- Misses       5425     5426       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@nuttycom nuttycom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK f54ee4a - it might have been nice to have the bugfix in a separate commit, but this is fine.

@@ -8,6 +8,9 @@ and this library adheres to Rust's notion of
## [Unreleased]
### Changed
- MSRV is now 1.70.0.
- `zcash_client_sqlite::error::SqliteClientError` has changed variants:
- Removed `HdwalletError`.
- Added `TransparentDerivation`.
Copy link
Contributor

@daira daira Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we also currently do an .unwrap() after calling derive_secret_key in hdwallet from zcash_client_backend here:

let secret_key = usk
.transparent()
.derive_secret_key(address_metadata.scope(), address_metadata.address_index())
.unwrap();

It would be good to be able to report a useful error there, but zcash_client_backend has no suitable error type to do so.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@nuttycom nuttycom merged commit 87e2308 into main Jun 17, 2024
28 checks passed
@nuttycom nuttycom deleted the dep-bip32 branch June 17, 2024 23:04
AArnott added a commit to nerdcash/Nerdbank.Cryptocurrencies that referenced this pull request Jun 19, 2024
librustzcash [changed their USK encoding](zcash/librustzcash#1421) recently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants