{"number":348,"title":"CHECKSIGFROMSTACK","authors":["Brandon Black","Jeremy Rubin"],"status":"Draft","type":"Specification","layer":"Consensus (soft fork)","created":"2024-11-26","license":"BSD-3-Clause","requires":[],"replaces":[],"replacedBy":[],"discussion":[],"abstract":"This BIP describes a new opcode for the purpose of checking cryptographic signatures in bitcoin scripts against data from the stack.","eli5":"Adds an instruction letting Bitcoin scripts verify a signature over any piece of data, not just over the spending transaction itself. That opens the door to things like delegating spending rights, using signed messages from outside parties (oracles), and building more efficient second-layer protocols.","categories":["consensus"],"filename":"bip-0348.md","githubUrl":"https://github.com/bitcoin/bips/blob/master/bip-0348.md","format":"markdown","readingMinutes":4,"inbound":2,"revisions":10,"impact":60,"core":false,"references":[],"lastModified":"2025-10-08","html":"<h2 id=\"abstract\">Abstract</h2>\n<p>This BIP describes a new opcode for the purpose of checking cryptographic\nsignatures in bitcoin scripts against data from the stack.</p>\n<h2 id=\"summary\">Summary</h2>\n<p>When verifying taproot script spends having leaf version 0xc0 (as defined in\n<a href=\"https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki\">BIP 342</a>), we propose <code>OP_CHECKSIGFROMSTACK</code> to replace <code>OP_SUCCESS204</code>\n(0xcc).</p>\n<p><code>OP_CHECKSIGFROMSTACK</code> has semantics similar to <code>OP_CHECKSIG</code>, as specified\nbelow. Briefly, it pops 3 elements from the stack: a 32-byte public key, a\nmessage, and a signature. If the signature is valid for that public key and\nmessage, 1 is pushed to the stack. If the signature is the empty vector, 0 is\npushed to the stack, and otherwise script execution fails.</p>\n<p>Only 32-byte keys are constrained. Similar to <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki\">BIP 342</a> unknown key types, for\nother key lengths no signature verification is performed and it is considered\nsuccessful.</p>\n<h2 id=\"specification\">Specification</h2>\n<ul>\n<li>If fewer than 3 elements are on the stack, the script MUST fail and terminate immediately.</li>\n<li>The public key (top element), message (second to top element), and signature (third from top element) are read from the stack.</li>\n<li>The top three elements are popped from the stack.</li>\n<li>If the public key size is zero, the script MUST fail and terminate immediately.</li>\n<li>If the public key size is 32 bytes, it is considered to be a public key as described in <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki\">BIP 340</a>:<ul>\n<li>If the signature is not the empty vector, the signature is validated against the public key and message according to <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki\">BIP 340</a>. Validation failure in this case immediately terminates script execution with failure.</li>\n</ul>\n</li>\n<li>If the public key size is not zero and not 32 bytes; the public key is of an unknown public key type. Signature verification for unknown public key types succeeds as if signature verification for a known public key type had succeeded.</li>\n<li>If the script did not fail and terminate before this step, regardless of the public key type:<ul>\n<li>If the signature is the empty vector: An empty vector is pushed onto the stack, and execution continues with the next opcode.</li>\n<li>If the signature is not the empty vector:<ul>\n<li>The opcode is counted towards the sigops budget as described in <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki\">BIP 342</a>.</li>\n<li>A 1-byte value 0x01 is pushed onto the stack.</li>\n</ul>\n</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"design-considerations\">Design Considerations</h2>\n<ol>\n<li>Message hashing: <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki\">BIP 340</a> is compatible with any size of message and does not require it to be a securely hashed input, so the message is not hashed prior to <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki\">BIP 340</a> verification.</li>\n<li>Lack of verify semantics: Adding a single opcode for this purpose keeps the implementation and design simple. An earlier draft had a verify variant as a NOP upgrade, and if this functionality is later brought to legacy scripts, that would be a good time to add a verify variant.</li>\n<li>Add/multisig: No concession is made to <code>OP_CHECKMULTISIG</code> or <code>OP_CHECKSIGADD</code> semantics with <code>OP_CHECKSIGFROMSTACK</code>. In Tapscript, add semantics can be implemented with 1 additional vByte per key (<code>OP_TOALTSTACK OP_CHECKSIGFROMSTACK OP_FROMALTSTACK OP_ADD</code>).</li>\n<li>Splitting R/S on the stack: Implementing split/separate signatures is left as an exercise for other bitcoin upgrades, such as <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0347.mediawiki\">BIP 347</a> (<code>OP_CAT</code>).</li>\n<li>APO-style (<a href=\"https://github.com/bitcoin/bips/blob/master/bip-0118.mediawiki\">BIP 118</a>) Taproot internal key: Rather than introducing an additional key type in this change, we suggest implementing <code>OP_INTERNALKEY</code> (<a href=\"https://github.com/bitcoin/bips/blob/master/bip-0349.md\">BIP 349</a>) or separately introducing that key type for all Tapscript signature checking operations in a separate change.</li>\n</ol>\n<h2 id=\"resource-limits\">Resource Limits</h2>\n<p>These opcodes are treated identically to other signature checking opcodes and\ncount against the sigops and budget.</p>\n<h2 id=\"motivation\">Motivation</h2>\n<h3 id=\"ln-symmetry\">LN Symmetry</h3>\n<p>When combined with <a href=\"https://github.com/bitcoin/bips/blob/master/bip-0119.mediawiki\">BIP 119</a> (<code>OP_CHECKTEMPLATEVERIFY</code>/CTV),\n<code>OP_CHECKSIGFROMSTACK</code> (CSFS) can be used to implement Lightning Symmetry\nchannels. The construction <code>OP_CHECKTEMPLATEVERIFY &lt;pubkey&gt; OP_CHECKSIGFROMSTACK</code> with a spend stack containing the CTV hash and a\nsignature for it is logically equivalent to <code>&lt;bip118_pubkey&gt; OP_CHECKSIG</code> and\na signature over <code>SIGHASH_ALL|SIGHASH_ANYPREVOUTANYSCRIPT</code>. The\n<code>OP_CHECKSIGFROMSTACK</code> construction is 8 vBytes larger.</p>\n<p>Summary of alternatives:</p>\n<ul>\n<li>CTV+CSFS is the minimal functionality needed for Lightning Symmetry but requires the use of an <code>OP_RETURN</code> for data availability</li>\n<li>APO is the original design for Lightning Symmetry and uses the taproot annex for data availability.</li>\n<li>LNHANCE (CTV+CSFS+IKEY+PC) is the most efficient and direct way currently designed to implement Lightning Symmetry.</li>\n</ul>\n<h3 id=\"delegation\">Delegation</h3>\n<p>Using a script like:\n<code>&lt;pubkey&gt; SWAP IF 2 PICK SWAP CSFS VERIFY ENDIF CHECKSIG</code>\neither direct verification or delegation can be achieved by the following\nunlock stacks: <code>&lt;sig&gt; 0</code> or <code>&lt;dsig&gt; &lt;dpubkey&gt; &lt;sig&gt; 1</code></p>\n<h3 id=\"advanced-delegation-when-combined-with-op-paircommit-or-op-cat\">Advanced delegation when combined with <a href=\"https://github.com/bitcoin/bips/pull/1699\">OP_PAIRCOMMIT</a> or OP_CAT</h3>\n<p>Using a script like:\n<code>CLTV OVER PAIRCOMMIT TOALT CHECKSIGVERIFY FROMALT &lt;pubkey&gt; CSFS</code>\nor:\n<code>CLTV SHA256 OVER CAT TOALT CHECKSIGVERIFY FROMALT &lt;pubkey&gt; CSFS</code>\nwith the unlock stack:\n<code>&lt;sig&gt; &lt;delegate_sig&gt; &lt;delegate_pubkey&gt; &lt;locktime&gt;</code></p>\n<p>Delegates to a public key after a lock time, enabling delegation to various\nkeys after various associated times.</p>\n<h2 id=\"reference-implementation\">Reference Implementation</h2>\n<p>A reference implementation is provided here:</p>\n<p><a href=\"https://github.com/bitcoin/bitcoin/pull/29270\">https://github.com/bitcoin/bitcoin/pull/29270</a></p>\n<h2 id=\"backward-compatibility\">Backward Compatibility</h2>\n<p>By constraining the behavior of an OP_SUCCESS opcode,\ndeployment of the BIP can be done in a backwards compatible, soft-fork manner.\nIf anyone were to rely on the OP_SUCCESS behavior of\n<code>OP_SUCCESS204</code>, <code>OP_CHECKSIGFROMSTACK</code> would invalidate\ntheir spend.</p>\n<h2 id=\"deployment\">Deployment</h2>\n<p>TBD</p>\n<h2 id=\"credits\">Credits</h2>\n<p>Reference implementation was made with reference to the implementation in\nElements and started by moonsettler.</p>\n<h2 id=\"copyright\">Copyright</h2>\n<p>This document is licensed under the 3-clause BSD license.</p>\n","toc":[{"id":"abstract","title":"Abstract","level":2},{"id":"summary","title":"Summary","level":2},{"id":"specification","title":"Specification","level":2},{"id":"design-considerations","title":"Design Considerations","level":2},{"id":"resource-limits","title":"Resource Limits","level":2},{"id":"motivation","title":"Motivation","level":2},{"id":"ln-symmetry","title":"LN Symmetry","level":3},{"id":"delegation","title":"Delegation","level":3},{"id":"advanced-delegation-when-combined-with-op-paircommit-or-op-cat","title":"Advanced delegation when combined with OP_PAIRCOMMIT or OP_CAT","level":3},{"id":"reference-implementation","title":"Reference Implementation","level":2},{"id":"backward-compatibility","title":"Backward Compatibility","level":2},{"id":"deployment","title":"Deployment","level":2},{"id":"credits","title":"Credits","level":2},{"id":"copyright","title":"Copyright","level":2}],"history":{"totalCommits":10,"firstCommit":"2024-04-24T14:40:53-07: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":"1dee48343649585d5a4b469edfc40a0187d819c2","date":"2025-03-10T16:20:42-04:00","author":"Antoine Poinsot","message":"Remove now unused reference to bip-0341","url":"https://github.com/bitcoin/bips/commit/1dee48343649585d5a4b469edfc40a0187d819c2","kind":"edit"},{"sha":"97a7edb0da7ec0ec7aaaff6cd43e106a3aee69e0","date":"2025-03-10T16:16:36-04:00","author":"Antoine Poinsot","message":"bip-0348: correct reference to Tapscript unknown key types","url":"https://github.com/bitcoin/bips/commit/97a7edb0da7ec0ec7aaaff6cd43e106a3aee69e0","kind":"edit"},{"sha":"726df6f4d54c7c7f9f1856ab37d07ece5defa0eb","date":"2025-02-08T20:04:18+10:00","author":"Anthony Towns","message":"Use code block instead of pre for markdown","url":"https://github.com/bitcoin/bips/commit/726df6f4d54c7c7f9f1856ab37d07ece5defa0eb","kind":"edit"},{"sha":"45fbec92cd6a1d016d96d6ce7616f9b346056112","date":"2024-12-16T15:23:08-05:00","author":"Danbo","message":"BIPs 348 and 379: spelling fixups (#1715)","url":"https://github.com/bitcoin/bips/commit/45fbec92cd6a1d016d96d6ce7616f9b346056112","kind":"edit"},{"sha":"f799ea1fa0509e45b0e5406e3ad19872ef5c240c","date":"2024-12-10T20:37:01-06:00","author":"kdmukai","message":"Trivial text correction","url":"https://github.com/bitcoin/bips/commit/f799ea1fa0509e45b0e5406e3ad19872ef5c240c","kind":"edit"},{"sha":"d2932bd00d16992d90df82d2a37db79c355046c4","date":"2024-04-24T14:40:53-07:00","author":"Brandon Black","message":"Add BIP 0348 - CHECKSGIFROMSTACK","url":"https://github.com/bitcoin/bips/commit/d2932bd00d16992d90df82d2a37db79c355046c4","kind":"edit"}]}}