In this episode of Bitcoin, Explained, Aaron and Sjors explain pay-to-script-hash (P2SH), which allows bitcoin to be sent to and from the hash of a script. Besides (the current implementation of) P2SH itself, Aaron and Sjors also discuss some alternatives that were proposed around the time that P2SH was adopted in 2012. For further reading on the history of P2SH, also see “The Battle for P2SH: The Untold History of Bitcoin’s First War“ Chapters 00:00:00 Introduction and listener boost 00:04:22 How pay-to-script-hash works 00:10:53 OP_EVAL: the first proposal 00:16:11 Why OP_EVAL raised recursion risks 00:23:43 P2SH script templates and soft forks 00:28:16 CheckHashVerify: the alternative proposal 00:33:58 Choosing P2SH: miner signaling and developer review 00:38:28 Deployment mishaps and upgrading Bitcoin Episode Sponsor: https://voltage.cloud/ Sjors New Book: https://www.amazon.com/Bitcoin-Technical-innovations-Sjors-Provoost/dp/9090360425
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
Aaron van WirdumLive from Utrecht, this is Bitcoin
Sjors ProvoostExplained.
Aaron van WirdumHey Sjors.
Sjors ProvoostHello.
Aaron van WirdumYou just came back from Advancing Bitcoin, is that right?
Sjors ProvoostThat's right.
Aaron van WirdumTechnical conference.
Sjors ProvoostYep.
Aaron van WirdumHow was that?
Sjors ProvoostIt was fun.
Aaron van WirdumDid you learn anything new?
Sjors ProvoostMany little things.
Aaron van WirdumAnything we can discuss on the podcast?
Sjors ProvoostI don't think so. Maybe later, but not.
Aaron van WirdumWell, I knew that because we got a topic for today. Today. We're going to discuss P2SH, which somehow we never did before.
Sjors ProvoostWell, we've mentioned it a few times, but we haven't done a full episode on it.
Aaron van WirdumYeah, we probably mentioned it many times, and it was actually a suggestion by someone. I don't remember who it was. Sorry if you're listening, dear listener, but it was someone on Twitter that suggested it, and then I went over the episode overview list, and I realized that we've never actually done an episode on P2SH. Pay-to-script-hash so let's do it today but first, Sjors, your favorite part of the show, you wanted to give us you what's it called again a
Aaron van Wirdumbooster… Explain what you're doing.
Sjors ProvoostI'm just gonna read one boostagram. This is
Aaron van WirdumAlso, you sent me a couple of links on how people can stream the sats to me is that right?
Sjors ProvoostThat's right.
Aaron van WirdumI'm not gonna do it Sjors, I decided… I decided, this is your special moment this is your special moment in the show. This is your love affair with the listeners.
Sjors ProvoostNo, you don't have to read any of the boost yourself. It's just that I now have to look at how many sats we got and then send you half and deal with invoices, which is annoying.
Aaron van WirdumI don't want half. It's all yours.
Sjors ProvoostAll right.
Aaron van WirdumDear listener, if you want to make Sjors rich, if you want to make me regret this decision, send all your sats to Sjors. Do you want your own intro tune for this part of the show? Sjors?
Sjors ProvoostThat is pretty good intro tune. Let's keep that one. it… for 20,000 sats from AtLawBitcoin saying appreciate you. so it's a pretty nice one. I think you're already regretting it.
Aaron van Wirdum20,000 oh my god. Okay, Sjors, back to the show. Pay-to-script-hash so the way we're going to structure this episode is because I think probably a lot of our listeners know what pay-to-script-hash is although we might go into some details that not everyone knows about but then also what we're going to do is we're going to discuss a little bit about the history of pay-to-SH.
Sjors ProvoostExactly.
Aaron van WirdumAnd that's actually largely based on an article that I wrote with Pete Rizzo Three years ago now something like that because it was kind of the first big Bitcoin controversy first big Bitcoin war you know it wasn't as big as a scaling war obviously but it was kind of like a prelude to that in a way it was sort of the precursor the prequel to to the big scaling war.
Sjors ProvoostYeah, there were at least like 20 angry posts on Bitcointalk.
Aaron van WirdumYeah, and there was some bickering on IRC and there was the [unclear]. Amir Taaki got involved with his own website. There was some debate about it back then.
Sjors ProvoostSpeaking of IRC, yesterday I tried to find the IRC logs from 2011 and all the websites that link to old IRC logs pointing to a website, Bitcoin something, which doesn't exist anymore. So it's a bit annoying.
Aaron van WirdumWait, the logs from 2011 are gone? is that what you're saying?
Sjors ProvoostI don't know if they're gone they're not on the sites where the other sites link to so if somebody still has IRC logs I'd like to know where they are.
Aaron van WirdumOh, I mean I can look that up for you I'm sure I would have that somewhere unless it got deleted. we'll find out. anyways, okay, so let's just start at the beginning and I think we'll start with a more sort of high-level description of pay-to-script-hash, P2SH. What is P2SH?
Sjors ProvoostBecause what we'll get to is that there were actually three proposals, but they're all really doing P2SH. It's just that one of them came to be known that. with by that name but P2SH just means pay-to-script-hash and there are multiple ways to pay to a script hash so what it does is…
Aaron van WirdumWell, I guess my question is about what we call pay-to-script-hash today but I think your point is that what you're going to describe kind of applies to all of them.
Sjors ProvoostYeah, exactly, so the idea is that so when you want to receive Bitcoin you need to tell the sender, where to send it to, and what you're really telling them is what script to send it to. And usually that script is just like, okay, whoever has the private key belonging to the public key can spend it, but the script can be more complicated. And this is a problem because the more complicated your script is, the longer it is. And so that means that the sender has to pay you fees and that the addresses can look very small or the addresses can look very long if you have a long script. So in order to avoid that, the idea was to send
Sjors Provoostyour coins to the hash of a script because a hash is always the same length. And so therefore, the idea of paying the script hash is that the recipient gives you not the script itself, but the hash of the script. And then you... turn that into a special your wallet will then do its magic and make sure that the coins are sent to the right place that can only and then when recipient wants to spend it they have to reveal the original script and the precise details vary per proposal but that's a general idea right? you reveal the script the blockchain
Sjors Provoostchecks that it matches the hash of the script that you previously said it would be, and then you have to satisfy whatever that script says right?
Aaron van WirdumSo back in the early days of Bitcoin if you wanted to receive money if you wanted to lock how do I say… what's the best way to put this?
Sjors ProvoostEncumber money.
Aaron van WirdumLet's say you you want to say I want to receive money from you sure but I want to receive it in such a way that the money is locked into a multisig let's say just a multisig.
Sjors ProvoostYeah,
Aaron van Wirdumthen what I would do in the early days well actually it wouldn't even work in the early days right because of… it would… No, policy rules… what's it called?
Sjors ProvoostWell, it would be difficult to get the transaction mined. Exactly. You'd have to work with a miner because of the standardness rules.
Aaron van WirdumStandardness, that's what I was looking for. but let's ignore that for a second so if I wanted to receive coins in such a way that it's in a multisig I got several keys dispersed in several locations that's how I want to receive the coins then I would actually send the script to you and you would send it to that script right?
Sjors ProvoostYeah, you would… Yeah, exactly. You would have to tell me, okay, this is my multisig script. Please send it here. And that was annoying because there was also no address format for it. And so it's a very difficult UI or user experience.
Aaron van WirdumRight. So then you're going to have to pay the fees for the fact that the transaction is not bigger because it contains a whole script. And also it's immediately visible on the blockchain that it is sent to a multisig, which is maybe not great for privacy.
Sjors ProvoostYeah, so the privacy, the nice thing about paying to script hash is that the privacy is slightly better. At least you have privacy for longer because eventually if you spend it, the script will show up. But until you spend it, the script will not show up.
Aaron van WirdumYeah, and and you're the one paying the fee rather like I'm the one who wants a complicated multisig address but then you have to pay the fee for including it in that address right?
Sjors ProvoostYeah, in so for P2SH yes I the sender— would have to pay a higher fee in order to send to somebody with a complicated setup which kind of doesn't make sense and now they'll… it's more fair in the sense that if you have a complicated setup anybody can send to you it doesn't cost them anything extra but once you want to spend from your complicated setup then you have to pay the extra fees
Aaron van WirdumRight? Yeah, no, I was just summing up how it would work before pay to a script hash was there so I sent you the whole script so that's big so you have to pay a big fee even though I'm the one who wants to use a complicated script and then also it's slightly worse for privacy so that's why developers early on in like 2011 came up with this idea let's instead send it to a hash and I give you just the hash I don't give you the script I give you the hash and when I want to spend it I reveal the whole scripts and then anyone can check that the
Aaron van Wirdumscript matches the hash and that's what I spend it from… that's how I it's only then that I… include all the multiple signatures in the multisig case, right?
Sjors ProvoostYeah.
Aaron van WirdumSo that's the basics of P2SH.
Sjors ProvoostYes, in general. And so the hash of a script happens to be the same size of the hash of a public key, which means that it will just look like an address. You just start with a three instead of a one. So that's nice too.
Aaron van WirdumRight. Why is it three, not a two?
Sjors ProvoostBecause it's a version number. So the first number in the address, in the legacy addresses, we've done an episode about addresses. The first letter represents a version number of the address scheme. So if it starts with a 1, which is not actually a 1 because it's base 58, but we're not going to bother you with that, that means that it has to be interpreted in a certain way, and if the address starts with a 3, it has to be interpreted in another way.
Aaron van WirdumBut why is it not a 2?
Sjors ProvoostBecause the numbers 1 and 3 do not actually represent the numbers 1 and 3 because it's base 58. We did a whole episode about that, Aaron. You should just listen back to the original episode about addresses.
Aaron van WirdumI definitely forgot about it. I thought the reason was because 2 was already used by testnet.
Sjors ProvoostYes.
Aaron van WirdumSo 1 mainnet, 2 testnet, 3, you know, next 1.
Sjors ProvoostThat could also be true.
Aaron van WirdumOkay.
Sjors ProvoostIt doesn't really matter. It's just that once you're sending to it, the wallet that's sending has to put something on the blockchain. And the only thing that's in the address is the hash of something, either the hash of a public key or the hash of a script. And that's not enough to put on the blockchain. You actually have to put more information on the blockchain as a sender. And the version number tells you your wallet exactly what to put on the blockchain. So the standard script templates that go around the hash.
Aaron van WirdumMoving on. So this was the basics of pay-to-script-hash and why it was implemented. But now we'll sort of take a trip down memory lane and go back to some historical context. So first of the first proposal that would do something like this. So this pay-to-script-hash idea was around. And then the first idea
Aaron van Wirdumthat was actually proposed and implemented and almost deployed was called OP_EVAL. So OP_EVAL, I think the right way to looking at it was a way of doing pay-to-script-hash, right?
Sjors ProvoostYes. And arguably the most obvious way to do it Though, of course, that depends on what you were thinking of at the time when you were designing it. But basically, the idea of OP_EVAL is that, again, as a sender, you just get a hash and you put that on the blockchain. Now, the recipient wants to spend it. They reveal the original script. And then the way that that original script is run is by this opcode called OP_EVAL. So that means the sender has to put the word OP_EVAL somewhere in the thing on the blockchain. And then the
Sjors Provoostrecipient will actually put the script and then the script gets executed. Yeah.
Aaron van WirdumSo to be perfectly clear, in case anyone is confused at this point, OP_EVAL is not actually in Bitcoin. This was an early proposal that was rejected.
Sjors ProvoostYes.
Aaron van WirdumOkay, so who's putting OP_EVAL? Maybe you just said this, but who's putting OP_EVAL where exactly?
Sjors ProvoostThe sender has to do it. So this is one of the things you implicitly communicate when you have a version number in your address. Now, in this case, this standard was never materialized, but maybe the address would have started with a 7 or something. And then as a sender, you get a hash of a script and you put on the blockchain something like OP_DUP, the hash of the script OP_EVAL. A little bit longer, but something like that.
Aaron van WirdumWait, so I'm the one who wants to receive money from you in a multisig address. Let's just stick to that example. So in the case of OP_EVAL, what exactly do I send you? Do I send you…
Sjors ProvoostThe hash of the script. So the hash of your multisig script.
Aaron van WirdumOkay, and does this script include OP_EVAL?
Sjors ProvoostNo.
Aaron van WirdumOkay, so I just sent you the script of the multisig. I sent it to you. What do you do?
Sjors ProvoostYou sent me the hash of the script of the multisig.
Aaron van WirdumI guess I can do either, right? But sure, I'll send you the hash.
Sjors ProvoostYeah, that's the whole point basically to make it simple. So you're sending me the hash. Then what I do is I create a script, a scriptPubKey on the blockchain. That's where the coins are going. And I think it says the first instruction is like duplicate whatever's on the stack and then put the hash there. And then it says compare the thing that's on the stack with the hash. And then if that's true, then you call OP_EVAL. And this is a very similar pattern to how you spend from a public key. Because of the public key, you're also basically, the
Sjors Provoostsender is putting the hash of the public key on the blockchain. And then the receiver, when they want to spend it, they have to reveal the actual public key.
Aaron van WirdumOh, sorry. Do you put OP_EVAL in the input or in the output?
Sjors ProvoostIn the output.
Aaron van WirdumOkay. So I sent you the hash and then you put that hash in the output and you put OP_EVAL next to it.
Sjors ProvoostYep.
Aaron van WirdumOkay, and then when I want to spend the coins then I include the script.
Sjors ProvoostYeah, the only basically what you will do when you're spending it you include the script and you include whatever is necessary to satisfy the script right?
Aaron van WirdumAnd do I put OP_EVAL anywhere?
Sjors ProvoostNo, no.
Aaron van WirdumOkay, so then other nodes on the network… They're gonna look at...
Sjors ProvoostThey start basically because you always start with the signature side. So what they'll do is they'll say, okay, I'm putting some signatures on the stack. I'm putting the actual script on the stack. And then I'm gonna run the scriptPubKey, which will say, okay, you need to duplicate. So you need to duplicate the hash of the script. No, I don't know what you need. Anyway, it basically says, okay, now you should check that the hash of the script actually matches the script that was put in the stack. And that's because then you call, then you encounter this eval instruction and that's when you execute the whole script and when you need the signatures.
Aaron van WirdumJust to make sure that I'm understanding this. So when other, when nodes verifying new transactions, they, what does OP_EVAL mean to them exactly? It means that they need to compare…
Sjors ProvoostIt means execute the script that's on the stack.
Aaron van WirdumShouldn't they always do that?
Sjors ProvoostNo, normally you are executing a script and the script can put things on the stack, like numbers, et cetera. The stacks are like plates basically. So you can put numbers on the plate and you can say, okay, is this number on the first plate? Is that the same as the number on the next plate? But you do not execute code that is on the stack. So things that are on the stack are numbers or text or keys or whatever it is or dates, but they are not code.
Aaron van WirdumOkay.
Sjors ProvoostAnd what this eval thing does is, no, no, no, pretend that what is on the stack is not a number or a text, pretend that it's code, and then just run it like that.
Aaron van WirdumOkay. Well, you say pretend, but it's actually code then, right?
Sjors ProvoostWell, so this is where the downside of this proposal comes in.
Aaron van WirdumOkay.
Sjors ProvoostBut maybe some people have worked with JavaScript in the past. And in JavaScript, you can, you know, there's also a command called eval. And it's extremely dangerous. So generally when you're building a JavaScript web application, you really should not use eval. And the reason for that tends to be that you cannot predict what that thing is going to do if you're just trying to analyze your JavaScript code. So your JavaScript code might see something like eval and then a piece of text. So if you're just analyzing the code, you might think, oh, it's just text. What could go wrong? But now it turns out this text is actually
Sjors Provoosttreated as code. You can no longer just treat text as if it texts. And the same thing goes with Bitcoin. That's sort of where the downside of this eval proposal comes in. Normally, when you see a piece of Bitcoin script, you can look at what it's going to do because you can see all the opcodes in it. And you can see, okay, it's pushing some number, whatever. It's pushing some text, doesn't matter. And you can reason about it. And then after you've done some sanity checks, that's when you actually run the script. But with eval, you cannot do that anymore because… anywhere in this script could be a piece of text that initially
Sjors Provoostyou think is just text, so you've ignored it, but now it's suddenly code, so you should not have ignored it. But conversely, if you're just looking at the text and you're treating it as code, well, maybe it really is just text and you should have ignored it.
Aaron van WirdumOkay.
Sjors ProvoostSo it just creates...
Aaron van WirdumSo it makes it hard to do a sanity check.
Sjors ProvoostYeah, a sanity check without running the code.
Aaron van WirdumWhat is insane in this context? What is it you're afraid of?
Sjors ProvoostWell, there's many things you'd be afraid of because my understanding is that this would actually make Bitcoin Turing complete. And Turing completeness is bad, basically, because it means you can execute any arbitrary program, which could include loops, infinite loops, for example. So one of the things you might be afraid of is an infinite loop.
Aaron van WirdumThat's the core risk, right?
Sjors ProvoostThat's one of the risks when you have, basically, when you can run any program you want. Well, one of those programs could be an infinite loop where you're trying to validate the block and you will never finish validating it because you keep going in circles because you have a loop.
Aaron van WirdumCan you give an example of an infinite loop just for people like me that this is not obvious to me what that means?
Sjors ProvoostWell, how you would do it, like normally in a programming language,
Aaron van WirdumYou can just say do while.
Sjors ProvoostWhich basically, you just basically say, okay, go in a loop until some condition is met. Usually that's how a programming language works. And then inside that loop, you might print something on the screen. And if the condition that to leave the loop never happens, then you never leave the loop. So you keep printing something on the screen line by line by line and you never stop.
Aaron van WirdumWhat is a loop?
Sjors ProvoostBasically, I guess a circle of code. So you run an instruction and then you go to the top of the loop and you run the instruction again. So it's a piece of code that you keep running again and again until you, for some reason, stop running it.
Aaron van WirdumOkay, so I'm going to just try an example.
Sjors ProvoostSo typically you might loop from 1 to 10, and you print the number. So you can say for i is 0, and then you say print i, and then at the end of the loop you do i++, which increases i, and then you check if i is more than 10, you exit the loop. That's one example.
Aaron van WirdumIf I tell my code, I write code that says hash this piece of data with the nonce until it spells Sjors is the king. And then I will keep hashing that until it says that. Is that like an infinite loop?
Sjors ProvoostWell, that's probably an infinite loop, yeah, because that's never going to happen.
Aaron van WirdumYeah, I mean, it might happen at some point, right?
Sjors ProvoostBut it's practically an infinite loop. Yeah, exactly. It's just as bad because it will grind your computer to a halt.
Aaron van WirdumOkay, so and then the problem is... To verify if a transaction is valid, you first have to basically keep checking all kinds of different things.
Sjors ProvoostYeah, and so an infinite loop in Bitcoin would probably be...
Aaron van WirdumNew blocks come in and just grinds your... Your node basically can't keep up with the blockchain because it's still verifying an infinite loop from a transaction from four years ago.
Sjors ProvoostYeah, and I guess an example of this infinite loop could be that the thing you're calling eval on says OP_DUP, which means duplicate. And then it says OP_EVAL again. And so what you would do is you see eval, you duplicate the actual thing that you want to evaluate, and then you call eval on it again. And then... you know you're calling eval on something that's that same string again which says okay duplicate myself and so you keep duplicating the thing that you're trying to evaluate and so that will be an
Sjors Provoostinfinite loop. Now there were in this proposal some protections against that.
Aaron van WirdumWell, just to be clear was this the example that you just gave was that sort of the specific concern with OP_EVAL?
Sjors ProvoostWell, that was one example of how it could be to an infinite loop.
Aaron van WirdumOkay.
Sjors ProvoostYeah, but there was a protection against that in the implementation of it it would basically only allow two loops or like to recurse that's the term basically recursion. so how often can you go back inside yourself inside the loop? and there was a limit of two, but I think then there was a mistake in the implementation that that protection didn't work and so people got a little scared.
Aaron van WirdumOkay, well this got real technical real fast but let's so… Do you think we've now explained the problem with OP_EVAL?
Sjors ProvoostYeah, so basically in theory you could have fixed all these specific issues, but the general risk remains when you have something like eval in any programming language is just kind of dangerous. So you don't want to, you preferably don't want to do it. It makes it more difficult to reason about the code, very easy to make a mistake, and one mistake and you have an infinite loop.
Aaron van WirdumOkay, so is it fair if I summarize the problem with OP_EVAL? In that it opens the door to potentially infinite loops, which would kind of break Bitcoin.
Sjors ProvoostYeah, I guess so.
Aaron van WirdumOkay.
Sjors ProvoostAnd keep in mind that Ethereum does allow something like Eval. And the reason they get away with it is because they have gas. And so you use up your gas and the loop won't be infinite because you run out of gas at some point.
Aaron van WirdumI see. Okay. So that was the problem with OP_EVAL. And then... This was discovered very last minute by Russell O'Connor back in 2011. It was ready to be deployed. And then Russell O'Connor said, guys, what are you doing? You got to stop this right now.
Sjors ProvoostYeah, he literally said, you guys need to stop what you're doing and really understand Bitcoin.
Aaron van WirdumRight, yeah. And then... The core developers at the time, which were led by Gavin Andresen, but also a lot of the kind of currently known developers were already involved, right? Greg Maxwell Pieter Wuille, Luke Dashjr, Amir Taaki also.
Sjors ProvoostYep.
Aaron van WirdumAnyway, so they figured out we've got to figure out something else.
Sjors ProvoostWell, they didn't even agree on that, I think, initially, because there were two possibilities. Either you do something completely different or you just... play whack-a-mole basically so you you stick with the OP_EVAL you fix the specific bug you find but you know there might be another bug but you just hope that there isn't
Aaron van WirdumRight, and but then Gavin Gavin Andresen he proposed pay to what we would call pay-to-script-hash today so really OP_EVAL is kind of a form of pay-to-script-hash so how we're just gonna name this one pay-to-script-hash because that's what we're calling it today, I guess.
Sjors ProvoostExactly. So he could have basically stuck to the OP_EVAL proposal. I think he tried initially. But then I guess somehow we got the idea of doing it in a different way that was safer.
Aaron van WirdumSo what is this different way and why is it safer?
Sjors ProvoostSo this different way is that we have a type of script. So when on the blockchain you see a script that has a very specific form. So I don't know, it starts with OP_EQUAL, then it has a hash, and then it starts with something like that. If the script interpreter sees that particular form, it will understand that what it tries to do is be a P2SH transaction. Because from the old node point of view, it would just see the hash of a script. And all it would do is check whether it matches the script that you're putting on the stack. But it wouldn't do anything.
Sjors ProvoostSo from an old node point of view, such a template just looks like doing nothing, giving the money away. But from the new node's point of view, they'll recognize this. They will take the script, the actual script, and run it.
Aaron van WirdumYeah, so you're getting into a topic that we haven't mentioned so far, which is that pay-to-script-hash as well as OP_EVAL can be implemented as a soft fork. This was kind of a discovery by the Bitcoin developers at the time that this was even possible.
Sjors ProvoostYeah, that's fun to read on the forums and probably also in IRC. You can find a log that... Yeah, they discovered that there are ways to do soft forks this way by either in the OP_EVAL proposal by saying we take an existing opcode that does nothing.
Aaron van WirdumYeah, the OP_NOPs.
Sjors ProvoostThe OP_NOP. And then because it does nothing, old nodes will think, okay, this transaction is valid because nothing changes. And new nodes will actually do what the new opcode says. And that mechanism was new for the developers, but very likely Satoshi knew that this would be possible because otherwise why did he put the OP_NOPs in there?
Aaron van WirdumRight. Yeah. So let's get into that.
Sjors ProvoostIt was rediscovered, essentially.
Aaron van WirdumRight. So let's get into that a little bit. So the OP_NOPs, these are op codes put in there by Satoshi, which... old nodes or non-upgraded nodes or whatever you want to call it, if they see OP_NOP, they will just consider the transaction valid?
Sjors ProvoostWell, they don't consider the transaction valid necessarily, but it doesn't change anything about the validity. So if whatever happened before OP_NOP... was valid then after OP_NOP it's still valid.
Aaron van WirdumRight but then these OP_NOP codes can be reinterpreted by newer nodes after a soft fork and then they start to mean something else. So in this specific example they would have started to mean OP_EVAL after that.
Sjors ProvoostYes, and although the OP_EVAL concept was abandoned the idea of doing a soft fork this way by having a script that means nothing to all nodes or like it just means take the money for all nodes it it has a more strict interpretation for the new nodes right?
Aaron van WirdumThe thing though is that with OP_EVAL there was an actual explicit reinterpretation of an OP_NOP. And then with pay-to-script-hash, that was not the case. So it's used the same logic for a soft fork. It just didn't reinterpret an actual OP_NOP.
Sjors ProvoostExactly. What it interpreted was a template. So if a transaction looks like a duck… For example, you know, your old rules would be, oh, we just take a photo and we say what animal it is. We see a photo and we say it's a cat or it's a dog. And the new rule would be, well, but if it's a cat, we're actually going to look at the skin color of the cat and do some other game. And this costs some friction because, you know, it depends on your taste, I guess, whether or not you think this particular way of doing it is good or bad.
Aaron van WirdumYeah, it was described at the time, even by people that supported it, like Amir Taaki. He said, I don't know the exact quote, I don't know if we have it here, but he definitely called it a hack.
Sjors ProvoostWell, and you could ask, was this the will of Satoshi, you know, that kind of interpretation, because the OP_NOP system was, well, at least you could think that the OP_NOP system was intended to be used in the way that eval was using it, whereas this idea of using a template was not basically in there. So mostly I think Luke Dashjr was very not happy with this way of doing it. And so for, I think for, you know, you could say aesthetic reasons, but you know, he might look at that differently. So he came up with a different proposal that was
Sjors Provoostsomewhere in between. It didn't use an OP_NOP, I think. In fact, I think it repurposed OP_CODESEPARATOR or something like that. In any case, he basically came up with an alternative design that didn't use this templating mechanism. And then there was a lot of drama. And the downside of the drama was that not much attention was really paid to the real proposal that Luke was doing. And there was much more bickering back and forth, at least on the forums. And so, yeah, I haven't studied that
Sjors Provoostproposal in a lot of detail either. I mean, I wasn't around it. I can say some things about it, but it might not be the most fair description.
Aaron van WirdumYeah, so let's get to that in a second, just to clarify. So first, there was OP_EVAL that turned out to have these problems with recursion then the alternative that was proposed by Gavin Andresen was we'll just call it pay-to-script-hash even though all of them are really pay-to-script-hash but this one is like explicitly called pay-to-script-hash and then like Luke Dashjr came around he said I don't like this at all let's do and this is what we call in our article at least CheckHashVerify So
Aaron van WirdumCHV is what we call it. I don't know if he called it that at a time, probably, though.
Sjors ProvoostRight, but you see it's really the same thing, right? You're checking a hash, namely the hash of a script, and you're verifying that it's actually a valid script.
Aaron van WirdumYou just blew my mind, Sjors. You're right. You're right. It's the same thing.
Sjors ProvoostYeah. So it's a way of you can pay to a script hash, or there's probably other things you could have done.
Aaron van WirdumCheckHashVerify so okay, so and you wanted to explain how that works kind of you have somebody so again this one wasn't implemented so if you are the listener don't really understand how this works it doesn't even matter because it's not in Bitcoin but if you're interested and curious anyways Sjors is going to explain it to you now
Sjors ProvoostWell, not entirely. so it's I think it's BIP 12, right? That was the number given to it?
Aaron van Wirdum[unclear], right, oh, the debate was between BIP 16, which was pay-to-script-hash, and 17.
Sjors ProvoostSo I don't completely understand how it works. All I know is that it did not use the templating technique.
Aaron van WirdumI think OP_EVAL may have been 12.
Sjors ProvoostAnd it didn't exactly, it didn't use eval, but it did something similar to eval. I believe it was still treating text as code, but I might be wrong about that part. In any case, one of the things that it contained was the legendary OP_CODESEPARATOR. And maybe one day we'll do an episode about OP_CO… OP_CODESEPARATOR. I don't understand it. I think it generally gives people two kinds of responses either they don't know it and so they have no response or they know it and they fear it.
Aaron van WirdumThis is something that is in Bitcoin or is not?
Sjors ProvoostYes, it is in Bitcoin it's been there from the beginning it led to the arguably biggest bug ever which is that in the beginning you could take everybody's Bitcoin right, and that had to do with the OP_CODESEPARATOR
Aaron van WirdumSo it's non-standard?
Sjors ProvoostI'm not sure I think it has become non-standard or at least it's become non-standard in certain circumstances. What you do see is a trend that newer soft forks like SegWit and Taproot will make more and more restrictions on that particular opcode. And there was a proposal by Matt Corallo, the Great Consensus Cleanup in 2015, that would also make it invalid outside of SegWit or P2SH. Though that was controversial because there might be some really obscure transaction out there that uses it.
Sjors ProvoostSo anyway, that is really almost FUD. I guess I'm saying, oh my God, this proposal had this evil opcode inside of it, but it did. But at the time, of course, it wasn't probably considered that evil. So really the question was, you have three proposals. Which one are you going to pick? If you ignore all the drama, it's like you have three options. What do you want to do? You also kind of want to do it quickly because that was sort of Gavin Andresen's point. People are losing Bitcoin left and right. We should have more advanced scripts functionality. I don't know how much of that actually got used in the end.
Aaron van WirdumWell, let me... Well, I mean, pay-to-script-hash is used all the time, right?
Sjors ProvoostWell, if you ignore wrapped SegWit, it's only used for very standard multisig transactions. Probably two or three that you could have done with raw script.
Aaron van WirdumThat still counts.
Sjors ProvoostYeah, but you could already do those.
Aaron van WirdumThat was the whole point.
Sjors ProvoostYou could already do those with bare multisig. If you just make them standard and invent an address format. Was it worth the risk? I mean, that's the question, right? Is it worth making a change to Bitcoin that could break it and almost would have broken it in the case of OP_EVAL?
Aaron van WirdumWell, I want to first ask, so I want to take one step back because I feel we moved on before I was ready to move on.
Sjors ProvoostAll right.
Aaron van WirdumOkay, so how does CheckHashVerify, Luke Dashjr's alternative proposal, if you know this, how did it... prevent the loop-de-loops?
Sjors ProvoostI'm not sure if it did. I think it did.
Aaron van WirdumI mean, it must have, right? Because that was the whole point.
Sjors ProvoostYeah, I think you somehow split the script and the hash of the script in a way that it's interpreted, but you're not using eval, so you can't duplicate it. So eval would allow you to sort of recursively duplicate stuff. But I think here you would just have the hash and then you would have the script itself. And so I don't think you'd have any recursion or loops.
Aaron van WirdumSo, yeah.
Sjors ProvoostAs you can see, I did not study that proposal in enough detail.
Aaron van WirdumThat's fair. Yeah. So I think the real situation, I think OP_EVAL was kind of done, right? So then the debate was really about pay-to-script-hash and CheckHashVerify.
Sjors ProvoostYeah. And then, of course, the pay-to-script-hash was implemented by Gavin Andresen, who also implemented OP_EVAL and who was the lead maintainer. And so that probably got the most attention, the most review. So that also tends to... give it a little bit of favor almost by default if the other proposal was equal.
Aaron van WirdumYeah, and also very important to… there was ultimately kind of really a vote between the two and that was a hash power vote. Like the miners could pretty explicitly just vote for one or the other.
Sjors ProvoostYeah, I think both of them kind of went on a campaign. Well, I think Luke Dashjr used his own pool to campaign for it, and they may have also convinced some other ones. So there was something similar to BIP 9, though much more primitive. The idea that miners would put something in the block to say that they liked the proposal or not. So that happened.
Aaron van WirdumYeah, well, it was kind of a precursor to BIP 9, I would say, where BIP 9 was more about readiness signaling. Like that idea kind of evolved over the years. Well, for the very first time that hash power signaling was used, it was arguably actually like a vote. Like that's really what happened the first time, I would say. So that's how pay-to-script-hash got, at least is what I remember.
Sjors ProvoostThat was one element in it. But I mean, there was debate about whether that was a fair way to do it at all, because the lead maintainer, of course, had access to many more miners. So from a social point of view, he would be able to get more votes that way because miners would not look at the actual code. But there was another thing that happened, which I think was more fair, at least relatively. I think after some of the initial heated debate died down, some of the core devs at the time, so Greg Maxwell and Pieter Wuille and a few others, were asked to like take a few days, look at all three proposals and... Then they made a little chart
Sjors Provoostor a little diagram.
Aaron van WirdumOh, that's right.
Sjors ProvoostYeah, saying like, okay, this one I'm absolutely against or this one I have a preference for or this one is fine. And if you look at that little table, the P2SH also won in the sense that nobody was completely opposed to it, not even Luke, although he really didn't prefer it. And it had the preference of some of the experienced developers.
Aaron van WirdumYeah, I'll include the article Rizzo and I wrote in the show notes where this whole debate is sort of outlined.
Sjors ProvoostYeah, so I think it was a little bit more to it than just a brute vote, basically. There was more review on it. But nowadays, I think if you had a situation like this, it would not be resolved in a matter of days and weeks. And back then it was resolved in a matter of days or weeks, which is way too quick for something like this.
Aaron van WirdumRight, yeah. And I think, well, actually, I'm sure. Fairly sure that, for example, Greg Maxwell, who at the time… preferred BIP 16 has come around and said that BIP 17 would have actually been better.
Sjors ProvoostOkay, I didn't know that so that that could be the case.
Aaron van WirdumYeah, in in Greg Maxwell style, he just you know mentioned this off the cuff in some Reddit comment somewhere, so it's hard to find but I'm pretty sure that I'm like sure that he did it I just don't really remember the reason or the motivation.
Sjors ProvoostRight, I I read a post by him during these days where he was articulating very well why he supported the P2SH variant that we have now but obviously you know as time goes by he could have changed his mind on it.
Aaron van WirdumYeah, okay, so we've discussed what pay-to-script-hash is both in a sort of general sense as well as in a more specific sense of the proposal that we actually call pay-to-script-hash and that we use today.
Sjors ProvoostAnd to make a very quick jump to the future we still use this pattern Basically in the way we, in SegWit and in Taproot, the idea of there is a hash and the blockchain magically knows that this hash should be revealed as a script and then the script should be executed. So this whole idea of pattern matching is still there. And so apparently it's good enough to keep repeating it. Though there is also the argument of not writing new code if you don't have to.
Aaron van WirdumYeah, well, I was going to say, so we've discussed P2SH more generally, more specifically, and then also some of the proposals that were rejected OP_EVAL and CHV. Gave an idea about the historical context. Is that the episode, Sjors?
Sjors ProvoostI guess there's two little things that might be fun to mention briefly. One is that there was some screw up with the deployment. At least that's what I read in the overview of soft forks in general. Apparently, because of this mechanism, which was kind of a vote, but also kind of an automatic activation, depending on how you run your software, a subgroup of miners... activated the software too early, and so they started rejecting blocks basically they they I think they I don't know if they activated OP_EVAL accidentally, or they activated P2SH but
Sjors Provoostanyway they did it too early and they weren't in in the majority, so they couldn't enforce the software, so it's like an accidental UASF except they weren't like super passionate about it so they just went on I mean at the time Bitcoin was worth nothing so they didn't worth… they didn't lose like a giant fortune. And the other thing that is probably fun to mention is I think the software was backported to even older versions of Bitcoin Core, like version 0.3 and 0.5. And apparently something went wrong doing that. So those versions of Bitcoin Core would actually also fork themselves
Sjors Provoostoff the network. So they had to be sort of undone again. So I guess the question to Jameson Lopp is, was that a hard fork? But I don't know.
Aaron van WirdumYeah, there's so this was the pay-to-script-hash was the first soft fork after Satoshi left so it was also the first protocol upgrade after Satoshi left so it was the first time that developers started to figure out how to actually upgrade Bitcoin and who should do what what… so that's a you know that's kind of the start of that whole debate and it's very interesting in that sense but I would also say that's like a whole other episode or…
Sjors ProvoostYes.
Aaron van WirdumSo as far as pay-to-script-hash itself comes, I think we've kind of covered it at this point right?
Sjors ProvoostI think so. So okay, in that case, thank you for listening to Bitcoin,
Aaron and Sjors discuss Bitcoin Core 32.1 and its updated security disclosure policy in this live conference recording, followed by audience questions. Links Bitcoin Core 32.1 release announcement and release notes...
Aaron and Sjors discuss the COLDCARD hack: the bug itself, how it could have happened, and some reflections on having had Coinkite as a sponsor. Note: If you’re using a COLDCARD and still haven’t moved your funds to a...
The COLDCARD hardware wallet has a critical vulnerability. If you are using the COLDCARD to store bitcoin, move them to a secure location as soon as you can. More information:...
Aaron and Sjors discuss what’s new in Bitcoin Core 31. Chapters 00:00:00 Episode 100 and Core 31 00:02:41 Cluster Mempool 00:10:45 Package Relay and Fee Selection 00:18:59 Private Broadcast over Tor 00:24:03 ASMAP and...