I have a few problems understanding the step of execution of transaction in smart contract.

1-When a user send a transaction to smart contract, this smart contract is not executed immediately instead is it pooled in a transaction pool.

2- At some point of time, every EVM is chosen an transaction to execute the code in smart contract line by line.

3-If all EVMS find the same result, what happens after? Else the smart contract cancelled this transaction.

what happens after? ==> 4- the miner would collect all transactions from transaction pool, and adds them to the newly created block and then the mining process starts between miners.( correct me if I'm wrong please in the steps)

5-finally, the blockchain is transitioned into a new state.

*How does the miner verify that these transactions are well executed by EVM?

*Does EVM play the role only in the first part of the execution of smart contract?

*Who will change state when the contract is executed? ( transaction ?)

1 Answer 1


You've misunderstood the steps. But close!

Consensus is easily misunderstood.

The fundamental problem first solved by Bitcoin was how to reach eventual consensus among nodes that do not know or necessarily trust each other. Add money to the environment and it becomes an adversarial environment. This is in no way like the situation in a typical cluster of computers that do know each other and do trust each other.

We get a hint about how to solve it from transaction logs employed by databases. If one has a replayable log with all the inputs in the right order, then one can reconstruct a database. It's not important to have "the state" if you have the inputs that created that state.

There is a non-obvious challenge to deal with. Given physics, it is not possible for all nodes to learn about all transactions at the same time or even in the same order. It will (probably) never be possible to make everything as fast or faster than everything else.

In a trustful environment, that could be resolved with accurate, trustworthy timestamps that would help everyone enumerate the "correct" transaction order. In an adversarial environment with no authority, that doesn't work because no one's clock is considered more trustworthy than anyone else's.

So, how to order the transactions?

The mining process collapses that ambiguity. The "winning" miner earns the privilege of setting a de facto network transaction order, for one block. Importantly, this is not even an attempt to resolve the temporal order of transactions. In fact, gasPrice, is a way to queue jump. One can probably incentivize a miner to include a transaction sooner by attaching a high bid. Conversely, one can save on transaction fees by being patient.

Nothing happens anywhere until nodes receive news of transactions included in blocks. Transactions in blocks are well-ordered. The blocks themselves are well-ordered. So, the chain of blocks is a well-ordered set of all transactions that have happened.

Each full node, not just the miners, processes transactions completely, reaching their own conclusions about state changes. This is very much like replaying a transaction log because everyone agrees on the inputs and the order of those inputs. The functions are deterministic (strict requirement) so there can be no disagreement between well-functioning nodes at the same block height.

Blocks have time-stamps but transactions don't. Block time is the minimal resolution, and all that can be said is that all transactions in a block were mined at that block time, in the order of inclusion. Each transaction executed in the context left by the previous transaction.

Miners have non-trivial privilege. Working together they can censor transactions. They can play with timestamps and transaction order, if there is selfish benefit doing so. This can be important in contract design when factors such as "deadline" exist.

In any case, the consensus resolves transaction order. Nodes figure out the state for themselves.

Hope it helps.

p.s. There is a lot more going on in mining but I wanted to focus on your question.

  • Can you please explain this sentence: Each full node, not just the miners, processes transactions completely. how processes transactions ?? But from what I read and in this link: [link](ethereum.stackexchange.com/questions/16990/… ) The smart contract is executed within the EVM, . The results of the execution should be exactly the same to add the transactions to the blockchain. I need a help to better understand Sir.
    – amira
    Commented May 15, 2019 at 9:18
  • Also says, Each node of the network, not only miners execute the smart contracts. The EVM is in every node, and the nodes form a swarm. This might help bring it into view: bitrates.com/guides/ethereum/… Commented May 15, 2019 at 11:21
  • To correct what I said at the beginning and from what I understood,when a miner receives transaction, it runs transaction on EVM and includes result of transaction in block to mine. Then, block eventually mined and added to Blockchain (if miner happens to successfly mine this block). Finaly, everyone copies the new block and verifies it by running EVM ( the transaction that go to the network they are run lots of times by everyone run it in EVMs to verify the transaction. I got the same output to check evrey think is okay) correct me if I'm wrong please
    – amira
    Commented May 15, 2019 at 14:10
  • 1
    It's almost right but I think there is confusion. Pardon me if I'm mistaken. This: and includes result of transaction in block to mine - completely misstated. It does not "include the result". It includes the transaction ... more specifically, it includes the inputs (from Alice, to Bob, amount, data ... signature) - not the result. This is not in a block "to mine". The miner's job is "to mine". The miner includes the transaction inputs in a transaction that "was mined." Yes, the miner runs the transaction. That's because all nodes run the transaction and "all nodes" includes the miner. Commented May 15, 2019 at 14:17
  • The transaction was included in a block, the block was transmitted to everyone. Everyone runs the transaction, including the miner. The miner was the first to know the transaction was included in a block, so it was the first the run it. No one cares what the miner thinks the transaction does. They will run it themselves to find out. Commented May 15, 2019 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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