Introduction to Distributed Ledgers

What is a Distributed Ledger?

Definitions used in this page:
  • Node: A computer that participates in the network and stores or validates ledger data.
  • Ledger state: The current snapshot of data such as balances, nonces, and contract storage.
  • Account: An address that can hold value and submit transactions.
  • Transaction: A signed instruction that changes ledger state.
  • Nonce: A per-account counter used to order transactions and prevent replay.
  • UTXO: Unspent Transaction Output, a spendable output in Bitcoin-like models.
  • State root: A cryptographic hash that represents the entire ledger state.

A distributed ledger is a database that is consensually shared and synchronized across multiple sites, institutions, or geographies. Unlike traditional centralized databases, distributed ledgers have no central administrator or central storage. Instead, they are maintained by a network of participants, each holding an identical copy of the ledger.

Key Concept: In a distributed ledger, all participants can see the same data simultaneously, and any changes are reflected across all copies in near real-time. This creates transparency and reduces the risk of fraud or manipulation.

Core Components

A distributed ledger consists of three fundamental components:

1. Accounts

An account in a distributed ledger represents an entity that can hold balances and initiate transactions. Each account has a unique address (often derived from a public key) and can hold a balance of cryptocurrency or tokens.

2. Balances

A balance represents the amount of cryptocurrency or tokens held by an account.

  • Balances are stored in the ledger state
  • Each account's balance may be publicly visible on the ledger
  • Balances can only be modified through valid transactions
  • The ledger maintains a complete history of all balance changes

The ledger ensures that balances are always accurate and that no funds can be created or destroyed without following the protocol's rules.

3. Transactions

A transaction is a signed instruction from an account to transfer value or trigger execution (e.g. smart contracts where supported). Key characteristics of transactions:

  • From: The account initiating the transaction (sender)
  • To: The recipient account address
  • Value: The amount of cryptocurrency to transfer
  • Nonce: A number that prevents transaction replay attacks
  • Signature: Cryptographic proof that the transaction was authorized by the account owner

When a transaction is created, it is signed with the sender's private key. The signed transaction is then broadcast to the network, validated, and added to the ledger.

How Distributed Ledgers Work

  1. Transaction Creation: A user creates a transaction to transfer funds or execute a smart contract, signing it with their private key.
  2. Broadcasting: The signed transaction is broadcast to the network of nodes (computers maintaining the ledger).
  3. Validation: Network nodes validate the transaction by checking:
    • The signature is valid
    • The sender has sufficient balance
    • The transaction format is correct
    • The nonce is valid (prevents replay attacks)
  4. Consensus: Network participants agree on which transactions to include and in what order (through consensus mechanisms like Proof of Work or Proof of Stake).
  5. Recording: Valid transactions are grouped into blocks and added to the ledger, updating all account balances accordingly.

Blockchain as a State Machine

A blockchain can be understood as a state machine - a system that maintains a current state and transitions to a new state when transactions are processed. Each block in the blockchain represents a state transition, moving the entire system from one valid state to another.

Blockchain Structure as State Machine

Blockchain State Machine: Each block contains transactions that transition the blockchain from one state to another, with each block verifying the integrity of the previous state.

Understanding State in Blockchain

The state of a blockchain at any given point includes:

  • Account Balances: The current balance of every account in the network
  • Smart Contract Storage: The current values stored in all smart contracts
  • Account Nonces: The transaction count for each account (prevents replay attacks)
  • Contract Code: The bytecode of all deployed smart contracts

State Transitions

When a block is added to the blockchain:

  1. Initial State: The blockchain starts with the state from the previous block (or genesis state for the first block)
  2. Transaction Processing: Each transaction in the block is executed, which modifies the state:
    • Transferring value between accounts updates balances
    • Executing smart contract functions updates contract storage
    • Deploying contracts adds new contract code to the state
  3. New State: After processing all transactions, the blockchain reaches a new valid state
  4. State Root: The new state is cryptographically hashed into a "state root" (Merkle root) that represents the entire state in a single hash

State Verification in Blocks

Each block in the blockchain contains a state root (or state hash) that serves as a cryptographic proof of the entire blockchain state at that point. This is crucial because:

  • Verification: The state root in the current block verifies that all previous blocks have been processed correctly and the state is valid
  • Integrity: Any change to any account balance, contract storage, or previous transaction would result in a different state root, immediately revealing tampering
  • Efficiency: Instead of storing all account data in every block, only the state root hash is stored, making the blockchain more efficient
  • Consensus: All nodes can independently verify they have the same state by comparing state roots
Key Insight: The state root in each block acts like a fingerprint of the entire blockchain state. If even a single account balance changes, the state root changes completely, making it impossible to alter the blockchain without detection.

This state machine model ensures that:

  • The blockchain always maintains a consistent, verifiable state
  • All nodes can independently verify they have the correct state
  • Historical states can be reconstructed by replaying transactions from the genesis block
  • The entire system behaves deterministically - the same transactions always produce the same state

Key Benefits

  • Transparency: All transactions are visible to all participants
  • Immutability: Once recorded, transactions cannot be easily altered
  • Decentralization: No single point of failure or control
  • Security: Cryptographic signatures ensure only authorized parties can initiate transactions
  • Trust: Participants don't need to trust a central authority
Important: While distributed ledgers provide many benefits, they also require careful management of private keys. If you lose your private key, you lose access to your account and funds permanently.