Smart Contracts —Can we just get straight to the point?

How much is that Solidity thing Turing-complete? Where to these “Smart Contracts” live?I think we can say that current Smart Contracts are as smart as the British Bombe, the machine developed by Alan Turing that exploited the Enigma machine’s lack of r…


This content originally appeared on Level Up Coding - Medium and was authored by Henrique Centieiro

How much is that Solidity thing Turing-complete? Where to these “Smart Contracts” live?

I think we can say that current Smart Contracts are as smart as the British Bombe, the machine developed by Alan Turing that exploited the Enigma machine’s lack of randomness in 1939.

Being “Turing-complete”

In Ethereum, smart contracts are written in a programming language called Solidity and these programs are run in the EVM — Ethereum Virtual Machine. You can see the EVM as a giant Turing-complete, decentralized virtual machine that is distributed across all the Ethereum nodes, all around the world (currently around 8500 if I’m not wrong).

Some blockchains like Ethereum or Hyperledger Fabric (public or private blockchains) use Turing complete programming languages meaning that developers use them to create smart contracts that can do pretty much anything, from simple to more complex functions. Turing complete means that it is computationally universal, being able to perform any real-world general-purpose function.

For example, the Ethereum Virtual Machine is a Turing complete decentralized virtual machine, meaning that it can replicate any possible computing logic or function. This computing logic in Ethereum is made via smart contracts, and they can be written in the Solidity programming language (although they can be written in other languages too as we will see below).

A smart contract is a piece of a computer program that can execute a contractual agreement between two parties. Smart contracts can pretty much execute any contractual condition or functions. They are Turing-complete, meaning that they use programming languages with conditional statements and conditional branching. These are the programming languages that have “if, then, else” and they can replicate any computer logic.

Let’s go back to Smart Contracts

Smart contracts are autonomously executed, meaning that there’s no need for third-party intervention to execute once deployed, and their execution cannot be stopped. Smart contracts can self-enforced the rules they were written/coded in the smart contract. For example, you can program a smart contract to work as an escrow and settlement service, where the smart contract can receive funds from Alice and release the funds to Bob once Bob sends asset D to Alize. In a smart contract, code is the law. You can also program a smart contract to lock $1000 worth of cryptocurrency and only unlock it in the year 2030. Once this contract is deployed, there’s nothing you can do to change it and the money will be locked in this vault until 2030 no matter what. Anything that you program in a smart contract will later self-execute.

Smart contracts are deployed in a blockchain such as Ethereum where they are executed in the EVM — Ethereum Virtual Machine. Many other blockchains, including private blockchains, feature smart contracts.

Illustration of a section of an escrow smart contract in the blockchain
Wow such smart! Illustration of a section of an escrow smart contract in the blockchain

Some of the characteristics of the smart contracts are:

  • Smart contracts are self-executed
  • Smart contracts are turing-complete
  • Parties remain pseudonymous
  • Smart contracts are transparent and fully auditable
  • Smart contracts are immutable

Side note: Turing completeness is more an idealization. In reality, computers and virtual machines are limited by finite memory and computing capacity. Additionally, smart contracts in the blockchain require fees to be executed. Smart contracts are thus limited and consequently not totally Turing-complete. To run a simple ERC-20 (fungible tokens) or ERC-721 (NFT) smart contract, it may cost the equivalent to 100 USD in Gas fees just for a couple of hundred lines of code so… yeah, to run a really complex smart contract and prove it to be fully Turing-complete, you would need to blow up A LOT of money! Oh and that’s why DeFi is also pouring so much money into it!

Smart contract languages. Decisions, decisions….

When choosing the protocol and the programming language to write a smart contract, we also need to consider the expressiveness and complexity of it. There is an efficient frontier, and trade-offs need to be considered between the smart contract’s expressiveness and complexity. The amount of computing power required to execute it, and the fees that one’s willing to pay to execute the smart contract (more functions equals more fees).

The Nobel Laureate Harry Markowitz introduced the Efficient Frontier theory in 1952, and it’s widely used in modern portfolio theory to efficiently create optimal investment portfolios. The efficient frontier shows the highest expected return for a defined level of risk. I think it’s pretty cool if we apply it to the Turing-completeness of blockchains.

