Difference between revisions of "OP CODESEPARATOR"

Line 21: Line 21:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! ScriptSig part 2
+
! ScriptSig part 2 (signs only ScriptPubKey part 2)
! ScriptSig part 1
+
! ScriptSig part 1 (signs whole transaction)
 
! Auto inserted OCS
 
! Auto inserted OCS
 
! ScriptPubKey part 1
 
! ScriptPubKey part 1

Revision as of 10:23, 6 January 2020

OP_CODESEPARATOR is an opcode used in the script evaluation engine to determine what parts of a script must be hashed to create the message used when creating Digital Signatures (ECDSA) for Bitcoin transactions. The opcode is inserted automatically between the ScriptSig and ScriptPubKey prior to the evaluation taking place, however further instances of OP_CODESEPARATOR can be inserted into scripts to removing prior script sections from the message. This can allow transactions with multiple signatures to be built additively.

Example 1

The following is a basic P2PKH script:

ScriptSig Auto inserted OCS ScriptPubKey
SIG1 PK1 OP_CODESEPARATOR OP_DUP OP_HASH160 <pkh1> OP_EQUALVERIFY OP_CHECKSIG

The OP_CODESEPARATOR is added between the ScriptSig and ScriptPubKey by the script interpreter so that it can determine what part of the message must be checked against the signature. Everything that follows the OP_CODESEPARATOR is included in the message hash.

Example 2

This next example shows a more complex script with an addition OP_CODESEPARATOR which separates two P2PKH scripts being used in a multisignature type script.

ScriptSig part 2 (signs only ScriptPubKey part 2) ScriptSig part 1 (signs whole transaction) Auto inserted OCS ScriptPubKey part 1 OCS ScriptPubKey part 2
SIG2 PK2 SIG1 PK1 OP_CODESEPARATOR OP_DUP OP_HASH160 <pkh1> OP_EQUALVERIFY OP_CHECKSIGVERIFY OP_CODESEPARATOR OP_DUP OP_HASH160 <pkh2> OP_EQUALVERIFY OP_CHECKSIG

In this second example, the OP_CODESEPARATOR which is placed between the two elements of the ScriptPubKey removes the requirement for the keyholder unlocking ScriptPubkey part 2 to sign ScriptPubKey part 1. The keyholder unlocking ScriptPubKey part 1 must sign the entire ScriptPubKey message to unlock the UTXO.