OP CODESEPARATOR

Revision as of 09:58, 6 January 2020 by Brendan (talk | contribs) (→‎Example)

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.

Examples

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.

This next example shows a more complex script with an addition OP_CODESEPARATOR which separates public key hash check and an R-Puzzle:

ScriptSig part 2 ScriptSig part 1 Auto inserted OCS ScriptPubKey part 1 OCS ScriptPubKey part 2
SIG1 PK1 OP_CODESEPARATOR OP_DUP OP_HASH160 <pkh1> OP_EQUALVERIFY OP_CHECKSIG 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.