Equity
Bitcoin Protocol Library
|
A script instruction. More...
#include <Instruction.h>
Classes | |
struct | Description |
Information about an opcode. More... | |
Public Types | |
enum | OpCode { OP_0 = 0x00, OP_FALSE = OP_0, OP_PUSHDATA1 = 0x4c, OP_PUSHDATA2 = 0x4d, OP_PUSHDATA4 = 0x4e, OP_1NEGATE = 0x4f, OP_RESERVED = 0x50, OP_1 = 0x51, OP_TRUE = OP_1, OP_2 = 0x52, OP_3 = 0x53, OP_4 = 0x54, OP_5 = 0x55, OP_6 = 0x56, OP_7 = 0x57, OP_8 = 0x58, OP_9 = 0x59, OP_10 = 0x5a, OP_11 = 0x5b, OP_12 = 0x5c, OP_13 = 0x5d, OP_14 = 0x5e, OP_15 = 0x5f, OP_16 = 0x60, OP_NOP = 0x61, OP_VER = 0x62, OP_IF = 0x63, OP_NOTIF = 0x64, OP_VERIF = 0x65, OP_VERNOTIF = 0x66, OP_ELSE = 0x67, OP_ENDIF = 0x68, OP_VERIFY = 0x69, OP_RETURN = 0x6a, OP_TOALTSTACK = 0x6b, OP_FROMALTSTACK = 0x6c, OP_2DROP = 0x6d, OP_2DUP = 0x6e, OP_3DUP = 0x6f, OP_2OVER = 0x70, OP_2ROT = 0x71, OP_2SWAP = 0x72, OP_IFDUP = 0x73, OP_DEPTH = 0x74, OP_DROP = 0x75, OP_DUP = 0x76, OP_NIP = 0x77, OP_OVER = 0x78, OP_PICK = 0x79, OP_ROLL = 0x7a, OP_ROT = 0x7b, OP_SWAP = 0x7c, OP_TUCK = 0x7d, OP_CAT = 0x7e, OP_SUBSTR = 0x7f, OP_LEFT = 0x80, OP_RIGHT = 0x81, OP_SIZE = 0x82, OP_INVERT = 0x83, OP_AND = 0x84, OP_OR = 0x85, OP_XOR = 0x86, OP_EQUAL = 0x87, OP_EQUALVERIFY = 0x88, OP_RESERVED1 = 0x89, OP_RESERVED2 = 0x8a, OP_1ADD = 0x8b, OP_1SUB = 0x8c, OP_2MUL = 0x8d, OP_2DIV = 0x8e, OP_NEGATE = 0x8f, OP_ABS = 0x90, OP_NOT = 0x91, OP_0NOTEQUAL = 0x92, OP_ADD = 0x93, OP_SUB = 0x94, OP_MUL = 0x95, OP_DIV = 0x96, OP_MOD = 0x97, OP_LSHIFT = 0x98, OP_RSHIFT = 0x99, OP_BOOLAND = 0x9a, OP_BOOLOR = 0x9b, OP_NUMEQUAL = 0x9c, OP_NUMEQUALVERIFY = 0x9d, OP_NUMNOTEQUAL = 0x9e, OP_LESSTHAN = 0x9f, OP_GREATERTHAN = 0xa0, OP_LESSTHANOREQUAL = 0xa1, OP_GREATERTHANOREQUAL = 0xa2, OP_MIN = 0xa3, OP_MAX = 0xa4, OP_WITHIN = 0xa5, OP_RIPEMD160 = 0xa6, OP_SHA1 = 0xa7, OP_SHA256 = 0xa8, OP_HASH160 = 0xa9, OP_HASH256 = 0xaa, OP_CODESEPARATOR = 0xab, OP_CHECKSIG = 0xac, OP_CHECKSIGVERIFY = 0xad, OP_CHECKMULTISIG = 0xae, OP_CHECKMULTISIGVERIFY = 0xaf, OP_NOP1 = 0xb0, OP_CHECKLOCKTIMEVERIFY = 0xb1, OP_NOP3 = 0xb2, OP_NOP4 = 0xb3, OP_NOP5 = 0xb4, OP_NOP6 = 0xb5, OP_NOP7 = 0xb6, OP_NOP8 = 0xb7, OP_NOP9 = 0xb8, OP_NOP10 = 0xb9, OP_INVALID = 0xff } |
All named opcodes. More... | |
Public Member Functions | |
Instruction (int op, std::vector< uint8_t > const &data=std::vector< uint8_t >(), size_t location=0) | |
Instruction (uint8_t const *&in, size_t &size, size_t location) | |
int | op () const |
Returns the opcode. | |
std::vector< uint8_t > const & | data () const |
Returns the data (if any) | |
size_t | location () const |
Returns the location of the instruction in the script. | |
size_t | size () const |
Returns the size of the instruction in the script. | |
bool | valid () const |
Returns true if the instruction is well-formed and its appearance does not mark the script as invalid. | |
Description const & | description () const |
Returns information related to this instruction's opcode. | |
Overrides Serializable | |
virtual void | serialize (std::vector< uint8_t > &out) const override |
virtual json | toJson () const override |
Static Public Member Functions | |
static Description const & | getDescription (int opcode) |
Returns information related to the given opcode (whether valid or not) | |
A script instruction.
A script instruction contains an opcode and optional data. It also contains additional information used for branching and validation.
All named opcodes.
Valid opcodes are in the range of 0x00 - 0xff. Not all values in this range represent valid opcodes. In addition, many named opcodes are considered disabled or invalid.
Enumerator | |
---|---|
OP_0 |
An empty array of bytes is pushed onto the stack. (This is not a no-op: an item is < added to the stack.) |
OP_PUSHDATA1 |
The next byte contains the number of bytes to be pushed onto the stack. |
OP_PUSHDATA2 |
The next two bytes contain the number of bytes to be pushed onto the stack. |
OP_PUSHDATA4 |
The next four bytes contain the number of bytes to be pushed onto the stack. |
OP_1NEGATE |
The number -1 is pushed onto the stack. |
OP_RESERVED |
Transaction is invalid unless occurring in an unexecuted OP_IF branch. |
OP_1 |
The number 1 is pushed onto the stack. |
OP_TRUE |
The number 1 is pushed onto the stack. |
OP_2 |
The number 2 is pushed onto the stack. |
OP_3 |
The number 3 is pushed onto the stack. |
OP_4 |
The number 4 is pushed onto the stack. |
OP_5 |
The number 5 is pushed onto the stack. |
OP_6 |
The number 6 is pushed onto the stack. |
OP_7 |
The number 7 is pushed onto the stack. |
OP_8 |
The number 8 is pushed onto the stack. |
OP_9 |
The number 9 is pushed onto the stack. |
OP_10 |
The number 10 is pushed onto the stack. |
OP_11 |
The number 11 is pushed onto the stack. |
OP_12 |
The number 12 is pushed onto the stack. |
OP_13 |
The number 13 is pushed onto the stack. |
OP_14 |
The number 14 is pushed onto the stack. |
OP_15 |
The number 15 is pushed onto the stack. |
OP_16 |
The number 16 is pushed onto the stack. |
OP_NOP |
Does nothing. |
OP_VER |
Transaction is invalid unless occurring in an unexecuted OP_IF branch. |
OP_IF |
If the top stack value is not 0, the statements are executed.The top stack value is < removed. |
OP_NOTIF |
If the top stack value is 0, the statements are executed.The top stack value is < removed. |
OP_VERIF |
Transaction is invalid even when occurring in an unexecuted OP_IF branch. |
OP_VERNOTIF |
Transaction is invalid even when occurring in an unexecuted OP_IF branch. |
OP_ELSE |
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 |
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 |
Marks transaction as invalid if top stack value is not true. |
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 unspendable, 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. |
OP_TOALTSTACK |
Puts the input onto the top of the alt stack. Removes it from the main stack. |
OP_FROMALTSTACK |
Puts the input onto the top of the main stack. Removes it from the alt stack. |
OP_2DROP |
Removes the top two stack items. |
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 |
The top two items on the stack are swapped. |
OP_TUCK |
The item at the top of the stack is copied and inserted before the second-to-top < item. |
OP_CAT |
Concatenates two strings. |
OP_SUBSTR |
Returns a section of a string. |
OP_LEFT |
Keeps only characters left of the specified point in a string. |
OP_RIGHT |
Keeps only characters right of the specified point in a string. |
OP_SIZE |
Pushes the string length of the top element of the stack(without popping it). |
OP_INVERT |
Flips all of the bits in the input. |
OP_AND |
Boolean and between each bit in the inputs. |
OP_OR |
Boolean or between each bit in the inputs. |
OP_XOR |
Boolean exclusive or between each bit in the inputs. |
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 |
Transaction is invalid unless occurring in an unexecuted OP_IF branch. |
OP_RESERVED2 |
Transaction is invalid unless occurring in an unexecuted OP_IF branch. |
OP_1ADD |
1 is added to the input. |
OP_1SUB |
1 is subtracted from the input. |
OP_2MUL |
The input is multiplied by 2. disabled. |
OP_2DIV |
The input is divided by 2. disabled. |
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 |
a is added to b. |
OP_SUB |
b is subtracted from a. |
OP_MUL |
a is multiplied by b. |
OP_DIV |
a is divided by b. |
OP_MOD |
Returns the remainder after dividing a by b. |
OP_LSHIFT |
Shifts a left b bits, preserving sign. |
OP_RSHIFT |
Shifts a right b bits, preserving sign. |
OP_BOOLAND |
If both a and b are not 0, the output is 1. Otherwise 0. |
OP_BOOLOR |
If a or b is not 0, the output is 1. Otherwise 0. |
OP_NUMEQUAL |
Returns 1 if the numbers are equal, 0 otherwise. |
OP_NUMEQUALVERIFY |
Same as OP_NUMEQUAL, but runs OP_VERIFY afterward. |
OP_NUMNOTEQUAL |
Returns 1 if the numbers are not equal, 0 otherwise. |
OP_LESSTHAN |
Returns 1 if a is less than b, 0 otherwise. |
OP_GREATERTHAN |
Returns 1 if a is greater than b, 0 otherwise. |
OP_LESSTHANOREQUAL |
Returns 1 if a is less than or equal to b, 0 otherwise. |
OP_GREATERTHANOREQUAL |
Returns 1 if a is greater than or equal to b, 0 otherwise. |
OP_MIN |
Returns the smaller of a and b. |
OP_MAX |
Returns the larger of a and b. |
OP_WITHIN |
Returns 1 if x is within the specified range (left-inclusive), 0 otherwise. |
OP_RIPEMD160 |
The input is hashed using RIPEMD-160. |
OP_SHA1 |
The input is hashed using SHA-1. |
OP_SHA256 |
The input is hashed using SHA-256. |
OP_HASH160 |
The input is hashed twice : first with SHA-256 and then with RIPEMD-160. |
OP_HASH256 |
The input is hashed two times with SHA-256. |
OP_CODESEPARATOR |
All of the signature checking words will only match signatures to the data after the < most recently-executed OP_CODESEPARATOR. |
OP_CHECKSIG |
The entire transaction's outputs, inputs, and script (from the most recently-executed < OP_CODESEPARATOR to the end) are hashed. The signature used by OP_CHECKSIG must be a < valid signature for this hash and public key. If it is, 1 is returned, 0 otherwise. |
OP_CHECKSIGVERIFY |
Same as OP_CHECKSIG, but OP_VERIFY is executed afterward. |
OP_CHECKMULTISIG |
Compares 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_CHECKMULTISIGVERIFY |
Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward. |
OP_NOP1 |
The word is ignored. Does not mark transaction as invalid. |
OP_CHECKLOCKTIMEVERIFY |
Marks 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 top stack item is negative; or 2. 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 3. the input's nSequence field is equal < to 0xffffffff. The precise semantics are described in BIP 0065 |
OP_NOP3 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP4 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP5 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP6 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP7 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP8 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP9 |
The word is ignored. Does not mark transaction as invalid. |
OP_NOP10 |
The word is ignored. Does not mark transaction as invalid. |
OP_INVALID |
Denotes an invalid instruction. |
Instruction::Instruction | ( | int | op, |
std::vector< uint8_t > const & | data = std::vector<uint8_t>() , |
||
size_t | location = 0 |
||
) |
op | opcode |
data | optional data |
location | location (default: 0) |
Instruction::Instruction | ( | uint8_t const *& | in, |
size_t & | size, | ||
size_t | location | ||
) |
[in,out] | in | pointer to the next byte to deserialize |
[in,out] | size | number of bytes remaining in the serialized stream |
location | location of the instruction |