Original Op Codes - Bitcoin includes a script system for transactions.
In simple, a script is a just a list of instructions that is recorded with each transaction that describe how the next user wanting to spend the Bitcoins being transferred can gain access to them.
The script for a Bitcoin transaction to a Bitcoin address simply enduce future spending of the bitcoins with two things that must be provided.
1. a public key that when hashed results in the destination address in the script.
2. a signature to prove ownership of the private key corresponding to the public key.
Definition
Operation codes from the Bitcoin Script language which push data or perform functions within a pubkey script or signature script.
OP Code descriptions taken from
https://en.bitcoin.it/wiki/ Op Code list taken from
File - script.h
@Lines 7-293
enum
{
SIGHASH_ALL = 1,
SIGHASH_NONE = 2,
SIGHASH_SINGLE = 3,
SIGHASH_ANYONECANPAY = 0x80,
};
enum opcodetype
{
// push value
OP_0=0,
OP_FALSE=OP_0, - Empty array of bytes pushed onto the stack. This is not classed as an no-op as a item is added to stack.
OP_PUSHDATA1=76, - The next byte will contain the number of bytes to be pushed to the stack.
OP_PUSHDATA2, - The next two bytes contain the number of bytes to be pushed to the stack in little endian order.
OP_PUSHDATA4, - The next four bytes contain the number of bytes to be pushed to the stack in little endian order.
OP_1NEGATE, - The number -1 is pushed onto the stack.
OP_RESERVED, - Transaction is invalid unless occurring in an un-executed OP_IF branch
OP_1,
OP_TRUE=OP_1, - The number 1 is pushed onto the stack.
OP_2,
OP_3,
OP_4,
OP_5,
OP_6,
OP_7,
OP_8,
OP_9,
OP_10,
OP_11,
OP_12,
OP_13,
OP_14,
OP_15,
OP_16,
// control
OP_NOP, - Does nothing.
OP_VER, - Transaction is invalid unless occurring in an un-executed OP_IF branch
OP_IF, - if [statements] [else [statements]]* endif If the top stack value is not False the statements are executed. The top stack value is removed.
OP_NOTIF, - notif [statements] [else [statements]]* endif If the top stack value is False the statements are executed. The top stack value is removed.
OP_VERIF, - True / false - Marks transaction as invalid if top stack value is not true the top stack value is removed.
OP_VERNOTIF,- Transaction is invalid even when occurring in an un-executed OP_IF branch
OP_ELSE, - if [statements] [else [statements]]* endif If the preceding OP_IF or OP_NOTIF or OP_ELSE was not executed then these statements are and if the preceding
OP_IF or OP_NOTIF or OP_ELSE was executed then these statements are not.
OP_ENDIF, - if [statements] [else [statements]]* endif Ends an if/else block. All blocks must end, or the transaction is invalid. An OP_ENDIF without OP_IF earlier is also invalid.
OP_VERIFY, - True / false Marks transaction as invalid if top stack value is not true. The top stack value is removed.
OP_RETURN, - Marks transaction as invalid. A standard way of attaching extra data to transactions is to add a zero-value output with a scriptPubKey consisting of OP_RETURN followed by exactly one pushdata op. Such outputs are provably undependable, reducing their cost to the network. Currently it is usually considered non-standard (though valid) for a transaction to have more than one OP_RETURN output or an OP_RETURN output with more than one pushdata op.
// stack ops
OP_TOALTSTACK, [Input = x1] [Output (alt)x] = Puts the input onto the top of the alt stack. Removes it from the main stack.
OP_FROMALTSTACK, [Input = (alt)x1] [Output x1] = Puts the input onto the top of the main stack. Removes it from the alt stack.
OP_2DROP, Removes the top stack item.
OP_2DUP, Duplicates the top two stack items.
OP_3DUP, Duplicates the top three stack items.
OP_2OVER, Copies the pair of items two spaces back in the stack to the front.
OP_2ROT, The fifth and sixth items back are moved to the top of the stack.
OP_2SWAP, Swaps the top two pairs of items.
OP_IFDUP, If the top stack value is not 0, duplicate it.
OP_DEPTH, Puts the number of stack items onto the stack.
OP_DROP, Removes the top stack item.
OP_DUP, Duplicates the top stack item.
OP_NIP, Removes the second-to-top stack item.
OP_OVER, Copies the second-to-top stack item to the top.
OP_PICK, The item n back in the stack is copied to the top.
OP_ROLL, The item n back in the stack is moved to the top.
OP_ROT, The top three items on the stack are rotated to the left.
OP_SWAP, Swaps the top two pairs of items.
OP_TUCK, The item at the top of the stack is copied and inserted before the second-to-top item.
// splice ops
OP_CAT, Concatenates two strings. [b]disabled. [/b]
OP_SUBSTR, Returns a section of a string. [b]disabled.[/b]
OP_LEFT, Keeps only characters left of the specified point in a string.[b] disabled. [/b]
OP_RIGHT, Keeps only characters right of the specified point in a string. [b]disabled. [/b]
OP_SIZE, Pushes the string length of the top element of the stack.
// bit logic
OP_INVERT, Flips all of the bits in the input. [b]disabled.[/b]
OP_AND, Boolean and between each bit in the inputs. [b]disabled. [/b]
OP_OR, Boolean or between each bit in the inputs. [b]disabled. [/b]
OP_XOR, Boolean exclusive or between each bit in the inputs. [b]disabled[/b].
OP_EQUAL, Returns 1 if the inputs are exactly equal, 0 otherwise.
OP_EQUALVERIFY, Same as OP_EQUAL, but runs OP_VERIFY afterward.
OP_RESERVED1,
OP_RESERVED2,
// numeric
OP_1ADD, 1 is added to the input.
OP_1SUB, 1 is subtracted from the input.
OP_2MUL, The input is multiplied by 2. [b]disabled. [/b]
OP_2DIV, The input is divided by 2. [b]disabled. [/b]
OP_NEGATE, The sign of the input is flipped.
OP_ABS, The input is made positive.
OP_NOT, If the input is 0 or 1, it is flipped. Otherwise the output will be 0.
OP_0NOTEQUAL, Returns 0 if the input is 0. 1 otherwise.
OP_ADD,
OP_SUB,
OP_MUL,
OP_DIV,
OP_MOD,
OP_LSHIFT,
OP_RSHIFT,
OP_BOOLAND,
OP_BOOLOR,
OP_NUMEQUAL,
OP_NUMEQUALVERIFY,
OP_NUMNOTEQUAL,
OP_LESSTHAN,
OP_GREATERTHAN,
OP_LESSTHANOREQUAL,
OP_GREATERTHANOREQUAL,
OP_MIN,
OP_MAX,
OP_WITHIN,
// crypto
OP_RIPEMD160,
OP_SHA1,
OP_SHA256,
OP_HASH160,
OP_HASH256,
OP_CODESEPARATOR,
OP_CHECKSIG,
OP_CHECKSIGVERIFY,
OP_CHECKMULTISIG,
OP_CHECKMULTISIGVERIFY,
// multi-byte opcodes
OP_SINGLEBYTE_END = 0xF0,
OP_DOUBLEBYTE_BEGIN = 0xF000,
// template matching params
OP_PUBKEY,
OP_PUBKEYHASH,
OP_INVALIDOPCODE = 0xFFFF,
};
inline const char* GetOpName(opcodetype opcode)
{
switch (opcode)
{
// push value
case OP_0 : return "0";
case OP_PUSHDATA1 : return "OP_PUSHDATA1";
case OP_PUSHDATA2 : return "OP_PUSHDATA2";
case OP_PUSHDATA4 : return "OP_PUSHDATA4";
case OP_1NEGATE : return "-1";
case OP_RESERVED : return "OP_RESERVED";
case OP_1 : return "1";
case OP_2 : return "2";
case OP_3 : return "3";
case OP_4 : return "4";
case OP_5 : return "5";
case OP_6 : return "6";
case OP_7 : return "7";
case OP_8 : return "8";
case OP_9 : return "9";
case OP_10 : return "10";
case OP_11 : return "11";
case OP_12 : return "12";
case OP_13 : return "13";
case OP_14 : return "14";
case OP_15 : return "15";
case OP_16 : return "16";
// control
case OP_NOP : return "OP_NOP";
case OP_VER : return "OP_VER";
case OP_IF : return "OP_IF";
case OP_NOTIF : return "OP_NOTIF";
case OP_VERIF : return "OP_VERIF";
case OP_VERNOTIF : return "OP_VERNOTIF";
case OP_ELSE : return "OP_ELSE";
case OP_ENDIF : return "OP_ENDIF";
case OP_VERIFY : return "OP_VERIFY";
case OP_RETURN : return "OP_RETURN";
// stack ops
case OP_TOALTSTACK : return "OP_TOALTSTACK";
case OP_FROMALTSTACK : return "OP_FROMALTSTACK";
case OP_2DROP : return "OP_2DROP";
case OP_2DUP : return "OP_2DUP";
case OP_3DUP : return "OP_3DUP";
case OP_2OVER : return "OP_2OVER";
case OP_2ROT : return "OP_2ROT";
case OP_2SWAP : return "OP_2SWAP";
case OP_IFDUP : return "OP_IFDUP";
case OP_DEPTH : return "OP_DEPTH";
case OP_DROP : return "OP_DROP";
case OP_DUP : return "OP_DUP";
case OP_NIP : return "OP_NIP";
case OP_OVER : return "OP_OVER";
case OP_PICK : return "OP_PICK";
case OP_ROLL : return "OP_ROLL";
case OP_ROT : return "OP_ROT";
case OP_SWAP : return "OP_SWAP";
case OP_TUCK : return "OP_TUCK";
// splice ops
case OP_CAT : return "OP_CAT";
case OP_SUBSTR : return "OP_SUBSTR";
case OP_LEFT : return "OP_LEFT";
case OP_RIGHT : return "OP_RIGHT";
case OP_SIZE : return "OP_SIZE";
// bit logic
case OP_INVERT : return "OP_INVERT";
case OP_AND : return "OP_AND";
case OP_OR : return "OP_OR";
case OP_XOR : return "OP_XOR";
case OP_EQUAL : return "OP_EQUAL";
case OP_EQUALVERIFY : return "OP_EQUALVERIFY";
case OP_RESERVED1 : return "OP_RESERVED1";
case OP_RESERVED2 : return "OP_RESERVED2";
// numeric
case OP_1ADD : return "OP_1ADD";
case OP_1SUB : return "OP_1SUB";
case OP_2MUL : return "OP_2MUL";
case OP_2DIV : return "OP_2DIV";
case OP_NEGATE : return "OP_NEGATE";
case OP_ABS : return "OP_ABS";
case OP_NOT : return "OP_NOT";
case OP_0NOTEQUAL : return "OP_0NOTEQUAL";
case OP_ADD : return "OP_ADD";
case OP_SUB : return "OP_SUB";
case OP_MUL : return "OP_MUL";
case OP_DIV : return "OP_DIV";
case OP_MOD : return "OP_MOD";
case OP_LSHIFT : return "OP_LSHIFT";
case OP_RSHIFT : return "OP_RSHIFT";
case OP_BOOLAND : return "OP_BOOLAND";
case OP_BOOLOR : return "OP_BOOLOR";
case OP_NUMEQUAL : return "OP_NUMEQUAL";
case OP_NUMEQUALVERIFY : return "OP_NUMEQUALVERIFY";
case OP_NUMNOTEQUAL : return "OP_NUMNOTEQUAL";
case OP_LESSTHAN : return "OP_LESSTHAN";
case OP_GREATERTHAN : return "OP_GREATERTHAN";
case OP_LESSTHANOREQUAL : return "OP_LESSTHANOREQUAL";
case OP_GREATERTHANOREQUAL : return "OP_GREATERTHANOREQUAL";
case OP_MIN : return "OP_MIN";
case OP_MAX : return "OP_MAX";
case OP_WITHIN : return "OP_WITHIN";
// crypto
case OP_RIPEMD160 : return "OP_RIPEMD160";
case OP_SHA1 : return "OP_SHA1";
case OP_SHA256 : return "OP_SHA256";
case OP_HASH160 : return "OP_HASH160";
case OP_HASH256 : return "OP_HASH256";
case OP_CODESEPARATOR : return "OP_CODESEPARATOR";
case OP_CHECKSIG : return "OP_CHECKSIG";
case OP_CHECKSIGVERIFY : return "OP_CHECKSIGVERIFY";
case OP_CHECKMULTISIG : return "OP_CHECKMULTISIG";
case OP_CHECKMULTISIGVERIFY : return "OP_CHECKMULTISIGVERIFY";
// multi-byte opcodes
case OP_SINGLEBYTE_END : return "OP_SINGLEBYTE_END";
case OP_DOUBLEBYTE_BEGIN : return "OP_DOUBLEBYTE_BEGIN";
case OP_PUBKEY : return "OP_PUBKEY";
case OP_PUBKEYHASH : return "OP_PUBKEYHASH";
case OP_INVALIDOPCODE : return "OP_INVALIDOPCODE";
default:
return "UNKNOWN_OPCODE";
}
};