<p>It is theoretically possible that Satoshi could have taken the entire C++ language (Bitcoin Core is written in C++) and then severely restricted what C++ functionality was available for Bitcoin scripting. Ethereum did something similar by making modifications to Javascript and calling it Solidity. An alternative approach that other altcoins took (e.g. Mimblewimble based altcoins such as Grin, Beam) was not to have a scripting language at all and only allow single signature spends (no multisignature, no timelocks etc).</p>
<p>As RedGrittyBrick says for various reasons it made sense to start from a much more limited language (<a href="https://en.wikipedia.org/wiki/Forth_(programming_language)" rel="nofollow noreferrer">Forth</a>) than C++ as even Forth was too expressive for Bitcoin Script; various Forth opcodes had to be disabled for Satoshi to be comfortable it wasn't exposing Bitcoin to uncertain verification costs. (There are also new opcodes that Bitcoin Script would like that aren't in Forth.)</p>
<p>Taking an existing language (C++, Javascript, Forth etc) and then removing and adding functionality so it can be used for Bitcoin scripting is an imperfect approach. <a href="https://bitcoinops.org/en/topics/simplicity/" rel="nofollow noreferrer">Simplicity</a> is an effort to build a scripting language for Bitcoin from the ground up. It is still a work in progress and would need a soft fork to be added to Bitcoin but designing specifically for the Bitcoin scripting use case and providing guarantees that aren't available in adjusted existing languages seems to be a much more promising approach.</p>

CC BY-SA 4.0
2022-06-11T12:23:35.373Z
2022-06-11T12:31:59.117Z
2022-06-11T12:31:59.117Z
Michael Folkson
<p>Consider a script that says</p>
<pre><code> While (true) {
   // some pointless but slow calculation
 }
</code></pre>
<p>in order to discover if the transaction containing it is valid, every node on the network has to run this until it returns a value.</p>
<p>The <a href="https://www.google.com/search?q=halting+problem" rel="nofollow noreferrer">halting problem</a> means that it is impossible to know whether a script will ever complete.</p>
<hr />
<p>These scripts are created by the transaction creators and could contain any script that a malicious person can dream up.</p>
<p>One way to combat malicious scripts is to have nodes know of a small number of standard scripts and not relay non standard scripts.</p>
<p>You could ask, if we only have a few standard transaction types, we don't need a scripting language at all, the evaluations could be hard coded in C++ and no scripts would be in the transaction itself. This would not be Bitcoin. Having a scripting language arguably provides for future flexibility.</p>
<p>We need the scripting language to be judiciously limited, so that we can be sure any script can be executed in finite time. we also need to be certain that no matter what malicious data is presented to the script by bad actors, it will terminate in finite time. having the scripting language be a carefully designed minimalistic language with limited capabilities arguably provides the best assurance of this.</p>
<hr />
<p>As <a href="https://crypto.news/introduction-bitcoins-scripting-language/" rel="nofollow noreferrer">Crypto News</a> said</p>
<blockquote>
<p>the limitations in Bitcoin Script prevents a “logic bomb,” or an infinite loop from being included in any single transaction. This restriction eliminates the possibility of a denial-of-service (DoS) attack on the network.</p>
</blockquote>
<hr />
<p>See also</p>
<ul>
<li><a href="https://bitcoin.stackexchange.com/q/25427/13866">The Bitcoin scripting system is purposefully not Turing-complete - why?</a></li>
</ul>

