How do Scripts work?

20

13

Bitcoin protocol supports scripts.

  • How do they work?
  • How are those implemented?
  • What are their intended usages?
  • When are they planned to be used?

ripper234

Posted 2011-09-04T14:46:21.473

Reputation: 25 192

I asked this as one question, if you think it's more appropriate as separate questions let me know.ripper234 2011-09-04T14:46:49.023

1

Related question providing script references: http://bitcoin.stackexchange.com/q/547/117

Gary Rowe 2011-09-05T14:12:28.340

Answers

33

Scripts are one of Bitcoin's more clever features. The most obvious way to implement a crypto-currency is to make a transfer be to a public key. To claim the transfer, you sign with the corresponding private key. This is not the way Bitcoin works.

When you send Bitcoins (the out of a transaction), you send them to a script. When you claim Bitcoins (the in) of a transaction) you claim them with a script. To determine if a transaction input correctly claims a transaction output, the two scripts are combined and the result is executed. If the result is true, then the input claims the output. The scripting language is stack-based and roughly similar to Forth.

The transaction input (the script trying to claim the Bitcoins) runs first. It will typically put a public key and a signature onto the stack. Then the output (the script whose Bitcoins are being claimed) runs. It will typically confirm that the public key is the correct one and that the signature signs the transaction with the corresponding private key.

Thus, you get the same effect as if you just specified a public key and signature, but you have the option of specifying more complex scripts. Unfortunately, this kind of simple script is pretty much the only kind of script supported right now. The original developer(s) imagined much more interesting scripts including things like contracts, multi-party signatures, and so on.

M of N signatures are planned. This way, you could list, say 3 public keys such that any 2 of them could claim the Bitcoins.

Unfortunately, some of the scripting components are feared to have security risks, so many of them are disabled currently.

David Schwartz

Posted 2011-09-04T14:46:21.473

Reputation: 46 931

Coolness. I never knew how integrated scripts were to the protocol.ripper234 2011-09-04T17:21:54.873