Skip to content

fix(wallet): validate network and genesis hash consistency - #520

Open
busayo-OD wants to merge 1 commit into
bitcoindevkit:masterfrom
busayo-OD:network-genesis-consistency
Open

fix(wallet): validate network and genesis hash consistency#520
busayo-OD wants to merge 1 commit into
bitcoindevkit:masterfrom
busayo-OD:network-genesis-consistency

Conversation

@busayo-OD

Copy link
Copy Markdown

Fixes #46

Description

Previously, Wallet::create_with_params and Wallet::load_with_params allowed Network::Bitcoin to be paired with a non-mainnet genesis hash, creating an internally inconsistent wallet configuration.

This PR adds validation to both entry points:

  • Wallet::create_with_params returns DescriptorError::GenesisHashMismatch when a mainnet wallet is configured with a non-mainnet genesis hash.
  • Wallet::load_with_params returns LoadError::GenesisNetworkMismatch when persisted wallet metadata contains the same inconsistency.

Regression tests have been added for both code paths.

Notes to the reviewers

This PR revisits the earlier implementation attempt (#1777) and implements the approach that emerged from the review discussion:

  • reject only custom genesis hashes for Network::Bitcoin;
  • preserve support for custom genesis hashes on Testnet, Signet, and Regtest;
  • apply the same validation during both wallet creation and wallet loading.

To report these validation failures without changing the existing API signatures, this PR introduces DescriptorError::GenesisHashMismatch and LoadError::GenesisNetworkMismatch.

Changelog notice

Validate that `Network::Bitcoin` is paired with the Bitcoin genesis hash during wallet creation and loading.

Checklists

All Submissions

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran just p before pushing

Bugfixes

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Reject wallets configured for Network::Bitcoin with a non-mainnet
genesis hash during wallet creation and loading.

Introduce dedicated error variants to report these validation failures
through the existing create and load APIs, and add regression tests
covering both entry points.

Signed-off-by: busayo-OD <toyinoluwabusayo@gmail.com>
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.81%. Comparing base (fc88144) to head (cd4e525).

Files with missing lines Patch % Lines
src/wallet/mod.rs 72.22% 2 Missing and 3 partials ⚠️
src/descriptor/error.rs 0.00% 4 Missing ⚠️
src/wallet/error.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #520      +/-   ##
==========================================
- Coverage   81.84%   81.81%   -0.03%     
==========================================
  Files          25       25              
  Lines        6487     6510      +23     
  Branches      296      300       +4     
==========================================
+ Hits         5309     5326      +17     
- Misses       1078     1081       +3     
- Partials      100      103       +3     
Flag Coverage Δ
rust 81.81% <50.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ValuedMammal ValuedMammal moved this to In Progress in BDK Wallet Jul 29, 2026
@ValuedMammal ValuedMammal added the bug Something isn't working label Jul 29, 2026
@ValuedMammal ValuedMammal added this to the Wallet 4.0.0 milestone Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

Verify network consistency between chain genesis and descriptors

2 participants