13.06.2017 Views

Whitepaper - Ethereum Classic With Cover

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Ethereum</strong> <strong>Classic</strong> Documentation, Release 0.1<br />

is to offer an efficient way to reach consensus on the system state without needing trusted third parties, oracles or<br />

violence monopolies. But importantly they are not there for optimal computation. The fact that contract executions<br />

are redundantly replicated across nodes, naturally makes them expensive, which generally creates an incentive not<br />

to use the blockchain for computation that can be done offchain.<br />

When you are running a decentralized application (dapp), it interacts with the blockchain to read and modify its<br />

state, but dapps will typically only put the business logic and state that are crucial for consensus on the blockchain.<br />

When a contract is executed as a result of being triggered by a message or transaction, every instruction is executed<br />

on every node of the network. This has a cost: for every executed operation there is a specified cost, expressed in<br />

a number of gas units.<br />

Gas is the name for the execution fee that senders of transactions need to pay for every operation made on an<br />

<strong>Ethereum</strong> blockchain. The name gas is inspired by the view that this fee acts as cryptofuel, driving the motion of<br />

smart contracts. Gas is purchased for ether from the miners that execute the code. Gas and ether are decoupled<br />

deliberately since units of gas align with computation units having a natural cost, while the price of ether generally<br />

fluctuates as a result of market forces. The two are mediated by a free market: the price of gas is actually decided<br />

by the miners, who can refuse to process a transaction with a lower gas price than their minimum limit. To get gas<br />

you simply need to add ether to your account. The <strong>Ethereum</strong> clients automatically purchase gas for your Ether in<br />

the amount you specify as your maximum expenditure for the transaction.<br />

The <strong>Ethereum</strong> protocol charges a fee per computational step that is executed in a contract or transaction to prevent<br />

deliberate attacks and abuse on the <strong>Ethereum</strong> network. Every transaction is required to include a gas limit and a<br />

fee that it is willing to pay per gas. Miners have the choice of including the transaction and collecting the fee or<br />

not. If the total amount of gas used by the computational steps spawned by the transaction, including the original<br />

message and any sub-messages that may be triggered, is less than or equal to the gas limit, then the transaction<br />

is processed. If the total gas exceeds the gas limit, then all changes are reverted, except that the transaction is<br />

still valid and the fee can still be collected by the miner. All excess gas not used by the transaction execution is<br />

reimbursed to the sender as Ether. You do not need to worry about overspending, since you are only charged for<br />

the gas you consume. This means that it is useful as well as safe to send transactions with a gas limit well above<br />

the estimates.<br />

Estimating transaction costs<br />

The total ether cost of a transaction is based on 2 factors:<br />

gasUsed is the total gas that is consumed by the transaction<br />

gasPrice price (in ether) of one unit of gas specified in the transaction<br />

Total cost = gasUsed * gasPrice<br />

gasUsed<br />

Each operation in the EVM was assigned a number of how much gas it consumes. gasUsed is the sum of all the<br />

gas for all the operations executed. There is a spreadsheet which offers a glimpse to some of the analysis behind<br />

this.<br />

For estimating gasUsed, there is an estimateGas API that can be used but has some caveats.<br />

gasPrice<br />

A user constructs and signs a transaction, and each user may specify whatever gasPrice they desire, which can<br />

be zero. However, the <strong>Ethereum</strong> clients launched at Frontier had a default gasPrice of 0.05e12 wei. As miners<br />

optimize for their revenue, if most transactions are being submitted with a gasPrice of 0.05e12 wei, it would be<br />

difficult to convince a miner to accept a transaction that specified a lower, or zero, gasPrice.<br />

1.7. Contracts and Transactions 75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!