Difference between revisions of "OP CODESEPARATOR"

Line 1: Line 1:
 
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.
 
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==
+
==Example 1==
 
The following is a basic [[Bitcoin Transactions#Pay to Public Key|P2PKH]] script:
 
The following is a basic [[Bitcoin Transactions#Pay to Public Key|P2PKH]] script:
  
Line 17: Line 17:
 
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.
 
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 [[Bitcoin Transactions#Pay to Public Key Hash|public key hash check]] and an [[Bitcoin Transactions#Pay to R-Puzzle Hash|R-Puzzle]]:
 
This next example shows a more complex script with an addition OP_CODESEPARATOR which separates [[Bitcoin Transactions#Pay to Public Key Hash|public key hash check]] and an [[Bitcoin Transactions#Pay to R-Puzzle Hash|R-Puzzle]]:
 
{| class="wikitable"
 
{| class="wikitable"
Line 27: Line 28:
 
! ScriptPubKey part 2
 
! ScriptPubKey part 2
 
|-
 
|-
 +
| SIG2 PK2
 
| SIG1 PK1
 
| SIG1 PK1
 
| OP_CODESEPARATOR
 
| OP_CODESEPARATOR

Revision as of 09:59, 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 public key hash check and an R-Puzzle:

ScriptSig part 2 ScriptSig part 1 Auto inserted OCS ScriptPubKey part 1 OCS ScriptPubKey part 2
SIG2 PK2 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.