1

For example:

1.Contract A makes a call to contract B to retrieve a state value from B

2.Contract A then uses the data provided by contract B to create modified value

3.Contract A sends the derived value back to contract B as an updated state

Is it possible for another contract C to call into contract B between step 1 and step 3, potentially changing the state without the knowledge of contract A, while B is effectively idle in between the end of step 1 and the beginning od step 3?

If this is not possible, why not? What provides this security?

If this is possible, I would assume that a Mutex of some kind could be used by A to lock the state of B until step 3 was complete. Is this the best practice for this situation?

1 Answer 1

1

If steps 1 to 3 are performed in a single transaction it is impossible for an unrelated C contract to interfere between A and B.

Ethereum guarantees that a transaction will be completed (all storage modifications saved to the Ethereum World State) before another transaction is performed.

5
  • No, the EVM doesn't have any mechanism to prevent calls. The only guarantee is that a function will execute in full or it will revert. For example reentrancy is possible: A call B, then B calls A. During A execution it transfers control to B, then B can do anything it is allowed to do (for example call A again). It is up to A to be in a consistent state when it calls B. The EVM is pretty simple for security reasons.
    – Ismael
    Apr 27, 2020 at 16:50
  • To clarify, then, from the perspective of a single transaction, the entire ethereum world state is frozen(except to modifications by the contract itself) until that transaction completes or reverts, even if it involves multiple calls into an external contract(s)? Or is the world state only consistent within functions or contracts, so that a call into an external contract brings with it the risk of a new world state? Apr 27, 2020 at 17:32
  • The world state is updated with each instruction executed by the EVM, but it will revert to the original state in case of an error or if the contract explicitly calls revert. It is up to each contract to define what is considered consistent
    – Ismael
    Apr 27, 2020 at 18:07
  • What I am understanding is that the world state is potentially modified by each EVM instruction, but each transaction is executed within a world state that is not modifiable by other transactions, until after the transaction is completed or reverted, including the completion of all internal and external function calls initiated by the transaction. I am taking transaction to mean a function call initiated by an ethereum wallet; within a single transaction, the world state will not be externally modified by any process not initiated as a result of the transaction itself. Apr 27, 2020 at 18:28
  • Yes, you are correct
    – Ismael
    Apr 27, 2020 at 22:34

Your Answer

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

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