OpCodes

Bitcoin Cash Script OP Codes are available on the bitbox.Script object.

Examples

  // list all op codes
  bitbox.Script.opcodes;
  // { OP_FALSE: 0,
  //   OP_0: 0,
  //   OP_PUSHDATA1: 76,
  //   OP_PUSHDATA2: 77,
  //   OP_PUSHDATA4: 78,
  //   OP_1NEGATE: 79,
  //   OP_RESERVED: 80,
  //   OP_TRUE: 81,
  //   OP_1: 81,
  //   OP_2: 82,
  //   OP_3: 83,
  //   OP_4: 84,
  //   ...
  // }

  // get the op code for a word
  bitbox.Script.opcodes.OP_SPLIT
  // 127
  bitbox.Script.opcodes.OP_NUM2BIN
  // 128
  bitbox.Script.opcodes.OP_BIN2NUM
  // 129

Constants

WordOpcodeHexInputsOutputsDescription
OP_000x00Nothing(empty value)An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.)
OP_FALSE00x00Nothing(empty value)An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is added to the stack.)
N/A1-750x01-0x4b(special)dataThe next opcode bytes is data to be pushed onto the stack
OP_PUSHDATA1760x4c(special)dataThe next byte contains the number of bytes to be pushed onto the stack.
OP_PUSHDATA2770x4d(special)dataThe next two bytes contain the number of bytes to be pushed onto the stack in little endian order.
OP_PUSHDATA4780x4e(special)dataThe next four bytes contain the number of bytes to be pushed onto the stack in little endian order.
OP_1NEGATE790x4fNothing.-1The number -1 is pushed onto the stack.
OP_TRUE810x51Nothing.The number 1 is pushed onto the stack.
OP_1810x51Nothing.The number 1 is pushed onto the stack.
OP2-OP1682-960x52-0x60Nothing.2-16The number in the word name (2-16) is pushed onto the stack.

Flow control

WordOpcodeHexInputsOutputsDescription
OP_NOP970x61NothingNothingDoes nothing.
OP_IF990x63 if [statements]else [statements]]* endif if [statements]else [statements]]* endifIf the top stack value is not False, the statements are executed. The top stack value is removed.
OP_NOTIF1000x64 notif [statements]else [statements]]* endif notif [statements]else [statements]]* endifIf the top stack value is False, the statements are executed. The top stack value is removed.
OP_ELSE1030x67 if [statements]else [statements]]* endif if [statements]else [statements]]* endifIf the preceding OPIF or OPNOTIF or OPELSE was not executed then these statements are and if the preceding OPIF or OPNOTIF or OPELSE was executed then these statements are not.
OP_ENDIF1040x68 if [statements]else [statements]]* endif if [statements]else [statements]]* endifEnds an if/else block. All blocks must end, or the transaction is invalid. An OPENDIF without OPIF earlier is also invalid.
OP_VERIFY1050x69True / falseNothing / failMarks transaction as invalid if top stack value is not true. The top stack value is removed.
OP_RETURN1060x6aNothingfailMarks transaction as invalid.

Stack

WordOpcodeHexInputsOutputsDescription
OP_TOALTSTACK1070x6bx1(alt)x1Puts the input onto the top of the alt stack. Removes it from the main stack.
OP_FROMALTSTACK1080x6c(alt)x1x1Puts the input onto the top of the main stack. Removes it from the alt stack.
OP_IFDUP1150x73xx / x xIf the top stack value is not 0, duplicate it.
OP_DEPTH1160x74NothingPuts the number of stack items onto the stack.
OP_DROP1170x75xNothingRemoves the top stack item.
OP_DUP1180x76xx xDuplicates the top stack item.
OP_NIP1190x77x1 x2x2Removes the second-to-top stack item.
OP_OVER1200x78x1 x2x1 x2 x1Copies the second-to-top stack item to the top.
OP_PICK1210x79xn ... x2 x1 x0 xn ... x2 x1 x0 xnThe item n back in the stack is copied to the top.
OP_ROLL1220x7axn ... x2 x1 x0 ... x2 x1 x0 xnThe item n back in the stack is moved to the top.
OP_ROT1230x7bx1 x2 x3x2 x3 x1The top three items on the stack are rotated to the left.
OP_SWAP1240x7cx1 x2x2 x1The top two items on the stack are swapped.
OP_TUCK1250x7dx1 x2x2 x1 x2The item at the top of the stack is copied and inserted before the second-to-top item.
OP_2DROP1090x6dx1 x2NothingRemoves the top two stack items.
OP_2DUP1100x6ex1 x2x1 x2 x1 x2Duplicates the top two stack items.
OP_3DUP1110x6fx1 x2 x3x1 x2 x3 x1 x2 x3Duplicates the top three stack items.
OP_2OVER1120x70x1 x2 x3 x4x1 x2 x3 x4 x1 x2Copies the pair of items two spaces back in the stack to the front.
OP_2ROT1130x71x1 x2 x3 x4 x5 x6x3 x4 x5 x6 x1 x2The fifth and sixth items back are moved to the top of the stack.
OP_2SWAP1140x72x1 x2 x3 x4x3 x4 x1 x2Swaps the top two pairs of items.

