AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 27 Bitcoin

wallet_db: put 'genesis_blockhash' in DB, detect mainnet/testnet mixup

Public commit record

What the developer wrote

Authored by SomberNight

98/100 · Strong
wallet_db: put 'genesis_blockhash' in DB, detect mainnet/testnet mixup

If the user tries to open a wallet for a different chain (mainnet vs testnet), try to show a reasonable error message.

See previous attempt at this: https://github.com/spesmilo/electrum/commit/c13e05770150c5210783c3d42d3d2b1a683f18b4, which added `wallet.test_addresses_sanity()`. However there are many codepaths where "random" exceptions might get raised before the Wallet object is even instantiated.
See [discussion there](https://github.com/spesmilo/electrum/commit/c13e05770150c5210783c3d42d3d2b1a683f18b4#commitcomment-28017341):
> should we actually fix that?
> if yes, it would be better to write the network type in storage

Indeed now I think we should do that. At the time I was concerned it would not help against altcoin forks if we put "mainnet" or "testnet" in the DB. Now I realise we should just put the genesis block hash in the DB instead.

Many of the reports in https://github.com/spesmilo/electrum/issues/6526 are likely due to users trying to open a mainnet wallet in testnet mode or vice-versa.

fixes https://github.com/spesmilo/electrum/issues/9134
same issue in wizard 2fa two-step wallet-creation flow
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit improves Electrum so that when a user accidentally opens a wallet created for one Bitcoin network (mainnet) while running Electrum configured for another (testnet), they get a clear error message instead of confusing crashes. It stores the network's genesis block hash inside the wallet file and checks it on load. It is a defensive hardening change, not a fix for an active security vulnerability or exploit.

Recommended action

No urgent action required. This is a defensive improvement. Users and downstream packagers should be aware that wallet files created or upgraded by this version will contain a genesis_blockhash field and will refuse to load on a mismatched network. Reviewers may want to confirm that the assertion in Abstract_Wallet.__init__ cannot be triggered by a missing key in a freshly created DB (the upgrade path and new-DB path both populate it).

Security signals we found

01

Hardening against user configuration error (mainnet/testnet mixup)

02

Adds integrity check using chain-specific genesis block hash

03

Replaces address-sanity check with deterministic genesis-hash comparison

04

Bumps wallet DB seed version from 70 to 71

05

Adds unit tests covering fresh and upgraded wallets opened on wrong network

Risk score

Why this scored 27/100

Our methodology →
Potential impact 4/30
Exploitability 0/25
Stealth signal 2/15
Affected reach 8/15
Confidence 9/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.