powered by Coinlib

Tuesday, February 19, 2019

How is Ethereum Different from Bitcoin?



When you download and run the Ethereum software, it creates and starts a segregated virtual computer on your machine called an ‘Ethereum Virtual Machine’ (EVM). This EVM processes all the Ethereum transactions and blocks, and keeps track of all the account balances and results of the smart contracts. Each node on the Ethereum network runs the same EVM and processes the same data, resulting in them all having the same view of the world. Ethereum can be described as a replicated state machine because all of the nodes running Ethereum are coming to consensus about the state of the Ethereum Virtual Machine.

Compared with Bitcoin’s primitive scripting language, the code that can be deployed in Ethereum and run as smart contracts is more advanced and approachable for developers. You can think of smart contracts as pieces of code run by all the nodes in Ethereum’s Virtual Machine. In Bitcoin, you can add a small amount of BTC as a transaction fee that goes to the miner who successfully mines the block. This compensates the miner for checking the validity of the transaction and including it in the block they are mining. Likewise, in Ethereum, you can add a small amount of ETH as a mining fee which goes to the miner who successfully mines the block.

The complication with Ethereum is that there are more types of transactions. Different transaction types have different computational complexities. For example, a transaction performing a simple ETH payment is less complex than a transaction to upload or run a smart contract. Therefore, Ethereum has a concept of ‘gas’ which is a sort of price list, based on the computational complexity of the different types of operation you are instructing the miners to make in your transaction.
Operations include searching for data, retrieving it, making calculations, storing data, and making changes to the ledger.

A basic transfer of ETH from one account to another uses 21,000 gas. Uploading and running smart contracts uses more gas depending on their complexity. When you submit an Ethereum transaction, you specify a gas price (how much ETH you are willing to pay per gas used) and a gas limit (the maximum amount of gas you will let the transaction use). Mining fee (in ETH) = gas price (in ETH per gas) x gas consumed (in gas). The gas price is the amount of ETH you are prepared to pay per unit of gas for the transaction to be processed. As with Bitcoin transaction fees, this is a competitive market, and in general the busier the network the higher the gas price people are willing to pay. In times of great demand gas, prices spike.

The gas limit you set provides a ceiling for how much gas you are prepared for a transaction to consume. This limit protects you from over-spending  on mining fees and you know that the maximum mining fee will be gas limit x gas price. This stops you over-paying if you accidentally
submitted a very complex transaction that you thought was simple.

Analogy time: driving your car 10km will use up a certain amount of fuel. If you run out of fuel, your car will stop before reaching the destination. The price of fuel is dependent on market conditions and can go up and down, but the price of fuel bears no relation to how far you may drive your car with it. Gas in Ethereum is similar. When you submit an Ethereum transaction, you specify how much gas you’re prepared to spend on making the transaction ‘work’ (this is the gas limit), and how much ETH you are prepared to pay the miner per unit of gas (this is the gas price). This results in a total amount of ETH you’re prepared to pay for the transaction to be processed.

The miner will execute the transaction and will charge you the amount of gas taken, multiplied by the gas price you specified. As with Bitcoin, the mining fee is up to you, and you need to bear in mind that you’re competing with other transactions which may have set a higher gas price. For example, a basic transaction of a transfer of ETH from one account to another uses 21,000 gas, so you can set the gas limit for this kind of transaction to 21,000, or higher; but it will only use 21,000 gas. If you set the gas limit below the amount of gas it takes to process the transaction, the transaction will fail and you will not be refunded your mining fee. This is like trying to make a journey with insufficient fuel in your tank; the fuel will be used, but you will not get to your destination.

Just like one dollar can be split into 100 cents, 1 BTC can be split into 100,000,000 Satoshi, and Ethereum too has its own unit naming convention. The smallest unit is a Wei and there are
1,000,000,000,000,000,000 of them per ETH. There are also some other intermediate names:
Finney, Szabo, Shannon, Lovelace, Babbage, Ada - all named after people who made significant contributions to fields related to cryptocurrencies or networks. Wei and Ether are the two most common denominations. Wei is usually used for gas price (a gas price of 2-50 Giga-Wei per gas is common, where 1 GWei is 1,000,000,000 Wei).

In Ethereum the time between blocks is around 14 seconds, compared with Bitcoin’s ~10 minutes. This means that, on average, if you made a Bitcoin transaction and an Ethereum transaction, the Ethereum transaction would be recorded into Ethereum’s blockchain faster than the Bitcoin transaction into Bitcoin’s blockchain. You could say Bitcoin writes to its database roughly every 10 minutes, whereas Ethereum writes to its database roughly every 14 seconds.

Currently, Bitcoin’s blocks are a little under 1MB in size whereas most Ethereum blocks are about 15-20kb in size. However, we should not compare blocks by the amount of data in them: while Bitcoin’s maximum block size is specified in bytes, Ethereum’s block size is based on complexity of contracts being run. It is known as a gas limit per block, and the maximum is allowed to vary slightly from block to block. So whereas Bitcoin’s block size limit is based on amount of data,
Ethereum’s block size limit is based on computational complexity.

Currently, the maximum block size in Ethereum is around 8 million gas. Basic transactions, or payments of ETH from one account to another (i.e., uploading or invoking a smart contract), have a complexity of 21,000 gas; so you can fit around 380 of those basic transactions into a block
(8,000,000 / 21,000). In Bitcoin, you currently get around 1,500-2,000 basic transactions in a 1MB block.

Because Ethereum’s rate of block generation is much higher than Bitcoin’s (250 blocks per hour on Ethereum vs six blocks per hour on Bitcoin), the rate of ‘block clashes’ increases. Multiple valid blocks can get created at almost the same time, but only one of them can make it into the main chain. The other one ‘loses,’ and the data in them is not considered part of the main ledger, even if the transactions are technically valid.

In Bitcoin, these non-mainchain blocks are called orphans, or orphaned blocks, and they do not form part of the main chain in any way and are never referenced again by any subsequent blocks. In Ethereum they are called uncles. Uncles can be referenced by a few of the subsequent blocks and although the data in them is not used, the slightly smaller reward for mining them is still valid.
Transactions that end up in orphaned blocks simply end up being remined on the main chain. They don’t cost the user any more gas, because the transaction in the orphaned block is treated as if it was never processed.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.