dvf / dvf/blockchain

Validating initial block?

Open
#139 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
8k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

I'm wondering if it is necessary to include a check at the beginning of the `valid_chain` to ensure that the chain has the same history as one would expect?

For example, wouldn't it be possible for a malicious node to make itself i.) the longest node and ii.) with a self-consistent history that nonetheless starts out in a way that is advantageous to the node's owner?

Perhaps something like this:

```py
class Blockchain(object)
...

def valid_chain(self, chain):

last_block = chain[0]
current_index = 1

# Check that initial block is as expected.
if last_block['previous_hash'] != 1 or last_block['proof'] != 100 or last_block['index'] != 1:
return False

while current_index < len(chain):
block = chain[current_index]
...
```

More generally, why isn't it necessary to validate the chain against some sort of "ground truth" contained within node? It seems like only checking that a given chain is self-consistent creates all sort of possibilities for veering off in bad directions.

A non-malicious related example arises when you have two nodes (on ports 5000 and 5001, say) and that transactions like the below occur:

```bash
curl -X POST -H "Content-Type: application/json" -d '{
"sender": "d4ee26eee15148ee92c6cd394edd974e",
"recipient": "someone-other-address",
"amount": 5
}' "http://localhost:5000/transactions/new"

# Send to another address on 5001
curl -X POST -H "Content-Type: application/json" -d '{
"sender": "d4ee26eee15148ee92c6cd394edd974e",
"recipient": "yet-other-address",
"amount": 5
}' "http://localhost:5001/transactions/new"
```

When and how is a case like this settled? In the present implementation it will be settled whenever a resolve occurs and one node's chain is strictly longer than the other. But that seems super arbitrary?

Perhaps all of this is material to be covered in 2? Or I'm just missing something fundamental...

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.