[Ethereum] Differences/similarities of “Bitcoin script” and “Ethereum smart contract”

bitcointerminology

Can we compare Bitcoin script and Ethereum smart contract ?

And if yes,

What are differences/similarities of Bitcoin script and Ethereum smart contract in sense of functionality, architecture and how to interact with blockchain?

Does Bitcoin script run on-chain (similar to Ethereum smart contracts) or they run off-chain?

Best Answer

There are a couple of differences between Bitcoin scripts and Ethereum smart contracts.

USE

BITCOIN

In bitcoin the transaction have a different format from Ethereum:

A transaction typically references previous transaction outputs as new transaction inputs and dedicates all input Bitcoin values to new outputs.

So a transaction is formed by one or more transaction input (i.e., the output of previous transactions) and one or more transaction output.

The transaction outputs specify a locking script (e.g. "only the user with the private key corresponding to address 1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2 can unlock this script") that defines the condition to spend the output. Whenever the transaction output is used as input in a new transaction, it must contain an unlocking script that "solves" the locking script. Those script are specified with the bitcoin script.

So, the scripts are used in Bitcoin to validate the transaction, therefore they should be run on chain, i.e. by each full node in the network.

ETHEREUM

The transactions do not reference previous transactions, because Ethereum stores directly the world-state (In bitcoin the state corresponds to the list of unspent transaction outputs (UTXO)).

In Ethreum a transaction may trigger the execution of a smart-contract if the receiver of the message call is a contract account or it may create a contract that persists on the world state.

In Ethereum the smart-contracts can be used to write applications on top of Ethereum.

Similarity/Differences

Both the execution environments of Ethereum smart contracts and Bitcoin scripts are stack-based and deterministic.

The main difference between bitcoin scripts and Ethereum smart contracts is the Turing completeness: bitcoin scripts do not have loops and neither recursion and have a language that is less expressive than a DFA (Deterministic Finite Automaton), as reported here, while the Ethereum Virtual Machine (EVM) is Turing complete (if we associate a gas limits equals to infinite).

Another major difference is the fact that the Bitcoin Script does not have a notion of state (as reported here) and all the information needed is contained in the locking and unlocking scripts. Whereas Ethereum smart contracts have contract storage that can influence the behavior of the program.

Moreover, bitcoin programs are part of the respective transactions, so, when with pruning some transactions are forgotten, also the corresponding scripts are forgotten. In Ethereum the smart contract code are persistent on the state and can be canceled only if the SELFDESTRUCT opcode is explicitly called during the execution of the smart contract.

Related Topic