1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2025-07-27 08:58:20 +00:00

Made changes to appdx-scriptops.asciidoc

This commit is contained in:
drusselloctal@gmail.com 2014-10-31 09:16:22 -07:00
parent b12d2264d3
commit 5aa84d2006

View File

@ -1,163 +1,179 @@
[[tx_script_ops]] [[tx_script_ops]]
[appendix] [appendix]
== Appendix: Transaction Script Language Operators, Constants and Symbols == Appendix: Transaction Script Language Operators, Constants, and Symbols
[[tx_script_ops_table_pushdata]] <<tx_script_ops_table_pushdata>> shows operators for pushing values onto the stack.
.Push Value onto Stack
[options="header"] [[tx_script_ops_table_pushdata]]
|======= .Push value onto stack
| Symbol | Value (hex) | Description [options="header"]
| OP_0 or OP_FALSE | 0x00 | An empty array is pushed on to the stack |=======
| 1-75 | 0x01-0x4b | Push the next N bytes onto the stack, where N is 1 to 75 bytes | Symbol | Value (hex) | Description
| OP_PUSHDATA1 | 0x4c | The next script byte contains N, push the following N bytes onto the stack | OP_0 or OP_FALSE | 0x00 | An empty array is pushed on to the stack
| OP_PUSHDATA2 | 0x4d | The next two script bytes contain N, push the following N bytes onto the stack | 1-75 | 0x01-0x4b | Push the next N bytes onto the stack, where N is 1 to 75 bytes
| OP_PUSHDATA4 | 0x4e | The next four script bytes contain N, push the following N bytes onto the stack | OP_PUSHDATA1 | 0x4c | The next script byte contains N, push the following N bytes onto the stack
| OP_1NEGATE | 0x4f | Push the value "-1" onto the stack | OP_PUSHDATA2 | 0x4d | The next two script bytes contain N, push the following N bytes onto the stack
| OP_RESERVED | 0x50 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause | OP_PUSHDATA4 | 0x4e | The next four script bytes contain N, push the following N bytes onto the stack
| OP_1 or OP_TRUE| 0x51 | Push the value "1" onto the stack | OP_1NEGATE | 0x4f | Push the value "1" onto the stack
| OP_2 to OP_16 | 0x52 to 0x60 | For OP_N, push the value "N" onto the stack. E.g., OP_2 pushes "2" | OP_RESERVED | 0x50 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause
|======= | OP_1 or OP_TRUE| 0x51 | Push the value "1" onto the stack
| OP_2 to OP_16 | 0x52 to 0x60 | For OP_N, push the value "N" onto the stack. E.g., OP_2 pushes "2"
[[tx_script_ops_table_control]] |=======
.Conditional Flow Control
[options="header"] <<tx_script_ops_table_control>> shows conditional flow control operators.
|=======
| Symbol | Value (hex) | Description [[tx_script_ops_table_control]]
| OP_NOP | 0x61 | Do nothing .Conditional flow control
| OP_VER | 0x62 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause [options="header"]
| OP_IF | 0x63 | Execute the statements following if top of stack is not 0 |=======
| OP_NOTIF | 0x64 | Execute the statements following if top of stack is 0 | Symbol | Value (hex) | Description
| OP_VERIF | 0x65 | Halt - Invalid transaction | OP_NOP | 0x61 | Do nothing
| OP_VERNOTIF | 0x66 | Halt - Invalid transaction | OP_VER | 0x62 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause
| OP_ELSE | 0x67 | Execute only if the previous statements were not executed | OP_IF | 0x63 | Execute the statements following if top of stack is not 0
| OP_ENDIF | 0x68 | Ends the OP_IF, OP_NOTIF, OP_ELSE block | OP_NOTIF | 0x64 | Execute the statements following if top of stack is 0
| OP_VERIFY | 0x69 | Check the top of the stack, Halt and Invalidate transaction if not TRUE | OP_VERIF | 0x65 | Halt - Invalid transaction
| OP_RETURN | 0x6a | Halt and invalidate transaction | OP_VERNOTIF | 0x66 | Halt - Invalid transaction
|======= | OP_ELSE | 0x67 | Execute only if the previous statements were not executed
| OP_ENDIF | 0x68 | End the OP_IF, OP_NOTIF, OP_ELSE block
[[tx_script_ops_table_stack]] | OP_VERIFY | 0x69 | Check the top of the stack, halt and invalidate transaction if not TRUE
.Stack Operations | OP_RETURN | 0x6a | Halt and invalidate transaction
[options="header"] |=======
|=======
| Symbol | Value (hex) | Description <<tx_script_ops_table_stack>> shows operators used to manipulate the stack.
| OP_TOALTSTACK | 0x6b | Pop top item from stack and push to alternative stack
| OP_FROMALTSTACK | 0x6c | Pop top item from alternative stack and push to stack [[tx_script_ops_table_stack]]
| OP_2DROP | 0x6d | Pop top two stack items .Stack operations
| OP_2DUP | 0x6e | Duplicate top two stack items [options="header"]
| OP_3DUP | 0x6f | Duplicate top three stack items |=======
| OP_2OVER | 0x70 | Copies the third and fourth items in the stack to the top | Symbol | Value (hex) | Description
| OP_2ROT | 0x71 | Moves the fifth and sixth items in the stack to the top | OP_TOALTSTACK | 0x6b | Pop top item from stack and push to alternative stack
| OP_2SWAP | 0x72 | Swap the two top pairs of items in the stack | OP_FROMALTSTACK | 0x6c | Pop top item from alternative stack and push to stack
| OP_IFDUP | 0x73 | Duplicate the top item in the stack if it is not 0 | OP_2DROP | 0x6d | Pop top two stack items
| OP_DEPTH | 0x74 | Count the items on the stack and push the resulting count | OP_2DUP | 0x6e | Duplicate top two stack items
| OP_DROP | 0x75 | Pop the top item in the stack | OP_3DUP | 0x6f | Duplicate top three stack items
| OP_DUP | 0x76 | Duplicate the top item in the stack | OP_2OVER | 0x70 | Copy the third and fourth items in the stack to the top
| OP_NIP | 0x77 | Pop the second item in the stack | OP_2ROT | 0x71 | Move the fifth and sixth items in the stack to the top
| OP_OVER | 0x78 | Copy the second item in the stack and push it on to the top | OP_2SWAP | 0x72 | Swap the two top pairs of items in the stack
| OP_PICK | 0x79 | Pop value N from top, then copy the Nth item to the top of the stack | OP_IFDUP | 0x73 | Duplicate the top item in the stack if it is not 0
| OP_ROLL | 0x7a | Pop value N from top, then move the Nth item to the top of the stack | OP_DEPTH | 0x74 | Count the items on the stack and push the resulting count
| OP_ROT | 0x7b | Rotate the top three items in the stack | OP_DROP | 0x75 | Pop the top item in the stack
| OP_SWAP | 0x7c | Swap the top three items in the stack | OP_DUP | 0x76 | Duplicate the top item in the stack
| OP_TUCK | 0x7d | Copy the top item and insert it between the top and second item. | OP_NIP | 0x77 | Pop the second item in the stack
|======= | OP_OVER | 0x78 | Copy the second item in the stack and push it on to the top
| OP_PICK | 0x79 | Pop value N from top, then copy the Nth item to the top of the stack
[[tx_script_ops_table_splice]] | OP_ROLL | 0x7a | Pop value N from top, then move the Nth item to the top of the stack
.String Splice Operations | OP_ROT | 0x7b | Rotate the top three items in the stack
[options="header"] | OP_SWAP | 0x7c | Swap the top three items in the stack
|======= | OP_TUCK | 0x7d | Copy the top item and insert it between the top and second item.
| Symbol | Value (hex) | Description |=======
| _OP_CAT_ | 0x7e | Disabled (Concatenates top two items)
| _OP_SUBSTR_ | 0x7f | Disabled (Returns substring) <<tx_script_ops_table_splice>> shows string operators.
| _OP_LEFT_ | 0x80 | Disabled (Returns left substring)
| _OP_RIGHT_ | 0x81 | Disabled (Returns right substring) [[tx_script_ops_table_splice]]
| OP_SIZE | 0x82 | Calculate string length of top item and push the result .String splice operations
|======= [options="header"]
|=======
[[tx_script_ops_table_binmath]] | Symbol | Value (hex) | Description
.Binary Arithmetic and Conditionals | _OP_CAT_ | 0x7e | Disabled (Concatenates top two items)
[options="header"] | _OP_SUBSTR_ | 0x7f | Disabled (Returns substring)
|======= | _OP_LEFT_ | 0x80 | Disabled (Returns left substring)
| Symbol | Value (hex) | Description | _OP_RIGHT_ | 0x81 | Disabled (Returns right substring)
| _OP_INVERT_ | 0x83 | Disabled (Flip the bits of the top item) | OP_SIZE | 0x82 | Calculate string length of top item and push the result
| _OP_AND_ | 0x84 | Disabled (Boolean AND of two top items) |=======
| _OP_OR_ | 0x85 | Disabled (Boolean OR of two top items)
| _OP_XOR_ | 0x86 | Disabled (Boolean XOR of two top items) <<tx_script_ops_table_binmath>> shows binary arithmetic and boolean logic operators.
| OP_EQUAL | 0x87 | Push TRUE (1) if top two items are exactly equal, push FALSE (0) otherwise
| OP_EQUALVERIFY | 0x88 | Same as OP_EQUAL, but run OP_VERIFY after to halt if not TRUE [[tx_script_ops_table_binmath]]
| OP_RESERVED1 | 0x89 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause .Binary arithmetic and conditionals
| OP_RESERVED2 | 0x8a | Halt - Invalid transaction unless found in an unexecuted OP_IF clause [options="header"]
|======= |=======
| Symbol | Value (hex) | Description
[[tx_script_ops_table_numbers]] | _OP_INVERT_ | 0x83 | Disabled (Flip the bits of the top item)
.Numeric Operators | _OP_AND_ | 0x84 | Disabled (Boolean AND of two top items)
[options="header"] | _OP_OR_ | 0x85 | Disabled (Boolean OR of two top items)
|======= | _OP_XOR_ | 0x86 | Disabled (Boolean XOR of two top items)
| Symbol | Value (hex) | Description | OP_EQUAL | 0x87 | Push TRUE (1) if top two items are exactly equal, push FALSE (0) otherwise
| OP_1ADD | 0x8b | Add 1 to the top item | OP_EQUALVERIFY | 0x88 | Same as OP_EQUAL, but run OP_VERIFY after to halt if not TRUE
| OP_1SUB | 0x8c | Subtract 1 from the top item | OP_RESERVED1 | 0x89 | Halt - Invalid transaction unless found in an unexecuted OP_IF clause
| _OP_2MUL_ | 0x8d | Disabled (Multiply top item by 2) | OP_RESERVED2 | 0x8a | Halt - Invalid transaction unless found in an unexecuted OP_IF clause
| _OP_2DIV_ | 0x8e | Disabled (Divide top item by 2) |=======
| OP_NEGATE | 0x8f | Flip the sign of top item
| OP_ABS | 0x90 | Change the sign of the top item to positive <<tx_script_ops_table_numbers>> shows numeric (arithmetic) operators.
| OP_NOT | 0x91 | If top item is 0 or 1 boolean flip it, otherwise return 0
| OP_0NOTEQUAL | 0x92 | If top item is 0 return 0, otherwise return 1 [[tx_script_ops_table_numbers]]
| OP_ADD | 0x93 | Pop top two items, add them and push result .Numeric Operators
| OP_SUB | 0x94 | Pop top two items, subtract first form second, push result [options="header"]
| OP_MUL | 0x95 | Disabled (Multiply top two items) |=======
| OP_DIV | 0x96 | Disabled (Divide second item by first item) | Symbol | Value (hex) | Description
| OP_MOD | 0x97 | Disabled (Remainder divide second item by first item) | OP_1ADD | 0x8b | Add 1 to the top item
| OP_LSHIFT | 0x98 | Disabled (Shift second item left by first item number of bits) | OP_1SUB | 0x8c | Subtract 1 from the top item
| OP_RSHIFT | 0x99 | Disabled (Shift second item right by first item number of bits) | _OP_2MUL_ | 0x8d | Disabled (Multiply top item by 2)
| OP_BOOLAND | 0x9a | Boolean AND of top two items | _OP_2DIV_ | 0x8e | Disabled (Divide top item by 2)
| OP_BOOLOR | 0x9b | Boolean OR of top two items | OP_NEGATE | 0x8f | Flip the sign of top item
| OP_NUMEQUAL | 0x9c | Return TRUE if top two items are equal numbers | OP_ABS | 0x90 | Change the sign of the top item to positive
| OP_NUMEQUALVERIFY | 0x9d | Same as NUMEQUAL, then OP_VERIFY to halt if not TRUE | OP_NOT | 0x91 | If top item is 0 or 1 boolean flip it, otherwise return 0
| OP_NUMNOTEQUAL | 0x9e | Return TRUE if top two items are not equal numbers | OP_0NOTEQUAL | 0x92 | If top item is 0 return 0, otherwise return 1
| OP_LESSTHAN | 0x9f | Return TRUE if second item is less than top item | OP_ADD | 0x93 | Pop top two items, add them and push result
| OP_GREATERTHAN | 0xa0 | Return TRUE if second item is greater than top item | OP_SUB | 0x94 | Pop top two items, subtract first from second, push result
| OP_LESSTHANOREQUAL | 0xa1 | Return TRUE if second item is less than or equal to top item | OP_MUL | 0x95 | Disabled (Multiply top two items)
| OP_GREATERTHANOREQUAL | 0xa2 | Return TRUE if second item is great than or equal to top item | OP_DIV | 0x96 | Disabled (Divide second item by first item)
| OP_MIN | 0xa3 | Return the smaller of the two top items | OP_MOD | 0x97 | Disabled (Remainder divide second item by first item)
| OP_MAX | 0xa4 | Return the larger of the two top items | OP_LSHIFT | 0x98 | Disabled (Shift second item left by first item number of bits)
| OP_WITHIN | 0xa5 | Return TRUE if the third item is between the second item (or equal) and first item | OP_RSHIFT | 0x99 | Disabled (Shift second item right by first item number of bits)
|======= | OP_BOOLAND | 0x9a | Boolean AND of top two items
| OP_BOOLOR | 0x9b | Boolean OR of top two items
| OP_NUMEQUAL | 0x9c | Return TRUE if top two items are equal numbers
[[tx_script_ops_table_crypto]] | OP_NUMEQUALVERIFY | 0x9d | Same as NUMEQUAL, then OP_VERIFY to halt if not TRUE
.Cryptographic and Hashing Operations | OP_NUMNOTEQUAL | 0x9e | Return TRUE if top two items are not equal numbers
[options="header"] | OP_LESSTHAN | 0x9f | Return TRUE if second item is less than top item
|======= | OP_GREATERTHAN | 0xa0 | Return TRUE if second item is greater than top item
| Symbol | Value (hex) | Description | OP_LESSTHANOREQUAL | 0xa1 | Return TRUE if second item is less than or equal to top item
| OP_RIPEMD160 | 0xa6 | Return RIPEMD160 hash of top item | OP_GREATERTHANOREQUAL | 0xa2 | Return TRUE if second item is great than or equal to top item
| OP_SHA1 | 0xa7 | Return SHA1 hash of top item | OP_MIN | 0xa3 | Return the smaller of the two top items
| OP_SHA256 | 0xa8 | Return SHA256 hash of top item | OP_MAX | 0xa4 | Return the larger of the two top items
| OP_HASH160 | 0xa9 | Return RIPEMD160(SHA256(x)) hash of top item | OP_WITHIN | 0xa5 | Return TRUE if the third item is between the second item (or equal) and first item
| OP_HASH256 | 0xaa | Return SHA256(SHA256(x)) hash of top item |=======
| OP_CODESEPARATOR | 0xab | Mark the beginning of signature-checked data
| OP_CHECKSIG | 0xac | Pop a public key and signature and validate the signature for the transaction's hashed data, return TRUE if matching <<tx_script_ops_table_crypto>> shows cryptographic function operators.
| OP_CHECKSIGVERIFY | 0xad | Same as CHECKSIG, then OP_VEIRFY to halt if not TRUE
| OP_CHECKMULTISIG | 0xae | Run CHECKSIG for each pair of signature and public key provided. All must match. Bug in implementation pops an extra value, prefix with OP_NOP as workaround [[tx_script_ops_table_crypto]]
| OP_CHECKMULTISIGVERIFY | 0xaf | Same as CHECKMULTISIG, then OP_VERIFY to halt if not TRUE .Cryptographic and hashing operations
|======= [options="header"]
|=======
[[tx_script_ops_table_nop]] | Symbol | Value (hex) | Description
.Non-Operators | OP_RIPEMD160 | 0xa6 | Return RIPEMD160 hash of top item
[options="header"] | OP_SHA1 | 0xa7 | Return SHA1 hash of top item
|======= | OP_SHA256 | 0xa8 | Return SHA256 hash of top item
| Symbol | Value (hex) | Description | OP_HASH160 | 0xa9 | Return RIPEMD160(SHA256(x)) hash of top item
| OP_NOP1-OP_NOP10 | 0xb0-0xb9 | Does nothing, ignored. | OP_HASH256 | 0xaa | Return SHA256(SHA256(x)) hash of top item
|======= | OP_CODESEPARATOR | 0xab | Mark the beginning of signature-checked data
| OP_CHECKSIG | 0xac | Pop a public key and signature and validate the signature for the transaction's hashed data, return TRUE if matching
| OP_CHECKSIGVERIFY | 0xad | Same as CHECKSIG, then OP_VERIFY to halt if not TRUE
[[tx_script_ops_table_internal]] | OP_CHECKMULTISIG | 0xae | Run CHECKSIG for each pair of signature and public key provided. All must match. Bug in implementation pops an extra value, prefix with OP_NOP as workaround
.Reserved OP codes for internal use by the parser | OP_CHECKMULTISIGVERIFY | 0xaf | Same as CHECKMULTISIG, then OP_VERIFY to halt if not TRUE
[options="header"] |=======
|=======
| Symbol | Value (hex) | Description <<tx_script_ops_table_nop>> shows non-operator symbols
| OP_SMALLDATA | 0xf9 | Represents small data field
| OP_SMALLINTEGER | 0xfa | Represents small integer data field [[tx_script_ops_table_nop]]
| OP_PUBKEYS | 0xfb | Represents public key fields .Non-operators
| OP_PUBKEYHASH | 0xfd | Represents a public key hash field [options="header"]
| OP_PUBKEY | 0xfe | Represents a public key field |=======
| OP_INVALIDOPCODE | 0xff | Represents any OP code not currently assigned | Symbol | Value (hex) | Description
|======= | OP_NOP1-OP_NOP10 | 0xb0-0xb9 | Does nothing, ignored.
|=======
<<tx_script_ops_table_internal>> shows operator codes reserved for use by the internal script parser.
[[tx_script_ops_table_internal]]
.Reserved OP codes for internal use by the parser
[options="header"]
|=======
| Symbol | Value (hex) | Description
| OP_SMALLDATA | 0xf9 | Represents small data field
| OP_SMALLINTEGER | 0xfa | Represents small integer data field
| OP_PUBKEYS | 0xfb | Represents public key fields
| OP_PUBKEYHASH | 0xfd | Represents a public key hash field
| OP_PUBKEY | 0xfe | Represents a public key field
| OP_INVALIDOPCODE | 0xff | Represents any OP code not currently assigned
|=======