CC BY-SA 4.0
2022-06-11T07:37:28.710Z
there is only one global script that is executing on every machine, if someone sends something that doesn't conform to the rules of the script, it would simply be return an error.
ezio
CC BY-SA 4.0
2022-06-11T08:01:29.160Z
i think you missunderstood my point, if i have the whole runtime of my blockchain as print('"hello world") then every node would execute only that and wouldn't recognise anything else and i could write that line only in one language .
ezio
CC BY-SA 4.0
2022-06-11T07:32:27.943Z
2022-06-11T08:53:55.437Z
2022-06-11T08:53:55.437Z
RedGrittyBrick
<blockquote>
<p>was it necessary to have another language for these operations? isn't it possible to write the whole runtime in one language?</p>
</blockquote>
<p>To be clear: the goal of the scripting language isn't for defining the runtime logic of blockchain validation. No part of Bitcoin Core itself is written in the Bitcoin Script language, just in C++. The goal of the Bitcoin Script language is for customizing the conditions under which transaction outputs can be spent. These scripts are intended to be written by &quot;<em>users</em>&quot; of the system, not by (authors of) the system itself. Of course, in practice they are written and designed by the authors of the wallet software these users use, but it permits a flexibility that wouldn't otherwise exist: wallet authors can develop and experiment with new scripts permitted by the language, without needing to wait for the entire Bitcoin ecosystem to adopt changes to specifically enable their use case.</p>
<p>Would it be possible to not have such a language: certainly. There are several cryptocurrencies that don't have such a concept at all. But this alternative doesn't need to mean that the Script language is replaced by C++ (or whatever other language the validation logic is written in) - it can simply mean there is no customizability of spending conditions at all, and every output is just e.g. a public key, and every input is just a signature, and nothing else is possible.</p>
<p>Having this language at all just introduces features that wouldn't be achievable through other means. The simplest example is having coins that can only be spent when multiple people sign off on it(*), or only after a certain amount of time, or after some secret gets revealed. Together these are the basis for example for trustless escrows (where the escrow can't steal the coins), or for systems built on top like payment channels.</p>
<p>Perhaps your question is: why is this customizability of spending conditions not done using the language as the one the validation logic is written in? There are several reasons for this:</p>
<ul>
<li>It is essential that the outcome of evaluation of Bitcoin Script (or whatever alternative you're envisioning) <em>only</em> depends on data committed to by the transaction itself, or possibly in the blockchain it ends up in. Anything else is inviting risk of forks. For example, Scripts can (perhaps surprisingly) not observe the current time in any way. The (local) time at which validation is performed by various validators differs, so including the current time in Script could lead to a script that some validators accept and others reject, just by virtue of performing validation at different points in time. Bitcoin Script <em>can</em> however (indirectly) observe the timestamp of blocks in the blockchain, because this value is guaranteed to be identical for all validators. Imposing such strong restrictions on an existing language intended for general purpose programming is hard, and having a separate language for it makes it much easier to enforce this.</li>
<li>Size matters. As a global consensus system, capacity is limited. Bandwidth and latency constraints of the slowest and least-well connected devices the system wishes to let participate set a bound on how much data can be included in the chain. One aspect of that size is how much data it takes to express typical conditions in the Script language (or whatever its replacement is). As we envision many transactions whose conditions for spending at least involve some form of signature check, it stands to reason that it should be very cheap to express these. In Bitcoin Script, the logic &quot;require a signature on the current transaction with public key X&quot; can be expressed in 2 bytes + the size of the public key. This would be much harder to accomplish using a general-purpose language.</li>
<li>Computation cost, and predictability for that, matters. As the scripts included in transactions submitted to the network will be run and re-run by every validator (possibly ever), we care about the computational cost that validation entails for those validators, and specifically want an upper-bound on that cost. This means there needs to be some mechanism for stopping execution if it takes too long, or being able to determine ahead of time how long it's going to take.</li>
<li>Not every piece of software that interacts with the blockchain or transactions is written in the same language. In Bitcoin, the currently most-used validation software is Bitcoin Core, which is written in C++, but it is far from the only wallet software, and these other wallets are written in a variety of languages. Using C++ for the scripting language would pretty much require all these implementations to have a C++ dependency. Given that C++ is a compiled language, it would additionally require access to a C++ compiler just to run the scripts received in blocks and transactions from the network. C++ isn't designed for such on-the-fly code updating, and using an abstraction to e.g. run it in a virtual machine or interpreter would negate whatever advantages existed to use the same language in the first place. The situation may be different for other languages of course, but the point remains that the goals for a language to write a validation engine is, and the goals for the language to write spendability conditions are wildly different, so there is little reason to want to cover both by a single language.</li>
</ul>
<p>(*) There are techniques in modern cryptography to actually make a single public key that can only be spent when multiple people cooperate to spend it.</p>

CC BY-SA 4.0
2022-06-11T16:45:19.357Z
2022-06-11T17:00:42.207Z
2022-06-11T17:00:42.207Z
Pieter Wuille
<p>satoshi created bitcoin script which is the language that the bitcoin client uses to handle most of the operations such as sending or verifying transactions.</p>
<p>was it necessary to have another language for these operations? isn't it possible to write the whole runtime in one language?</p>

<script><satoshi-nakamoto><simplicity><turing-completeness>
Is bitcoin script necessary?
ezio
# Is bitcoin script necessary?

(Asked by: username_0 on 2022-06-11)

satoshi created bitcoin script which is the language that the bitcoin client uses to handle most of the operations such as sending or verifying transactions.

was it necessary to have another language for these operations? isn't it possible to write the whole runtime in one language?

**Tags:** script, satoshi-nakamoto, simplicity, turing-completeness


---

## 3 answers

### Answer by username_3 on 2022-06-11. Score: 9 | Accepted answer

> was it necessary to have another language for these operations? isn't it possible to write the whole runtime in one language?

To be clear: the goal of the scripting language isn't for defining the runtime logic of blockchain validation. No part of Bitcoin Core itself is written in the Bitcoin Script language, just in C++. The goal of the Bitcoin Script language is for customizing the conditions under which transaction outputs can be spent. These scripts are intended to be written by "*users*" of the system, not by (authors of) the system itself. Of course, in practice they are written and designed by the authors of the wallet software these users use, but it permits a flexibility that wouldn't otherwise exist: wallet authors can develop and experiment with new scripts permitted by the language, without needing to wait for the entire Bitcoin ecosystem to adopt changes to specifically enable their use case.

Would it be possible to not have such a language: certainly. There are several cryptocurrencies that don't have such a concept at all. But this alternative doesn't need to mean that the Script language is replaced by C++ (or whatever other language the validation logic is written in) - it can simply mean there is no customizability of spending conditions at all, and every output is just e.g. a public key, and every input is just a signature, and nothing else is possible.

Having this language at all just introduces features that wouldn't be achievable through other means. The simplest example is having coins that can only be spent when multiple people sign off on it(\*), or only after a certain amount of time, or after some secret gets revealed. Together these are the basis for example for trustless escrows (where the escrow can't steal the coins), or for systems built on top like payment channels.

