Demystifying Bitcoin Script - Bitcoin developers conference
Have you managed to attend Bitcoin SV DevCon? For those who missed out, we are making the most popular presentations available in written format.
The most-watched Bitcoin SV DevCon presentation of 2020 was a practical session where nChain's Steve Shadders walked attendees through the basics of Bitcoin Script and demonstrated a tool to make the language sleeker and more efficient for developers to use. Though this tool is still in the prototype phase, nChain hopes to launch it to the public later in 2021.
As most of this presentation comprises video demos, we have included a time-stamped video index after a summary of the theoretical content from Shadders’s Bitcoin SV DevCon 2020 presentation.
Why was Script the language chosen to embody Bitcoin’s smart contract capabilities ?
‘Script is a language that is analogous to Assembly language. It looks very much like Assembly language, and the bytecode also looks very similar to the bytecode you see in a Java virtual machine and several other machines. This means that it is very compact,’ Shadders says.
Script lets you produce compact code that works very well on small microprocessors as it is a stack-based language , and the way stack-based languages work is similar to how CPUs process operations.
‘It is also very fast because it is not very different from the native Forth , which is frequently included in embedded systems like tiny CPUs and IoT devices, as well as military applications. Due to its simplicity and refined design, Forth is an incredibly resilient programming language.’
The similarity between Bitcoin and embedded systems
Embedded systems are tiny, resource-constrained systems. Although the Bitcoin network is designed to be run by miners in massive data centres with plenty of resources , we can draw some analogies between these two systems. Bitcoin is resource-constrained in the sense that on-chain processing incurs a cost which you want to keep as low as possible. Forth-like languages enable developers to express functionality in a compact and efficient way, making Script an ideal fit for the Bitcoin network.
‘We can do similar things with Bitcoin Script, and I'm certainly not the first to experiment with this. The sCrypt team has a different approach which is equally valid as it is better for some use cases. But the lower-level approach I'm about to demonstrate addresses cases where Script might be more of an infrastructure than you need.‘
Script hacking for fun and profit
Bitcoin developers often experience native Script code as difficult to read and debug. Shadders notes that this is something that needs to improve so more developers can start working on Bitcoin Script in new and interesting ways to discover the latent potential of this fantastic tool.
In the demos below, Steve introduces developers to a tool that will make their Bitcoin Script sleeker, more readable and more efficient.
01:06 Why Script for Bitcoin?
02:31 The similarity between Bitcoin and embedded systems
04:44 Script hacking for fun and profit
17:00 What is a Stack?
18:14 Reverse Polish Notation (RPN) demo
29:46 Compile-time vs Runtime demo
36:06 Script language features demo
40:37 The use of variables demo
45:29 How to add loops to the script demo
47:25 While loops demo
55:46 Q & A
Attend future Bitcoin SV DevCons for free
If you found this presentation valuable, you are sure to benefit from attending the next Bitcoin SV Developers Week. Sign up to be notified about the next event to make sure you don’t miss it.
Get BSV DevCon Updates
Sign up for news and information about BSV DevCons and other Bitcoin Association initiatives.