Splice

WordOpcodeHexInputsOutputsDescription
OP_CAT1260x7ex1 x2outConcatenates two strings
OP_SUBSTR1270x7fin begin sizeoutReturns a section of a string
OP_LEFT1280x80in sizeoutKeeps only characters left of the specified point in a string.
OP_RIGHT1290x81in sizeoutKeeps only characters right of the specified point in a string.
OP_SIZE1300x82inin sizePushes the string length of the top element of the stack (without popping it).

Bitwise logic

WordOpcodeHexInputsOutputsDescription
OP_INVERT1310x83inoutFlips all of the bits in the input.
OP_AND1320x84x1 x2outBoolean and between each bit in the inputs.
OP_OR1330x85x1 x2outBoolean or between each bit in the inputs.
OP_XOR1340x86x1 x2outBoolean exclusive or between each bit in the inputs.
OP_EQUAL1350x87x1 x2True / falseReturns 1 if the inputs are exactly equal, 0 otherwise.
OP_EQUALVERIFY1360x88x1 x2Nothing / failSame as OPEQUAL, but runs OPVERIFY afterward.

Arithmetic

WordOpcodeHexInputsOutputsDescription
OP_1ADD1390x8binout1 is added to the input.
OP_1SUB1400x8cinout1 is subtracted from the input.
OP_2MUL1410x8dinoutThe input is multiplied by 2.
OP_2DIV1420x8einoutThe input is divided by 2.
OP_NEGATE1430x8finoutThe sign of the input is flipped.
OP_ABS1440x90inoutThe input is made positive.
OP_NOT1450x91inoutIf the input is 0 or 1, it is flipped. Otherwise the output will be 0.
OP_0NOTEQUAL1460x92inoutReturns 0 if the input is 0. 1 otherwise.
OP_ADD1470x93a bouta is added to b.
OP_SUB1480x94a boutb is subtracted from a.
OP_MUL1490x95a bouta is multiplied by b.
OP_DIV1500x96a bouta is divided by b.
OP_MOD1510x97a boutReturns the remainder after dividing a by b.
OP_LSHIFT1520x98a boutShifts a left b bits, preserving sign.
OP_RSHIFT1530x99a boutShifts a right b bits, preserving sign.
OP_BOOLAND1540x9aa boutIf both a and b are not "" (null string), the output is 1. Otherwise 0.
OP_BOOLOR1550x9ba boutIf a or b is not "" (null string), the output is 1. Otherwise 0.
OP_NUMEQUAL1560x9ca boutReturns 1 if the numbers are equal, 0 otherwise.
OP_NUMEQUALVERIFY1570x9da bNothing / failSame as OPNUMEQUAL, but runs OPVERIFY afterward.
OP_NUMNOTEQUAL1580x9ea boutReturns 1 if the numbers are not equal, 0 otherwise.
OP_LESSTHAN1590x9fa boutReturns 1 if a is less than b, 0 otherwise.
OP_GREATERTHAN1600xa0a boutReturns 1 if a is greater than b, 0 otherwise.
OP_LESSTHANOREQUAL1610xa1a boutReturns 1 if a is less than or equal to b, 0 otherwise.
OP_GREATERTHANOREQUAL1620xa2a boutReturns 1 if a is greater than or equal to b, 0 otherwise.
OP_MIN1630xa3a boutReturns the smaller of a and b.
OP_MAX1640xa4a boutReturns the larger of a and b.
OP_WITHIN1650xa5x min maxoutReturns 1 if x is within the specified range (left-inclusive), 0 otherwise.

Crypto

WordOpcodeHexInputsOutputsDescription
OP_RIPEMD1601660xa6inhashThe input is hashed using RIPEMD-160.
OP_SHA11670xa7inhashThe input is hashed using SHA-1.
OP_SHA2561680xa8inhashThe input is hashed using SHA-256.
OP_HASH1601690xa9inhashThe input is hashed twice: first with SHA-256 and then with RIPEMD-160.
OP_HASH2561700xaainhashThe input is hashed two times with SHA-256.
OP_CODESEPARATOR1710xabNothingNothingAll of the signature checking words will only match signatures to the data after the most recently-executed OP_CODESEPARATOR.
OP_CHECKSIG1720xacsig pubkeyTrue / falseThe entire transaction's outputs, inputs, and script (from the most recently-executed OPCODESEPARATOR to the end) are hashed. The signature used by OPCHECKSIG must be a valid signature for this hash and public key. If it is, 1 is returned, 0 otherwise.
OP_CHECKSIGVERIFY1730xadsig pubkeyNothing / failSame as OPCHECKSIG, but OPVERIFY is executed afterward.
OP_CHECKMULTISIG1740xaex sig1 sig2 ... pub1 pub2 True / FalseCompares the first signature against each public key until it finds an ECDSA match. Starting with the subsequent public key, it compares the second signature against each remaining public key until it finds an ECDSA match. The process is repeated until all signatures have been checked or not enough public keys remain to produce a successful result. All signatures need to match a public key. Because public keys are not checked again if they fail any signature comparison, signatures must be placed in the scriptSig using the same order as their corresponding public keys were placed in the scriptPubKey or redeemScript. If all signatures are valid, 1 is returned, 0 otherwise. Due to a bug, one extra unused value is removed from the stack.
OP_CHECKMULTISIGVERIFY1750xafx sig1 sig2 ... pub1 pub2 ... Nothing / failSame as OPCHECKMULTISIG, but OPVERIFY is executed afterward.

Locktime

WordOpcodeHexInputsOutputsDescription
OP_CHECKLOCKTIMEVERIFY1770xb1xx / failMarks transaction as invalid if the top stack item is greater than the transaction's nLockTime field, otherwise script evaluation continues as though an OP_NOP was executed. Transaction is also invalid if 1. the stack is empty; or 2. the top stack item is negative; or 3. the top stack item is greater than or equal to 500000000 while the transaction's nLockTime field is less than 500000000, or vice versa; or 4. the input's nSequence field is equal to 0xffffffff. The precise semantics are described in BIP 0065.
OP_CHECKSEQUENCEVERIFY1780xb2xx / failMarks transaction as invalid if the relative lock time of the input (enforced by BIP 0068 with nSequence) is not equal to or longer than the value of the top stack item. The precise semantics are described in BIP 0112.

Pseudo-words

WordOpcodeHexDescription
OP_PUBKEYHASH2530xfdRepresents a public key hashed with OP_HASH160.
OP_PUBKEY2540xfeRepresents a public key compatible with OP_CHECKSIG.
OP_INVALIDOPCODE2550xffMatches any opcode that is not yet assigned.

Reserved words

WordOpcodeHexWhen Used
OP_RESERVED800x50Transaction is invalid unless occuring in an unexecuted OP_IF branch
OP_VER980x62Transaction is invalid unless occuring in an unexecuted OP_IF branch
OP_VERIF1010x65Transaction is invalid even when occuring in an unexecuted OP_IF branch
OP_VERNOTIF1020x66Transaction is invalid even when occuring in an unexecuted OP_IF branch
OP_RESERVED11370x89Transaction is invalid unless occuring in an unexecuted OP_IF branch
OP_RESERVED21380x8aTransaction is invalid unless occuring in an unexecuted OP_IF branch
OP_NOP11760xb0The word is ignored. Does not mark transaction as invalid.
OP_NOP41790xb3The word is ignored. Does not mark transaction as invalid.
OP_NOP101850xb9The word is ignored. Does not mark transaction as invalid.

Do You Want To Get Free Developer Resources?