TeachMeBitcoin

The Redeem Script

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Redeem Script and Unlocking P2SH

The Redeem Script is the heart of a P2SH transaction. It is the actual set of instructions that governs the spending of the coins. In a P2SH spend, the spender must provide both the signatures and the full Redeem Script itself.

1. What is a Redeem Script?

A Redeem Script is any valid Bitcoin script. The most common use case is a multisig script: OP_2 [PubKey1] [PubKey2] [PubKey3] OP_3 OP_CHECKMULTISIG

To create a P2SH address, you simply take the double-hash (Hash160) of this entire byte sequence.

2. The Unlocking Script (ScriptSig)

When spending, the ScriptSig must follow this pattern: [Signatures...] [Full Redeem Script]

3. The Two-Phase Execution

The Bitcoin Virtual Machine (BVM) processes P2SH in two distinct phases:

Phase A: Hash Verification

The BVM takes the Full Redeem Script from the end of the ScriptSig and hashes it. It compares this to the hash in the ScriptPubKey. If they match, the first part of the verification is successful.

Phase B: Script Execution

If Phase A passes, the BVM "unwraps" the Full Redeem Script and executes it as if it were the actual locking script. It uses the Signatures provided earlier in the ScriptSig to satisfy the conditions.

4. The Critical Rule

The Full Redeem Script must be the last item pushed in the ScriptSig. If it is placed anywhere else, the hashing step will fail, and the coins will be unspendable.

Step Data Logic
1 [Full Script] Must hash to the Target
2 [Signatures] Must satisfy the Full Script

In the next section, we will discuss the Benefits of P2SH in more detail.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!