Read Time:5 Minute
- The blockchain technology can be used to create “contracts” that can be used to encode arbitrary state transition functions.
- Bitcoin’s ledger can be thought of as a state transition system, where there is a “state” consisting of the ownership status of all existing bitcoins and a “state transition function” that takes a state and a transaction and outputs a new state.
- The algorithm for checking if a block is valid requires that the sum of the denominations of all input UTXO is less than the sum of the denominations of all output UTXO.
- The purpose of the proof-of-work requirement is to make block creation computationally “hard”, thereby preventing sybil attackers from remaking the entire blockchain in their favor.
- In order to compensate miners for their work, the miner of every block is entitled to include a transaction giving themselves 25 BTC out of nowhere.
- If any transaction has a higher total denomination in its inputs than in its outputs, the difference also goes to the miner as a “transaction fee”.
- An attacker’s strategy is to produce another transaction sending the same 100 BTC to himself and try to convince the network that his transaction to himself was the one that came first.
- In order for the attacker to make his blockchain the longest, he would need to have more computational power than the rest of the network combined in order to catch up (hence, “51% attack”).
Scripting and Alternative Applications
- Bitcoin’s scalability is due in part to its use of a multi-level data structure called the Merkle tree.
The Merkle tree allows for a piecemeal delivery of data, which is essential for long-term sustainability.
- The Bitcoin protocol can be used to create a variety of alternative applications, including Namecoin and Colored Coins.
- The Bitcoin protocol has limitations, including a lack of Turing-completeness and value-blindness.
- There are three approaches to building advanced applications on top of cryptocurrency: building a new blockchain, using scripting on top of Bitcoin, and building a meta-protocol on top of Bitcoin.
Ethereum State Transition Function
- Ethereum is an alternative protocol for building decentralized applications
- Ethereum accounts contain four fields: the nonce, the account’s current ether balance, the account’s contract code (if present), and the account’s storage (empty by default)
- There are two types of Ethereum accounts: externally owned accounts (controlled by private keys) and contract accounts (controlled by their contract code)
- In Ethereum, the state is made up of objects called “accounts”
- Transactions in Ethereum contain the recipient of the message, a signature identifying the sender, the amount of ether to transfer from the sender to the recipient, and an optional data field
- Messages in Ethereum are virtual objects that are never serialized and exist only in the Ethereum execution environment; a message is produced when a contract currently executing code executes the CALL opcode
- The Ethereum state transition function can be defined as follows: check if the transaction is well-formed, calculate the transaction fee, transfer the transaction value from the sender’s account to the receiving account, and if the value transfer failed because the sender did not have enough money, or the code execution ran out of gas, revert all state changes except the payment of the fees
Code Execution – Mining and Applications
- The code in Ethereum contracts is written in a low-level, stack-based bytecode language, referred to as “Ethereum virtual machine code” or “EVM code”.
- The code consists of a series of bytes, where each byte represents an operation.
- Code execution is an infinite loop that consists of repeatedly carrying out the operation at the current program counter (which begins at zero) and then incrementing the program counter by one, until the end of the code is reached or an error or STOP or RETURN instruction is detected.
- The operations have access to three types of space in which to store data: the stack, memory, and the contract’s long-term storage.
- The code can also access the value, sender and data of the incoming message, as well as block header data, and the code can also return a byte array of data as an output.
- The formal execution model of EVM code is surprisingly simple.
- The Ethereum blockchain is in many ways similar to the Bitcoin blockchain, although it does have some differences. The main difference between Ethereum and Bitcoin with regard to the blockchain architecture is that, unlike Bitcoin, Ethereum blocks contain a copy of both the transaction list and the most recent state.
- In general, there are three types of applications on top of Ethereum: financial applications, semi-financial applications, and non-financial applications.
- Token systems are surprisingly easy to implement in Ethereum. The key point to understand is that all a currency, or token system, fundamentally is, is a database with one operation: subtract X units from A and give X units to B, with the proviso that (i) A had at least X units before the transaction and (2) the transaction is approved by A.
- Financial derivatives are the most common application of a “smart contract”, and one of the simplest to implement in code.
Decentralization and Further Applications
- The key piece of technology for a decentralized file storage system is the “decentralized Dropbox contract”. This contract allows users to store their files on a decentralized network of nodes, with the contract rewarding nodes for storing the file.
- A decentralized autonomous organization (DAO) is a virtual entity that is controlled by a group of shareholders. The shareholders can vote to change the code of the DAO or to allocate its funds.
- DAOs can be used for a variety of purposes, such as savings wallets, crop insurance, or smart multi signature escrow.
- Prediction markets can be used to predict the outcome of events, and can be implemented on the Ethereum blockchain.
Scaling and Conclusion
- The Ethereum protocol was conceived as an upgraded version of a cryptocurrency, providing advanced features such as on-blockchain escrow, withdrawal limits, financial contracts, gambling markets and the like via a highly generalized programming language.
- The Ethereum protocol would not “support” any of the applications directly, but the existence of a Turing-complete programming language means that arbitrary contracts can theoretically be created for any transaction type or application.
- What is more interesting about Ethereum, however, is that the Ethereum protocol moves far beyond just currency. Protocols around decentralized file storage, decentralized computation and decentralized prediction markets, among dozens of other such concepts, have the potential to substantially increase the efficiency of the computational industry, and provide a massive boost to other peer-to-peer protocols by adding for the first time an economic layer.
- The concept of an arbitrary state transition function as implemented by the Ethereum protocol provides for a platform with unique potential; rather than being a closed-ended, single-purpose protocol intended for a specific array of applications in data storage, gambling or finance, Ethereum is open-ended by design, and we believe that it is extremely well-suited to serving as a foundational layer for a very large number of both financial and non-financial protocols in the years to come.