6 minute read

UCL Course COMP0143 Cryptocurrencies: LEC-02


Bitcoin V.S. Ethereum

All known cryptocurrency systems define currency units to realize an incentive system

however, dose not provide them a legal status of any form

Here give Bitcoin and Ethereum as examples

who are representatives of different design philosophies

Bitcoin Ethereum
UTXO (Unspent Transaction Output) Model Account Model
transactions transfer ownership of coins transactions update account balances
Stateless: traced from all UTXOs Stateful: update continuously
Requires change Requires No change
Value computed from
traceability of every unit
to its coinbase transaction
Value computed from
the validity of all state transitions
Not fungible Fungible

Bitcoin’s Transaction Layer

Address

The hash of the public key \(pk\) from an ECDSA key pair \((pk,sk)\)

Regular Bitcoin addresses always start with 1

Transaction

Inputs Outputs
ptx
Hash of a previous transaction
val
Number of Satoshi
this output is worth when claimed
idx
Specific output in the referenced transaction
scr:
Second half of a script
which specifies receiver and other things
sig
First half of a script
which includes a signature
 

Properties

  • The referenced transactions must be UTXOs

  • UTXOs can only be spent in their entirety

  • Change is refunded via output addresses

Double Spending

Problem

Since Bitcoin transactions are digital objects,

it is possible to be used multiple times (unlike physical coins)

Solution

Decentralized Bookkeeping: Distributed Ledger Technique (DLT, Blockchain)

Distributed Ledger Technology (DLT)

Blockchain is a linked list of blocks with hash pointers linked with each other (append-only)

Each block has a header (metadata) and payload (transactions)

Block Structure

Size Field Description
4 Magic number Fixed network identifier 0xD9B4BEF9
4 Block size Number of bytes to end of block
4 Version Block version number
32 Previous Block Hash Hash of the previous block header
32 Merkle Root Merkle root hash of all transactions
4 Time Block timestamp in seconds
4 Target Number of leading zeroes in block hash (difficulty)
4 Nonce Proof-of-work mining counter
1-9 Transaction counter Number of included transactions
Variable Transactions List of transactions

Simplified Payment Verification (SPV)

Method that not need to store all blocks in the blockchain

  • Store only block headers which are on the order of tens of megabytes

  • Enables them to selectively verify transactions but not the entire blockchain

  • Trust that miners do not include bad transactions or that full nodes watch out for this

  • Often used in resource-constraint environments, e.g. mobile wallets

Block Rewards

  • The first transaction of every block, the so-called coinbase transaction,

    assigns a block reward and the sum of all fees to the consensus leader (e.g., a miner)

  • These coinbase transactions do not have any other inputs or signatures

  • Outputs of coinbase transactions can only be spent after 100 blocks (cooldown)

  • These block rewards provide incentives for consensus nodes (e.g., miners)

    to invest their computational resources and keep the system up and running

Bitcoin’s Scripting Language

Bitcoin Script Wiki

Features

  • Stack-based, stateless

  • Intentionally not Turing complete, no loops

  • Support for cryptography

  • Time / memory usage bound by program size

  • Commands are specified as opcodes

Types

Pay-To-PubKeyHash (P2PKH)

  • Allows to send transactions to public key hashes (addresses starting with 1)

  • Basic Bitcoin transaction form

Pay-To-Script-Hash (P2SH)

  • Allows to send transactions to script hashes (addresses starting with 3)

  • To spend bitcoins sent via P2SH,

    recipient must provide a redeem script matching the script hash

  • Enables richer functionality than P2PKH (e.g. multi-signatures)


Ethereum’s Transaction Layer

Key Feature: The Ethereum Virtual Machine (EVM)
can execute Turing-complete scripts and run decentralized applications

Account Types

Externally Owned Account (EOA)

  • Controlled by a signing key

  • Can be created for free

  • Can initiate transactions

Code Account (CA)

  • Controlled by program logic

  • Creation produces cost because it requires network storage

  • Can only send transactions (message calls) in response to receiving transactions.

  • Transactions from an EOA to a CA can trigger code

    which can execute many different actions,

    such as transferring tokens or even creating a new contract

Account Structure

The account address with account state

Account state have four fields

Field Description
nonce Number of transactions sent from the account
which ensures that transactions are only processed once
balance Amount of wei owned by the account
codeHash Hash of the code that is stored in the state database for CAs
Empty for EOAs
storageRoot Root hash of a Merkle Patricia tree
that encodes the storage contents of the account

Transaction Structure

Field Description
Nonce Sequence number set by the originating EOA
used to prevent message replay
Gas price Price of gas (in wei) the originator is willing to pay
Gas limit Maximum amount of gas the originator is willing to pay
Recipient Destination Ethereum address
Value Amount of ether to send to the destination
Data Variable-length binary data payload
(v; r ; s) ECDSA signature components of the origination EOA

Transaction Fees

Goals

  • Compensation for provisioning of computational resources

  • Prevent abuse of Ethereum’s Turing-complete execution environment

Concepts

  • Every instruction has a gas price

  • Exchange rate between gas and ether is market-determined:

    \[\textit{fee} = \textit{consumed_gas} \times \textit{gas_price}\]
  • If a computation needs more gas than provided by the user,

    the corresponding transaction is rolled back and the miner gets the fee

Ethereum Virtual Machine (EVM)

  • Quasi-Turing-complete

  • Stack-based

  • 256-bit words

  • State transitions can be specified (almost) arbitrarily

  • Low-level programming language: EVM byte code

  • High-level programming languages: Solidity, LLL, Serpent, Vyper

Other Important Concepts

Swarm

  • Distributed database that stores arbitrary information

  • Unlike on a blockchain there are no serialization and validity checks

  • Hash-based addressing

  • Ether-based incentive system

Ethereum Name Service (ENS)

  • Distributed database that maps human-readable strings to Ethereum addresses

  • Ether-based incentive system

Oracles

  • Services that push details on real-world events onto the blockchain

    to make them available to code accounts.

  • Hard to decentralize, trust in a few responsible parties necessary.