Accelerating Smart Contracts
Glossary
Term DefinitionsBlockchainA publicly visible, immutable, distributed ledger that records the history of cryptocurrency transactions. Smart ContractsPrograms stored on the blockchain that are automatically executed when preset conditions are met.MinersA node that verifies transactions and adds them to the blockchain, earning cryptocurrency rewards.ValidatorsA node that verifies the integrity of blockchain data and the validity of transactions.Software Transactional Memory (STM)A concurrency control mechanism that allows programs to access shared memory in a transactional manner.Atomic OperationsAn indivisible operation that either all succeeds or all rolls back.Speculative ExecutionExecutes instructions ahead of time when the results are unknown to improve efficiency.ConflictsOccur when multiple threads attempt to access shared data in incompatible ways.RollbackReverses the effects of executed operations and restores to a previous state.Fork-joinA parallel programming model that recursively decomposes a task into subtasks until they can be executed in parallel, and then merges the results.SolidityA programming language for writing smart contracts.Ethereum Virtual Machine (EVM)A virtual machine that executes Ethereum smart contracts.Abstract LocksA synchronization mechanism used to control access to shared resources.Reverse LogsThe inverse of executed operations for rollback. Lock profiles record information about threads acquiring and releasing locks, which is used to determine the order of execution.
Short answer questions
Explain what smart contracts are and their role in cryptocurrency systems.
Smart contracts are self-executing contracts stored on the blockchain. They are used in cryptocurrency systems to implement complex financial transactions and other decentralized applications.
Why does the traditional smart contract execution model limit system throughput?
The traditional smart contract execution model is serial, and miners and validators must execute contracts one by one, which cannot take advantage of the parallel processing capabilities of modern multi-core and cluster architectures.
What is software transactional memory (STM)? How is it used to improve the efficiency of smart contract execution?
STM is a concurrency control mechanism that allows programs to access shared memory in a transactional manner. In smart contracts, STM allows miners to treat contract calls as speculative atomic operations and detect and resolve conflicts at runtime, thereby achieving parallel execution.
Explain how miners use speculative execution to parallelize smart contract execution.
Miners use STM to treat contract calls as speculative atomic operations. They run multiple contracts in parallel and detect data conflicts at runtime. If a conflict occurs, one of the contracts is delayed or rolled back until a serializable execution order is found.
Why does the validator need to be able to reproduce the miner's parallel execution in a deterministic manner?
In order to verify the honesty of the miner, the validator needs to reproduce the same (or equivalent) contract execution order. If the validator cannot reproduce the parallel execution in a deterministic manner, it may cause verification failure.
How can the miner enable the validator to reproduce its parallel execution deterministically?
Miners achieve deterministic reproduction by recording lock profiles. The lock profile records the information of each thread acquiring and releasing abstract locks, and the validator can use this information to build a fork-join program to replay the contract execution in the same order.
What mechanism does the validator use to ensure that the parallel execution schedule provided by the miner is correct?
The validator uses an abstract lock trace to record the abstract locks acquired by each thread during execution. After the execution ends, the validator compares the trace it has generated with the lock profile provided by the miner. If the two do not match, the block is rejected.
What motivations do miners have for publishing highly parallel schedules?
Miners can get more rewards, such as higher block rewards or lower transaction fees, by publishing highly parallelized schedules.
How to ensure that concurrently executed smart contracts do not cause data inconsistency?
By using STM and abstract lock mechanisms, it is possible to ensure that all concurrent executions are serializable. This means that the results of concurrent executions are the same as those of serial executions in a specific order, thus ensuring data consistency.
Describe the basic architecture of a system that uses STM and fork-join mechanisms to implement concurrent execution of smart contracts.
The system includes miners and validator nodes. Miners use STM to execute smart contracts in parallel and generate locking profiles. The validator uses the locking profile to build a fork-join program to deterministically reproduce the parallel execution and verify the correctness of the results.