Reading Assignment: Script

Welcome to this reading assignment on the Script programming language. If you haven’t already, read through the wiki page (https://en.bitcoin.it/wiki/Script) describing all the op-codes in script and answer the following questions. Post your answers in this forum thread.

  1. What is the practical difference between OP_OP_CHECKSIG and OP_OP_CHECKSIGVERIFY?
  2. What is the “Pop” functions called in Script? (It is not called OP_POP)
  3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
2 Likes
  1. What is the practical difference between OP_OP_CHECKSIG and OP_OP_CHECKSIGVERIFY?
    Answer:
    OP_CHECKSIG returns either 1 or 0 for True/False; thus, OP_OP_CHECKSIG would be OP of the return value from the first operation which is OP_1 or OP_0 (still returns True or False)
    OP_CHECKSIGVERIFY performs first the operations which is OP_CHECKSIG; returns stated above, thereafter performs OP_VERIFY on the return. This would return fail (mark the transaction invalid and remove it from the top of the stack) if the input value is false.
    So OP_OPCHECKSIGVERIFY would be the OP of the return from OP_CHECKSIGVERIFY.
  2. What are the “Push” and “Pop” functions called in Script? (They are not called OP_PUSH and OP_POP)
    Answer
    No idea (help me out)
  3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
    Answer: 174
1 Like
  1. Hint. Look through the script wiki page and go down to the script section with op-codes. There you will find them: https://en.bitcoin.it/wiki/Script
  2. Correct, but in hex it is 0xae

1. What is the practical difference between OP_OP_CHECKSIG and OP_OP_CHECKSIGVERIFY?
OP_CHECKSIG will push TRUE (1) or FALSE (0) to the stack after evaluating 2 input parameters (public key and signature of the script). OP_CHECKSIGVERIFY (is combination of OP_CHECKSIG and OP_VERIFY) leaves nothing on the stack after evaluation and will fail the script if the OP_CHECKSIG doesn’t return true.

2. What are the “Push” and “Pop” functions called in Script? (They are not called OP_PUSH and OP_POP)
POP: OP_DROP (removes the top item from the stack but doesn’t do anything with it, there are other OPcodes that pop items from the stack, for example: OP_NIP, OP_2DROP, …)

PUSH: no specific OPcode found for this. But there are OPcodes that push data onto the stack (OP_DUP, OP_OVER, OP_2DUP, …)

3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
it is 0xae

1 Like

1. What is the practical difference between OP_CHECKSIG and OP_CHECKSIGVERIFY?
OP_CHECKSIG checks to see if the hash is true (1) or false (0) giving the corresponding output.
OP_CHECKSIGVERIFY does the same thing then calls OP_VERIFY which checks the top stack value. If the value is false (0) it marks it as invalid and then removes it.

2. What are the “Push” and “Pop” functions called in Script? (They are not called OP_PUSH and OP_POP)

Push: The functions listed from @filip’s hint are not directly a Push OP but could be any of the following which adds a constant to the stack:
OP_CHECKLOCKTIMEVERIFY
OP_DROP
OP_DUP
OP_HASH160 <pubKeyHash>
OP_EQUALVERIFY
OP_CHECKSIG

POP: OP_DROP

3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
0xae

4 Likes

That’s a good point. I’ve edited the question now to make it easier.

  1. The practical difference between them is that OP_CHECKSIGVERIFY calls OP_VERIFY in the end, which means that it returns nothing or fails instead of returning true/false like in OP_CHECKSIG
  2. OP_DROP is the opcode to only remove the top stack item, but there are two others to remove (pop) items like OP_NIP which removes the second from the top and OP_2DROP that removes the top two.
  3. 0xae
1 Like
  • What is the practical difference between OP_OP_CHECKSIG and OP_OP_CHECKSIGVERIFY?

OP_CHECKSIGVERIFY combines OP_CHECKSIG and OP_VERIFY (OP_VERIFY is pushed to stack after the result of OP_CHECKSIG. Actually, after OP_CHECKSIG itself).

  • What is the “Pop” functions called in Script? (It is not called OP_POP)

Not sure I understand this question. Is it about OP_DROP removing the top element from the stack?

  • What is the hexadecimal OP Code for OP_CHECKMULTISIG?
    0xAE
1 Like
  1. What is the practical difference between OP_CHECKSIG and OP_CHECKSIGVERIFY?
    OP_CHECKSIG hashes the entire transaction’s outputs, inputs and script (from the most recently-executed OP_CODESEPARATOR to the end). OP_CHECKSIGVERIFY does the same, but OPVERIFY is executed afterwards, namely the transaction is marked as invalid if top stack value is not true.

  2. What are the “Pop” functions called in Script? (It is not called OP_POP)
    OP_DROP, OP_NIP, OP_2DROP
    Did I miss some other “Pop” functions?

  3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
    0xae

1 Like
  1. “Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.”
  2. Not sure there’s a single one, can’t find it. Any op that takes values from the stack and then puts a result back, like OP_ADD, etc.?
  3. 0xae

I don’t understand how OP_DROP is a pop. I’ve always understood pop to mean get it from the stack and use it. To throw it away and not give access to the value like OP_DROP I don’t think of as a pop - since nothing is done with the value. However OP_DROP does remove it from the stack. And there are a ton of other opcodes that pop the stack too… :slight_smile:

1 Like

Well yeah, you might be right on that definition. Maybe I shouldn’t refer to it as pop.

  1. What is the practical difference between OP_OP_CHECKSIG and OP_OP_CHECKSIGVERIFY?
    OP_CHECKSIG checks the hash and OP_CHECKSIGVERIFY calls OP_VERIFY as well which checks the top stack value.

  2. What is the “Pop” functions called in Script? (It is not called OP_POP)
    It popped the last value out of the stack.

  3. What is the hexadecimal OP Code for OP_CHECKMULTISIG?
    0xae

2 Likes
  1. OP_Verify runs after OP_CHECKSIG
    2.OP_DROP
    3.0xae
1 Like
  1. OP_CHECKSIGVERIFY marks transaction as invalid if the OP_CHECKSIG returns 0 then removes the top value from the stack (the return)

When would you want to check a transaction and not verify it?
my best guess was when you are constructing it to make sure its all there before sending it.

2)OP_Drop removes the top item from the stack

3)OP_CHECKMULTISIG: 0xae

1 Like
    • OP_CHECKSIG checks the transaction signature and returns true if its a valid signature
    • OP_CHECKSIGVERIFY same as CHECKSIG, but also executes OP_VERIFY and returns true if the transactions is valid
  1. OP_DROP
  2. 0xAE
2 Likes
  1. the latter marks the transaction as valid/invalid in addition to checking the signature.
  2. they are part of the STACK category of functions as listed out, where some have implicit pushing and popping behaviour.
  3. 0X ae
1 Like
  1. Same as OP_CHECKSIG, but OP_VERIFY is executed afterward.
  2. OP_DROP
  3. 0xae
1 Like
  1. Well if I got it right then it just means that op_verify command gets executed after op_multisig
    2.op_drop
    3.0xac
1 Like
  1. OP_OP_CHECKSIG hashes the entire transaction from input to output. If it is valid by output 1, then and only then can the transaction be verified by OP_OP_CHECKSIGVERIFY. If Checksig gives 0, the transaction won`t be verified.

  2. OP_DROP

  3. 0xae

1 Like