Blockchain, Bitcoin, And Cryptocurrency


If totally new to the subject, I wrote some notes about blockchain in general with some definitions etc.

What is a Blockchain? A simple definition is 'a distributed ledger'. A ledger is a collection of financial accounts. Distributed means the exact copy exists in multiple places. But what does this mean? How does it work?

Blockchain is a combination of existing and new technolgies:

  • Peer-to-peer
  • Database and data structures (ledger)
  • Cryptography
  • Specific blockchain protocol (Bitcoin, Ethereum, et al)

Peer to peer

A peer to peer network consists of nodes. A node is a computer running specific software on a network, communicating to other nodes.

But isnt't that just a server? The terminology is different because a node is not a stand alone server, it works along side others, so the client server paradigm doesn't quite match.

Not all nodes are the same, some are full nodes (have the full blockchain database), some are light nodes (do not have the full database), a miner has a full node, unless it is mining through a mining pool.


A ledger is simply a record of accounts; a running record of transactions. These records are stored in a database such as Berkeley db or Leveldb.


What gets stored in the ledger? Transactions. I want to pay Bob 157 Satoshis. I need to have my address/account, Bob's address/account, how much I want to pay, plus my signature (traditionally a signature, with blockchain it is a digital signature).

Cryptographic hash

A hash algorithm takes in content and returns a fixed length string.

  1. The resultant hash should be a fixed length
  2. It should be impossible to reverse
  3. It should be fast to verify
  4. A tiny change results in a vastly different hash
  5. Two different inputs should not result with the same hash

The five items above comprise the attributes of a hashing function.

Transactions, addresses and signatures

In order to make transactions you need an address. In traditional terms, an address for another to send you funds would be a bank account number. An address is really a public key. A public key has a counterpart; a private key. The private key is the proof of ownership of the address - if you have the private key you own everything.

[my address] => [recipient address] [amount] [fee] [signature]

What prevents a fraudulent transaction? That is what the signature is for.

  • Hash the [my address] => [recipient address] [amount] [fee]
  • Take that hash, and encrypt it with your private key, creating a signature

Your signature can only be decrypted using your public key. This is how a transaction can be verified in order for it to be included in the block.

Digital Signatures are an important part, not just for the authentication of a transaction, but it could be used in an actual contract. Imagine you have a document to sign, an actual document, a PDF for example. This document could be hashed, then encrypted with your private key, to get . another takes the same document, hashes it, then decripts your signed document, checks the hash, if the hashes matches, then you really did 'sign' it by using your private key (only you could have done that).

A transaction gets submitted to the network and is collected into a transaction pool.

You can generate a public/private key with openssl:

openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout

Which generates this:

read EC key
Private-Key: (256 bit)
ASN1 OID: secp256k1


A block consists of:

  • A list transactions (included at the miners discretion)
  • A reference to the previous block hash, a nonce (for proof of work)

The first transaction in the list is called a coinbase, and consists of the miners address, any coin rewards plus the total mining fees from the transactions. The hash of all this information will become the link to the next block.

All chains start somewhere. With Blockchain it is the Genesis block. Geneis means 'the origin or mode of formation of something'.


Block creation is regulated by the network, one block every 10 minutes, and is achieved by using a mining difficulty. A SHA (Secure HAsh) algorithm is used. The attributes of a SHA algorithm are:

any input always produces the same output
computing the hash of an input is efficient, O(1)
a tiny change in the input produces a vastly different hash
the original input cannot be recreated from the hash
Collision protection
should not be able to generate the same hash from two different inputs

A way to do this is to use a SHA hash, and state that the beginning of the hash must begin with an agreed (by the network) number of zeros. In our case we will go for one zero.

Create a text file, 0.txt for example and add this:

mark -> bob 1000 1
bob -> alice 40 1

8 0

Lets check this block with:

shasum -a 256 0.txt

And we get:

0b49856216b097e83eb8c9459638fbfa1ce02df7b6938b6903f4411aaa1bc72d  0.txt

In our example protocol, lets assume the last line with text is the hash of the previous block (in this case it is a genesis block, so previous would be 0). Then, the line before that would be the nonce. The first hash would use 0 for the nonce. We would hash, if the hash begins with a zero, then we have mined a block. If not we need to increment the nonce, perform a hash, and rinse and repeat.

This is proof of work.