Blockchain


A digital ledger is an electronic system or database used to record and track transactions.

  • used in finance, business, etc.

Blockchain is a decentralized and distributed public digital ledger that records and links transactions across a network of computers secured using cryptography.

  • Each record is referred to as a block and is run through a hash function
  • hash value of the previous block in the chain is added to the hash calculation of the next block in the chain
    • ensures that each successive block is cryptographically linked
  • each block validates the hash of the previous block all the way through to the beginning of the chain
    • ensures each historical transaction has not been tampered with
  • each block typically includes:
    • a time stamp of one or more transactions
    • and the data involved in the transactions themselves
  • blockchain is recorded in an open public ledger
    • is a distributed public record of transactions that underpins the integrity of blockchains
      • enables anyone to verify recorded transactions
    • does not exist as an individual file on a single computer
    • ledger is distributed across a peer-to-peer (P2P) network
      • mitigates the risks associated with having a single point of failure or compromise
      • users can therefore trust each other equally
    • everyone has the same ability to view every transaction on a blockchain
  • uses:
    • ensure the integrity and transparency of
      • financial transactions
      • legal contracts
      • copyright and intellectual property (IP) protection
      • online voting systems
      • identity management systems
      • data storage

Comparison of Traditional Digital Ledgers and Blockchain

AspectTraditional digital ledgerBlockchain
ArchitectureCentralizedDecentralized
SecurityCentralized security measures such as data encryption and access controlUse of cryptographic services to enable transparency and tamper-resistant record-keeping
TrustRelies on a central authority such as a company or governmentRelies on cryptographic verification and decentralized consensus across a network of computers
ApplicationGeneral transaction recordingCryptocurrencies, smart contracts, decentralized finance (DeFi)

Merkle Tree

A Merkle tree is a hierarchical data structure used for verifying the integrity of large data sets.

  • facilitate secure data verification in diverse applications
  • organized in a binary tree format
    • data elements are initially stored in the tree’s leaves,
      • with each leaf node containing a data element’s hash
    • tree is built by repeatedly hashing child node pairs to create parent nodes until reaching a single top node
  • used in:
    • blockchain transaction verification
    • PKI digital certificate revocation status
    • file integrity assurance in distributed file systems

A Merkle root is the topmost hash in a Merkle tree, uniquely representing the entire dataset’s cryptographic hashes.

  • aka root hash

A Merkle path is the sequence of nodes connecting a data element to the root.

  • a data element’s Merkle path consists of the hashes of sibling nodes along the path from the data element to the root
  • verifies a data element’s integrity and inclusion in the tree without full dataset access

Merkle Tree

  1. Each data element’s hash is computed and stored in the tree’s leaves.
  •  , and  are the hashes of Data A, Data B, Data C, and Data D, respectively.
  1. The hashes of child nodes are paired and hashed to create parent nodes.
  •  and  are paired and hashed to create node 
  •  and  are paired and hashed to create node 
  1. The iteration continues until a single hash, known as the Merkle root, is obtained at the top of the tree.
  •  is the Merkle root
  1. The Merkel path of Data D is ().  and  are combined to compute the parent hash , followed by combining  with  to compute  (the Merkle root)

Blockchain Block Structure

  • blockchain functions within a network of computers (nodes)
    • each node maintains a copy of the entire ledger
  • transaction data is grouped into distinct blocks
    • organized using a Merkle tree structure
  • a block has two components:
    • block header
      • is the block component that provides metadata about the block
      • includes:
        • block hash
        • previous block hash
        • blockchain protocol version
        • block creation timestamp
        • and Merkle root of the block’s transactions
    • block body
      • is the block component that contains the content or payload of the block
      • depending on the blockchain purpose, can contain transactions or application-specific data
  • every new block is cryptographically linked to the preceding block
    • through the previous block hash
    • forming a chain that is tamper-resistant
      • difficult to alter retroactively without altering all subsequent blocks
    • once a block is added to the chain, it becomes immutable
  • Merkle root optimizes data transmission and verification within a blockchain network
    • nodes can validate the inclusion of a particular transaction in a block by computing the hashes along the transaction’s Merkle path
      • removes the need to download and verify the entire set of transactions within the block

Consensus Algorithms

  • Decentralization means network nodes must verify the validity of transactions and reach consensus before a new block is added to the blockchain

Consensus algorithm enables a network of decentralized nodes to agree on the state of a shared digital ledger.

  • 3 kinds:
    • Proof of Work (PoW)
      • is a blockchain consensus algorithm that requires network participants to perform a computationally intensive task, known as mining.
        • work typically involves finding a value (nonce) which when combined with a block’s data, produces a certain hash
      • used by Bitcoin
    • Proof of Authority (PoA)
      • is a blockchain consensus algorithm where validators are chosen based on the validator’s identity and reputation.
      • authority to create new blocks is only granted to known and trust participants
    • Proof of Stake (PoS)
      • is a blockchain consensus algorithm that selects a network participant to create a new block based on the amount of assets the participant holds and is willing to stake
      • staking is the act of committing an asset as collateral to participate in the consensus process
      • used by Ethereum
  • choice of algorithm affects scalability, security, and decentralization level

Comparison of Consensus Algorithms

AspectPoWPoAPoS
Consensus algorithmsParticipants solve mathematical problemsValidators chosen based on authorityValidators chosen based on stake
Energy efficiencyHigh energy consumptionLower energy consumption compared to PoWEnergy efficient
SecurityHigh security due to computational effortModerate security (relies on trusted nodes)Security through economic incentives
IncentivesParticipants motivated by block rewards and transaction feesValidators motivated by maintaining network authorityValidators motivated by staking rewards