Skip to content

fix(electrum): reject a custom server that is on another chain - #232

Open
coolstack-coder wants to merge 1 commit into
CypherCommons:masterfrom
coolstack-coder:fix/electrum-wrong-chain
Open

coolstack-coder wants to merge 1 commit into
CypherCommons:masterfrom
coolstack-coder:fix/electrum-wrong-chain

Conversation

@coolstack-coder

Copy link
Copy Markdown

Problem

testConnection only checks server.version and server.ping, so any reachable server passes. Saving a server for another chain is accepted, whether by hand or from a setelectrumserver link:

  • A mainnet server saved on Signet: scripthash queries come back empty, the regular balance and history disappear, and broadcasts fail.
  • A Signet server saved on Mainnet: a real wallet shows 0.
  • A wrong port is enough on hosts that serve several chains. testnet.aranguren.org:51002 is testnet3, next to testnet4 on 52002.

The per-chain preference keys stop a saved server leaking across networks, but they can't stop the wrong chain's server from being saved under the active one.

Fix

  • NetworkConfig gets genesisHash.
  • testConnection compares server.features().genesis_hash with the chain's own. On a mismatch, or when the server doesn't report one, it throws an error naming the network. ElectrumServerSettings already shows a thrown error's message, so the server isn't saved and the user sees why. An unreachable server still resolves false, as before.
  • testConnection takes an optional networkId, which defaults to the active network.

I checked the three hashes against the shipped peers. bluewallet and foundationdevices return the mainnet hash, aranguren 52002 the testnet4 hash, and the Shroud signet Fulcrum the signet hash. aranguren 51002 returns the testnet3 hash, so it's rejected.

Tests

  • New tests/unit/electrum-test-connection.test.ts, with a mocked client, covers: the right chain, the hash in either case, the wrong chain, an explicit networkId, a missing hash, and an unreachable server.
  • tests/integration/Electrum.test.js passes each fallback peer's chain and asserts the wrong-chain cases reject. It passes against the live servers.
  • tsc and eslint are clean.

sendDetails.test.tsx › "fills in a payment request opened from home" fails on master too, so it's unrelated to this change.

The server test only checked that a server answered server.version and
server.ping, so a mainnet server could be saved as the Signet one (by
hand or from a setelectrumserver link) and the reverse. Once saved it
took over: scripthash queries came back empty, so balances and history
vanished, and broadcasts failed. A wrong port is enough on hosts that
serve several chains, such as testnet3 on 51002 next to testnet4 on
52002.

testConnection now compares the genesis hash from server.features with
the chain's own and, on a mismatch, throws an error naming the network,
which the settings screen shows instead of saving. Each network config
carries its genesis hash, checked against the shipped peers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant