2

Anyone know how / where to run

enum optypecode

(or some other method) to get a list of current opcodes? Like this result... enter image description here

https://www.slideshare.net/gvrooyen/20140220-bitcoin/34-We_just_used_4_opcodesenum

2

This is the list of opcodes supported by Bitcoin Core v0.14.0:

https://github.com/bitcoin/bitcoin/blob/v0.14.0/src/script/script.h#L46L187

1
  • Thanks. That appears to be the section of code from the screenshot. Mar 10 '17 at 23:35
3

I don't think there is a command you can run, besides looking at Bitcoin's source code. (look for enum opcodetype)

Note that a lot of the opcodes listed there

  • are disabled to reduce complexity, (OP_CAT)
  • change meanings depending on which softforks are applied, (OP_CHECKLOCKTIMEVERIFY and OP_NOP2 have the same opcode) or
  • may have no meaning in a script. (OP_SMALLINTEGER)

To get a list of ones that can actually be used without making a script fail, you need to look at the code that actually evaluates scripts. (look for Bool EvalScript)

Here's a list of legal opcodes, as of time of writing:

(direct push, opcode 0x01-0x4b)
OP_PUSHDATA1
OP_PUSHDATA2
OP_PUSHDATA4
OP_0-16
OP_TRUE
OP_FALSE
OP_1NEGATE
OP_CHECKLOCKTIMEVERIFY
OP_CHECKSEQUENCEVERIFY
OP_NOP
OP_NOP1-10
OP_IF
OP_NOTIF
OP_ELSE
OP_ENDIF
OP_VERIFY
OP_RETURN
OP_TOALTSTACK
OP_FROMALTSTACK
OP_2DROP
OP_2DUP
OP_3DUP
OP_2OVER
OP_2ROT
OP_2SWAP
OP_IFDUP
OP_DEPTH
OP_DROP
OP_DUP
OP_NIP
OP_OVER
OP_PICK
OP_ROLL
OP_ROT
OP_SWAP
OP_TUCK
OP_SIZE
OP_EQUAL
OP_EQUALVERIFY
OP_NUMNOTEQUAL
OP_1ADD
OP_1SUB
OP_NEGATE
OP_ABS
OP_NOT
OP_0NOTEQUAL
OP_1ADD
OP_1SUB
OP_NEGATE
OP_ABS
OP_NOT
OP_0NOTEQUAL
OP_ADD
OP_SUB
OP_BOOLAND
OP_BOOLOR
OP_NUMEQUAL
OP_NUMEQUALVERIFY
OP_NUMNOTEQUAL
OP_LESSTHAN
OP_GREATERTHAN
OP_LESSTHANOREQUAL
OP_GREATERTHANOREQUAL
OP_MIN
OP_MAX
OP_ADD
OP_SUB
OP_BOOLAND
OP_BOOLOR
OP_NUMEQUAL
OP_NUMEQUALVERIFY
OP_NUMNOTEQUAL
OP_LESSTHAN
OP_GREATERTHAN
OP_LESSTHANOREQUAL
OP_GREATERTHANOREQUAL
OP_MIN
OP_MAX
OP_WITHIN
OP_RIPEMD160
OP_SHA1
OP_SHA256
OP_HASH160
OP_HASH256
OP_CODESEPARATOR
OP_CHECKSIG
OP_CHECKSIGVERIFY
OP_CHECKMULTISIG
OP_CHECKMULTISIGVERIFY

Bitcoin Wiki has an excellent page on this subject, if you're trying to figure out what is possible in Bitcoin script.

4
  • Thanks for the detailed answer and links. Very helpful. (I don't have enough reputation to up-vote your answer) Mar 10 '17 at 23:37
  • Many thanks again. Just wondering, where did you get the list of legal opcodes (without hex values)? Did you draft it yourself or is it available somewhere? It's very handy to have it cleanly formatted like that. Mar 11 '17 at 18:06
  • 1
    @ColmanMcMahon I had a copy of interpreter.cpp. I used grep to find case statements and sed to cut it down. This didn't catch every opcode, because a few push opcodes are handled differently. As for hex values, I can add that to the listing if that's helpful to you.
    – Nick ODell
    Mar 11 '17 at 18:12
  • Thanks. Thanks really helpful. The way you have it here is great for what I currently need (presenting opcodes on a slide). I'm just thinking of when I have to revise the list in the future. Mar 11 '17 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.