Cryptocurrency Tutorial

Cryptocurrency Basics

1. Introduction To Cryptocurrency
2. Blockchain Technology
3. Cryptocurrency Mining
4. Decentralized Applications
5. Smart Contracts
6. Initial Coin Offering (ICO)
7. The Whitepaper
8. Hard Fork & Soft Fork
9. Proof-Of-Work & Proof-Of-Stake


1. Introduction To Cryptocurrency

Cryptocurrency is a digital currency that functions as a medium of exchange, utilizing the process of cryptography enables users to transact securely using these digital coins. Cryptocurrencies operate on a distributed ledger called a blockchain, where all transactions using a cryptocurrency is made public and permanently recorded. Units of a cryptocurrency are produced through a process known as mining, where special computer software is used to solve mathematical problems in exchange for a unit or more of that cryptocurrency. Due to the decentralized technology on which cryptocurrencies operate, the supply of a cryptocurrency is not subject to the control of a central authority; the total supply of a cryptocurrency is normally predetermined, which is made clear to all users.

Bitcoin possesses the title as the first ever decentralized cryptocurrency, originally conceived in 2009 by an individual or group under the pseudonym Satoshi Nakamoto. However, there are now numerous cryptocurrencies since the inception of Bitcoin, the number being well above 800+. These cryptocurrencies are known as ‘altcoins’, signifying an alternative to Bitcoin.


2. Blockchain Technology

A blockchain is a public ledger of all cryptocurrency transactions. Each group of transactions are referred to as a block, with each block then being combined chronologically into a chain. Information that exists on the blockchain is shared and public, therefore, every node connected to the network, possesses a copy of the blockchain. Each node will be able to have access to all transactions that have ever taken place, or will take place on the blockchain. The distributed nature of blockchain technology also means that the database cannot be controlled by a single entity, nor can it easily be hacked as there is not one single point of failure. Unauthorized changes to the blockchain would be unlikely, as overriding the network would require a tremendous amount of computing power.

The first implementation of blockchain technology was by Satoshi Nakamoto in 2008, where the technology was applied to the digital currency now known as Bitcoin.


3. Cryptocurrency Mining

Cryptocurrency mining is a process by which new coins are introduced into the existing circulating supply, as well as a process used to secure the network that the coins operate on. The people who mine a coin, are known as miners. Therefore, instead of having a central authority that produces and secures the money supply, this is spread out across the network.

The Mining Process
Transactions that occur on the network such as, “Alice sends 10 Bitcoins to Bob”, are collected by a miner and bundled up into a block. The miner then verifies that all transactions in the block are valid. If a miner attempts to submit a block with an invalid transaction, the block will be rejected. An example of an invalid transaction would be, Alice sending 10 Bitcoins to Bob, even though she does not have 10 Bitcoins to send.

After the miner has successfully verified that all transaction in the block are valid, he must then compute a cryptographic hash. It is necessary for miners perform this computation in-order to prevent just anyone from being able to create blocks, this therefore secures the network against fraudulent blocks. Computing a cryptographic hash requires a large amount of computing power, as hundreds of millions of calculations are needed to be performed each second. This process is known as proof-of-work. Once the miner successfully solves the hash, the block is then relayed to the network to be checked against the consensus rules. Once accepted, the block is then added to the blockchain network and the miner is rewarded with a set amount of the cryptocurrency.


4. Decentralized Applications

Typically associated with the Ethereum project, a decentralized application, or DApp, is an application that runs on a peer-to-peer network of computers, as opposed to a single computer. The key benefit of this is, users of the network do not depend on a central computer in-order to send and receive information.

In-order to fully understand the difference between a decentralized application and a centralized application, let us consider some examples of centralized applications such as: Facebook, Twitter and YouTube. These are all examples of centralized applications, because in-order to use them, the user is dependent on a network owned and operated by a central entity. This is in contrast with a decentralized application, where the user is not dependent on a central entity to send and receive information.

Even though a DApp does not necessarily require a blockchain from which to operate on top of, most DApps harness the power of blockchain technology using what are known as, smart contracts. Smart contracts are self-executing contracts designed to enforce the terms of an agreement. For example, if you want to purchase a house, this process would involve multiple third parties such as estate agents and lawyers, who would settle the purchase for you. However, with the use of a smart contract, the process need only involve the buyer and the seller. Once all the conditions are met, the smart contract would execute independently of any third party.

