{"number":17,"title":"OP_CHECKHASHVERIFY (CHV)","authors":["Luke Dashjr"],"status":"Closed","type":"Specification","layer":"Consensus (soft fork)","created":"2012-01-18","license":"BSD-2-Clause","requires":[],"replaces":[],"replacedBy":[],"discussion":[],"abstract":"This BIP describes a new opcode (OP_CHECKHASHVERIFY) for the Bitcoin scripting system, and a new 'standard' transaction type that uses it to enables the receiver of bitcoins to specify the transaction type needed to re-spend them.","eli5":"A competing proposal to P2SH that would have added a script command, OP_CHECKHASHVERIFY, letting recipients set their own spending conditions. The community chose BIP 16 instead, and this approach was not adopted.","categories":["scripts","opcodes"],"filename":"bip-0017.mediawiki","githubUrl":"https://github.com/bitcoin/bips/blob/master/bip-0017.mediawiki","format":"mediawiki","readingMinutes":4,"inbound":2,"revisions":16,"impact":69,"core":false,"references":[11,13],"lastModified":"2025-10-08","html":"<h2 id=\"abstract\">Abstract</h2>\n<p>This BIP describes a new opcode (OP_CHECKHASHVERIFY) for the Bitcoin scripting system, and a new 'standard' transaction type that uses it to enables the receiver of bitcoins to specify the transaction type needed to re-spend them.</p>\n<h2 id=\"copyright\">Copyright</h2>\n<p>This BIP is licensed under the BSD 2-clause license.</p>\n<h2 id=\"motivation\">Motivation</h2>\n<p>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.</p>\n<p>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.</p>\n<h2 id=\"specification\">Specification</h2>\n<p>OP_CHECKHASHVERIFY will re-define the existing OP_NOP2 opcode, and will function as follows when executed:</p>\n<ul><li>\nFirst, hash the end of the prior script (in the general case, scriptSig; if no prior script, a null string is hashed) beginning from the last evaluated OP_CODESEPARATOR onward (or from the beginning of the script, if no OP_CODESEPARATOR was present)\n</li></ul>\n<ul><li>\nThen, compare this with the item on the top of the stack (if there is none, the script fails immediately)\n</li></ul>\n<ul><li>\nIf the hashes match, do nothing, proceed as if an OP_NOP; if they do not match, the script fails immediately.\n</li></ul>\n<ul><li>\nNote that in the case of a matched hash, the top stack item (the hash being compared with) is <u>not</u> popped off the stack. This is for backward compatibility.\n</li></ul>\n<p>This opcode reassignment shall be applied when validating transactions in blocks only with timestamps after February 23, 2012 (see the Backwards Compatibility section for details).</p>\n<p>A new standard transaction type that is relayed and included in mined blocks is defined:</p>\n<p>[20-byte-hash-value] OP_CHECKHASHVERIFY OP_DROP</p>\n<p>[20-byte-hash-value] shall be the push-20-bytes-onto-the-stack opcode (0x14) followed by exactly 20 bytes.</p>\n<p>This new transaction type is redeemed by a standard scriptSig:</p>\n<p>...signatures... OP_CODESEPARATOR {script}</p>\n<p>Transactions that redeem these pay-to-script outpoints are only considered standard if they contain exactly one OP_CODESEPARATOR and the appended <em>script</em> is, itself, one of the other standard transaction types.</p>\n<h2 id=\"example\">Example</h2>\n<p>For example, the scriptPubKey and corresponding scriptSig for a one-signature-required transaction is:</p>\n<p>scriptSig: [signature] OP_CODESEPARATOR [pubkey] OP_CHECKSIG     scriptPubKey: [20-byte-hash of {[pubkey] OP_CHECKSIG} ] OP_CHECKHASHVERIFY OP_DROP</p>\n<p>2-of-3:</p>\n<p>scriptSig: [signatures...] OP_CODESEPARATOR 2 [pubkey1] [pubkey2] [pubkey3] 3 OP_CHECKMULTISIG     scriptPubKey: [20-byte-hash of {2 [pubkey1] [pubkey2] [pubkey3] 3 OP_CHECKMULTISIG} ] OP_CHECKHASHVERIFY OP_DROP</p>\n<h2 id=\"rationale\">Rationale</h2>\n<p>This BIP replaces BIP 12 and BIP 16, which propose evaluating a Script from the stack after verifying its hash.</p>\n<p>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.</p>\n<p>There is a 1-confirmation attack on old implementations, but it is expensive and difficult in practice. The attack is:</p>\n<ol><li>\nAttacker 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.\n</li></ol>\n<ol><li>\nAttacker also creates a standard transaction that spends the pay-to-script transaction, and pays the victim who is running old software.\n</li></ol>\n<ol><li>\nAttacker mines a block that contains both transactions.\n</li></ol>\n<p>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's invalid block.</p>\n<p>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.</p>\n<h2 id=\"backwards-compatibility\">Backwards Compatibility</h2>\n<p>These transactions are non-standard to old implementations, which will (typically) not relay them nor include them in blocks.</p>\n<p>Old implementations will not validate that the {script}'s hash value matches when they validate blocks created by software that fully support this BIP.</p>\n<p>Avoiding a block-chain split by malicious pay-to-script transactions requires careful handling of one case:</p>\n<ul><li>\nA pay-to-script-hash transaction that is invalid for new clients/miners but valid for old clients/miners.\n</li></ul>\n<p>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.</p>\n<p>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 \"p2sh/CHV\" in the input of the coinbase transaction for blocks that they create.</p>\n<p>On February 8, 2012, the block-chain will be examined to determine the number of blocks supporting pay-to-script-hash for the previous 7 days. If at least 60% contain \"p2sh/CHV\" in their coinbase, then all blocks with timestamps after 23 Feb 2012, 00:00:00 GMT shall have their pay-to-script-hash transactions validated.</p>\n<p>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).</p>\n<p>OP_NOP2 is used, so existing OP_EVAL (BIP 12) transactions in the block chain can still be redeemed.</p>\n<h2 id=\"reference-implementation\">Reference Implementation</h2>\n<p><a href=\"https://gitorious.org/~Luke-Jr/bitcoin/luke-jr-bitcoin/commits/checkhashverify\">Validation, sending, and receiving for bitcoind git master</a></p>\n<p><a href=\"https://gitorious.org/~Luke-Jr/bitcoin/luke-jr-bitcoin/commits/checkhashverify_backport\">Validation only for 0.3.19+</a></p>\n<h2 id=\"see-also\">See Also</h2>\n<ul><li>\nThe <a href=\"/bip/13\">Address format for Pay to Script Hash BIP</a>\n</li></ul>\n<ul><li>\n<a href=\"/bip/11\">M-of-N Multisignature Transactions (BIP 11)</a>\n</li></ul>\n<ul><li>\nExample BIP 17 transaction chain: <a href=\"http://blockexplorer.com/tx/b8fd633e7713a43d5ac87266adc78444669b987a56b3a65fb92d58c2c4b0e84d\">a</a> <a href=\"http://blockexplorer.com/tx/eb3b82c0884e3efa6d8b0be55b4915eb20be124c9766245bcc7f34fdac32bccb\">b</a> <a href=\"http://blockexplorer.com/tx/055707ce7fea7b9776fdc70413f65ceec413d46344424ab01acd5138767db137\">c</a> <a href=\"http://blockexplorer.com/tx/6d36bc17e947ce00bb6f12f8e7a56a1585c5a36188ffa2b05e10b4743273a74b\">d</a>\n</li></ul>","toc":[{"id":"abstract","title":"Abstract","level":2},{"id":"copyright","title":"Copyright","level":2},{"id":"motivation","title":"Motivation","level":2},{"id":"specification","title":"Specification","level":2},{"id":"example","title":"Example","level":2},{"id":"rationale","title":"Rationale","level":2},{"id":"backwards-compatibility","title":"Backwards Compatibility","level":2},{"id":"reference-implementation","title":"Reference Implementation","level":2},{"id":"see-also","title":"See Also","level":2}],"history":{"totalCommits":16,"firstCommit":"2012-01-27T18:51:24+00:00","lastUpdated":"2025-10-08T14:59:36-07:00","events":[{"sha":"24e96e870fffaa257b465ce1f0370c14aac588e8","date":"2025-10-08T14:59:36-07:00","author":"Murch","message":"process: Created ↦ Assigned","url":"https://github.com/bitcoin/bips/commit/24e96e870fffaa257b465ce1f0370c14aac588e8","kind":"edit"},{"sha":"5207ef92a52d0b8902895b0dbb40823a4d698ec9","date":"2025-04-11T20:08:17-07:00","author":"Murch","message":"process: Author ↦ Authors","url":"https://github.com/bitcoin/bips/commit/5207ef92a52d0b8902895b0dbb40823a4d698ec9","kind":"edit"},{"sha":"59730dec4fb641a41589aa1b91d3c452f13e0e36","date":"2025-04-11T20:05:13-07:00","author":"Murch","message":"process: Remove Comments-URI and -Summary","url":"https://github.com/bitcoin/bips/commit/59730dec4fb641a41589aa1b91d3c452f13e0e36","kind":"edit"},{"sha":"a233bde4af52c6a11269e2e6dd9707abce441ffe","date":"2025-04-11T18:19:21-07:00","author":"Murch","message":"process: Standards Track ↦ Specification","url":"https://github.com/bitcoin/bips/commit/a233bde4af52c6a11269e2e6dd9707abce441ffe","kind":"edit"},{"sha":"66defbdc03ad64ccddfd373e1c59af9a41ab990f","date":"2025-04-11T18:11:55-07:00","author":"Murch","message":"process: Deferred/Obsolete/Rejected/Replaced/Withdrawn ↦ Closed","url":"https://github.com/bitcoin/bips/commit/66defbdc03ad64ccddfd373e1c59af9a41ab990f","kind":"status"},{"sha":"9a56d3544eac1f949a747c251810f7a440d63fb9","date":"2024-07-25T18:35:39+03:00","author":"Orfeas Stefanos Thyfronitis Litos","message":"Remove trailing whitespace from all BIPs","url":"https://github.com/bitcoin/bips/commit/9a56d3544eac1f949a747c251810f7a440d63fb9","kind":"edit"},{"sha":"395262bd1d26263b0105b5ac96782b3f3cf3bf71","date":"2016-11-30T10:09:54+00:00","author":"Luke Dashjr","message":"BIPs 17, 18, 19, 20, 22, and 23: Add missing Copyright section","url":"https://github.com/bitcoin/bips/commit/395262bd1d26263b0105b5ac96782b3f3cf3bf71","kind":"edit"},{"sha":"959fecc15bdad070afa63455468b1dba54655fa6","date":"2016-11-30T09:47:31+00:00","author":"Luke Dashjr","message":"Promote BIP 2 Draft->Active, and implement it","url":"https://github.com/bitcoin/bips/commit/959fecc15bdad070afa63455468b1dba54655fa6","kind":"status"},{"sha":"72f18918a8ae655212ea2700b30f0dc4d758b843","date":"2016-11-30T09:45:33+00:00","author":"Luke Dashjr","message":"Promote BIP 123 Draft->Active, and implement it","url":"https://github.com/bitcoin/bips/commit/72f18918a8ae655212ea2700b30f0dc4d758b843","kind":"status"},{"sha":"5866744d0ebe8fe40bf7d0ea79eb7fa67d562794","date":"2015-09-04T02:13:37+00:00","author":"Luke Dashjr","message":"Bugfix: BIP17: Withdrawn is the status, not the type","url":"https://github.com/bitcoin/bips/commit/5866744d0ebe8fe40bf7d0ea79eb7fa67d562794","kind":"status"},{"sha":"1647c7e6d3e3866454b803fd874df2d0c4991f4a","date":"2014-04-05T13:46:56+02:00","author":"Wladimir J. van der Laan","message":"Change date format to ISO 8601","url":"https://github.com/bitcoin/bips/commit/1647c7e6d3e3866454b803fd874df2d0c4991f4a","kind":"edit"},{"sha":"d9e890a8f27e46806238e298a346397871fd7e87","date":"2013-10-21T02:18:47-04:00","author":"Peter Todd","message":"Fix formatting","url":"https://github.com/bitcoin/bips/commit/d9e890a8f27e46806238e298a346397871fd7e87","kind":"edit"},{"sha":"16fe80c1c61b0d78581af78854e419f7ab544c69","date":"2013-10-21T00:44:39-04:00","author":"Peter Todd","message":"Archive Revision as of 17:37, 28 April 2013","url":"https://github.com/bitcoin/bips/commit/16fe80c1c61b0d78581af78854e419f7ab544c69","kind":"edit"},{"sha":"1f64d2b06d628dffdc297be9a8afbb9da4e6b6ca","date":"2013-10-21T00:32:10-04:00","author":"Peter Todd","message":"Rename to mediawiki extension","url":"https://github.com/bitcoin/bips/commit/1f64d2b06d628dffdc297be9a8afbb9da4e6b6ca","kind":"rename"},{"sha":"d0c10bae34af073b8a0e06aa496b5afc5e84b24d","date":"2012-03-13T19:45:23-04:00","author":"Luke Dashjr","message":"Withdraw BIP 17","url":"https://github.com/bitcoin/bips/commit/d0c10bae34af073b8a0e06aa496b5afc5e84b24d","kind":"edit"},{"sha":"823066539702dcf9af226527454281919c3d8265","date":"2012-01-27T18:51:24+00:00","author":"genjix","message":"BIP 0017","url":"https://github.com/bitcoin/bips/commit/823066539702dcf9af226527454281919c3d8265","kind":"edit"}]}}