Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: Is there any useful place where OP_CODESEPARATOR is used?
by
pooya87
on 13/02/2022, 03:58:39 UTC
⭐ Merited by vapourminer (1)
Here is an example how you could use it in an interesting way: https://github.com/coins/bitcoin-scripts/blob/master/op-codeseparator.md
I think I saw this 2 months ago when I started the topic and it still doesn't make any sense. Take the last example:
Code:
OP_IF   
    # Case 1
    OP_CODESEPARATOR
    600300   
OP_ENDIF


OP_IF
    # Case 2
    OP_CODESEPARATOR
    600200   
OP_ENDIF


OP_IF 
    # Case 3
    OP_CODESEPARATOR
    600100   
OP_ENDIF


OP_CHECKLOCKTIMEVERIFY
OP_DROP

2
<Alice.Pubkey>
<Bob.Pubkey>
2
OP_CHECKMULTISIG 
When you spend it with something like
Code:
<Bob.SignatureCase1>
<Alice.SignatureCase1>
0 0 1
The first IF pops 1 but the second IF is not popping the 0, instead it pops 600300 that was pushed to the stack inside the conditional branch! And OP_CODESEPARATOR doesn't seem to be doing anything here. Then 600200 will be pushed to the stack to be popped by the next IF and finally 600100 which will be popped by OP_CHECKLOCKTIMEVERIFY.
So why not use a nested IF?
Code:
OP_IF
  600300
OP_ELSE
  OP_IF
    600200
  OP_ELSE
    600100
  OP_ENDIF
OP_ENDIF

OP_CHECKLOCKTIMEVERIFY
OP_DROP

2
<Alice.Pubkey>
<Bob.Pubkey>
2
OP_CHECKMULTISIG
It is shorter and achieves the same thing without OP_CODESEPARATOR.