Pay to script hash

P2SH

Locks to the hash of a script, which the spender reveals. Retired from Bitcoin at the Genesis upgrade.

What it is

A P2SH output holds the hash of a script, not the script itself. From 2012, a spender showed the matching script and met its conditions, and nodes ran that script as an extra step. Since the Genesis upgrade in 2020, nodes no longer take that extra step for new outputs, so this shape only checks the hash.

Script pattern

  1. OP_HASH160 Hashes the script the spender supplies.
  2. <script hash> 20 bytes: the hash the script must match.
  3. OP_EQUAL Succeeds only when the two hashes match.

23 bytes in all.

How it is spent

Before Genesis: the script's own unlock data, then the script. After it: the bytes that hash to the value in the lock.

Background

BIP 16 added P2SH in 2012, so that multisig and other long scripts could fit behind a short address. Genesis restored the original script rules at block 620,538, and P2SH was retired with that change. Outputs created before Genesis still spend by the old rule.

On chain

Examples coming. They come from the blocks we have typed, and no typed block holds one yet.

Specification