Blockchain has been thrown around in popular culture as a phenomenon, which seems to be able to steer our financial revolution. Yet I believe its over simplified. The core technology behind the Crypto trend is the blockchain and when classifying it as technology is also a over simplification.

Many storage options exist, most notably SQL which is a way of storing data, and is widely adapted for online (as well as offline) applications. This very site uses a SQL database.
This allows the site to peek in a fetch a record, given a key. such as the post ID or the post Name.

Now imagine that this site ran on the blockchain, its not much different than SQL in practice, you could query the chain for a given record or block as its named in the case of blockchain. Lets say record 3 .. this could be an integer, a hash or GUID. the blockchain will serve us this record just like SQL would. however the blockchain has a feature which databases seem to lack. its data integrity via record hashing.

static bool CheckBlockChain(List<Block> blockchain = null) {
    blockchain = blockchain ?? LoadBlockChain();
    for(int i = 1; i<blockchain.Count; i++) 
        if(HashBlock(blockchain[i-1], blockchain[i]) != blockchain[i].Hash) {
            Console.Error.WriteLine($"Blockchain is not valid - Block: #{i} - {blockchain[i].Hash} does not belong there.");
            return false;
        }
    return true;
}

We could ask for record 3 and ask the blockchain to run a verification. it will iterate through all records/block and check the integrity of the chain, this can be done in various ways, but lets say we take the previous block (block 2) and try to hash block 2 with the value of block 3. this should give us the hash of block 3 …

static string HashBlock(Block prevBlock, Block block) => 
    Convert.ToBase64String(System.Security.Cryptography.SHA256.Create()
    .ComputeHash(Encoding.UTF8.GetBytes($"{prevBlock.Id}{prevBlock.Value}{prevBlock.Hash}{block.Id}{block.Value}")));

If this hash does not meet the hash of the current block, we can assume that the current block has been corrupted or modified by someone. thus invalidating the chain. This is the core principal behind the blockchain, to validate the data integrity. This is not a technology that needs to be glorified outside of itself. rather a feature which conventional SQL databases should add as an optional feature which can be enabled. record data integrity.

I took the time to write a blockchain from scratch, The FULL source code is available here:

As stated this is an over simplified version of a blockchain, modern blockchains are more adaptable for data structure and verification checks. but with the following code you could make some modifications and take over the financial market (not really) but it serves to provide the example of how over hyped the technology really is as a bare bone version can be written up in less than 50 lines of code.

Example usage:

# Verify the chain
picochain.exe -v 

# Add a record to the chain
picochain.exe "hello"

Tagged in:

, , , ,