Intro to Blockchain

education Oct 7, 2020

This post is in reference to my webinar on Blockchain on 2nd October 2020. The webinar was focused on developers.

Bitcoin and Blockchain – The Basics

There's a lot of hype and noise surrounding "Blockchain". Though Blockchain isn't revolutionary at all. What is revolutionary is Decentralization.

but why is decentralization revolutionary?

There are many aspects. Much of it revolves around openness. Networks like Bitcoin and Ethereum are:

1) Open source: The code is open and verifiable. We don't have to trust the developer's words.
2) Open network: The network is decentralized because it's open. Anyone can join the network and participate. Just like the world wide web.
3) Permission-less: There is no permission or restriction to joining the network. Just like I don't need permission to run a web server on WWW, I don't need permission to run nodes/apps on Bitcoin/Ethereum.

Communication before internet. Money before Bitcoin.

Before the internet we had institutions of communication. We had traditional media companies, newspapers, post offices. These are institutions/middle men of communication.

Today, anyone can boot up a webserver and start a blog. What's amazing is that blog has a greater reach than biggest media companies back then. The internet brought power of communication to everyone.

Similarly, we have institutions/middle men of money. Banks, Stock exchanges, Payment gateways. These companies are middle men of trade.

Today, anyone can download a simple app from play store and have ability to send and receive money globally, instantly, with minimal fees with no middle men.

This is truly revolutionary, the power of the biggest banks and institutions in the pockets of everyone.

Byzantine General's Problem

This post is for developers. So let's understand some basics.

Byzantine General's Problem is one very popular unsolved problem in computer science. It has been unsolved for years, until 2008 when bitcoin was invented, bitcoin is the first solution to byzantine generals problem.

Problem statement: The byzantine empire has to attack their target. But they can only defeat their enemy if all troops attack at once.

A representation of the byzantine attacking their target
source: https://blockgeeks.com/blockchain-infographics/

The problem is how do you trust everyone will attack at the same time as you? You cannot trust what message you get from other troops. What if the messages they sent as to what time to attack gets intercepted and you get incorrect time? What if other troops are compromised and you cannot trust them?

One solution is to elect one person that will be the soul decider and everyone has to trust that person. This is a centralized approach. There is always the possibility of this central source of information to get compromised.

How do you have consensus in system where no one trusts each other?

The solution bitcoin proposed is every node (troop) maintains a copy of a ledger (called the blockchain) and follow certain consensus rules to decide if the information they've received is valid or not.

To propose a block (time when to attack) the person who is proposing has to also prove that they have staked something valuable to come up with this value.

Here "something valuable" is the electricity you spent on doing the "proof of work".

Now here's the amazing part: Everyone in the network are doing the same. They are proposing a block. You have a situation where if you lie, you will lose all the electricity and if you're honest you will rewarded with money (block reward of 6.25 bitcoin). So everyone has the incentive to be honest. As a listener you can decide who is telling the truth with some criteria. Bitcoin considers the chain with highest cumulative proof of work as the valid chain.

This is how the network has reached consensus. No one trusts each other, but as everyone is incentivized to be honest coupled with some consensus rules you can have consensus. In case of bitcoin, the consensus rules are called "Nakamoto Consensus Rules" and the consensus is on the ledger (blockchain), which is basically a list of transactions that have happened.

A core idea we need to understand is we cannot have decentralization without money. This entire process depends on incentivising people be honest. If you don't have money involved. There is no incentive to keep the network decentralized and it will end up becoming centralized and dishonest.

Crypto in Cryptocurrency

A part solution towards decentralization is cryptography. Cryptography is one of the most powerful fields of mathematics. Cryptography has won wars for nations.

Cryptography is the practice and study of techniques for secure communication in the presence of third parties.

Bitcoin uses 3 aspects of cryptography:
1) Elliptic curve cryptography: creates public private key pairs.
2) SHA256 Hash functions: One way functions that output a random text that cannot be reserved.
3) Digital Signatures: A way to verify authenticity of a message.

Cryptography is huge subject so I cannot explain everything. If you wish to learn practical cryptography from basics try out: https://cryptopals.com.

Blockchain

It's really just a spicy linked list.

It's a linked list of blocks. Each block is list of transactions.

What's spicy is every block has a hash. And every block has the hash of previous block in itself. So the hash of previous block is input to the next hash.

(think of hash as a fingerprint)

This "chain" of hashes creates a scenario where if you change the content of any block, its hash will change and so would the hash of every block after it. What this does is make this "chain of blocks" immutable. Any tampering in any content will be detected and invalidate all blocks after it.

source: https://medium.com/hashtaagco/blockchain-say-what-8e16ed29e543

