Bitcoin and Cryptocurrencies CS198.x BerkeleyX edX course notes
Last Updated: August 14, 2018 by Pepe Sandoval
If you find the information in this page useful and want to show your support, you can make a donation
Use PayPal
This will help me create more stuff and fix the existent content...
bitcoin is a decentralized, digital currency built using principles of computer science, cryptography and economics
Bitcoin is the network and protocol governing the bitcoin cryptocurrency
The Bitcoin Blockchain is a data structure that stores a permanent history of all transactions to ever occur in the history of bitcoin, its and append-only ledger so things CANNOT be deleted once added
The Bitcoin network validates transactions ans stores the entire transaction history
Bitcoin solves inconsistent transaction and double spending attack problems by using the blockchain and consensus protocol (PoW)
Service | Banks | Bitcoin |
---|---|---|
Manage accounts (Identity) | Verify our identity so only we can use the funds, to do this they ask us for identification | Give user autonomously created identities |
Transfer money (Transactions) | Send and receive money for us | Transactions are peer-to-peer |
Record management (Record Keeping) | Keep track of our balance | Each node keeps it's own ledger and the transactions are validated by the entire network |
Trust (Consensus) | Put trust in the banks "professionals" and that the banks are under regulations of government | Provides trust through a protocol that incentivizes actors to be honest |
Needed to verify no-one else can act in your behalf and only you can perform what you want -> Your Identity
Identity can be used for integrity which means guarantee no one else can replicate out authentication methods -> Your Signature
To implement identity Bitcoin uses public and private keys
Public key != BTC Address
: The BTC address is derived from your public key but NOT identicalBitcoin has 2^160
possible addresses so the probability that 2 people get the same address is very, very, very, very, small; considered impossible
Distributed database so everyone keeps a copy of the ledger to keep track of it
Everyone stores the ledger
The Ledger doesn't update for every single transaction, it updates in blocks of transactions (a batch that can contain thousands of transactions) and each block is chained to previous blocks which forms a blockchain
Every block contains information about the previous block, as every block is built off the previous one. If any block from the past is mutated we would have to change not only information within that block but information in subsequent blocks in all the distributed copies of the blockchain
Defines/decides which blocks (batch of transactions) are valid, since everyone needs to agree on the history of transactions
Not only everyone needs to agree on the update, but they also need to agree on a valid update to make sure no corrupted information is accepted
Consensus is achieved through voting but we cannot assume that each online identity deserves the same voting power to reach consensus, as people with a lot of spare time could create multiple identities, to ensure that a vote is real, we have to make a vote expensive.
Each vote must be cast with resources not identities, in Bitcoin the resource is computing power
The consensus algorithm used is Proof of Work (PoW) which provides evidence that someone has spent resources. It is the method to translate computing power into voting power. Process
Bitcoin's correct operation hinges on one key assumption: that there is an honest majority of computational power.
An honest majority would be able to mine faster than a malicious minority, and thus have a higher probability of creating the next block. Once the network comes to consensus on these new blocks, generally it is in a miner’s best interest to follow protocol and mine on the longest observed blockchain. The longest chain is seen as the “true” valid transaction history because it has had the most work put into it. Therefore, the majority defines the transaction history.
Privacy is the power to selectively reveal oneself to the world
Bitcoin block are created every 10 minutes and can only hold 1MB of transactions
How do you calculate that Bitcoin blockchain can process about three transactions a second?
Governance is the mechanism by which a protocol makes changes to itself, but no such mechanism was encoded into the Bitcoin protocol.
Ethereum was developed as a platform to execute peer-to-peer smart contracts and applications
Ethereum supports Turing-complete languages, meaning that it can perform general computation. This means, any type of code that I run on a regular computer can also be run on Ethereum.
Code execution on Ethereum is fueled by Ethereum’s internal token, called ether (ETH).
Tamper-evident: means that if the information is manipulated we can easily know about this manipulation
We need to generate unique identifiers (standardized randomness) for the meaningful data and associated these two to ensure integrity of our information
Shouldn't be able to guess that data knowing the identifier
Cryptographic Hash functions are one way math functions that take some input and always produce the same output for that given input
Output looks may look random to us
Output is of a given-fixed size
Crypto Hash functions are a specific case of Hash functions designed for security, this means it they have the following properties:
x'
such that H(x) == H(x')
y
and x
such that H(x) == H(y)
The consequence of these properties is the Avalanche Effect which means a small change in input can produce significant differences in the output
Bitcoin uses SHA-256^2
(SHA-256 squared) which means SHA-256 is used twice in a row
< 2^64
bits and produces a 256 bits
fixed size outputThe blockID
(also called Block Header
) is the Hash of all the fields of the block header concatenated -> BlockId = H(prevBlockHash || merkleRoot || nonce ...)
The Block Header represents the Metadata for the block components, contains the fields:
Nonce: Proof of Work is done with Bitcoin's partial preimage hash puzzle.
H(BlockHeader) < target
Timestamp:
Target:
Version:
The coinbase transaction is a transaction that the miners include in the block which is always the first transaction of the Merkle tree
A Bitcoin Transaction Contains the following fields:
scriptSig
).In Bitcoin senders specific a locking script in the output of the transaction, recipients provide an unlocking script in the input whenever they want to redeem their bitcoin
Timelocks are a type of functionality in Bitcoin that restrict the spending of funds until a later time or a specific block height.
Users who only need a wallet to help manage keys and send/receive bitcoin
The mains functionality of a wallet is to keep track of out identity which means securing/storing a user private key and send/receive and list transactions
Wallet forms: Smartphone Apps, Online Web-wallets (Hosted on websites), HW wallets, Paper-Wallets (literal pieces of papers with your private key printed on it) etc.
Simple Payment Verification (SPV) is a method for verifying if a particular transactions are including in a block without downloading the entire block, just by downloading the block headers (these header include all the transactions so a Merkle Proof of Inclusion can be used). Clients using this method are called thin clients
A miner must:
Create a block with its metadata. This means generating the Merkel Root and all the other components of a block
Find the PoW, this means finding a valid Nonce. A valid nonce in this case is a nonce which makes the hash of the block header less than some target value
Broadcast your block, other miners validated the block and broadcast the block once more
All Proof-of-Work really is at its base, a random lottery
Other coins like Litecoin use memory-bound puzzles (e.g. Scrypt) which instead of computing power need a lot of memory, these make then more ASIC resistant but requires also a lot of memory to verify them
Other alternative to puzzles is to chain a lot of hash functions (e.g. x11 or x13 algorithms used by DASH) or to switch mining puzzles every some random time
Confirmations refer to the number of blocks mined on top of a block containing some particular transaction
The Bitcoin network is peer to peer, so the way that messages get sent around the network is through a gossip protocol (also called flooding)
Bitcoin is special because is a system that allows us to:
Bitcoin's intended purpose is solely to allow the transaction of bitcoins, its native asset. "It’s a global payment system"
Ethereum is a decentralized platform designed to run smart contracts, it's like a distributed computer (spread across nodes around the world) to execute code
Because of decentralization applications are run exactly as programmed without possibility of downtime, censorship, fraud or third party intervention
Bitcoin blockchain enabled used to conduct transactions that were decentralized a more general case is to allow the execution of arbitrary computation on the blockchain that's what smart contracts enable us to do in Ethereum
Ethereum allows the creation of decentralized apps, otherwise known as dApps which are just SW running on the Ethereum blockchain
smart contract is a piece of code that facilitates verifies and/or enforces the negotiation or execution of a digital contract. A Trusted entity must run (enforce) this code (smart contract)
Ethereum is implemented as a distributed state machine and uses a user-based blockchain -> Ethereum is account based
Ethereum supports a Turing complete scripting language
Ethereum is a smart contract blockchain platform, a distributed world computer. It's native asset ether(ETH) exists to fund computation and to align incentives.
Smart contracts in Ethereum are like autonomous agents that live inside of the Ethereum network. Smart contracts react to the external world when they are poked by transactions, which call specific functions.
Ethereum's main goal is to enable distributed and trustless computation
Ethereum is redundantly parallel so contract executions are redundantly replicated across all nodes which makes it expensive
Externally owned accounts
Contract accounts
Smart contracts in Ethereum are usually written in a high level programming language.
Smart contracts are compiled to Ethereum Virtual Machine (EVM) code, this is the code that is executed by every node in Ethereum, then nodes come to consensus on the new state of the network by using PoW
Miners in Ethereum competitively create blocks by executing EVM code and searching for a solution to a mining puzzle.
Gas is what fuels the execution of a given contract, every EVM op-code requires gas in order to execute so every contract requires "gas" which "fuels" contract execution
startgas
which is the max quantity of gas is willing to consume and the gasprice
which is the fee in ETH the contract is willing to pay per unit gasEVM execution and Gas process
startgas * gasprice
(represents the amount of ether paid for a computation) is subtracted from the sender who is the one invoking the contract by sending a transaction.startgas * gasprice
is not refundedThe Internet focuses much more on information exchange, while blockchain focuses on value exchange. When thinking about a blockchain use case, ask yourself whether it leverages some value exchange, particularly that which cannot be handled by a single authority. Blockchain’s innovation was not to enable distributed information sharing, but distributed record-keeping and decentralized exchange of value.
Blockchains allow us to solve coordination failures, allow us to create a system which incentivizes individuals to operate according to our expectations.
The most abstract yet fundamental property of a good blockchain use case is pure decentralization for the sake of keeping it out of the hands of a central authority.
If you find the information in this page useful and want to show your support, you can make a donation
Use PayPal
This will help me create more stuff and fix the existent content...