Understanding Bitcoin and Ethereum: A Deep Dive into Blockchain Technology
Bitcoin and Ethereum: A Deep Dive into Blockchain Technology
Bitcoin Transactions
The $1000 is broken up into many smaller amounts and mixed in a tumbler with funds from other people. Then, the person receives $1000 from the tumbler, but with no connection to the addresses used to provide the original funds.
Analogy: Suppose you have a large group of people who each put cash in a closed box. Then, each person takes out from the box the exact amount that he put in, although the specific coins and bills he/she extracts will be different from the ones he/she put in.
Transaction Process:
- The sender needs to have previously received (and still hold) an amount sufficient for the transaction.
- Broadcast a message to the network referencing:
- Address(es) holding funds sufficient for the transaction
- Recipient addresses and amounts
- At least one of the recipient addresses is usually controlled by the sender
- The difference between inputs and outputs is a transaction fee (in this case 0.0001 BTC) to encourage miners to process it.
- The transaction is signed using a private key(s).
- The transaction (including the signature) is then broadcast publicly to the network.
Blockchain Integrity
In order for a blockchain algorithm to work, it must resolve competing branches over a reasonable amount of time.
- If this doesn’t occur, the integrity of the blockchain is lost (e.g., in cryptocurrency applications, people could engage in “double spending”).
- The older a block is, the more likely it is to remain in the consensus blockchain.
Difficulty
- A 4-byte long number that determines the target.
- The higher the difficulty target, the more difficult it will be to solve for a valid hash.
- The difficulty target is reset every 2016 blocks (~every 2 weeks).
Double Spending
- If someone tries to spend the same Bitcoin twice, the transaction belonging to the longest chain “wins” out in the end.
- The transaction belonging to the longest chain will be valid; the other(s) will be invalid.
- However, a scenario can arise where some miners in the network accept a block containing transaction A and other miners accept a block containing transaction B (causing there to be two different blockchains in the network).
- After several more blocks have been mined, the network should return to consensus, validating one of the transactions (either transaction A or B) and invalidating the other.
- For this reason, it is commonly agreed that once ~6 additional blocks have been added to the blockchain, a transaction is “final” (meaning that in a blockchain of length N, your transaction is in a block ≤ N-6).
- This is all determined by the Bitcoin client.
- Remember, no miner is consciously making decisions here; the system works through computers running a client and communicating with one another.
Ethereum
Ethereum Functions:
- Virtual machine to generate small contracts.
- Blockchain to maintain the transaction data.
Ethereum charges developers for the computing power in Ether. Ethereum wants to use the blockchain to replace internet third parties, like storage providing.
Locktime in Bitcoin
- Can prevent a transaction from being mined until a specific time (or block height).
- Can restrict spending of a transaction output until a specific time is reached.
Turing Completeness
A Turing machine is a state machine. Its actions are completely determined by:
- The current state
- The input
- A set of transition rules
Bitcoin is not Turing complete. For example, there is no mechanism to implement loops in Bitcoin.
ERC Standards
ERC-20: For money and money-like tokens
ERC-721: For things and thing-like tokens
Bitcoin vs. Ethereum
Supply:
- Bitcoin: Capped at 21 million
- ETH: 18 million per year
Block Time:
- Bitcoin: Approx every 10 minutes
- ETH: Approx every 10-20 seconds
Block Reward:
- Bitcoin: 12.5 per block (currently)
- ETH: 5 per block
Gas
Gas is a unit of measure used in Ethereum to measure the cost of performing calculations.
Bitcoin Script
Bitcoin script is a declarative language – it describes what should be done.
Bitcoin script contains:
- A public key when hashed provides the destination address D embedded into the script.
- A signature proving the ownership of the private-key corresponding to the public key just provided.
The validation of a transaction on the Bitcoin network requires two types of scripts: a locking script and an unlocking script, also known as scriptPubKey and scriptSig.
A transaction is valid if nothing in the combined script triggers failure and the top stack item is True (non-zero) when the script exits.
The party originally sent the bitcoins now being spent dictates the script operations that will occur last in order to release them for use in another transaction.
The party wanting to spend them must provide the input(s) to the previously recorded script that results in the combined script completing execution with a true value on the top of the stack.
<sig><pubkey> DUP HASH160 <PUBKHASH> EqualVerify CheckSig
Ethereum Virtual Machine (EVM)
Ethereum is a public blockchain with the ability to run smart contracts, blockchains are transactional based state-machines, they retain states and changed by transactions.
Ethereum is interacted by the use of an account, which are 20byte identifiers holds the state unique to it.
External: Used by humans to initiate transactions with each other and smart contracts.
Contract accounts: Accounts hold the state and content of a smart contract, can initiate transactions as a response to external accounts but cannot by their own.
Accounts have:
- Nonce: (# of tx sent from this address (external) or the # of contracts created from the smart contract account)
- Balance: (# of ether)
- Hash of the data of the account
- Hash of the code (contract only)
Ethereum has op codes and the processor behind all of the op codes is the EVM.
