This is an old revision of the document!
On Ethereum, each low-level operation available in the Ethereum Virtual Machine (EVM) is called an Operational Code (OPCODE). There are OPCODES for the following categories1):
A spreadsheet is available documenting the Ethereum OPCODDES and the cost of each OPCODE: See EVM-OPCODE-GAS-COSTS.
Each OPCODE (i.e, ADD) within each category has an associated cost that is expressed in terms of Gas units. Gas is an abstract number that represents the relative complexity of operations. For example, the integer ADD (i.e., addition) operation uses 3 gas units while the Integer MUL (i.e.m multiplication) uses 5 gas units. Therefore the MUL OPCODE is more complex than ADD OPCODE.
The Ethereum Virtual Machine (EVM) is the runtime environment used by the Ethereum platform. There are several reasons why Ethereum uses a Virtual Machine (VM) for its runtime on every node within the Node Network.
It allows smart contract code to run by compiling to EVM bytecode. EVM plays a core role in the Ethereum blockchain to ensure a trustless mechanism without having any central administrator. EVM keeps each node systemically isolated from others in order to avoid security risks. Even if one node is compromised, it does not influence any other nodes and the blockchain network. EVM ensures the Ethereum blockchain is secured.
The Smart Contract written in Solidity is compiled into a stream of EVM Bytcodes. EVM Bytecode The Ethereum Yellow Paper Appendix G, provides a cost for processing each
Gas Units are the calculated cost of every operation the EVM can perform.
The number of Gas units each operation consumes remains constant. However, the cost of the gas is dynamic and dictated by market conditions and reflects the amount each user is willing to pay to get their operations executed (i.e., the gas price expressed in Gwei which equals 0.000000001 ETH). The Gas value is attached to the user's transaction when the Transaction is submitted. Note, that as the price of an ETH varies, so will the gas price, but the amount of gas remains constant. In other words, the gas is associated with the relative cost of the operation and the gas price reflects how valuable the end-user thinks their operation is. The actual cost to the end-user is market-driven. The total fee the end-user pays is equal to gas_price * gas_used.
Miners are paid from the transaction fee and consequently, the miners to maximize profits prioritize transactions with a higher gas price. So, in essence, the higher the gas price you are willing to pay, the faster your transaction will be processed.
The following is a summary of an excellent article by Danny Ryan 2).
The sample data shown in the first part of Table 1 rows 1-2, demonstrates the cost of Gas for performing simple add operations on the Ethereum blockchain. The first row in the table shows the cost of performing a single addition on the Ethereum Blockchain. Note: the same would occur for a single subtraction.
The sample data shown in the first part of Table 1 rows 3-5, demonstrates the cost of Gas for storing data on the blockchain. This could be a simple, single value such as the number of days until a Smart COntract expires (i.e., simple integer) or it could be something more ambitious such as a short story, a music file, or a video.
Storing data on the blockchain is extremely expensive. The reason for the cost is the storage of data on a blockchain is immutable and is replicated across tens of thousands of Ethereum Nodes in the Node Network. Therefore, uploading a short story, a music file, or a video onto the blockchain is cost-prohibitive:
Another bottleneck in storing large amounts of data is the current Block Gas Limit of approximately 4700000 gas/block. At this cap of gas per block, it would take over 132 blocks to write 1 MB of data to the blockchain, and that is assuming you can manage to hog all of the gas per block and that there are no other operations required!
| Processing | ||||||||
|---|---|---|---|---|---|---|---|---|
| Row Number * Task | Gas required | Cost (ETH) | Cost (USD) | Ops per ETH | Ops per USD | Ops per Block | Blocks to complete OP | |
| 1 | Add or subtract two integers | 3 | 0.000000009 | 0.000002655 | 11111111.11 | 37664.78343 | 1566666.667 | 0.0000006382978230 |
| 2 | Add two Integers, 1 Million times | 3000000 | 0.09 | 26.550000000 | 11.1111111 | 0.037664783 | 1.566666667 | 0.638297872 |
| Storage | ||||||||
| Task | Gas required | Cost (ETH) | Cost (USD) | Ops per ETH | Ops per USD | Ops per Block | Blocks to complete OP | |
| 3 | Save a 256-bit word to Storage | 20000 | 0.0006 | 0.171 | 1666.666667 | 5.649711751 | 243 | 0.004255319 |
| 4 | Save 1MB to Storage (31250 256-bit words) | 625000000 | 18.75 | 5531.25 | 0.053333333 | 0.000180791 | 0.00752 | 132.9787234 |
| 5 | Save 1GB to Storage (31250 256-bit words) | 6250000000000 | 18750.00 | 5531250 | 0.00005333333 | 0.00000018079 | 0.00000752 | 132978.7234 |
| Note: The data mentioned above are only true for a public Ethereum blockchain. The data could be totally different for private or permissioned blockchains. | ||||||||