I have a condition in my contract.

require(msg.sender == tempTeam.getConvener());

If I send a transaction to this contract which violates this condition, ethereum wallet immediately notifies me with an alert without even executing the transaction that it is going to fail. How is it doing that? Is there a web3 API that can pre-verify the execution.

enter image description here


I am not sure about this, but may be it uses the same mechanic as the estimateGas function from web3js.

This function runs the transaction on the EVM and check if it worked, if the gas is ok, etc (without mining it of course) and returns you the result, or an error if the transaction is not valid/failed.

So maybe Mist uses the same mechanic.

| improve this answer | |
  • Do you have any link that could support this hunch? It makes sense to me but I would like to check if there is any evidence supporting this – Hitesh Joshi Feb 5 '18 at 19:16

I now understand how a wallet or web3 call can determine if a transaction will succeed or fails. The answer was buried in the Vitalik Buterin's blog post about Merkling in Ethereum.

If you want to query ethereum for - "Pretend to run this transaction on this contract. What would the output be?"

Ethereum uses three different types of Merkle trees-

  1. Transactions
  2. Receipts
  3. State

For responding to the above query , ethereum uses the state tree by constructing a Merkle state transition proof. To Quote Vitalik -

Essentially, it is a proof which make the claim “if you run transaction T on the state with root S, the result will be a state with root S', with log L and output O” (“output” exists as a concept in Ethereum because every transaction is a function call; it is not theoretically necessary).

To compute the proof, the server locally creates a fake block, sets the state to S, and pretends to be a light client while applying the transaction. That is, if the process of applying the transaction requires the client to determine the balance of an account, the light client makes a balance query. If the light client needs to check a particular item in the storage of a particular contract, the light client makes a query for that, and so on. The server “responds” to all of its own queries correctly, but keeps track of all the data that it sends back. The server then sends the client the combined data from all of these requests as a proof. The client then undertakes the exact same procedure, but using the provided proof as its database; if its result is the same as what the server claims, then the client accepts the proof.

So, how does an Ethereum wallet know that your transaction is going to fail? It applies the state transition mechanism your function call either fell short of gas or threw an error or failed a required condition.

| improve this answer | |

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.