Script, P2SH, and Miniscript

If you’re at the Bitcoin Park in Nashville this week, come say hi.

In other news, I’m happy to announce that I received a grant from OpenSats to continue my work on Bitcoin Core!

https://opensats.org/blog/sjors-provoost-receives-opensats-lts-grant

Today we start with chapter 10 about Script, P2SH, and Miniscript. Just a reminder that you can buy the chapter as a printer friendly PDF. You can also order the physical book and pay with Bitcoin via the Konsensus Network. Or you can buy the e-book from me.

Script, P2SH, and Miniscript

This chapter will talk about Miniscript and how it makes using Bitcoin Script much easier. It’ll break down how Script works, how you can do more complicated and even absurd things with it, and how Miniscript emerged to make transactions less complicated and more secure. Additionally, it’ll cover what policy language is and how it can make it easier to create scripts.

Constraints

Scripts are how the Bitcoin blockchain constrains how a given coin can be spent: When you want to receive bitcoin, you tell the person sending it what rules apply to the transaction. For example, with no constraints, anybody can touch whatever’s in your wallet. Usually you would add the constraint that only you can spend these coins. Or, to be more precise, “These coins can only be spent if the transaction includes a signature that’s made with a specific public key, i.e. my key.”

So you’d tell the person sending bitcoin either your public key or the hash of it. This is what addresses are for. Then, they’d put that on the blockchain with a note on it saying that only the owner of that public key can spend the bitcoin.

However, although this is by far the most common type of constraint, there are all sorts of other types of constraints, and you can even specify several different options for the spender, such as “I can spend this, but my mom also needs to sign it. But after two years, maybe I can sign it alone.” In such a scenario, if you want to spend the money, you need to specify which option you’re using and fulfill only the specific criteria for that option.