But wait! how does it know a block is invalid? After all, hashes are easy to calculate. So the hacker (person who's tampering with block data) can just recalculate all the hashes and claim this to be the valid chain.

The solution is every block has to have certain number of zeros in the beginning. This makes finding a hash exponentially difficult. This, is called Proof of Work. This "number of zeros" is part of consensus and is calculated by everyone in the network. So if the required number of zeros is 18, and you give me a block with a block hash with 2 zeros, I will know this is an invalid block. (because you haven't put much work into this)

All this makes Blockchain an immutable append only ledger of transactions.

You can do demo at https://blockchaindemo.io.

Let's Talk Development

Okay, phew. To the 5 people who got till here - we can now discuss the development aspects of decentralized networks.

One thing we should remember is we should build application on top of existing chains/networks. You don't need to build your own blockchain from scratch. Just like if you wish to start a website you don't re-invent the internet. You don't re-invent a decentralized network to make a decentralized app.

What's a DAPP?

A dApp is short for decentralized application. These are platforms that run on top of decentralized network like Ethereum or Bitcoin.

Both Bitcoin and Ethereum are programmable blockchains. Bitcoin has its own language called Bitcoin Script and Ethereum has it own language called Solidity.

Ethereum's language is turing complete (which means general purpose) while bitcoin script is turing incomplete (purposely).

If you want to build decentralized applications that are general purpose and cannot be done with bitcoin, use Ethereum.

If you want to build decentralized applications that are highly secure, use bitcoin.

Examples of DAPPs

1 - Decentralized Exchanges

Check out: https://bisq.network

This is a decentralized exchange that is run by its users. An exchange with no middle men.

2 - Digital Notary

Check out: https://proofofexistence.com

This is a decentralized way proving that something exists. For example I can take a pdf of my degree and upload it here. This site will create an empty bitcoin transaction with hash of my file and push it to the network. This means once that transaction is mined there is proof of existence of that file that can be seen on the blockchain. A sort of digital notary.

I can use the keys used in that transaction and use the private key as proof of ownership that I own this file. This concept can be taken to the idea of ownership of lands as well.

This is possible because of OP_RETURN in Bitcoin Script. You can learn some basics here: https://www.youtube.com/watch?v=8FeAXjkmDcQ (part 1)

3 - Decentraland

Check out: https://decentraland.org

This is decentralized game where users own their own land.

This is possible via Ethereum Smart Contracts.

What's a LAPP?

LAPP is a Lightning App. Lightning is a layer 2 solution that scales bitcoin to instant low transactions. It does this by moving transactions off-chain and only referring the blockchain when someone cheats.

A lightning app is an application that runs on top of the Lightning Network. These apps can do instance global transactions. This fits nicely with IoT where machines can do transactions on their own between themselves.

The Lightning Network is itself is Bitcoin DAPP.

Examples of LAPPs

1 - Decentralized instant messaging

Check out: https://github.com/joostjager/whatsat

This is a private messaging platform on top of Lightning Network. Think of it like WhatsApp but without facebook as a middle men. This frees us from the metadata analytics that facebook does.

2 - Reward based forum

Check out: https://soldirac.com

This is forum where users are rewarded bitcoin for correctly answering problems posted by other users. This is developed by me and I've documented the entire process of how I built soldirac (formerly Lnsolve): https://blog.lnpay.co/building-lapps-series-lnsolve.com-using-lnpay

Personally I would suggest focusing on Lightning Network.

Difference between Bitcoin and Ethereum

  • Bitcoin Script is turing incomplete language so you cannot do certain things like loops or make compilers. Ethereum is turing complete so it's general purpose and you can make compilers. I recommend using web3.js instead of solidity.
  • If you want make applications that are general purpose and cannot be done with Bitcoin use Ethereum. If you want to build applications that are highly secure use Bitcoin.
  • Bitcoin Script is low-level a stack based polish notation language. Ethereum Solidy a high level language that runs on the EVM (Ethereum Virtual Machine).

Some demos

You can try out Bitcoin Script in browser here: https://siminchen.github.io/bitcoinIDE/build/editor.html (for educational purpose only)

You can try out Ethereum programming in browser here: https://remix.ethereum.org/

Wrap up

In today's world, centralization is big problem. Only few companies like Facebook and Google own all our data. We are vendor locked to them. People who don't like Facebook still have to use whatsapp.

Decentralized application is the biggest hope of a world where power isn't concentrated to a few.

Since the invention of Bitcoin many ideas has come out for decentralization. Especially the concept of Federation. Which is beautiful concept that deserves it's own post. Someday I'll write about The Fediverse as well.

Some great work is being done by Mastadon and PeerTube (Federated Twitter and YouTube)

Imagine a world where you can host your own Twitter account and be able to follow a friend on facebook without creating a facebook account.

Social media as protocol. That's a world worth building.

1) People to follow:

2) Bitcoin Basics: https://www.youtube.com/watch?v=bBC-nXj3Ng4 and https://www.youtube.com/watch?v=FYo5E7zT-vM

3) Technical Intro to Bitcoin Script: https://www.youtube.com/watch?v=8FeAXjkmDcQ (part 1)

4) Easy Intro to Lightning Network: https://www.youtube.com/watch?v=rrr_zPmEiME (video 3 years old)

5) Technical Intro to Lightning Network: https://www.youtube.com/watch?v=E1n3sKKPD_k

6) How to make LAPPs: https://blog.paramdeep.ml/how-to-make-a-bitcoin-lightning-app/

7) How I build lnsolve.com: https://blog.lnpay.co/building-lapps-series-lnsolve.com-using-lnpay

8) Books:

Tags

ParmuTownley

Tis' my blog

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
BTC: 32i5xEudvVemzYNPmiY3t6aB2hNtw4mcVr You can tip me ₿itcoin via the Lightning Network ⚡