This post was very first released on Medium.

OP_CODESEPARATOR is perhaps the most strange opcode in Bitcoin Script. We provide an intro to it and show its use in an useful application: enhancing preimage size in OP_PUSH_TX.


Sighash preimage is what gets checked in a Bitcoin signature, whose format is as follows:


scriptCode in Sighash Preimage

Part 5, scriptCode, generally includes the whole locking script. The only exception is when there is OP_CODESEPARATOR (OCS) in it. In this case, the scriptCode is the locking script however getting rid of whatever as much as and consisting of the last carried out OCS prior to OP_CHECKSIG is performed.

OCS in sCrypt

We have actually included OCS assistance in sCrypt. 3 or more in a line inserts an OCS. We have actually revealed 2 OCSs in the example listed below: very first represented by 3 asterisks, 2nd 5

P2PKH Contract with OCSs

We have actually likewise included assistance in our SDK and IDE considering that v1.4.1.

Use Case: Optimizing OP_PUSH_TX

In lots of cases, scriptCode, or part of it, is not required when utilizing OP_PUSH_TX. OCS can be utilized to cut its size. In the following agreement, just part 9, nLocktime, of the entire preimage is required. We utilize Tx.checkPreimageOCS(), a version of the traditional Tx.checkPreimage() The only distinction is that an OCS is placed right prior to OP_CHECKSIG within the previous. Note we put Tx.checkPreimageOCS() as the last declaration for optimum optimization.

CheckLockTimeVerifyOCS Contract

After the modification, the preimage size is cut from 915 to 201 bytes, a considerable cost savings of ~80%


We have actually shown the very first extensively appropriate use of OCS. Other prospective uses consist of in-script functions and signing various execution courses in off-chain deals.

Watch: CoinGeek New York discussion, Secure & Compliant Document Workflow utilizing Blockchain

New to Bitcoin? Have a look at CoinGeek’s Bitcoin for Beginners area, the supreme resource guide to get more information about Bitcoin– as initially pictured by Satoshi Nakamoto– and blockchain.


Please enter your comment!
Please enter your name here