OP CODESEPARATOR

Revision as of 06:27, 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.

Example

The following is a basic P2PK script:

ScriptSig Inserted OCS ScriptPubKey
SIG1 OP_CODESEPARATOR PK1 OP_CHECKSIG

The OP_CODESEPARATOR shown would normally be added by the script interpreter prior to the script being evaluated.

This script can be added to without SIG1 needing to be modified in the following way:

SIG1 SIG2 OP_CODESEPARATOR PK2 OP_CHECKSIG OP_CODESEPARATOR PK1 OP_CHECKSIG

In this second revision, we add SIG2 to the top of the stack. The OP_CHECKSIG after PK2 would sign back to the OP_CODESEPARATOR added by the interpreter, covering the whole ScriptPubKey, however the second OP_CHECKSIG would only sign back to the preceding OP_CODESEPARATOR, removing the added PK2 and OP_CHECKSIG from the signature message.