4

When I connect with a wallet to the bitcoin network, how is the balance actually retrieved? One node? Or more? I understand it is a sum of all transactions. But when I load my wallet I assume I connect to certain node. How do I know that that particular (malicious) node has the most recent or valid blockchain? In other words: can it be possible for a node to cheat by adjusting the blockchain which I could connect to with a wallet and get a faulty balance?

I read some articles about this and they state that this will be rejected by the network. But I have no idea how this works. Can somebody help?

3 Answers 3

3

Edit: this answer is written assuming you are asking about ‘SPV’ or ‘light wallet’ implementations, not a full node implementation

How do I know that that particular (malicious) node has the most recent or valid blockchain?

This is two separate questions: are you up to date? And is the info valid?

Up to date: it is possible for light wallets to query data from multiple network peers, though not every implementation will do so. This helps ensure no single node is ‘lying by omission’, which means they are withholding information from you (Interesting related info: ‘fraud proofs’ are apparently very, very difficult to craft. It is an ongoing area of research in the field). If you are only connected to malicious nodes, this may become an issue, though in practice it is not a difficult issue to overcome (see: Sybil attacks / eclipse attacks).

Some light wallets will connect to a server run by the developers of that wallet, while others will connect directly to a node(s) in the bitcoin network. Using a service that does not hardcode their own server into the wallet is probably better, though if they follow a standard HD wallet scheme it should be no problem importing your seed phrase to a different wallet in case that service goes down.

I think the best advice is to run your own node. Many light wallets allow you to point your wallet at your own node as a manual setup option. This gives you sovereignty, and greatly increased privacy as well.

Validity: light wallets work by downloading the chain of block headers, and then requesting info related to the wallet’s address’ from connected nodes. By only downloading the blockheaders, resource usage stays low enough for the wallet to work on mobile (less than 100mb for the entire bitcoin history, currently).

The header contains the transaction merkle root, which can be used to locally verify that a valid transaction is included in a certain block, without having all of that block’s data. A node will serve the transaction in question to the wallet, along with the intermediate hashes in the merkle tree. This allows the node to recalculate the merkle root locally, giving proof that the transaction is confirmed on the bitcoin network (and thus valid according to the network’s rules). If even one bit of information is changed, the merkle root will be calculated differently, and the wallet will know the transaction served is invalid.

2

This is a good question. Your best bet is two-fold:

  1. Connect to known peers. These are hard coded as DNS seeds in the full-node application. See chainparams.cpp #L132
  2. Connect to many peers to get as much of a view into the network as possible.

If you don't do these 2 things it's possible you get connected to an invalid side-chain rather than the more popularly accepted chain, though not very likely.

0

When you first load up the bitcoin client you are searching for the network of peers that you can download the blockchain from, starting from block 1.

So you could connect to a malicious node but the malicious node will have altered the latest blocks only. There are hardcoded checkpoints in the blockchain history written into the code, so altering the history and getting all the other nodes of the bitcoin network to agree with your blockchain can only be done with > 51% of the mining power and some other funky stuff.

Your coins in your wallet will not be spendable until the blockchain has fully caught up, it is reading the local transactions into and out of the wallet that it knows about and as the blockchain is downloaded it learns more of any recent transactions not made from that wallet.dat file of addresses.

The malicious node as you say is rejected by the network for not having agreement of blocks and transactions and they can only not be orphaned on their own chain if they have the 51% or more hashing power.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.