Can smart contracts handle two function calls simultaneously?

I was wondering whether smart contracts can handle two function calls at the same time or one of them has to execute first before the second.

Solidity is a deterministic language, meaning it only runs one function at a time and at a deterministic order.

1 Like

Okay. I got it, thanks Koray :slight_smile:

I disagree with @Koray_Kaya. This is not so much about Solidity as a language but about the EVM as a runtime. Indeed, the EVM does not allow parallel execution, but this can be deceiving. Concurrent execution is still possible through reentrancy, and it's no less deterministic.

If contact A is executing foo and it makes a call to contract B, B can now call A again and execute function bar. In a sense, at that point, both foo and bar are executing concurrently.

This is actually a very important thing to understand, because it's how reentrancy attacks become possible.

Isn't that the same as saying if a function call is made inside of a function, both functions are running concurrently? Indeed two functions are being ran, but in no way are they running at the same time. Never would for example a race condition occur.

E.g. foo in contract A executes bar. How is this different from your example?

Race conditions can't occur.