Perhaps your question is: why is this customizability of spending conditions not done using the language as the one the validation logic is written in? There are several reasons for this:

* It is essential that the outcome of evaluation of Bitcoin Script (or whatever alternative you're envisioning) *only* depends on data committed to by the transaction itself, or possibly in the blockchain it ends up in. Anything else is inviting risk of forks. For example, Scripts can (perhaps surprisingly) not observe the current time in any way. The (local) time at which validation is performed by various validators differs, so including the current time in Script could lead to a script that some validators accept and others reject, just by virtue of performing validation at different points in time. Bitcoin Script *can* however (indirectly) observe the timestamp of blocks in the blockchain, because this value is guaranteed to be identical for all validators. Imposing such strong restrictions on an existing language intended for general purpose programming is hard, and having a separate language for it makes it much easier to enforce this.
* Size matters. As a global consensus system, capacity is limited. Bandwidth and latency constraints of the slowest and least-well connected devices the system wishes to let participate set a bound on how much data can be included in the chain. One aspect of that size is how much data it takes to express typical conditions in the Script language (or whatever its replacement is). As we envision many transactions whose conditions for spending at least involve some form of signature check, it stands to reason that it should be very cheap to express these. In Bitcoin Script, the logic "require a signature on the current transaction with public key X" can be expressed in 2 bytes + the size of the public key. This would be much harder to accomplish using a general-purpose language.
* Computation cost, and predictability for that, matters. As the scripts included in transactions submitted to the network will be run and re-run by every validator (possibly ever), we care about the computational cost that validation entails for those validators, and specifically want an upper-bound on that cost. This means there needs to be some mechanism for stopping execution if it takes too long, or being able to determine ahead of time how long it's going to take.
* Not every piece of software that interacts with the blockchain or transactions is written in the same language. In Bitcoin, the currently most-used validation software is Bitcoin Core, which is written in C++, but it is far from the only wallet software, and these other wallets are written in a variety of languages. Using C++ for the scripting language would pretty much require all these implementations to have a C++ dependency. Given that C++ is a compiled language, it would additionally require access to a C++ compiler just to run the scripts received in blocks and transactions from the network. C++ isn't designed for such on-the-fly code updating, and using an abstraction to e.g. run it in a virtual machine or interpreter would negate whatever advantages existed to use the same language in the first place. The situation may be different for other languages of course, but the point remains that the goals for a language to write a validation engine is, and the goals for the language to write spendability conditions are wildly different, so there is little reason to want to cover both by a single language.

(\*) There are techniques in modern cryptography to actually make a single public key that can only be spent when multiple people cooperate to spend it.


---

### Answer by username_1 on 2022-06-11. Score: 4

It is theoretically possible that Satoshi could have taken the entire C++ language (Bitcoin Core is written in C++) and then severely restricted what C++ functionality was available for Bitcoin scripting. Ethereum did something similar by making modifications to Javascript and calling it Solidity. An alternative approach that other altcoins took (e.g. Mimblewimble based altcoins such as Grin, Beam) was not to have a scripting language at all and only allow single signature spends (no multisignature, no timelocks etc).

As username_2 says for various reasons it made sense to start from a much more limited language ([Forth](https://en.wikipedia.org/wiki/Forth_(programming_language))) than C++ as even Forth was too expressive for Bitcoin Script; various Forth opcodes had to be disabled for Satoshi to be comfortable it wasn't exposing Bitcoin to uncertain verification costs. (There are also new opcodes that Bitcoin Script would like that aren't in Forth.)

Taking an existing language (C++, Javascript, Forth etc) and then removing and adding functionality so it can be used for Bitcoin scripting is an imperfect approach. [Simplicity](https://bitcoinops.org/en/topics/simplicity/) is an effort to build a scripting language for Bitcoin from the ground up. It is still a work in progress and would need a soft fork to be added to Bitcoin but designing specifically for the Bitcoin scripting use case and providing guarantees that aren't available in adjusted existing languages seems to be a much more promising approach.


---

### Answer by username_2 on 2022-06-11. Score: 3

Consider a script that says

```
 While (true) {
   // some pointless but slow calculation
 }

```

in order to discover if the transaction containing it is valid, every node on the network has to run this until it returns a value.

The [halting problem](https://www.google.com/search?q=halting+problem) means that it is impossible to know whether a script will ever complete.

---

These scripts are created by the transaction creators and could contain any script that a malicious person can dream up.

One way to combat malicious scripts is to have nodes know of a small number of standard scripts and not relay non standard scripts.

You could ask, if we only have a few standard transaction types, we don't need a scripting language at all, the evaluations could be hard coded in C++ and no scripts would be in the transaction itself. This would not be Bitcoin. Having a scripting language arguably provides for future flexibility.

We need the scripting language to be judiciously limited, so that we can be sure any script can be executed in finite time. we also need to be certain that no matter what malicious data is presented to the script by bad actors, it will terminate in finite time. having the scripting language be a carefully designed minimalistic language with limited capabilities arguably provides the best assurance of this.

---

As [Crypto News](https://crypto.news/introduction-bitcoins-scripting-language/) said

> the limitations in Bitcoin Script prevents a “logic bomb,” or an infinite loop from being included in any single transaction. This restriction eliminates the possibility of a denial-of-service (DoS) attack on the network.

---

See also

* [The Bitcoin scripting system is purposefully not Turing-complete - why?](https://bitcoin.stackexchange.com/q/25427/13866)

> **Comments:**
> **username_0**: there is only one global script that is executing on every machine, if someone sends something that doesn't conform to the rules of the script, it would simply be return an error.  
> **username_0**: i think you missunderstood my point, if i have the whole runtime of my blockchain as print('"hello world") then every node would execute only that and wouldn't recognise anything else and i could write that line only in one language .  

---

