8

I have a question regarding smart contract execution.

It is my understanding that when a user requests a smart contract, miners will execute the smart contract, and bundle its output in a block before broadcasting to the network.

But then all other full nodes / miners will have to check the transactions inside the received block, and doing such requires also executing the smart contract to see if the output is the same as the miner's. And so all full nodes end up executing the smart contract requested by the user.

However, only the miner earns the gas associated with the smart contract execution. Does that mean that all nodes that execute the smart contract after the miner to verify its result do not earn any gas?

I understand why in Bitcoin it's not really problematic to only reward the miner because most of the computation goes into solving a proof of work. But verifying a block is "easy" (verify transactions, the pow solution, and a few other things). So it's fair to say that block creation is where most of the calculation is at, not block verification (cost per node; energy consumption of block creation vs verification network wide is another question I guess...)

In Ethereum however, it's not exactly the same thing, because verifying a block may include executing many smart contracts. Which is more costly than just verifying a user<=>user transaction I assume.

Am I missing Something?

Is it worrying for smart contract scalability that all nodes execute the contact?

What are the energy code of adding two integers together via an Ethereum smart contract considering all nodes will execute this addition?

What will convince nodes to become full nodes and verify blocks if it becomes costly for them ? What is the most computationally intensive smart contract one could reasonably have on Ethereum?

I guess I've just realized the implications of everyone node running smart contracts at some point hence my many questions. I would love it if someone could enlighten me a bit on that aspect!

Cheers!

7

However, only the miner earns the gas associated with the smart contract exectution. Does that mean that all nodes that execute the smart contract after the miner to verify its result do not earn any gas?

Correct.

I understand why in Bitcoin it's not really problematic to only reward the miner because most of the computation goes into solving a proof of work. But verifying a bloc is "easy" (verify transactions, the pow solution, and a few other things). So it's fair to say that bloc creation is where most of the calculation is at, not bloc verification (cost per node; energy consumption of bloc creation vs verification network wide is another question I guess...) In Ethereum however, it's not exactly the same thing, because verifying a bloc may include exectuting many smart contracts. Which is more costly than just verifying a user<=>user transaction I assume.

This is also true in Ethereum: Most of the effort in mining is in the proof-of-work, and validation is fairly trivial in comparison. The amount of computation and/or storage permitted in a block is quite small.

This changes a bit if you scale up the system very big - in Bitcoin with a much larger block size, in Ethereum with a much larger gas limit. One proposal to handle this problem in Ethereum is to shard, so that each node only needs to execute a subset of the transactions.

  • But in both bitcoin and ethereum, aren't most of the nodes that got the broadcast also all competing to try to get the POW done? (But only winner (block creator) gets the 12.5BTC or the gas in ETH?) – gunit Feb 22 '18 at 17:44
  • @gubit Well, in practice most nodes on the network aren't mining. There are varying opinions about how important it is to have lot of nodes on the network that are verifying but not mining. – Edmund Edgar Feb 23 '18 at 3:46
4

Great question!

Am I missing Something?

I believe you are missing one important aspect of Ethereum: Contracts contain very little code and their methods require very few instructions to execute (always less than a million and usually less than one thousand).

In Ethereum you pay for each instruction that your transaction executes. In other words: when you execute code on the blockchain you pay for that. You pay in gas and the gas has a price in ether.

The maximum gas limit is 3.14 million gas per block. This means that a block can only contain transactions which cost 3.14m gas to execute. 3.14m gas is at maximum 1.5 million instructions (in a very theoretical, unrealistic scenario) since the cheapest instruction costs 2 gas per instruction. An expensive instruction such as writing to storage is 20000 gas. So a block can only contain instructions that write to storage about 150 times.

Compare this to regular computers which execute several billion instructions per second and you see that this aspect of verifying a block is not very computationally demanding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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