Skip to content
BIP ATLAS

BIP 0016

How can a sender pay without knowing the spending rules?

The recipient chooses the spending conditions. The sender pays to their script hash. The spender later reveals the script and satisfies its rules.

Suppose a recipient wants two signatures to spend a payment. Without P2SH, the sender would have to understand that arrangement and put the complete spending script in the output. BIP 16 lets the recipient supply a script hash instead, so the sender can use the same payment form for different spending conditions.123

BIP 16, assigned in 2012 and recorded as deployed, turned that around. The sender pays to a fixed-length 20-byte hash of a script. The receiver keeps the script and reveals it only when spending. The author’s stated purpose was to move responsibility for the spending conditions from the sender to the redeemer.145

Source revision
bitcoin/bips @ 3a10b5b
Source checked
1 October 2026
Review state
Awaiting review
Source details

This chapter is an independent explanation, not the proposal itself. Preamble fields are shown as the pinned files record them, without author e-mail addresses. Status is the proposal’s own field. It is not an endorsement or a sign of consensus.

BIP 16: Pay to Script Hash

BIP
16
Layer
Consensus (soft fork)
Title
Pay to Script Hash
Authors
Gavin Andresen
Status
Deployed
Type
Specification
Assigned
2012-01-03

Pinned source · Reader view on bips.dev
SHA-256 9f89c0731bd718ae084802c897c95eb6f85ed2730d01fbc3233ee963b4679feb
Git blob 21d0e32278fd9ad6bbd049e0836526755d155e3d

Fig. A09.1 Twenty bytes now, the script later

Twenty bytes now, the script laterLegacy P2SH 2-of-2 (BIP 174 input 0). The output is 23 bytes and holds only the 20-byte hash 0fb9463421696b82c833af241c78c17ddbde4934. The spend reveals the 71-byte redeem script OP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIG; its HASH160, 0fb9463421696b82c833af241c78c17ddbde4934, equals the hash in the output.OUTPUT · 23 BTHE LOCK IS ONLY A HASH0fb94634…20 B, WHATEVER THE CONDITIONSREDEEM SCRIPT · 71 B · KEPT BY THE RECEIVEROP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIGHASH1600fb94634…=✓ THE SPEND'S SCRIPT HASHES TO THE LOCK
Exact values
Output script
a9140fb9463421696b82c833af241c78c17ddbde493487
Redeem script
5221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae
HASH160 of the redeem script (RIPEMD-160 of SHA-256)
0fb9463421696b82c833af241c78c17ddbde4934
The 2-of-2 multisig spend from BIP 174’s published trace. The output’s lock is only a hash; the spend supplies the script, and its HASH160 must give the lock back.2367

A fixed shape

Every P2SH output has the same three parts: OP_HASH160, a push of exactly 20 bytes, and OP_EQUAL. That is 23 bytes whether the hidden conditions are one key or fifteen. A spend supplies the signatures or other data the script needs, followed by the script itself, serialized as one more piece of pushed data. BIP 16 calls that last item the redeemScript.238

Fig. A09.2 A script behind a fixed-size output

A fixed output shapeLegacy P2SH 2-of-2: a 71-byte redeem script (OP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIG) gives a 23-byte output, OP_HASH160, the hash 0fb9463421696b82c833af241c78c17ddbde4934, OP_EQUAL.REDEEM SCRIPT, TO SCALEOUTPUT71 BLEGACY MULTISIGHASH160a9140fb9463…8723 B
Exact output hashes
Legacy P2SH 2-of-2
a9140fb9463421696b82c833af241c78c17ddbde493487
The published legacy spend reveals a 71-byte redeem script behind a 23-byte P2SH output.237

The BIP’s own example is the simplest case: a script that checks one signature against one key. The output holds the 20-byte hash of that script, and the spending scriptSig holds a signature and the script. Nothing in the output says what kind of script it is, or how many keys it has.19

The receiver must keep the full redeem script. Knowing its hash is enough to receive a payment, but spending requires the exact script bytes and data that make the script succeed.1210

How the script is hashed

The 20 bytes are the HASH160 of the script. This site’s model computes it as RIPEMD-160 of SHA-256, and Fig. A09.1 recomputes it for a real spend and compares it with the output byte for byte.37

Checked twice

BIP 16 gives the rules as three steps. First, the scriptSig may contain nothing but push operations; anything else fails. Second, normal validation runs. The pushed items become the stack and the output’s script hashes the top item. Validation fails at once if that hash differs from the one in the output.10

Third, and only for these outputs, the serialized script is popped off the stack, decoded, and run against whatever is left. The coin moves only if that second run also succeeds. The same pushed bytes are used twice: once as data to be hashed, once as a program.10

Start with the redeem script hidden, then reveal it and step through the spend. First watch the hash check, then watch the revealed script run. The script must match the commitment and satisfy its spending rules.6710

Fig. A09.3 One push, two evaluations

Static view: the published spend at its last stage. With JavaScript you can hide the redeem script and step through each check.

One push, two evaluationsThe output is 23 bytes: OP_HASH160, the 20-byte hash 0fb9463421696b82c833af241c78c17ddbde4934, OP_EQUAL. The spend reveals the 71-byte redeem script, OP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIG (legacy P2SH). Stages: 1 The scriptSig only pushes data, passes; 2 Its hash matches the output, passes; 3 The redeem script runs on the remaining stack, passes. Legacy P2SH 2-of-2, stage 3 of 3: The redeem script runs on the remaining stack. Finishes with true on top: the spend is valid.LEGACY P2SH 2-OF-2 · BIP 174 INPUT 0OUTPUT · 23 Ba9140fb94634…87OP_HASH160 · 20-BYTE HASH · OP_EQUALREDEEM SCRIPT · 71 B · LEGACY P2SHOP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIGHASH160 = 0fb94634… = THE LOCK1 PUSH-ONLY ✓2 HASH CHECK ✓3 SCRIPT RUNS ✓STACK LEFT AFTER THE SCRIPT IS POPPEDsignature · 72 Bsignature · 71 BemptyRUNS: OP_2 <33 BYTES> <33 BYTES> OP_2 OP_CHECKMULTISIGCHECKS: SIG 1 → KEY 1, SIG 2 → KEY 2LEFT ON THE STACK: TRUE✓ THE SPEND IS VALID
One push, two evaluationsThe output is 23 bytes: OP_HASH160, the 20-byte hash 0fb9463421696b82c833af241c78c17ddbde4934, OP_EQUAL. The spend reveals the 71-byte redeem script, OP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIG (legacy P2SH). Stages: 1 The scriptSig only pushes data, passes; 2 Its hash matches the output, passes; 3 The redeem script runs on the remaining stack, passes. Legacy P2SH 2-of-2, stage 3 of 3: The redeem script runs on the remaining stack. Finishes with true on top: the spend is valid.LEGACY P2SH 2-OF-2 · BIP 174 INPUT 0OUTPUT · 23 Ba9140fb94634…87OP_HASH160 · 20-BYTE HASH · OP_EQUALREDEEM SCRIPT · 71 B · LEGACY P2SHOP_2 <33 bytes> <33 bytes> OP_2 OP_CHECKMULTISIGHASH160 = 0fb94634… = THE LOCK1 PUSH-ONLY ✓2 HASH ✓3 SCRIPT ✓STACK LEFT AFTER THE SCRIPT IS POPPEDsignature · 72 Bsignature · 71 BemptyRUNS:OP_2 <33 BYTES> <33 BYTES> OP_2 OP_CHECKMULTISIGCHECKS: SIG 1 → KEY 1, SIG 2 → KEY 2LEFT ON THE STACK: TRUE✓ THE SPEND IS VALID

Legacy P2SH 2-of-2, stage 3 of 3: The redeem script runs on the remaining stack. Finishes with true on top: the spend is valid.

Exact values
Output script (23 bytes)
a9140fb9463421696b82c833af241c78c17ddbde493487
Redeem script (71 bytes)
5221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae
HASH160 of the redeem script
0fb9463421696b82c833af241c78c17ddbde4934

BIP 174 line 833. Recorded at build time by the tested model; every signature verified (noble) against the digest it computed. Nothing here signs. BIP 16 sigops for this redeem script: 2.

A legacy P2SH spend from BIP 174’s published trace demonstrates BIP 16’s rules. First check the script hash, then run the revealed script. The signature digests are computed at build time and both signatures verify.671011
Signature order in this example

Step through the legacy P2SH spend below. Its redeem script requires both keys to sign. Each signature must match a key in order. The tests behind this page swap the two signatures and the spend fails, even though both are valid signatures by the right keys. CHECKMULTISIG also takes one extra item off the stack; in this spend it is empty.711

Each stage can fail on its own. Change one byte of the redeem script inside the scriptSig and the hash no longer matches: the second stage stops the spend before the script ever runs. Put a non-push opcode into the scriptSig and the first stage stops it.1012

Fig. A09.4 Three ways to fail

  1. Three ways to fail, step 1 of 3With byte 70 of the redeem script changed from ae to af, its HASH160 is 7497726d053d5706176c8f5905c1ce50b158c242, not 0fb9463421696b82c833af241c78c17ddbde4934. Validation fails at the hash check.STAGE 1 ✓STAGE 2 ✗STAGE 3 ·HASH160 = 7497726d…≠ THE LOCK 0fb94634…

    Change one byte of the redeem script (its last, ae to af) and its hash no longer fits the lock: stage 2 fails.

  2. Three ways to fail, step 2 of 3With OP_DUP (0x76) in front of the scriptSig, it is no longer push-only and validation fails at stage 1.STAGE 1 ✗STAGE 2 ·STAGE 3 ·76THE PUSHESNOT PUSH-ONLY ✗

    Put a non-push opcode (OP_DUP, 0x76) in front of the scriptSig and stage 1 rejects it before anything runs.

  3. Three ways to fail, step 3 of 3With the two signatures in the other order the hash still matches, but CHECKMULTISIG walks the keys in order: signature 1 matches key 2, signature 2 finds no key left. The redeem script does not finish with true.STAGE 1 ✓STAGE 2 ✓STAGE 3 ✗SIGNATURES SWAPPED, AS THE MODEL RAN THEM:SIG 1 → KEY 2 ✓SIG 2 → NO KEY LEFT ✗

    Swap the two signatures: both are valid, but CHECKMULTISIG walks the keys in order and never goes back, so the script fails at stage 3.

Exact hashes
HASH160 of the altered script
7497726d053d5706176c8f5905c1ce50b158c242
Hash in the output
0fb9463421696b82c833af241c78c17ddbde4934
The legacy spend broken three ways and re-run through the same model; each fails at a different stage.101112
Caveat

The redeem script is hidden only until the first spend. After that it is public, in the spending transaction, for anyone to read.210

A later use: compatibility with SegWit

BIP 141 later reused P2SH so that older wallets could pay SegWit recipients through an address they already understood. This is an application of BIP 16’s fixed payment form. The witness rules and weight savings come from SegWit.131415

Fig. A09.5 Where the signatures live

Where the signatures liveLegacy P2SH: scriptSig 218 bytes (push bytes 4, signature 71, signature 72, redeem script 71); witness empty; weight 4 × 218 + 0 = 872. P2SH-P2WSH: scriptSig 35 bytes (push bytes 1, redeem script 34); witness 218 bytes (count, lengths 5, signature 71, signature 71, witness script 71); weight 4 × 35 + 218 = 358. P2SH-P2WPKH: scriptSig 23 bytes (push bytes 1, redeem script 22); witness 107 bytes (count, lengths 3, signature 71, public key 33); weight 4 × 23 + 107 = 199.LEGACY P2SHSCRIPTSIG · 218 Bsignaturesignatureredeem scriptWITNESS · NONE872 WUSCRIPTSIG + WITNESS: 4 × 218 + 0 = 872 WUP2SH-P2WSHSCRIPTSIG · 35 B← redeem scriptWITNESS · 218 Bsignaturesignaturewitness script358 WUSCRIPTSIG + WITNESS: 4 × 35 + 218 = 358 WUP2SH-P2WPKHSCRIPTSIG · 23 B← redeem scriptWITNESS · 107 Bsignature← public key199 WUSCRIPTSIG + WITNESS: 4 × 23 + 107 = 199 WU
scriptSig and witness of the three pinned spends, to one byte scale, with their weight. Wrapping leaves only the redeem script in the scriptSig and moves the signatures into the witness.141516
Later SegWit wrappers: scripts, signatures and weight

When SegWit arrived, BIP 141 reused this envelope. If the redeem script is exactly a witness version and a witness program, the output is a P2SH witness program. The scriptSig must hold nothing but that one push, and the real conditions move into the witness.14

The later comparison below shows two wrapped spends. In the P2SH-wrapped P2WPKH from BIP 143, the 22-byte redeem script wraps a 20-byte key-hash witness program; the witness holds a signature and the key. In the P2SH-wrapped P2WSH from BIP 174, the 34-byte redeem script wraps a 32-byte script-hash witness program, and the witness holds the signatures and the 2-of-2 script itself. Both redeem scripts begin with OP_0 and a one-byte push-length opcode: 14 for 20 bytes, 20 for 32 bytes, in hexadecimal. Their signatures commit to the BIP 143 digest, not the original one.6714

The difference shows in where the bytes sit. The legacy 2-of-2 puts 218 bytes in its scriptSig. The wrapped 2-of-2 needs a 35-byte scriptSig, and its witness serializes to 218 bytes. Since weight counts a byte outside the witness four times and a witness byte once, those bytes come to 872 weight units against 358, so moving the signatures makes the wrapped spend lighter.1516

The wrapper had a practical reason. BIP 141 lists, among the things a wallet that never upgraded can still do, sending bitcoin to upgraded wallets using a P2SH address. The payer sees an ordinary P2SH output; only the spender has to understand the witness.1314

Wrapped SegWit is still not native SegWit. The output is an ordinary 23-byte P2SH output and the scriptSig is not empty. BIP 141 notes that native P2WSH outputs use 34 bytes instead, and its authors chose the longer hash for better resistance to collision attacks.814

What fits inside the wrapper

Because the redeem script travels as pushed data, it obeys the 520-byte limit on any push. BIP 16 works the consequence through for multisig with 33-byte keys: three bytes plus 34 per key allows at most 15 keys, 513 bytes in all.17

Fig. A09.6 Why fifteen keys

Why fifteen keysA pushed item is at most 520 bytes. A multisig redeem script with 33-byte keys takes 3 bytes plus 34 per key, so 15 keys fit in 513 bytes and one more would need 547. The pinned 2-of-2 is 71 bytes: 3 + 34 × 2.0100200300400520 B LIMIT15 KEYS = 3 + 34 × 15 = 513 BA 16TH KEY WOULD NEED 547 B (DASHED)THIS SPEND'S 2 KEYS: 71 B = 3 + 34 × 2
A redeem script is pushed data, so 520 bytes at most: three bytes plus 34 per 33-byte key stops at fifteen keys.717

Signature operations inside the redeem script still count toward the block’s limit, by scanning rather than running. A CHECKSIG counts as one. A CHECKMULTISIG counts as its key count when preceded by OP_1 to OP_16, and as 20 otherwise. The BIP’s examples come to 3 and 22. The author explains that the counting is meant to be quick, and that the per-block limit protects miners from blocks crafted to be slow to validate.1819

The original rollout and the dates recorded in BIP 16

The rest is history the BIP records. It replaced an earlier proposal, BIP 12’s OP_EVAL, and the author describes recognizing one special output form as ugly, but less so than the alternatives. Its rollout asked miners to mark their blocks with /P2SH/, and its rules were to apply to blocks timestamped from 1 April 2012; some earlier transactions in the chain fail them. Old nodes, the BIP notes, check only that the hash matches, which is why it also discusses a costly one-confirmation attack against them.20212223

The rollout plan in the text is concrete. To avoid a lasting split, more than half of miners had to switch to the new rules at once. On 1 February 2012 the previous week’s blocks would be counted: with 550 or more of roughly 1,000 carrying /P2SH/, full validation would start for blocks after 15 February. The rule section, as recorded, names 1 April 2012 instead; the BIP keeps both dates, and this chapter does not try to reconcile them. To old software, meanwhile, these spends were non-standard: it would typically neither relay nor mine them.212425

Relay policy versus validation

One more distinction matters. BIP 16 says spends are only standard, meaning relayed and mined by default, if the redeem script is itself one of the standard script types. That was relay policy as BIP 16 states it, separate from the three validation rules that decide whether a block containing the spend is valid.26

P2SH gives the sender a fixed payment form while leaving the recipient to choose the spending conditions. Spending later brings those conditions into view and proves they were satisfied.1310

Evidence

Each numbered marker in the text points here, and the ↩ links lead back to the text. Quotes are verbatim from the BIP files at commit 3a10b5b, wiki markup included. Links open the exact lines. Labels say what kind of statement each entry is: a rule, the author’s rationale, history, a test vector, or our own inference.

  1. ↩ a b c d e Author’s rationale The author's aim is to move the job of supplying spending conditions from the sender to the redeemer, so a sender can fund any transaction, however complex, with a fixed 20-byte hash. The BIP records that some felt P2SH unnecessary, preferring to give the sender the complete script.

    Quoted source text (3)

    The purpose of pay-to-script-hash is to move the responsibility for supplying the conditions to redeem a transaction from the sender of the funds to the redeemer.

    BIP 16, line 17

    The benefit is allowing a sender to fund any arbitrary transaction, no matter how complicated, using a fixed-length 20-byte hash that is short enough to scan from a QR code or easily copied and pasted.

    BIP 16, line 19

    several people feel that it is unnecessary, and complex/multisignature transaction types should be supported by simply giving the sender the complete {serialized script}.

    BIP 16, line 66
  2. ↩ a b c d e f Rule It is redeemed by a scriptSig of signatures followed by the serialized script, also called the redeemScript.

    Quoted source text (2)

    ...signatures... {serialized script}

    BIP 16, line 31

    the ''serialized script'' - also referred to as the ''redeemScript'' -

    BIP 16, line 33
  3. ↩ a b c d e f Rule A P2SH output's script is OP_HASH160, a push of exactly 20 bytes, and OP_EQUAL.

    Quoted source text (1)

    OP_HASH160 [20-byte-hash-value] OP_EQUAL [20-byte-hash-value] shall be the push-20-bytes-onto-the-stack opcode (0x14) followed by exactly 20 bytes.

    BIP 16, lines 25–27
  4. ↩ History BIP 16 is a consensus soft-fork proposal by Gavin Andresen, assigned in 2012; its preamble records the status Deployed.

    Quoted source text (4)

    Layer: Consensus (soft fork)

    BIP 16, line 3

    Authors: Gavin Andresen

    BIP 16, line 5

    Status: Deployed

    BIP 16, line 6

    Assigned: 2012-01-03

    BIP 16, line 8
  5. ↩ Rule BIP 16 describes a new standard transaction type and additional validation rules that apply only to it.

    Quoted source text (1)

    This BIP describes a new "standard" transaction type for the Bitcoin scripting system, and defines additional validation rules that apply only to the new transactions.

    BIP 16, line 13
  6. ↩ a b c d Test vector BIP 174's published role trace ends in a transaction whose first input spends a legacy P2SH 2-of-2 multisig and whose second spends a P2SH-wrapped P2WSH 2-of-2; BIP 143 publishes a P2SH-wrapped P2WPKH example.

    Quoted source text (3)

    0200000000010258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd75

    BIP 174, line 833

    === P2SH-P2WPKH ===

    BIP 143, line 203

    scriptPubKey : a9144733f37cf4db86fbc2efed2500b4f4e49f31202387, value: 10 redeemScript : 001479091972186c449eb1ded22b78e40d009bdf0089

    BIP 143, lines 215–216
  7. ↩ a b c d e f g h Test vector For all three pinned spends, this site's model finds the scriptSig push-only and the redeem script's HASH160 (computed as RIPEMD-160 of SHA-256) equal to the output's, and every signature verifies (with noble) against the digest the model computes: the original digest for the legacy spend, BIP 143's for the wrapped ones.

    Quoted source text (1)

    # Validation fails if there are any operations other than "push data" operations in the scriptSig.

    BIP 16, lines 37–39
  8. ↩ a b Author’s rationale BIP 141 notes that a native P2WSH output takes 34 bytes against BIP 16's 23, a size its authors chose for better collision resistance.

    Quoted source text (1)

    The scriptPubKey occupies 34 bytes, as opposed to 23 bytes of BIP16 P2SH. The increased size improves security against possible collision attacks, as 280 work is not infeasible anymore

    BIP 141, line 216
  9. ↩ Rule The BIP's example is a one-signature script: the scriptSig holds a signature and the serialized {pubkey OP_CHECKSIG}, and the output holds its 20-byte hash.

    Quoted source text (1)

    scriptSig: [signature] {[pubkey] OP_CHECKSIG} scriptPubKey: OP_HASH160 [20-byte-hash of {[pubkey] OP_CHECKSIG} ] OP_EQUAL

    BIP 16, lines 45–46
  10. ↩ a b c d e f g h i Rule Validation fails if the scriptSig has anything but push operations; normal validation then hashes the serialized script and fails at once if it does not match the output; finally the serialized script is popped and the transaction is validated again with the remaining stack and the deserialized script.

    Quoted source text (1)

    # Validation fails if there are any operations other than "push data" operations in the scriptSig. # Normal validation is done: an initial stack is created from the signatures and {serialized script}, and the hash of the script is computed and validation fails immediately if it does not match the hash in the outpoint. # {serialized script} is popped off the initial stack, and the transaction is validated again using the popped stack and the deserialized script as the scriptPubKey.

    BIP 16, lines 37–39
  11. ↩ a b c Test vector In the legacy 2-of-2 spend, signature 1 matches key 1 and signature 2 matches key 2; with the two signatures swapped the redeem script fails, because the model's CHECKMULTISIG, like Bitcoin Core's, walks the keys in order. CHECKMULTISIG also pops one extra item, which here is empty.

    Quoted source text (1)

    the transaction is validated again using the popped stack and the deserialized script as the scriptPubKey.

    BIP 16, line 39
  12. ↩ a b Test vector Changing one byte of the redeem script inside the scriptSig makes its hash differ from the output and validation fails at the second stage; adding a non-push opcode to the scriptSig fails the first.

    Quoted source text (1)

    the hash of the script is computed and validation fails immediately if it does not match the hash in the outpoint.

    BIP 16, line 38
  13. ↩ a b Rule BIP 141 lists sending to upgraded wallets using a P2SH address among the things a non-upgraded wallet can still do.

    Quoted source text (2)

    What a non-upgraded wallet can do

    BIP 141, line 293

    Sending bitcoin to upgraded wallets using a P2SH address

    BIP 141, line 297
  14. ↩ a b c d e f Rule Under BIP 141, if the redeemScript is exactly a version push opcode, a one-byte push-length opcode and the witness-program bytes, it is a P2SH witness program: the scriptSig must be exactly a push of the redeemScript, and the witness carries the rest; a native witness program instead requires an exactly empty scriptSig. Signatures in version 0 witness programs use BIP 143's digest.

    Quoted source text (4)

    Triggered when a <code>scriptPubKey</code> is a P2SH script, and the BIP16 <code>redeemScript</code> pushed in the <code>scriptSig</code> is exactly a push of a version byte plus a push of a witness program. The <code>scriptSig</code> must be exactly a push of the BIP16 <code>redeemScript</code> or validation fails.

    BIP 141, line 92

    The scriptSig must be exactly empty or validation fails.

    BIP 141, line 91

    A new transaction digest algorithm is defined, but only applicable to sigops in version 0 witness program:

    BIP 143, line 27

    * First, byte 0x00 (<code>OP_0</code>) or any byte between 0x51 (<code>OP_1</code>) and 0x60 (<code>OP_16</code>) inclusive (the version byte). * Then, a byte ''L'' between 0x02 (push of 2 bytes) and 0x28 (push of 40 bytes) inclusive. * Finally, ''L'' arbitrary bytes (the witness program).

    BIP 141, lines 86–88
  15. ↩ a b c Rule Transaction weight is base size × 3 plus total size, so a byte outside the witness counts four times and a witness byte once.

    Quoted source text (1)

    ''Transaction weight'' is defined as ''Base transaction size'' * 3 + ''Total transaction size''

    BIP 141, line 140
  16. ↩ a b Test vector Measured on the pinned transactions: the legacy spend's scriptSig is 218 bytes with an empty witness; the P2SH-P2WSH spend's scriptSig is 35 bytes and its witness serializes to 218 bytes (item count and length prefixes included); the P2SH-P2WPKH spend's are 23 and 107. Counting scriptSig bytes four times and witness bytes once gives 872 against 358 weight units for the two 2-of-2 spends.

    Quoted source text (1)

    ''Transaction weight'' is defined as ''Base transaction size'' * 3 + ''Total transaction size''

    BIP 141, line 140
  17. ↩ a b Rule Because the serialized script is pushed like any other data, it cannot exceed 520 bytes, so a P2SH multisig with 33-byte keys can have at most 15 keys: 3 + 15 × 34 = 513 bytes.

    Quoted source text (2)

    no data greater than 520 bytes may be pushed to the stack. Thus it is not possible to spend a P2SH output if the redemption script it refers to is >520 bytes in length.

    BIP 16, line 102

    it is only possible to spend a P2SH output requiring a maximum of 15 pubkeys to redeem: 3 bytes + 15 pubkeys * 34 bytes/pubkey = 513 bytes

    BIP 16, line 102
  18. ↩ Rule Signature operations in the serialized script count toward the block limit: CHECKSIG as 1, CHECKMULTISIG after OP_1–OP_16 as that number, and any other CHECKMULTISIG as 20, whether or not they run; the BIP's examples count 3 and 22.

    Quoted source text (3)

    Signature operations in the {serialized script} shall contribute to the maximum number allowed per block (20,000) as follows: # OP_CHECKSIG and OP_CHECKSIGVERIFY count as 1 signature operation, whether or not they are evaluated. # OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY immediately preceded by OP_1 through OP_16 are counted as 1 to 16 signature operation, whether or not they are evaluated. # All other OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY are counted as 20 signature operations.

    BIP 16, lines 48–52

    +3 signature operations: {2 [pubkey1] [pubkey2] [pubkey3] 3 OP_CHECKMULTISIG}

    BIP 16, lines 56–57

    +22 signature operations: {OP_CHECKSIG OP_IF OP_CHECKSIGVERIFY OP_ELSE OP_CHECKMULTISIGVERIFY OP_ENDIF}

    BIP 16, lines 59–60
  19. ↩ Author’s rationale The author explains the counting rule is meant to be quick to apply by scanning the script, and that the block limit guards miners against denial-of-service blocks.

    Quoted source text (1)

    The signature operation counting rules are intended to be easy and quick to implement by statically scanning the {serialized script}. Bitcoin imposes a maximum-number-of-signature-operations per block to prevent denial-of-service attacks on miners.

    BIP 16, line 70
  20. ↩ Author’s rationale BIP 16 replaced BIP 12's proposed OP_EVAL; the author describes recognizing one special output form as ugly but less so than the alternatives, and notes the motivation was controversial.

    Quoted source text (3)

    This BIP replaces BIP 12, which proposed a new Script opcode ("OP_EVAL") to accomplish everything in this BIP and more.

    BIP 16, line 64

    The Motivation for this BIP (and BIP 13, the pay-to-script-hash address type) is somewhat controversial

    BIP 16, line 66

    Recognizing one 'special' form of scriptPubKey and performing extra validation when it is detected is ugly. However, the consensus is that the alternatives are either uglier, are more complex to implement, and/or expand the power of the expression language in dangerous ways.

    BIP 16, line 68
  21. ↩ a b History BIP 16 says its rules should apply only to blocks with timestamps from 1 April 2012, and that earlier transactions in the chain fail them; its rollout plan counted blocks carrying "/P2SH/" in the coinbase.

    Quoted source text (3)

    These new rules should only be applied when validating transactions in blocks with timestamps >= 1333238400 (Apr 1 2012)

    BIP 16, line 41

    There are transactions earlier than 1333238400 in the block chain that fail these new validation rules.

    BIP 16, line 41

    miners are asked to upgrade their software and put the string "/P2SH/" in the input of the coinbase transaction for blocks that they create.

    BIP 16, line 94
  22. ↩ Rule Old implementations check only that the serialized script's hash matches, and do no other validation, when they validate blocks from upgraded software.

    Quoted source text (1)

    Old implementations will validate that the {serialize script}'s hash value matches when they validate blocks created by software that fully support this BIP, but will do no other validation.

    BIP 16, line 86
  23. ↩ Author’s rationale The BIP describes a 1-confirmation attack on old implementations, which the author judges expensive and difficult in practice.

    Quoted source text (1)

    There is a 1-confirmation attack on old implementations, but it is expensive and difficult in practice.

    BIP 16, line 72
  24. ↩ History To avoid a lasting split, BIP 16 says more than 50% of miners had to enforce the new rules at the same time; its plan was to count blocks marked /P2SH/ over the week before 1 February 2012 and, with 550 or more of roughly 1,000, fully validate these spends in blocks after 15 February 2012.

    Quoted source text (2)

    more than 50% of miners must support full validation of the new transaction type and must switch from the old validation rules to the new rules at the same time.

    BIP 16, line 92

    On February 1, 2012, the block-chain will be examined to determine the number of blocks supporting pay-to-script-hash for the previous 7 days. If 550 or more contain "/P2SH/" in their coinbase, then all blocks with timestamps after 15 Feb 2012, 00:00:00 GMT shall have their pay-to-script-hash transactions fully validated.

    BIP 16, line 96
  25. ↩ Rule To old implementations these transactions are non-standard, so they typically neither relay nor mine them.

    Quoted source text (1)

    These transactions are non-standard to old implementations, which will (typically) not relay them or include them in blocks.

    BIP 16, line 84
  26. ↩ History Spends of these outputs are only considered standard if the redeemScript is itself one of the other standard types.

    Quoted source text (1)

    Transactions that redeem these pay-to-script outpoints are only considered standard if the ''serialized script'' - also referred to as the ''redeemScript'' - is, itself, one of the other standard transaction types.

    BIP 16, line 33