3 ms·
Bitcoin's smart contracting language is a Forth variant, and arguably this was a very astute and smart choice by Satoshi. When designing a multi-party contract
by adastra22 3y ago
Bitcoin's smart contracting language is a Forth variant, and arguably this was a very astute and smart choice by Satoshi.
When designing a multi-party contract, the essential problem is that two people specify the terms they each want to apply to any case in which the funds must be spent, then these two sets of requirements must be merged into a single program. This is, in general, difficult to do securely. We can establish conventions that are relatively easy to follow, but it would be a lot nicer and more powerful if we could syntactically enforce that both sets of requirements are enforced in the combined program.
Concatenative languages like Forth meet this requirement nicely. If you represent the spend requirements as a program, then combining the two programs together in such a way that they both are equally enforce is as simple as literally concatenating the two programs together.
For example, suppose Alice's requirement is that Alice signs the transaction with her key, and Bob's requirement is that Bob signs with his key, and the spending transaction is after some specified time T. Expressed in bitcoin script:
Alice: <AlicePubkey> CHECKSIGVERIFY
Bob: <T> CHECKLOCKTIMEVERIFY DROP <BobPubkey> CHECKSIGVERIFY
The combined script that meets both these sets of requirements is as simple as putting Alice's script, then Bob's, unaltered:
Alice&Bob: <AlicePubkey> CHECKSIGVERIFY <T> CHECKLOCKTIMEVERIFY DROP <BobPubkey> CHECKSIGVERIFY 1
(The `1` at the end is a quirk of bitcoin that it has to finish with a non-zero value on the stack. This combined script could also be simplified in a couple of ways. Also there's a couple of ways in which this can fail in practice. Alice's script could contain OP_RETURN, for example, which causes the entire script to become unspendable. Or a mismatched IF/ELSE. A better designed and strongly typed Forth dialect would fix these issues.)
Bitcoin's Forth is not type checked, but suppose that it were. And furthermore, suppose that it had a powerful dependently typed system that captured various key signing and stack requirements at the type level. It could be used to track not just what a program does, but also the properties of a program. Alice could put a constraint in her program that says "lock time can be no later than April 2024," and this becomes part of both the input and output type requirements of her program. Then when Bob's program is specified with T=15 May 2024, then his program no longer type checks when concatenated to the end of Alice's.
No one has yet written a system like this, but it would be really powerful if it did exist. Alice writes here smart contract conditions all by lonesome self, and Bob writes his. Then they literally concatenate one program to the other, and if it type checks then Alice and Bob can be certain that both sets of conditions are satisfied.
- eternityforest 3y agoForth doesn't seem to do much to stop you from making mistakes, unless Bitcoin has added extra stuff. I don't use or study anything crypto related, so I'm just guessing, but wouldn't something like Prolog work for describing contracts?
- rebolek 3y agoThings that make sense and crypto are two set for which there's very small intersection.
- adastra22 3y agoYes, I’ve long advocated for a high level smart contracting language that would be similar to prolog in structure and semantics. It would compile down to a state machine, and then the state machine would be interpreted as a series of outputs (nodes on the state machine graph) and spending transactions (edges). The actual spend condition language would be lower level, however, and Forth-like languages are a good fit for this part of the stack.
- tromp 3y agoBitcoin script is a large source of complexity, and it turns out to be mostly redundant. Schnorr signatures allow the use of so-called scriptless scripts [1] [2], which can do most of the things than Bitcoin script is used for, including multisig, absolute and relative timelocks, payment channels, discrete log contracts, and atomic swaps (using adaptor signatures). All without the need for a scripting language. The example you gave of a multisig output that can be spent by either Alice, or Bob after some time, is easily handled too. [1] https://github.com/BlockstreamResearch/scriptless-scripts https://github.com/BlockstreamResearch/scriptless-scripts [2] https://tlu.tarilabs.com/cryptography/introduction-to-scriptless-scripts https://tlu.tarilabs.com/cryptography/introduction-to-script...
- adastra22 3y ago> absolute and relative timelocks That's a stretch. Replacing timelocks with hashcash (or equivalent) is hardly the same thing. But generally speaking "scriptless scripts" suffer from the need for interactive construction. There's a long way to go until scriptless scripts is a full replacement for script, if it is even possible.