How Does Ethereum Work?
Since Satoshi Nakamoto created the concept of bitcoin, the world has struggled to find purpose in digital coins. On one hand, its bank-free money, but on the other, there is not enough distrust of the banks to justify it. On one hand, it is a way to store and convey value. But, on the other hand, so is gold, and gold has been around a lot longer. On one hand, bitcoin is a secure, hacker-resistant payment methodology. On the other hand, it is non-scalable, initially incapable of instant payments, and beset by a change-resistant mining community.
There has always been room for change with bitcoin. One coin that sought to build on the bitcoin foundation and improve it is Ethereum.
Ethereum is not the first bitcoin alternative or even the first altcoin that sought to bringing scripting to bitcoin. However, it is the first altcoin to move cryptocurrency from a means of conveying value to a means of doing work.
This article will look at Ethereum and how it works.
What is Ethereum?
“When Satoshi Nakamoto first set the Bitcoin blockchain into motion in January 2009, he was simultaneously introducing two radical and untested concepts,” Ethereum creator Vitalik Buterin wrote in his white paper. “The first is the ‘bitcoin’, a decentralized peer-to-peer online currency that maintains a value without any backing, intrinsic value or central issuer. So far, the ‘bitcoin’ as a currency unit has taken up the bulk of the public attention, both in terms of the political aspects of a currency without a central bank and its extreme upward and downward volatility in price. However, there is also another, equally important, part to Satoshi’s grand experiment: the concept of a proof of work-based blockchain to allow for public agreement on the order of transactions. Bitcoin as an application can be described as a first-to-file system: if one entity has 50 BTC, and simultaneously sends the same 50 BTC to A and to B, only the transaction that gets confirmed first will process. There Is no intrinsic way of determining from two transactions which came earlier, and for decades this stymied the development of decentralized digital currency. Satoshi’s blockchain was the first credible decentralized solution. And now, attention is rapidly starting to shift toward this second part of Bitcoin’s technology, and how the blockchain concept can be used for more than just money.”
“Commonly cited applications include using on-blockchain digital assets to represent custom currencies and financial instruments (‘colored coins’), the ownership of an underlying physical device (‘smart property’), non-fungible assets such as domain names (“Namecoin”) as well as more advanced applications such as decentralized exchange, financial derivatives, peer-to-peer gambling and on-blockchain identity and reputation systems. Another Important area of inquiry is ‘smart contracts’ – systems which automatically move digital assets according to arbitrary pre-specified rules. For example, one might have a treasury contract of the form ‘A Can withdraw up to X currency units per day, B can withdraw up to Y per day, A and B together can withdraw anything, and A Can shut off B’s Ability to withdraw’. The logical extension of this is decentralized autonomous organizations (DAOs) — long-term smart contracts that contain the assets and encode the bylaws of an entire organization. What Ethereum Intends to provide is a blockchain with a built-in fully fledged Turing-complete programming language that can be used to create ‘contracts’ that can be used to encode arbitrary state transition functions, allowing users to create any of the systems described above, as well as many others that we have not yet imagined, simply by writing up the logic in a few lines of code.”
Ethereum was not Buterin’s first bite of the apple. The idea of a scriptable bitcoin did not come organically, but from the result of a failed and severely hacked cryptocurrency attempt. Yet the same, the results of “trying to remake the wheel” resulted in the model for “bitcoin 2.0,” or blockchains used as a data-driver for non-blockchain applications.
The Ethereum model consists of the Ethereum token, the Ethereum Virtual Machine, and the Ethereum blockchain. By understanding how these components work, one can appreciate how blockchain can be used to interface with “real-world” applications and do non-financial work.
The Ethereum Blockchain
On a most basic level, the Ethereum blockchain is no different from the bitcoin blockchain. Both are Merkle tree-based and are based on cryptographical hashes. Ethereum is based on the Ethash protocol, while bitcoin is based on the double-SSH protocol.
The difference, however, rotates around the blockchains’ end purpose. While both blockchains can store transactions, bitcoin’s transactions take a specific format that can only be changed in minor details, such as adding text to the transaction record. Ethereum transactions, however, as long as they have a valid header, can take any form the developer wants for them.
Ethereum depends on state transactions – a ledger of accounts and balances – instead of bitcoin’s unspent transaction outputs. The state transactions record all of the current balances for the accounts, plus any other data, to a separate Merkle Patricia tree off-blockchain. As there are no unspent outputs to “unlock,” an Ethereum wallet stores both the private and public encryption keys. This gives ether wallets the unique ability of being able to directly write to the blockchain.
Before talking about transaction scripting, we should talk about how else the Ethereum blockchain is different:
- Ethereum’s block time is about 15 seconds, compared to ten minutes with bitcoin. This result in cheaper transaction fees for Ethereum;
- Mining with Ethereum produces coins at a consistent rate. Bitcoin’s rate drops every four years;
- Ethereum is resistant to ASIC-mining due to its Ethash algorithm;
- Ethereum fees depend on computational complexity and storage requirement, while bitcoin transactions are based on transaction size;
- Ethereum’s coin supply has not been capped yet, while bitcoin’s is at 21 million;
- Ethereum transaction fees (called “gas”) can be specified in the transaction; and
- Ethereum’s accounting system is a credit/debit system where one account is credited and one account is debited simultaneously. Bitcoin’s unspent transaction output systems is more akin of paying for something with physical money and receiving change back; it is a one-way flow of commerce.
Now, looking at a transaction, a transaction on Ethereum can be generated from a user’s account or from an account managed by a program. This program is called a dApp or a decentralized application. Ethereum differs primarily from bitcoin because it allows a developer to create this “virtual robot” to manage the account. Contrary to popular beliefs, the dApp is not on the blockchain, but on the adjacent Patricia tree.
However, when a user accesses the dApp to perform some action – play a game, make a bet, reserve a car, etc.—the transaction is recorded to the Ethereum blockchain just like any other transaction. The blockchain is plastic enough to allow certain dApps to create its own Ethereum-based coins – known as ERC-20 tokens – for its transactions, with the coins’ records being stored in the Ethereum blockchain besides Ether transactions.
As such, this allows Ethereum to be the first scriptable platform for cryptocurrency and distributed ledger applications. So, any transaction that would need a third party in the real world can be executed, exacted, and processed automatically. This transaction template – called a smart contract – gives Ethereum the power to do work, such as serve as the backbone of a real-time tracking system or a real estate managing service.
“The basic idea of smart contracts is that many kinds of contractual clauses (such as liens, bonding, delineation of property rights, etc.) can be embedded in the hardware and software we deal with, in such a way as to make breach of contract expensive (if desired, sometimes prohibitively so) for the breacher,” wrote computer scientist Nick Szabo in 1994 when he pioneered the concept of a smart contract. “A canonical real-life example, which we might consider to be the primitive ancestor of smart contracts, is the humble vending machine. Within a limited amount of potential loss (the amount in the till should be less than the cost of breaching the mechanism), the machine takes in coins, and via a simple mechanism, which makes a beginner’s level problem in design with finite automata, dispense change and product fairly. Smart contracts go beyond the vending machine in proposing to embed contracts in all sorts of property that is valuable and controlled by digital means. Smart contracts reference that property in a dynamic, proactively enforced form, and provide much better observation and verification where proactive measures must fall short. And where the vending machine, like electronic mail, implements an asynchronous protocol between the vending company and the customer, some smart contracts entail multiple synchronous steps between two or more parties.”
The Ethereum Virtual Machine
The blockchain, the dApps, and the smart contracts all live in the Ethereum Virtual Machine – a processing stack that runs on every Ethereum mining node. The idea of the EVM is to give everyone an identical “open room” to conduct their transactions.
As asking someone donate their electricity and processing capability is rude and can open the miner to rampant abuses, Ethereum is designed to reward smaller dApps and smart contracts. Take, for example, the following pseudo code program:
- 10 CREATE VARIABLE A,,C of type INT
- 20 INPUT transaction_input AS A
- 30 IF A > 0 THEN
- 40 CREATE VARIABLE B as STRING
- 50 INPUT transaction_id AS B
- 60 DEBIT (B ,A, DELAY = 0)
- 70 ACCESS POINTER LIST (ASSETS)
- 80 FIND AVAILABLE_ASSET and STORE to C
- 90 ASSIGN_ASSET (C, B)
- 100 BREAK
- 110 ELSE PRINT (“Insufficient funds”)
- 120 BREAK
This poorly-written program would require 12 computational units to complete, not counting the subroutines. In Ethereum, computational units are priced in “gas weis” or “gwei” – a wei is the equivalent of a satoshi in bitcoin, with one Ether worth 1,000,000,000,000,000,000 wei. This price – like bitcoin – is not set, but higher gas prices tend to get processed first. Certain instructions cost more than others. A user can set a limit on the gas he/she is willing to use; if the user does not have enough gas to run a function, the application fails.This is different from the gasLimit, or the set cost to run a function.
“Every transaction has a specific amount of gas associated with it: gasLimit. This is the amount of gas which is implicitly purchased from the sender’s account balance. The purchase happens at the according gasPrice, also specified in the transaction. The transaction is considered invalid if the account balance cannot support such a purchase. It is named gasLimit since any unused gas at the end of the transaction is refunded (at the same rate of purchase) to the sender’s account. Gas does not exist outside of the execution of a transaction. Thus for accounts with trusted code associated, a relatively high gas limit may be set and left alone.”
“In general, Ether used to purchase gas that is not refunded is delivered to the beneficiary address, the address of an account typically under the control of the miner. Transactors are free to specify any gasPrice that they wish, however miners are free to ignore transactions as they choose. A higher gas price on a transaction will therefore cost the sender more in terms of Ether and deliver a greater value to the miner and thus will more likely be selected for inclusion by more miners. Miners, in general, will choose to advertise the minimum gas price for which they will execute transactions and transactors will be free to canvas these prices in determining what gas price to offer. Since there will be a (weighted) distribution of minimum acceptable gas prices, transactors will necessarily have a trade-off to make between lowering the gas price and maximising the chance that their transaction will be mined in a timely manner.”
The final part of the equation is the token. While the blockchain supports a native coin, the Ether, which can be used as the equivalent of a bitcoin or as a storage of value, it also allows the creation of daughter tokens, or ERC (Ethereum Request for Comment) -20 tokens, that can be traded or used in their own rights.
These daughter tokens are not related to Ethers in any way and are not directly exchangeable for Ethers but must meet some of the same requirements as Ether coins. This includes setting up a coin with functions such as totalSupply, balanceOf, transfer, transferFrom, approve, and allowance. Ether does not conform with the full definition of ERC-20, however.
Taken together, the EVM, the token, and the blockchain creates an ecosystem that allows for the decentralized storage and transfer of data. This bears the potential of changing the world. While bitcoin changed the way we looked at money, Ethereum changed the way we look at the world.