Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Samarkand on September 12, 2017, 11:39:06 AM



Title: P2SH address additional security
Post by: Samarkand on September 12, 2017, 11:39:06 AM
I read an article from Bitcoinwiki about Pay to script hash today:
https://en.bitcoin.it/wiki/Pay_to_script_hash

Quote
The recipient might need the signatures of several people to spend these bitcoins, or a password might be required, or the requirements could be completely unique.

This part sounds really interesting to me. What additional security measures are possible that are only hinted at in the quote? Does
anybody have a link where can I find a more detailed explanation of all the features that P2SH addresses offer in terms of security?


Title: Re: P2SH address additional security
Post by: achow101 on September 12, 2017, 02:00:59 PM
P2SH allows you to make and use whatever scripts you want and still have a standard transaction. There are fancy scripts you can make that would be considered non-standard if they were in an output. P2SH moves those scripts into the input and those scripts can be anything and still be considered standard. The requirements for spending from a P2SH address are unique because you can have any script you want. It is not that P2SH enables special things to be done, but rather it just makes those special things be standard scripts.


Title: Re: P2SH address additional security
Post by: mensa84 on September 13, 2017, 09:25:39 AM
P2SH just lets you be even more secure by easily putting more conditions on the redemption of your coins, like requiring more than 1 key to spend.

If I use P2SH, the scriptPubKey is just 23 bytes and the sender doesn't have to worry about what exactly the redeem condition I am setting on my coins is. P2SH works like this. I take the script that I want to be my scriptPubKey and I serialize it (I'll use {} to denote serialization):
Code:
redeemScript = {OP_3 {pubkey1} {pubkey2} {pubkey3} {pubkey4} {pubkey5} OP_5 OP_CHECKMULTISIG}
redeemScript_hash = hash160(sha256(redeemScript))

And then the scriptPubKey that the sender actually uses is:
Code:
OP_HASH160 {redeemScript_hash} OP_EQUAL

Which is just 23 bytes in total. The nice thing is that it provides a layer of abstraction. The person who is sending me coins doesn't need to know how I am keeping my coins secure. All they see is a hash of a redeemScript, but they don't know what conditions that redeemScript actually puts on redeeming the coins.

Basically, P2SH itself is not inherently more secure because the redeem script can be anything. But what it does is enable coin-receivers to easily communicate how coin-senders should send them coins, while letting the coin-receivers dictate the conditions of how/when those coins can be spent.