When we try to run a smart contract using tezos-client, it estimates the gas cost and predicts the final output of the contract.

It simulates the contract execution under the current block-chain, input parameters including the argument, transfer amount and the counter of the caller's account, therefore it seems to me that the simulation is quite accurate for simple contract calls.

But since it calls itself a simulation, it may fail to predict the outcome. In which situation the simulator fails to predict the execution of a transfer?

1 Answer 1


Whenever you inject an operation, you have some fundamental uncertainty. The state (the "context") you see now may change before your operation is applied, due to other operations or blocks.

The context includes accounts, balances, delegates, contract scripts and storage, and other things. It affects the behavior of all operations in many ways. If the simulation is based on a different context than the actual context in the end, the simulation can be wrong.

To reason about the possible effect of an operation, you should rely on invariants upheld by the protocol or by contract scripts, not on the current context or simulation.

In particular, remember that even an operation forged in response to another can happen first. It is easy for an adversary to observe an operation in the mempool and then put their own operation in before it. Of course, the simulation cannot predict this.

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.