visit
Since about a week, I have been reading about Turing machine and slowly extending the concept to the world of blockchain. Primarily, the Ethereum blockchain. After gaining enough insights into the subject, I decided to give voice to my thoughts.
Let me delineate the scope of this article so that you know what you’re in for.
I’ll start off by giving a gentle introduction to the Turing machine followed by a discussion on the Church-Turing thesis. I’ll touch the Chomsky hierarchy. (Just a bit) I’ll discuss the fundamentals of an I/O Turing Machine by taking an example, accompanied with some basic mathematics. After this, we will see how the Ethereum blockchain is not completely Turing complete and why it is rudimentary in the present-day. We will see what implications Turing completeness can have on the Ethereum blockchain with respect to the concept of Ethereum gas. We will go over the fundamentals of the Vyper language. We will then see in what scenarios a true Turing machine can transform smart contracts (this section contains futuristic talk).I’ll try to keep my language as simple as possible, for obvious reasons.
This article is best enjoyed with a cup of strong filter coffee. If you don’t know what is filter coffee then you are missing out on life, my friend.
The Turing machine is a theoretical, abstract idea which can simulate any algorithm that can be logically constructed. This means that a Turing machine can solve any problem if it can be coded out. There’s special emphasis on the word any. It certainly doesn’t guarantee how much time it will take to solve the problem, but it is certain that it will solve the problem. So it can take a second, a minute, a lifetime, or an entire generation to solve a problem.
But don’t you worry, your problem will be solved sooner or later!
Everything that is to be deleted from the tape and everything that is to be added to the tape is governed by user-described instructions. When a Turing machine starts, anything written on the tape is the input. When the Turing machine halts after completion of the problem, anything written on the tape is the output. To compute the solution for a given problem, the Turing machine may read and write on the tape for infinite amount of time. There is no boundary on any resource like time, memory whatsoever. Each cell has an associated state with it which is governed by user-described instructions. The state of the cell changes when an event occurs. When state changes, the value on the cell may be rewritten. The mappings on the Turing machine are as follows:
Where,
𝛿 is a function.
q is the current state
a is the value on the cell
P is the new state
A is the new value on the cell
R means that the head will move right
L would mean that the head would move left
In , the halting problem is the problem of determining, from a description of an arbitrary and an input, whether the program will finish running (i.e., halt) or continue to run forever. Source: Wikipedia.
Problem statement: Check if the number of 1s in the string is even or odd.
Let’s take an infinitely long tape with a random string on it. Let the string be0 1 0 1 1 0. The other cells are blank.
The Turing machine should print ‘o’ if the number of 1s is odd and should print ‘e’ if the number of 1s is even. The rules governing machine behavior are as follows:
The initial state of the machine is q0. Since the head is on the start of the string, the mapping would be as follows:
The Turing machine will look like this now:
This is because the data on the first cell was 0. The state will change only when the machine head will encounter 1.
Next mapping:The Turing machine will look like this now:
Next mapping:
The Turing machine will look like this now:
Next mapping:
The Turing machine will look like this now:
Next mapping:
The Turing machine will look like this now:
Next mapping:
The Turing machine will look like this now:
Next mapping:
H is the halting state. This means the machine has stopped since it encountered a blank. The head won’t move left or right so there is a — . The Turing machine will look like this now:
Since the machine halted at q1 state, there are odd number of 1s. If the machine halted at q0 state, there would be even number of 1s. Note that ‘o’ is printed on the first encountered blank. This is how a Turing machine is an I/O device. I hope this gave you a gist of what a Turing machine really is. In the next section, we will explore the consequences of Turing machine with respect to the Ethereum blockchain.
Let’s see how the Ethereum blockchain is NOT actually Turing complete.
For those who don’t know the concept of Gas in Ethereum. This will be used a lot in the article. Here’s a basic definition:
Gas is the unit of measurement used to measure cost of running an operation on the Ethereum blockchain. The concept of gas exists to separate computational cost of running an operation (opcode) from market value of Ethereum (which is currently highly volatile).
Each block on the Ethereum blockchain has Block gas limit. This is the maximum amount of gas that can be spent.
On 14th Feb 2019, 3:10 PM, the gas limit was 8000029 gas and the gas price was 5.1 gwei. This information can be easily found at . It’s a really cool site.Such limits are imposed to protect the blockchain from DDoS attacks.
If you want to translate gas spent per unit time, you can check out for the conversion. So effectively, there are 2 limits imposed on any I/O on the Ethereum blockchain. These are gas cost and block gas limit. And, we know that a true Turing machine works with unlimited resources and the concept of Gas prevents the Ethereum blockchain to be truly Turing complete.Don’t get me wrong, the language Solidity is Turing complete but the “world-computer” EVM is not.
The language Vyper is NOT Turing complete, Solidity is. At the same time, a program written in Vyper will always have a predictable output. A program written in Solidity will not have a predictable output until and unless it is deployed and executed. In Vyper, simplicity and readability of the language by a lay-man is more important than freedom and flexibility of Turing complete languages.A fun fact, in Python 0.3 + 0.3 + 0,3 + 0.1 is NOT equal to 1.
Will deliberately forbid things or make things harder if it deems fit to do so for the goal of increasing security.Don’t get me wrong. Vyper was NOT created to replace Solidity. It was created to boost security. A recent study found more than 3000 vulnerable contracts contain security flaws.
Since we are talking about blockchain, let’s take a while to remember the Bitcoin blockchain. The Bitcoin scripting language is NOT Turing complete. The script only performs one function: transfer funds from one account to another. So there is no need for Turing completeness. So the behavior space of bitcoin script is predictable, as opposed to Solidity.
I’d like to take this final opportunity to re-emphasise on the future of smart contracts. Some of us might call autonomous machines interacting with each other ‘too fancy’. But I kid you not, probably by the time you are a grandparent, you’d be surprised to see that this, in fact, will become a reality. Do you want to be one of those old people who don’t understand technology anymore? I am guessing the answer here is no. So, don’t tag such ideas as ‘fancy’ and start contributing to these futuristic thoughts! Who cares if we sound crazy? If crazy people love to ideate, call me crazy! That’s enough of me ranting there, lol. In the next article, I’d probably show you how to write smart contracts in Vyper language.