If I understand Ethereum correctly, the result of a transaction is known and verified by everyone because everyone runs the code using their own copy of the blockchain. If that is indeed the case, why is it that only the miner of a block gets the gas for the transactions in that block? I would understand if it was because of the resources they used to complete the proof of work, but if that were the case then the amount of gas would not depend on the VM instructions executed. I also have heard that the main purpose of gas is not so much to reward the miner as it is to provide mitigation and/or a disincentive to infinite loops and whatnot. In this case, I can see two scenarios:

  1. The cost of the gas far outweighs the resources needed to execute the code, i.e. it is only there as a protection from denial of service attacks, etc.
  2. The cost of gas is in fact proportional to the cost of running the code, and thus is also there to provide an incentive to the miner to run it.

If scenario 1 is accurate, wouldn't miners prioritize more CPU-intensive contracts in order to get the most gas, as opposed to prioritizing contracts with the highest cost per unit of gas?

If scenario 2 is accurate, what is the incentive for non-miners to run the code?

There are multiple questions in this, I'll try to address all your concerns...

  1. The cpu-power needed to run the smart contracts should in most cases be tiny compared to the cpu-power needed to generate a new block hash. Thats what the miner gets "paid" for, finding a new block hash, not executing the smart contracts.
  2. Yes, all operations and all data will be shared by all nodes, thats why its important to keep them small, thats the reason for transaction fees. Afterall, every byte in the blockchain is replicated on thousands of nodes.
  3. Transaction fees are also an incentive for a miner to actually include your transaction. If a miner would get nothing out of it, why would he ever go through the trouble of including your transaction(and executing the smart contract, of course) if he would get just the same amount without it? (so basically both of your scenarios are correct)
  4. It is in your own interest to validate the block even if you are not a miner. Only this way, you can ensure that you actually have a valid copy of the chain. The CPU-power needed for this is negligible.

I am not a miner though... Maybe a miner has more insights on the economics of mining than I do.

  • I wouldn't call the CPU power for verifying relatively negligible, since mining has GPU-based since basically the beginning. From an absolute perspective, my own geth node is currently going between 0.2 Mg/s to 1 Mg/s while syncing. Good answer, otherwise. – Matthew Schmidt Mar 17 '17 at 18:32
  • Update: A more correct estimate is 1-3 Mg/s. It appeared to take some time to get to full speed. – Matthew Schmidt Mar 17 '17 at 18:39

Gas is used so contracts don't run forever. It initiates all the code and based on the density it will have a certain gas price.

Mining a block first carries the highest bounty. Mining the block later also carries a bounty( generating uncles) although this bounty diminishes very rapidly after a block is mined first time. Uncles make the chain heavy and resistant to attack and hence generation of uncles is incentivised to s certain extent. Contract execution is just one of the way transactions in a block are added. Other transactions, such as transfering ether also constitute a typical block. Contract execution is not only limited by gas, but also by a block gas limit set by miners. Any contract which is so large that it exceeds the block gas limit would be rejected. In that sense, gas in a contract execution is a way to keep the contract code in check and limit DOS attacks.

Theoretically, the cost for a transaction should increase as the number of mining nodes increase, as each node executes it for the same cost, but only one can include it. That is, if it takes one finney's worth of computational resources to verify a transaction, and there are ten equally powerful miners, transactions should logically cost (1 finney * 10), since each miner has only a one-in-ten chance of collecting the reward.

This is the argument of the original White Paper, whereupon it points out that this deviates from reality immediately. (See: non-mining nodes, as you mention.)

In practice, years after the White Paper was written, I have not heard of any miner using this game-theoretic strategy. Usually, it amounts to every choosing the default gas price of 20 Gwei.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.