[Ethereum] If everyone runs the same transaction, why does only the miner get gas

economicsgas

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?

Best Answer

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.

Related Topic