How nodes verify if the hash on a P2SH output is from a valid script?

1

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?

Pitchas

Posted 2018-07-10T20:15:03.000

Reputation: 83

Answers

2

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.

Murch

Posted 2018-07-10T20:15:03.000

Reputation: 41 609

Thanks for the thoughtful answer. So if the recipient makes a mistake the coins will simply be lost?Pitchas 2018-07-11T14:05:20.633

If the redeem script is unspendable, they are lost.Murch 2018-07-11T16:47:03.817

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.

Andrew Chow

Posted 2018-07-10T20:15:03.000

Reputation: 40 910