DApps rely on smart contracts in-order to access the blockchain and operate, much in the same way centralized applications rely on centralized servers to operate.

Here are some common requirements of an application before it can be truly considered decentralized:

  • Application must be open-source
  • Application’s data must be stored on a decentralized blockchain
  • Application must use a cryptographic token e.g. Bitcoin, or one inherent to the application
  • Application must generate tokens via a cryptographic algorithm, e.g. Proof-of-work

In-order to crystallise your understanding of what a DApp is, let us consider a real-world example of a decentralized application.

Eth-Tweet
Eth-Tweet is a decentralized blogging platform that provides functionality similar to Twitter. However, because Eth-Tweet operates on top of the decentralized Ethereum blockchain, no centralized entity can control what a user decides to publish.


5. Smart Contracts

A smart contract is a self-executing contract that is designed to enforce the terms of an agreement created between two parties. Terms of the contract are recorded in a computer language such as C++ as a set of instructions, and are carried out automatically. The aim of smart contracts is to facilitate the exchange of money, or anything of value, whilst also reducing costs associated with the formation of a contract e.g. legal fees. For example, If Bob wanted to enter into a contractual agreement with Alice for the sale of a house, normally, both parties would seek the help of a real estate agent or a lawyer in order to form a contract. However, through the use of a smart contract, the parties respective wishes can be encoded and automatically executed, therefore, eliminating the need for middlemen.

Example of a smart contract:

pragma solidity ^0.4.16;

contract MyToken {
    // This creates an array with all balances
    mapping (address => uint256) public balanceOf;

    // Initializes contract with initial supply tokens to the creator of the contract
    function MyToken(
        uint256 initialSupply
    ) {
        balanceOf[msg.sender] = initialSupply;              // Give the creator all initial tokens
    }

    // Send coins
    function transfer(address _to, uint256 _value) {
        require(balanceOf[msg.sender] >= _value);           // Check if the sender has enough
        require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
        balanceOf[msg.sender] -= _value;                    // Subtract from the sender
        balanceOf[_to] += _value;                           // Add the same to the recipient
    }
}

Source: Ethereum.org

A well-known use of smart contracts can be found on the Ethereum blockchain, where they are integrated into decentralized applications (DApps). The trust less and self-executing nature of smart contracts means that the operation of DApps need not depend on a centralized network. However, the use of smart contracts does not come without risk. The code included in a smart contract may contain bugs and security holes that are exploitable. This was the case when, in June of 2016, approximately $50 million worth of ETH was stolen from the Decentralized Autonomous Organization (DAO), due to an exploitable security hole in its smart contract.


6. Initial Coin Offering (ICO)

An initial coin offering (ICO) is a means by which a start-up can raise capital by selling cryptocurrency inherent to their project, in exchange for a more valuable cryptocurrency, such as Bitcoin or Ethereum. ICOs are unregulated and so are classified as high-risk investments.

The ICO Process
If a start-up hopes to launch a successful ICO, information about the project is usually presented in what is known as a whitepaper. In this whitepaper, investors can expect to find information such as: what the project is about, the team behind the project and how much money is looking to be raised from the ICO.

When it is time to participate in the ICO of a project, the token purchased may give the owner certain benefits. An ICO token that has been purchased may give the owner access to a specific protocol or network, and so is therefore known as a utility token. However, a token may simply be purchased in hopes that it appreciates in value.

The funds raised by an ICO are typically collected via a public address with which participants send their cryptocurrencies to. Alternatively, an account may be created for each participant, providing them with their own unique public address.

If the minimum amount of money is raised, an ICO is considered to be a success. The underlying token of that project then becomes listed on cryptocurrency exchanges, where they are traded against other cryptocurrencies. However, if the minimum amount of money is not met, the ICO will be considered a failure and the funds returned back to the investors.


7. The Whitepaper

In the cryptocurrency space, a whitepaper is a document presented by a start-up with the intention of informing and encouraging investors to participate in the start-up’s ICO.

A whitepaper contains more technical and in-depth discussions on the project that the start-up is building. This could include: The consensus algorithm the project decides to use, how the nodes that operate on project’s platform would function, and the token system.

Although not all white papers will have the same structure, they tend to discuss in some form or another the following topics:

  • Introduction
  • Definition of the problem
  • Project’s technical solution
  • Applications of the project
  • Roadmap
  • Token sale

