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

<blockquote>
  <p>How do I know that that particular (malicious) node has the most recent or valid blockchain?</p>
</blockquote>

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

<p><strong>Up to date</strong>: 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). </p>

<p>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. </p>

<p><em>I think the best advice is to run your own node</em>. 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. </p>

<p><strong>Validity:</strong> 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). </p>

<p>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 <strong>all</strong> 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. </p>

CC BY-SA 4.0
2018-07-27T00:03:37.240Z
2018-07-27T06:38:29.063Z
2018-07-27T06:38:29.063Z
chytrik
<p>This is a good question. Your best bet is two-fold:</p>

<ol>
<li>Connect to known peers. These are hard coded as DNS seeds in the full-node application. See <a href="https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L132" rel="nofollow noreferrer">chainparams.cpp #L132</a></li>
<li>Connect to many peers to get as much of a view into the network as possible.</li>
</ol>

<p>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.</p>

CC BY-SA 4.0
2018-07-26T21:21:03.620Z
2018-07-26T23:44:04.273Z
2018-07-26T23:44:04.273Z
JBaczuk
<p>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.</p>

<p>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.</p>

<p>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.</p>

<p>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.</p>

CC BY-SA 4.0
2018-07-26T21:20:39.397Z
2018-07-26T21:20:39.397Z
Fuzzybear
<p>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? </p>

<p>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?</p>

<blockchain><nodes><block-validity>
How do I know that a node provides the accurate blockchain
Ray
# How do I know that a node provides the accurate blockchain

(Asked by: username_0 on 2018-07-26)

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?

**Tags:** blockchain, nodes, block-validity


---

## 3 answers

### Answer by username_1 on 2018-07-27. Score: 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.


---

### Answer by username_2 on 2018-07-26. Score: 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](https://github.com/bitcoin/bitcoin/blob/master/src/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.


---

### Answer by username_3 on 2018-07-26. Score: 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.


---

