Home » News » Bitcoin as Turing complete system for building smart contracts & tokens

Bitcoin News

Bitcoin as Turing complete system for building smart contracts & tokens

Deggen’s presentation at WeAreDevelopers World Congress in Berlin lay a technical foundation for understanding Bitcoin SV as Turing complete – and thus suitable for building smart contracts.

A common misconception about Bitcoin is that it is not a suitable blockchain to build applications on it. The misunderstanding is largely due to the fact that this is true for the Bitcoin implementations BTC and BCH. However, when it comes to the original Bitcoin protocol as it was published by the inventor of Bitcoin, Bitcoin is ideal for building smart contracts, issue tokens and hosting dapps.

Today, Bitcoin SV is the only protocol that has followed this original implementation. While the first stage session during the WeAreDevelopers (WAD) World Congress in Berlin showed how Bitcoin SV’s scalability and infrastructural design make it a widely useful blockchain, the question of whether it is suitable for smart contracts remained open. 

In a presentation later at the WAD event, Darren Kellenschwiler, Co-Founder & CTO of Elas and Developers Community Manager at Bitcoin Association substantiated the idea, put forth by several developers, that Bitcoin is a Turing complete System. 

Bitcoin as a Turing complete system

Darren Kellenschwiler tackled the issue from a theoretical standpoint. In the view of most people that work with blockchain, Bitcoin is a protocol that is only suited for simple payment transactions, whereas Ethereum is regarded as the blockchain for smart contracts.

He describes how this is a misconception ever since the release of the Bitcoin protocol, which has led to creation of altcoins and forks. As a consequence, ‘a misallocation of money took place on a grand scale.’ This could have been prevented if Bitcoin would have been regarded as a Turing complete system from the get-go.

With reference to Ray X. Charles, the Founder of Money Button and Co-Founder and CEO of Heartmail, Kellenschwiler pointed out that Bitcoin is Turing complete in three ways:

  • Unrolling Loops in Script
  • Payment Channels
  • Emulating an Unbounded Tape

Kellenschwiler continued to explain these three different aspects in more detail.

Unrolling loops on Bitcoin

In order to explain how Bitcoin is Turing complete, Kellenschwiler started off with explaining what the Bitcoin Script is and its constituents; As a predicate system, it uses UTXOs rather than accounts. It locks coins in a function, which you unlock with a certain variable. In the standard case, this locking and unlocking would take place with a signature and a private key, although you can write arbitrarily complex scripts instead.

As Bitcoin Script is a low-level language you can write scripts that would emulate what high-level languages like JavaScript do. Thus, you can write unrolling loops that JavaScript automatically facilitates. As the microprocessor reads the functions one by one, you simply have to repeat yourself when writing these scripts and you end up with unrolling loops – one way in which Bitcoin is Turing complete.

Bitcoin payment channels

There are recursive functions in JavaScript. What you do with them is that you hash the value several times until you reach a known value.  

Recursive Function

Argument
x = ’01’

Function
const t = ‘9c12cfdc04c74584d787ac3d23772132c10524bc7ab28dec4219b8fc5b425170’
function f(x) { 
const h sha256 (x) 
if (h === t) return true
return f(h)
}

In Bitcoin Script you can implement this recursive function in payments channels, where you have locking and unlocking scripts. 

Unlocking Script
OP_1

Locking Script
OP_SHA256 OP_DUP 9c12cfdc04c74584d787ac3d23772132c18524bc7ab28dec4219b8fc5b425170
OP_EQUAL
OP_IF
OP_DROP OP_TRUE
OP_ENDIF
OP_RETURN

Return
V4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a

If you start with 1, the locking script returns the value (here: V4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a) instead of coming back as true.

If you put this back into the input, you get no return value. Instead, the script will validate it as being true. This is another way to loop Bitcoin. 

Unlocking Script
4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a

Locking Script
OP_SHA256 OP_DUP 9c12cfdc04c74584d787ac3d23772132c18524bc7ab28dec4219b8fc5b425170
OP_EQUAL
OP_IF
OP_DROP OP_TRUE
OP_ENDIF
OP_RETURN

Return
// nothing so we know that the loop can break

The loop would then be in the node software that runs the script validation.

How Bitcoin emulates an unbounded tape

To understand the concept of emulating an unbounded tape, you can imagine a Turing machine in which a Bitcoin output is like a piece of memory that stores something. In order to change the value in that memory location you spent this UTXO into a new one. This is like a change of state for that memory location.

In Bitcoin SV, this has been done with _unwriter’s tools. Unwriter is/was an anonymous open-source developer on Bitcoin SV. Also, the Run token protocol uses a similar mechanism. Today about 90% of tokens in Bitcoin SV rely on that protocol. It is very similar to JavaScript and it allows you to write high level programming. It allows you to have individual transactions stated on-chain. You can update them with functions and make it arbitrarily complex.

This principle is used today to build very different applications on BSV. From NFT marketplaces, blockchain games and in general to allocate rewards for certain actions.

What makes these applications viable, is the massive scalability and data throughput that Bitcoin SV provides.

Stay tuned for an illustrate of Bitcoin as a Turing complete system

Darren’s presentation offered a theoretical basis for Mihael Šinkec’s later (Software developer at sCrypt) illustration of how you can use Bitcoin to build smart contracts and issue tokens. To get our overview of what went down in Šinkec’s part of the presentation, follow us on Twitter.

23rd Jun 2022
Copy link
Powered by Social Snap