Different blockchains and programming languages present different return/complexity levels and correlate with certain risk and contract expressiveness levels. More loose programming languages may allow for more complexity. Still, they may be less easy to reason about, developers make more mistakes, are prone to more bugs, and the blockchain capacity also limits them in terms of computing power, throughput, and fees that are feasible to pay.

In Ethereum, developers can use a programming language called Solidity or Kotlin and C++. DAML is, however, a more safe way to program smart contracts. These smart contracts can achieve different levels of complexity, considering that Ethereum is Turing-complete.

Although possible, building extremely complex smart contracts is not advised because the execution of more complex smart contracts requires more gas (the fee that is paid in Ether to execute smart contracts). The smart contracts are executed by the Ethereum nodes (any person can have an Ethereum node because it is a permissionless network), and these nodes run EVM Ethereum Virtual Machine. The users’ gas fees reward the nodes for transaction execution and executing functions in the smart contracts.

Each Ethereum smart contract has an address used to interact with it, including interacting with other smart contracts, which expands the automation capabilities.

Smart contracts allow for the first time in the history of IT the creation of dApps that offer come new advantages:

  • Enhanced security: improved dApps security with the public key cryptography and the blockchain consensus mechanism, which ensures the correct execution of smart contracts
  • Autonomy: dApps are developed on the top of smart contracts (the app logic), and these smart contracts run in a decentralized way in the blockchain. dApps can run automatically and autonomously without the need for third-party intervention
  • Traceable: transactions or any events of the dApp are traceable considering that the information (related to the smart contracts) is stored in the blockchain (note that a dApp may also have off-chain information)
  • Stability: because smart contracts are distributed across many nodes in the blockchain with redundancy, the dApps will continue to run smoothly even if some nodes fail.

Other permissionless blockchains allow smart contract creation and execution. Other than Ethereum, blockchains like Cardano, Tron, Lisk, Stellar, Monax, RSK and Counterparty also allow smart contract scripting and can be a decent alternative to Ethereum. Some of these blockchains use the same programming languages used by Ethereum since their creation was inspired by it. Oh, and don’t forget private/permissioned blockchains. The Hyperledger blockchains, Corda, and others also allow smart contracts.

Wow, we have covered a lot! Feeling smart? ??

? Follow me and also check my ? blockchain book and course:

? Unblockchain Book — Kindle and Paperback

?‍? Unblockchain Course

? The Non-Fungible Booklet: The History and Technologies Behind NFT and how they are changing the art world

?‍? The Complete NFT Course — Learn Everything About NFTs


Smart Contracts —Can we just get straight to the point? was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Henrique Centieiro


Print Share Comment Cite Upload Translate
APA
Henrique Centieiro | Sciencx (2022-10-06T02:44:02+00:00) » Smart Contracts —Can we just get straight to the point?. Retrieved from https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/.
MLA
" » Smart Contracts —Can we just get straight to the point?." Henrique Centieiro | Sciencx - Friday April 30, 2021, https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/
HARVARD
Henrique Centieiro | Sciencx Friday April 30, 2021 » Smart Contracts —Can we just get straight to the point?., viewed 2022-10-06T02:44:02+00:00,<https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/>
VANCOUVER
Henrique Centieiro | Sciencx - » Smart Contracts —Can we just get straight to the point?. [Internet]. [Accessed 2022-10-06T02:44:02+00:00]. Available from: https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/
CHICAGO
" » Smart Contracts —Can we just get straight to the point?." Henrique Centieiro | Sciencx - Accessed 2022-10-06T02:44:02+00:00. https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/
IEEE
" » Smart Contracts —Can we just get straight to the point?." Henrique Centieiro | Sciencx [Online]. Available: https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/. [Accessed: 2022-10-06T02:44:02+00:00]
rf:citation
» Smart Contracts —Can we just get straight to the point? | Henrique Centieiro | Sciencx | https://www.scien.cx/2021/04/30/smart-contracts-can-we-just-get-straight-to-the-point/ | 2022-10-06T02:44:02+00:00
https://github.com/addpipe/simple-recorderjs-demo