Central insight: “… smart contracts need to deal with concurrent execution.” “Accounts using smart contracts in a blockchain are like threads using concurrent objects in shared memory”
- blockchain ~ shared memory
- accessible by many parties
- smart contract ~ concurrent object
- accessing them without good synchronization —> data races + loss of data and data integrity
- account ~ thread
- concurrent objects (smart contracts) invoked by threads (accounts)
Differences between traditional concurrent objects and smart contracts:
- smart contract’s methods are atomic due to transactional model of computation
- sequential execution of instructions after a contract is called no interrupts
- but atomicity is not for free - concurrent behaviour noticeable at blockchain level!
- The order of transactions can change the outcome in a block.
- Contract logic can spread across several blockchain transactions.
- Contracts that call other contracts exhibit cooperative multi-tasking, a yield. The caller might call code that it had not anticipated.
- Contracts can be used as service managing access to shared resource.