Gas is an internal fee for effectuating a transaction or contract in Ethereum. At the time of writing before the publishment of Frontier, it is fixed to 10 Szabo, which is around 1/100,000 of an Ether. It’s to separate the unit of Ether (ETH) and its market value from the unit to measure computational use (gas). Therefore, a miner has the authority to increase or decrease the use of gas due to his demand. When needed, the rate of gas can be increased or decreased accordingly, avoiding a situation that leads the price of ETH increases, this would make the need to change all gas prices. This is also a response to the discussion in Bitcoin about costs structure.
What is “Gas” in Ethereum?
The gas system is not different from kW system for measure the electricity used in a household. There is just one little difference from the electrical market, which is the originator of the transaction sets the price of gas, to which the miner can accept or not, this causes an emergence of a market around gas. You can see the evolution of the price of gas here:
Ethereum also has a block size limitation, thus you’re paying for premium space in the next block just like with Bitcoin.
For the Bitcoin miners, they prefer the transaction with the highest fee. this is also the fact to Ethereum, where miners are free to skip the transaction with an over low fee.
the gas fee on every transaction or contract is set for avoiding Turing complete ability of Ethereum and EVM (Ethereum Virtual Machine Code) – the idea to limit infinite loops. For example, 10 Szabo, or 0.00001 Ether or 1 Gas can execute a line of code or some command. If there is not enough Ether in the account to complete the transaction or message then it is considered invalid. The idea is to stop rejection of service attacks from infinite loops, encourage efficiency in the code – and to make an attacker pay for the resources they use, from bandwidth through to CPU calculations through to storage.
The more complex commands you want to execute, the more gas (and Ether) you have to pay. For example, if A wants to send B 1 Ether unit, An would need to pay a total cost of 1.00001 Ether (one Gas for dealing the transaction). However, if A wanted to set a contract with B depending on the future rate of Ether, there would be more lines of code executable and more of an onus or energy consumption placed on the distributed Ether network, A would have to pay more than one Gas to deal transaction.
Some computational steps cost more than others because they are computationally expensive or because they increase the amount of data that has to be stored in the state. Here are a list of operations in the Ethereum Virtual Code and their costs in gas (which is Ethers!).
Operation name Gas Cost Function
step 1 Default amount of gas to pay for an execution cycle.
stop 0 Nothing paid for the SUICIDE operation.
sha3 20 Paid for a SHA3 operation.
sload 20 Paid for a SLOAD operation.
sstore 100 Paid for a normal SSTORE operation (doubled or waived sometimes).
balance 20 Paid for a BALANCE operation
create 100 Paid for a CREATE operation
call 20 Paid for a CALL operation.
memory 1 Paid for every additional word when expanding memory
txdata 5 Paid for every byte of data or code for a transaction
transaction 500 Paid for every transaction
At present these gas rates are set as above to keep the Ethereum system stable. But the rates may be free float depending on the demand and total gas in every block to steadily increase, which will encourage the stability of the Ethereum network