<p>A cryptographic hash function projects an arbitrary amount of data to a limited image space. In the case of P2SH, the hash is a RIPEMD160 hash, projecting the redeem script to an hash digest of exactly 20 B (160 b) length.</p>

<p>This is a trapdoor or one-way function that cannot be reverted (if it can be reverted, it's broken and therefore not a cryptographic hash function). Thus, a recipient cannot tell what redeem script was hashed to produce the P2SH address, and consequently cannot evaluate the validity of the redeem script.</p>

<p>If the recipient makes a mistake and provides the hash of an invalid script, there is no recourse.</p>

CC BY-SA 4.0
2018-07-11T14:05:20.633Z
Thanks for the thoughtful answer. So if the recipient makes a mistake the coins will simply be lost?
João Grilo Bitcoinheiro
CC BY-SA 4.0
2018-07-11T16:47:03.817Z
If the redeem script is unspendable, they are lost.
Murch
CC BY-SA 4.0
2018-07-11T03:23:55.273Z
2018-07-11T03:23:55.273Z
Murch
<p>No, it is not possible. The only way that a node can verify the hash is correct is by having the script itself and checking the hash. Even then, there is no guarantee that the hash really belongs to some other valid script that the node does not know about. Since there are an infinite number of scripts, it would be impossible to check all possible valid scripts and their hashes.</p>

CC BY-SA 4.0
2018-07-10T21:09:42.513Z
2018-07-10T21:09:42.513Z
Ava Chow
<p>I understand how the validation works if someone wants to spend coins from a multisig address. But what if the receiver makes a mistake and provides an invalid script hash to the sender? Is there anyway that nodes can verify if the hash is from a valid script?</p>

<hash><p2sh><validation>
How nodes verify if the hash on a P2SH output is from a valid script?
João Grilo Bitcoinheiro
# How nodes verify if the hash on a P2SH output is from a valid script?

(Asked by: username_0 on 2018-07-10)

I understand how the validation works if someone wants to spend coins from a multisig address. But what if the receiver makes a mistake and provides an invalid script hash to the sender? Is there anyway that nodes can verify if the hash is from a valid script?

**Tags:** hash, p2sh, validation


---

## 2 answers

### Answer by username_1 on 2018-07-11. Score: 2 | Accepted answer

A cryptographic hash function projects an arbitrary amount of data to a limited image space. In the case of P2SH, the hash is a RIPEMD160 hash, projecting the redeem script to an hash digest of exactly 20 B (160 b) length.

This is a trapdoor or one-way function that cannot be reverted (if it can be reverted, it's broken and therefore not a cryptographic hash function). Thus, a recipient cannot tell what redeem script was hashed to produce the P2SH address, and consequently cannot evaluate the validity of the redeem script.

If the recipient makes a mistake and provides the hash of an invalid script, there is no recourse.

> **Comments:**
> **username_0**: Thanks for the thoughtful answer. So if the recipient makes a mistake the coins will simply be lost?  
> **username_1**: If the redeem script is unspendable, they are lost.  

---

### Answer by username_2 on 2018-07-10. Score: 0

No, it is not possible. The only way that a node can verify the hash is correct is by having the script itself and checking the hash. Even then, there is no guarantee that the hash really belongs to some other valid script that the node does not know about. Since there are an infinite number of scripts, it would be impossible to check all possible valid scripts and their hashes.


---

