Skip to content

Instantly share code, notes, and snippets.

@eshaben
Created April 2, 2021 17:04
Show Gist options
  • Save eshaben/c0e6b3f32321791243d035e5fa5ac916 to your computer and use it in GitHub Desktop.
Save eshaben/c0e6b3f32321791243d035e5fa5ac916 to your computer and use it in GitHub Desktop.

Blockchain Basics

A blockchain, also known as a distributed ledger technology (DLT), is a special type of database.

Data is added through structures called blocks. Each block is built on top of the last, in order, and includes information to link back to the previous, parent block. The very first block in the chain is known as the genesis block.

These blocks are connected using hash functions. A hash function essentially takes in some data and passes it through a mathematical function and returns a hash of the data. The returned hashes are always the same length.

A collision can occur when two different inputs give us the same output. However, the odds of this occurring are astronomically low and there aren't any known SHA256 collisions. SHA256 hashing is used extensively in Bitcoin and Ethereum. What this means for Bitcoin and Ethereum is that each block in the chain can point back to its parent block using its hash. Blocks already mined cannot be edited, the hash cannot be changed.

Nodes are the machines connected to the network. They store copies of the blockchain and communicate with other machines about transactions and blocks. All nodes have equal power.

Since all nodes have equal power, there needs to be a consensus mechanism for fairly determining who can add blocks to the blockchain. The system needs to make it expensive for users to cheat and rewards honest actors; providing an economic benefit to act rationally. There is also a need to give users "correct" information. So consensus algorithms are used to enforce robust rules and allow network participants to reach consensus on what block should be added next. A user can participate in block creation and gaining mining rewards if they "stake" and put some of their own money at risk.

Proof of Work (PoW)

  • What is it?

    • A consensus algorithm used to validate transactions and broadcast new blocks to the blockchain.
  • How does it work?

    • Miners on a network compete against each other on a network to solve complex computational puzzles. Difficult to solve, but easy to verify. Once a miner finds a solution the other miners will be able to verify the solution is correct.

    • Miners are responsible for adding new blocks into the blockchain by guessing a pseudo-random number aka nonce. The nonce combined with the data in the block, passed thru a hash function, generates the solution of a specific block hash. Each validated block contains a block hash that represents the work done by the miner... proof of work.

  • Why use miners?

    • The calculations that miners perform add new blocks into the blockchain and secure the blockchain. The "proof of work" block hash created by miners creates a tamper resistant blockchain which enables trust and prevents fraud.
  • Why use 10 minute blocktimes in Bitcoin but 12-17 second blocktimes in Ethereum

    • For Bitcoin, 10 minutes was chosen by Satoshi as a tradeoff between first confirmation time and the amount of work wasted by miners. Once a block is mined, it takes some time for other miners to find out about it, and until they do find about it they are still competing against the new block (instead of adding to it). Increasing the time between blocks reduces waste of miners competing for a new block that has already been mined. In other words, as block time increases the wastage percentage decreases.
    • For Ethereum, the block time is between 10 to 19 seconds because of the concept of uncle blocks. Uncle blocks are created when more than one child block is created from a parent block. This happens when a block is mined and other miners are still competing to mine that block. Only one block with that block hash can be mined. In Bitcoin, the work that the other miners are still doing is wastage. In Ethereum, the rejected/orphaned blocks make up the uncle blocks. The uncle block receives some percentage of the normal block reward. 10 to 19 second blocktimes are as fast as possible in Ethereum. A 2013 paper reports that 12.6 seconds is how long it takes for 95% of the nodes to see a new block.
    • The expected blocktimes are set at these constant values to make sure that miners cannot impact the security of the network by adding more computational power.
  • Resources found along the way: Toward a 12-second Block Time by Vitalik (Check out the Mining Overview section), Why the bitcoin difficulty is set to 10 minutes per block by Lingyong Wang, What is Proof of Work (PoW), The Mystery Behind Block Time (has awesome explanation & use of examples under Why Bitcoin Block Time is 10 Minutes? section. Also check out the Why Ethereum's Block Time Drastically Less than Bitcoin's section for more in-depth explanation of Uncles).

Proof of Stake (PoS)

  • How does it work?

    • Miners are replaced with validators, there's no mining involved, and no race to guess complex puzzles. Blocks are "forged" rather than mined. Instead of mining, the Proof of Stake algorithm uses a pseudo-random election process to select a node to be a validator of the next block. To take part in this process, users will need to participate in staking. Staking is the concept of locking up a stake which is a predetermined amount of the blockchain's native currency. The bigger the stake, the bigger the chances of being the next validator, the longer you've staked, the greater the chances too (via Randomized Block Selection and Coin Age Selection). When a node is chosen to forge the next block, it will validate transactions in the block, sign the block, and add it to the blockchain. If the block is valid, they'll receive a reward made up of fees from the block's transaction.
    • No need for high-powered mining farms
  • What is the main idea?

    • "The stake works like bail: just as defendants put up a large sum of money to disincentivize them from skipping trial, validators lock up a stake to disincentivize cheating. If they act dishonestly, their stake (or a portion of it) will be taken."
  • Why validators?

    • Validators are used to secure the network. Since validators are staking, the stake is a financial motivator to act honestly and not create fraudulent transactions as the stake will be lost if that is the case. Plus, they get paid well if they play by the rules.
  • Why nominators?

    • Nominators are also used to secure the network. Nominators are token-holders that publish a list of validator candidates that they trust and puts down an amount of DOTs at stake to support them with. If the candidates are elected as validators, the nominators share the payments with them. As long as the nominator chooses good acting candidates, they will get paid well.
  • Why the nominator-validator arrangement?

    • It provides super strong security guarantees. It allows the system to select validators with large amounts of DOTs staked, which makes it difficult to select a bad-acting validator (reputation is required to get backing) and its very costly to attack the system.

Finality

  • Defintion:
    • "...the assurance or guarantee that cryptocurrency transactions cannot be altered, reversed, or canceled after they are completed"
    • "So, finality is used to measure the amount of time one has to wait for a reasonable guarantee that crypto transactions executed on the blockchain will not be reversed or changed. In other words, they will not be lost."

Probabilistic Finality

  • What is the main idea?

    • The idea is that transactions are not automatically final but become more final over time as more blocks are confirmed.
    • Most blockchain protocols use probabilistic finality
  • How does it compare to instant finality?

    • The transactions are not automatically final.

Instant Finality

  • What is the main idea?
    • The idea is that transactions are automatically final.
  • How does it compare to probabilistic finality?
    • The transactions are automatically final.

Wallets

  • How do they work in Ethereum?

    • Ethereum wallets are applications that allow you to interact with your Ethereum account. It lets you read balances, send transactions, and connect to applications. A wallet is a product that lets you manage your Ethereum account. It holds your private key and supplies you with a public Ethereum address. Some wallets allow you to deploy a smart contract. Wallets are sometimes referred to clients or nodes. Examples of full nodes would be Geth and Parity. Full nodes keep a full copy of the blockchain, no 3rd party reliance, and execute code within transactions.
  • How are Ethereum wallets different than Bitcoin wallets? Why?

    • Bitcoin doesn't need a lot of the functionality that Ethereum has. Wallets in Bitcoin are solely used to transfer payment.

Ethereum vs Bitcoin (i.e. Storage, EVM, etc.)

  • How does Ethereum compare with Bitcoin?
    • Bitcoin is really just meant to transfer payments and Ethereum is a lot more robust. Ethereum has smart contract technology that enables sending code and instructions along with transactions. Therefore, a lot more is involved to handle and process the code.e with Bitcoin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment