<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kcrary</id>
	<title>Bitcoin Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://en.bitcoin.it/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kcrary"/>
	<link rel="alternate" type="text/html" href="https://en.bitcoin.it/wiki/Special:Contributions/Kcrary"/>
	<updated>2026-04-24T18:14:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://en.bitcoin.it/w/index.php?title=BIP_0016&amp;diff=42028</id>
		<title>BIP 0016</title>
		<link rel="alternate" type="text/html" href="https://en.bitcoin.it/w/index.php?title=BIP_0016&amp;diff=42028"/>
		<updated>2013-10-28T18:29:14Z</updated>

		<summary type="html">&lt;p&gt;Kcrary: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{bip}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  BIP: 16&lt;br /&gt;
  Title: Pay to Script Hash&lt;br /&gt;
  Author: Gavin Andresen &amp;lt;gavinandresen@gmail.com&amp;gt;&lt;br /&gt;
  Status: Final&lt;br /&gt;
  Type: Standards Track&lt;br /&gt;
  Created: 03-01-2012&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Abstract==&lt;br /&gt;
&lt;br /&gt;
This BIP describes a new &amp;quot;standard&amp;quot; transaction type for the Bitcoin scripting system, and defines additional validation rules that apply only to the new transactions.&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
==Specification==&lt;br /&gt;
&lt;br /&gt;
A new standard transaction type that is relayed and included in mined blocks is defined:&lt;br /&gt;
&lt;br /&gt;
    OP_HASH160 [20-byte-hash-value] OP_EQUAL&lt;br /&gt;
&lt;br /&gt;
[20-byte-hash-value] shall be the push-20-bytes-onto-the-stack opcode (0x14) followed by exactly 20 bytes.&lt;br /&gt;
&lt;br /&gt;
This new transaction type is redeemed by a standard scriptSig:&lt;br /&gt;
&lt;br /&gt;
    ...signatures... {serialized script}&lt;br /&gt;
&lt;br /&gt;
Transactions that redeem these pay-to-script outpoints are only considered standard if the &#039;&#039;serialized script&#039;&#039; is, itself, one of the other standard transaction types.&lt;br /&gt;
&lt;br /&gt;
The rules for validating these outpoints when relaying transactions or considering them for inclusion in a new block are as follows:&lt;br /&gt;
&lt;br /&gt;
# Validation fails if there are any operations other than &amp;quot;push data&amp;quot; operations in the scriptSig.&lt;br /&gt;
# 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.&lt;br /&gt;
# {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.&lt;br /&gt;
&lt;br /&gt;
These new rules should only be applied when validating transactions in blocks with timestamps &amp;gt;= 1333238400 (Apr 1 2012) &amp;lt;ref&amp;gt;[https://github.com/bitcoin/bitcoin/commit/8f188ece3c82c4cf5d52a3363e7643c23169c0ff Remove -bip16 and -paytoscripthashtime command-line arguments]&amp;lt;/ref&amp;gt;. There are transactions earlier than 1333238400 in the block chain that fail these new validation rules. &amp;lt;ref&amp;gt;[http://blockexplorer.com/tx/6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192 Transaction 6a26d2ecb67f27d1fa5524763b49029d7106e91e3cc05743073461a719776192]&amp;lt;/ref&amp;gt;. Older transactions must be validated under the old rules. (see the Backwards Compatibility section for details).&lt;br /&gt;
&lt;br /&gt;
For example, the scriptPubKey and corresponding scriptSig for a one-signature-required transaction is:&lt;br /&gt;
&lt;br /&gt;
    scriptSig: [signature] {[pubkey] OP_CHECKSIG}&lt;br /&gt;
    scriptPubKey: OP_HASH160 [20-byte-hash of {[pubkey] OP_CHECKSIG} ] OP_EQUAL&lt;br /&gt;
&lt;br /&gt;
Signature operations in the {serialized script} shall contribute to the maximum number allowed per block (20,000) as follows:&lt;br /&gt;
&lt;br /&gt;
# OP_CHECKSIG and OP_CHECKSIGVERIFY count as 1 signature operation, whether or not they are evaluated.&lt;br /&gt;
# 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.&lt;br /&gt;
# All other OP_CHECKMULTISIG and OP_CHECKMULTISIGVERIFY are counted as 20 signature operations.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
+3 signature operations:&lt;br /&gt;
    {2 [pubkey1] [pubkey2] [pubkey3] 3 OP_CHECKMULTISIG}&lt;br /&gt;
&lt;br /&gt;
+22 signature operations&lt;br /&gt;
    {OP_CHECKSIG OP_IF OP_CHECKSIGVERIFY OP_ELSE OP_CHECKMULTISIGVERIFY OP_ENDIF}&lt;br /&gt;
&lt;br /&gt;
==Rationale==&lt;br /&gt;
&lt;br /&gt;
This BIP replaces BIP 12, which proposed a new Script opcode (&amp;quot;OP_EVAL&amp;quot;) to accomplish everything in this BIP and more.&lt;br /&gt;
&lt;br /&gt;
The Motivation for this BIP (and BIP 13, the pay-to-script-hash address type) is somewhat controversial; several people feel that it is unnecessary, and complex/multisignature transaction types should be supported by simply giving the sender the complete {serialized script}. The author believes that this BIP will minimize the changes needed to all of the supporting infrastructure that has already been created to send funds to a base58-encoded-20-byte bitcoin addresses, allowing merchants and exchanges and other software to start supporting multisignature transactions sooner.&lt;br /&gt;
&lt;br /&gt;
Recognizing one &#039;special&#039; 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.&lt;br /&gt;
&lt;br /&gt;
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. If there was no limit, a rogue miner might broadcast a block that required hundreds of thousands of ECDSA signature operations to validate, and it might be able to get a head start computing the next block while the rest of the network worked to validate the current one.&lt;br /&gt;
&lt;br /&gt;
There is a 1-confirmation attack on old implementations, but it is expensive and difficult in practice. The attack is:&lt;br /&gt;
&lt;br /&gt;
# Attacker creates a pay-to-script-hash transaction that is valid as seen by old software, but invalid for new implementation, and sends themselves some coins using it.&lt;br /&gt;
# Attacker also creates a standard transaction that spends the pay-to-script transaction, and pays the victim who is running old software.&lt;br /&gt;
# Attacker mines a block that contains both transactions.&lt;br /&gt;
&lt;br /&gt;
If the victim accepts the 1-confirmation payment, then the attacker wins because both transactions will be invalidated when the rest of the network overwrites the attacker&#039;s invalid block.&lt;br /&gt;
&lt;br /&gt;
The attack is expensive because it requires the attacker create a block that they know will be invalidated by the rest of the network. It is difficult because creating blocks is difficult and users should not accept 1-confirmation transactions for higher-value transactions.&lt;br /&gt;
&lt;br /&gt;
==Backwards Compatibility==&lt;br /&gt;
&lt;br /&gt;
These transactions are non-standard to old implementations, which will (typically) not relay them or include them in blocks.&lt;br /&gt;
&lt;br /&gt;
Old implementations will validate that the {serialize script}&#039;s hash value matches when they validate blocks created by software that fully support this BIP, but will do no other validation.&lt;br /&gt;
&lt;br /&gt;
Avoiding a block-chain split by malicious pay-to-script transactions requires careful handling of one case:&lt;br /&gt;
&lt;br /&gt;
* A pay-to-script-hash transaction that is invalid for new clients/miners but valid for old clients/miners.&lt;br /&gt;
&lt;br /&gt;
To gracefully upgrade and ensure no long-lasting block-chain split occurs, 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. &lt;br /&gt;
&lt;br /&gt;
To judge whether or not more than 50% of hashing power supports this BIP, miners are asked to upgrade their software and put the string &amp;quot;/P2SH/&amp;quot; in the input of the coinbase transaction for blocks that they create.&lt;br /&gt;
&lt;br /&gt;
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 &amp;quot;/P2SH/&amp;quot; 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. Approximately 1,000 blocks are created in a week; 550 should, therefore, be approximately 55% of the network supporting the new feature.&lt;br /&gt;
&lt;br /&gt;
If a majority of hashing power does not support the new validation rules, then rollout will be postponed (or rejected if it becomes clear that a majority will never be achieved).&lt;br /&gt;
&lt;br /&gt;
==Reference Implementation==&lt;br /&gt;
&lt;br /&gt;
https://gist.github.com/gavinandresen/3966071&lt;br /&gt;
&lt;br /&gt;
==See Also==&lt;br /&gt;
&lt;br /&gt;
* https://bitcointalk.org/index.php?topic=46538&lt;br /&gt;
* The [[BIP 0013|Address format for Pay to Script Hash BIP]]&lt;br /&gt;
* M-of-N Multisignature Transactions [[BIP 0011|BIP 11]]&lt;br /&gt;
* [[BIP_0016_QA|Quality Assurance test checklist]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:BIP|D]]&lt;/div&gt;</summary>
		<author><name>Kcrary</name></author>
	</entry>
</feed>