cs_mwc_bch/script/
op_codes.rs

1//! Script commands
2
3// --------------------------------------------------------------------------------------------
4// Constants
5// --------------------------------------------------------------------------------------------
6
7/// Pushes 0 onto the stack
8pub const OP_0: u8 = 0;
9/// Pushes 0 onto the stack
10pub const OP_FALSE: u8 = 0;
11
12/// Offset by n to push n bytes onto the stack, where n: [1-75]
13pub const OP_PUSH: u8 = 0;
14
15/// The next byte sets the number of bytes to push onto the stack
16pub const OP_PUSHDATA1: u8 = 76;
17/// The next two bytes sets the number of bytes to push onto the stack
18pub const OP_PUSHDATA2: u8 = 77;
19/// The next four bytes sets the number of bytes to push onto the stack
20pub const OP_PUSHDATA4: u8 = 78;
21
22/// Pushes -1 onto the stack
23pub const OP_1NEGATE: u8 = 79;
24/// Pushes 1 onto the stack
25pub const OP_1: u8 = 81;
26/// Pushes 1 onto the stack
27pub const OP_TRUE: u8 = 81;
28
29/// Pushes 2 onto the stack
30pub const OP_2: u8 = 82;
31/// Pushes 3 onto the stack
32pub const OP_3: u8 = 83;
33/// Pushes 4 onto the stack
34pub const OP_4: u8 = 84;
35/// Pushes 5 onto the stack
36pub const OP_5: u8 = 85;
37/// Pushes 6 onto the stack
38pub const OP_6: u8 = 86;
39/// Pushes 7 onto the stack
40pub const OP_7: u8 = 87;
41/// Pushes 8 onto the stack
42pub const OP_8: u8 = 88;
43/// Pushes 9 onto the stack
44pub const OP_9: u8 = 89;
45/// Pushes 10 onto the stack
46pub const OP_10: u8 = 90;
47/// Pushes 11 onto the stack
48pub const OP_11: u8 = 91;
49/// Pushes 12 onto the stack
50pub const OP_12: u8 = 92;
51/// Pushes 13 onto the stack
52pub const OP_13: u8 = 93;
53/// Pushes 14 onto the stack
54pub const OP_14: u8 = 94;
55/// Pushes 15 onto the stack
56pub const OP_15: u8 = 95;
57/// Pushes 16 onto the stack
58pub const OP_16: u8 = 96;
59
60// --------------------------------------------------------------------------------------------
61// Flow Control
62// --------------------------------------------------------------------------------------------
63
64/// Does nothing
65pub const OP_NOP: u8 = 97;
66/// If the top stack is true, statements are executed. Top stack value is removed.
67pub const OP_IF: u8 = 99;
68/// If the top stack is false, statements are executed. Top stack value is removed.
69pub const OP_NOTIF: u8 = 100;
70/// If the preceding OP_IF or OP_NOTIF statemetns were not executed, then statements are executed.
71pub const OP_ELSE: u8 = 103;
72/// Ends an if-else block
73pub const OP_ENDIF: u8 = 104;
74/// Marks a statement as invalid if the top stack value is false. Top stack value is removed.
75pub const OP_VERIFY: u8 = 105;
76/// Marks a statements as invalid
77pub const OP_RETURN: u8 = 106;
78
79// --------------------------------------------------------------------------------------------
80// Stack
81// --------------------------------------------------------------------------------------------
82
83/// Moves the top item on the main stack to the alt stack
84pub const OP_TOALTSTACK: u8 = 107;
85/// Moves the top item on the alt stack to the main stack
86pub const OP_FROMALTSTACK: u8 = 108;
87/// Duplicates the top stack value if it is not zero
88pub const OP_IFDUP: u8 = 115;
89/// Puts the number of stack items onto the stack
90pub const OP_DEPTH: u8 = 116;
91/// Drops the top stack value
92pub const OP_DROP: u8 = 117;
93/// Duplicates the top stack item
94pub const OP_DUP: u8 = 118;
95/// Removes the second-to-top stack item
96pub const OP_NIP: u8 = 119;
97/// Copies the second-to-top stack item to the top
98pub const OP_OVER: u8 = 120;
99/// The item n back in the stack is copied to the top
100pub const OP_PICK: u8 = 121;
101/// The item n back in the stack is moved to the top
102pub const OP_ROLL: u8 = 122;
103/// The top three items on the stack are rotated to the left
104pub const OP_ROT: u8 = 123;
105/// The top two items on the stack are swapped
106pub const OP_SWAP: u8 = 124;
107/// The item at the top of the stack is copied and inserted before the second-to-top item
108pub const OP_TUCK: u8 = 125;
109/// Removes the top two items from the stack
110pub const OP_2DROP: u8 = 109;
111/// Duplicates the top two stack items
112pub const OP_2DUP: u8 = 110;
113/// Duplicates the top three stack items
114pub const OP_3DUP: u8 = 111;
115/// Copies the pair of items two spaces back to the front
116pub const OP_2OVER: u8 = 112;
117/// The fifth and sixth items back are moved to the top of the stack
118pub const OP_2ROT: u8 = 113;
119/// Swaps the top two pairs of items
120pub const OP_2SWAP: u8 = 114;
121
122// --------------------------------------------------------------------------------------------
123// Splice
124// --------------------------------------------------------------------------------------------
125
126/// Concatenates two byte sequences
127pub const OP_CAT: u8 = 126;
128/// Splits the byte sequence at position n
129pub const OP_SPLIT: u8 = 127;
130/// Pushes the byte sequence length of the top stack item without popping it
131pub const OP_SIZE: u8 = 130;
132
133// --------------------------------------------------------------------------------------------
134// Bitwise Logic
135// --------------------------------------------------------------------------------------------
136
137/// Boolean and between each bit in the inputs
138pub const OP_AND: u8 = 132;
139/// Boolean or between each bit in the inputs
140pub const OP_OR: u8 = 133;
141/// Boolean exclusive or between each bit in the inputs
142pub const OP_XOR: u8 = 134;
143/// Returns 1 if the inputs are exactly equal, 0 otherwise
144pub const OP_EQUAL: u8 = 135;
145/// Same as OP_EQUAL, but runs OP_VERIFY afterward
146pub const OP_EQUALVERIFY: u8 = 136;
147
148// --------------------------------------------------------------------------------------------
149// Arithmetic
150// --------------------------------------------------------------------------------------------
151
152/// Adds 1 to the input
153pub const OP_1ADD: u8 = 139;
154/// Subtracts 1 from the input
155pub const OP_1SUB: u8 = 140;
156/// The sign of the input is flipped
157pub const OP_NEGATE: u8 = 143;
158/// The input is made positive
159pub const OP_ABS: u8 = 144;
160/// If the input is 0 or 1, it is flipped. Otherwise, the output will be 0.
161pub const OP_NOT: u8 = 145;
162/// Returns 0 if the input is 0. 1 otherwise.
163pub const OP_0NOTEQUAL: u8 = 146;
164/// Adds a to b
165pub const OP_ADD: u8 = 147;
166/// Subtracts b from a
167pub const OP_SUB: u8 = 148;
168/// Divides a by b
169pub const OP_DIV: u8 = 150;
170/// Returns the remainder after dividing a by b
171pub const OP_MOD: u8 = 151;
172/// If both a and b are not empty, the output is 1. Otherwise, 0.
173pub const OP_BOOLAND: u8 = 154;
174/// If a or b is not empty, the output is 1. Otherwise, 0.
175pub const OP_BOOLOR: u8 = 155;
176/// Returns 1 if the numbers are equal. Otherwise, 0.
177pub const OP_NUMEQUAL: u8 = 156;
178/// Same as OP_NUMEQUAL, but runs OP_VERIFY afterward
179pub const OP_NUMEQUALVERIFY: u8 = 157;
180/// Returns 1 if the numbers are not equal. Otherwise, 0.
181pub const OP_NUMNOTEQUAL: u8 = 158;
182/// Returns 1 if a is less than b. Otherwise, 0.
183pub const OP_LESSTHAN: u8 = 159;
184/// Returns 1 if a is greater than b. Otherwise, 0.
185pub const OP_GREATERTHAN: u8 = 160;
186/// Returns 1 if a is less than or equal to b. Otherwise, 0.
187pub const OP_LESSTHANOREQUAL: u8 = 161;
188/// Returns 1 if a is greater than or equal to b. Otherwise, 0.
189pub const OP_GREATERTHANOREQUAL: u8 = 162;
190/// Returns the smaller of a and b
191pub const OP_MIN: u8 = 163;
192/// Returns the larger of a and b
193pub const OP_MAX: u8 = 164;
194/// Returns 1 if x is within the specified range, left inclusive. Otherwise, 0.
195pub const OP_WITHIN: u8 = 165;
196/// Converts numeric value a into a byte sequence of length b
197pub const OP_NUM2BIN: u8 = 128;
198/// Converts byte sequence x into a numeric value
199pub const OP_BIN2NUM: u8 = 129;
200
201// --------------------------------------------------------------------------------------------
202// Cryptography
203// --------------------------------------------------------------------------------------------
204
205/// The input is hashed using RIPEMD-160
206pub const OP_RIPEMD160: u8 = 166;
207/// The input is hashed using SHA-1
208pub const OP_SHA1: u8 = 167;
209/// The input is hashed using SHA-256
210pub const OP_SHA256: u8 = 168;
211/// The input is hashed twice: first with SHA-256 and then with RIPEMD-160
212pub const OP_HASH160: u8 = 169;
213/// The input is hashed two times with SHA-256
214pub const OP_HASH256: u8 = 170;
215/// Marks the part of the script after which the signature will begin matching
216pub const OP_CODESEPARATOR: u8 = 171;
217/// Puts 1 on the stack if the signature authorizes the public key and transaction hash. Otherwise 0.
218pub const OP_CHECKSIG: u8 = 172;
219/// Same as OP_CHECKSIG, but OP_VERIFY is executed afterward
220pub const OP_CHECKSIGVERIFY: u8 = 173;
221/// Puts 1 on the stack if m of n signatures authorize the public key and transaction hash. Otherwise 0.
222pub const OP_CHECKMULTISIG: u8 = 174;
223/// Same as OP_CHECKMULTISIG, but OP_VERIFY is executed afterward
224pub const OP_CHECKMULTISIGVERIFY: u8 = 175;
225
226// --------------------------------------------------------------------------------------------
227// Locktime
228// --------------------------------------------------------------------------------------------
229
230/// Marks transaction as invalid if the top stack item is greater than the transaction's lock_time
231pub const OP_CHECKLOCKTIMEVERIFY: u8 = 177;
232/// Marks transaction as invalid if the top stack item is less than the transaction's sequence used for relative lock time
233pub const OP_CHECKSEQUENCEVERIFY: u8 = 178;
234
235// --------------------------------------------------------------------------------------------
236// Pseudo-words
237// --------------------------------------------------------------------------------------------
238
239/// Represents a public key hashed with OP_HASH160
240pub(crate) const OP_PUBKEYHASH: u8 = 253;
241/// Represents a public key compatible with OP_CHECKSIG
242pub(crate) const OP_PUBKEY: u8 = 254;
243/// Matches any opcode that is not yet assigned
244pub(crate) const OP_INVALIDOPCODE: u8 = 255;
245
246// --------------------------------------------------------------------------------------------
247// Reserved words
248// --------------------------------------------------------------------------------------------
249
250/// Transaction is invalid unless occuring in an unexecuted OP_IF branch
251pub(crate) const OP_RESERVED: u8 = 80;
252/// Transaction is invalid unless occuring in an unexecuted OP_IF branch
253pub(crate) const OP_VER: u8 = 98;
254/// Transaction is invalid even when occuring in an unexecuted OP_IF branch
255pub(crate) const OP_VERIF: u8 = 101;
256/// Transaction is invalid even when occuring in an unexecuted OP_IF branch
257pub(crate) const OP_VERNOTIF: u8 = 102;
258/// Transaction is invalid unless occuring in an unexecuted OP_IF branch
259pub(crate) const OP_RESERVED1: u8 = 137;
260/// Transaction is invalid unless occuring in an unexecuted OP_IF branch
261pub(crate) const OP_RESERVED2: u8 = 138;
262/// The word is ignored. Does not mark transaction as invalid.
263pub(crate) const OP_NOP1: u8 = 176;
264/// The word is ignored. Does not mark transaction as invalid.
265pub(crate) const OP_NOP4: u8 = 179;
266/// The word is ignored. Does not mark transaction as invalid.
267pub(crate) const OP_NOP5: u8 = 180;
268/// The word is ignored. Does not mark transaction as invalid.
269pub(crate) const OP_NOP6: u8 = 181;
270/// The word is ignored. Does not mark transaction as invalid.
271pub(crate) const OP_NOP7: u8 = 182;
272/// The word is ignored. Does not mark transaction as invalid.
273pub(crate) const OP_NOP8: u8 = 183;
274/// The word is ignored. Does not mark transaction as invalid.
275pub(crate) const OP_NOP9: u8 = 184;
276/// The word is ignored. Does not mark transaction as invalid.
277pub(crate) const OP_NOP10: u8 = 185;
278
279/// Words at or above this number are invalid
280pub(crate) const OP_INVALID_ABOVE: u8 = 186;
281
282// --------------------------------------------------------------------------------------------
283// Disabled words
284// --------------------------------------------------------------------------------------------
285
286/// Flips all of the bits in the input
287pub(crate) const OP_INVERT: u8 = 131;
288/// The input is multiplied by 2
289pub(crate) const OP_2MUL: u8 = 141;
290/// The input is divided by 2
291pub(crate) const OP_2DIV: u8 = 142;
292/// Multiplies a by b
293pub(crate) const OP_MUL: u8 = 149;
294/// Shifts a left b bits, preserving sign
295pub(crate) const OP_LSHIFT: u8 = 152;
296/// Shifts a right b bits, preserving sign
297pub(crate) const OP_RSHIFT: u8 = 153;