This post was first published on Medium.
Sighash preimage is what gets signed in a Bitcoin signature, whose format is as follows:
Part 5, scriptCode, usually contains the entire locking script. The only exception is when there is OP_CODESEPARATOR (OCS) in it. In this case, the scriptCode is the locking script but removing everything up to and including the last executed OCS before OP_CHECKSIG is executed.
OCS in sCrypt
Use Case: Optimizing OP_PUSH_TX
In many cases, scriptCode, or portion of it, is not needed when using OP_PUSH_TX. OCS can be used to cut its size. For example, in the following contract, only part 9, nLocktime, of the whole preimage is needed. We use Tx.checkPreimageOCS(), a variant of the conventional Tx.checkPreimage(). The only difference is that an OCS is inserted right before OP_CHECKSIG within the former. Also note we put Tx.checkPreimageOCS() as the last statement for maximal optimization.
After the change, the preimage size is cut from 915 to 201 bytes, a significant savings of ~80%.
Watch: CoinGeek New York presentation, Secure & Compliant Document Workflow using Blockchain
New to Bitcoin? Check out CoinGeek’s Bitcoin for Beginners section, the ultimate resource guide to learn more about Bitcoin—as originally envisioned by Satoshi Nakamoto—and blockchain.
View Original Source Here
Author: Xiaohui Liu