An introduction is important in providing a primer as to what the reader can expect from reading the whitepaper. It can vary in technical difficulty depending on the audience that the whitepaper is intended for.

A definition of the problem that the start-up is trying to solve provides context as to why the project is needed in the first place. The clearer the definition of problem to the reader, the easier it becomes for them to see the need and therefore the potential benefits of the project.

The project’s solution to the proposed problem is an area of the whitepaper that tends to be more technical. It demonstrates to those able to understand that the project is feasible. It also shows to an extent, that the team behind the project has a good grasp of the technology in-order to successfully implement it.

A start-up’s white paper is likely to detail the relevant applications of their actual project. For example, the application of Bitcoin as a peer-to-peer electronic cash system. Or the application of Ethereum as a decentralized platform that runs smart contracts. It is paramount that a start-up can demonstrate a real-world application for their project.

A roadmap sets out a project’s objectives and a date for which they intend to achieve this by. A roadmap is important in managing the expectations of the people interested in a project. The more realistic the roadmap, the better managed the expectations of the stakeholders will be. If a project habitually fails in meeting the goals set out in their roadmap, it may be a point of concern for the investor.

The token sale section typically contains details on the sale of the token, such as: Duration of the token sale, the number of tokens that will be on sale, and how to participate in the token sale.


8. Hard Fork & Soft Fork

Hard Fork
A hard fork is a permanent divergence from the previous version of a blockchain; a new set of consensus rules are introduced into the network that is not compatible with the older network. Under a hard fork, blocks (transactions) that are confirmed by nodes that are not yet upgraded to the latest version of the protocol software will be invalid. Nodes running the older version of the software will have to follow the new set of consensus rules for their blocks to be valid on the forked network.

A hard fork can take place to augment the functionality of a blockchain, increase the security of operating on the network, or even to reverse transactions on the blockchain. With the latter scenario occurring for the Ethereum blockchain, where a hard fork was implemented in order to reverse transactions following a hack on the DAO (Decentralized Autonomous Organization).

Soft Fork
A soft fork is a backward compatible method of upgrading a blockchain. Soft forks do not require old nodes to upgrade to maintain consensus, because all blocks on the softforked blockchain follow the old set of consensus rules as well as their new ones. However, blocks produced by nodes conforming to the old set of consensus rules will violate the new set of consensus rules, and as a result, will likely be made stale by the upgrading mining majority. This is because for a soft fork to work, a majority of miners need to recognize and enforce the new set of consensus rules. If this majority is reached, then the older network will fall into disuse, with the newer blockchain gaining recognition as the ‘true’ blockchain.


9. Proof-Of-Work & Proof-Of-Stake

Proof of Work
Proof-of-work (PoW) is a requirement that must be performed by a miner in order to add a block to the blockchain. PoW occurs in the mining process, when a miner successfully solves a complex mathematical puzzle on the network. Answers to the problem are known as a hash; the hash that is produced must be valid, in that it must be lower than the target hash. A target hash is simply the hash value that has been determined by the network. A hash that is above the target hash will be invalid, and the puzzle will not be solved. As more of these puzzles are solved, the network will automatically increase its difficulty. What this means is that the target hash value will be lowered, so that the number of valid hash values capable of being produced are also lowered. This correspondingly makes it much more difficult for a miner to generate a valid hash and solve the network’s mathematical puzzle.

Solving these mathematical puzzles often requires a lot of guesses, or the generation of hash values. As a result, mining can be an expensive process for miners, as the machinery and electrical power needed to produce hash values can be costly. So much so that miners will often use mining pools to reduce costs, and also increase the likelihood of generating a valid hash value.

PoW also serves as a security measure, it deters denial of service (DoS) attacks because the network requires the attacker to commit significant processing power to generate a valid hash value, which can be an extremely expensive process.

Proof of Stake
A limitation to the PoW model is that a significant amount of electrical energy is wasted generating random guesses. It is estimated that PoW for the Bitcoin blockchain could consume as much electricity as Denmark by 2020. Proof-of-stake (PoS) aims to solve this energy problem by requiring miners to put up a stake or lock up a certain amount of their funds to validate a block, instead of having to generate hash values. PoS miners are limited to mining a percentage of transactions that is reflective of their stake in the cryptocurrency. For example, a miner who owns 5% of Bitcoin available may only mine 5% of blocks on the network. Furthermore, there is no block reward in the PoS system, instead, miners are rewarded with transaction fees for the verification of a block.