Skip to main content

bitcoin/blockdata/
opcodes.rs

1// Rust Bitcoin Library
2// Written in 2014 by
3//   Andrew Poelstra <apoelstra@wpsoftware.net>
4//
5// To the extent possible under law, the author(s) have dedicated all
6// copyright and related and neighboring rights to this software to
7// the public domain worldwide. This software is distributed without
8// any warranty.
9//
10// You should have received a copy of the CC0 Public Domain Dedication
11// along with this software.
12// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
13//
14
15//! Opcodes
16//!
17//! Bitcoin's script uses a stack-based assembly language. This module defines
18//! all of the opcodes
19//!
20
21#![allow(non_camel_case_types)]
22
23#[cfg(feature = "serde")] use serde;
24
25use std::fmt;
26
27// Note: I am deliberately not implementing PartialOrd or Ord on the
28//       opcode enum. If you want to check ranges of opcodes, etc.,
29//       write an #[inline] helper function which casts to u8s.
30
31/// A script Opcode
32#[derive(Copy, Clone, PartialEq, Eq)]
33pub struct All {
34    code: u8,
35}
36
37pub mod all {
38    //! Constants associated with All type
39    use super::All;
40
41    /// Push an empty array onto the stack
42    pub const OP_PUSHBYTES_0: All = All {code: 0x00};
43    /// Push the next byte as an array onto the stack
44    pub const OP_PUSHBYTES_1: All = All {code: 0x01};
45    /// Push the next 2 bytes as an array onto the stack
46    pub const OP_PUSHBYTES_2: All = All {code: 0x02};
47    /// Push the next 2 bytes as an array onto the stack
48    pub const OP_PUSHBYTES_3: All = All {code: 0x03};
49    /// Push the next 4 bytes as an array onto the stack
50    pub const OP_PUSHBYTES_4: All = All {code: 0x04};
51    /// Push the next 5 bytes as an array onto the stack
52    pub const OP_PUSHBYTES_5: All = All {code: 0x05};
53    /// Push the next 6 bytes as an array onto the stack
54    pub const OP_PUSHBYTES_6: All = All {code: 0x06};
55    /// Push the next 7 bytes as an array onto the stack
56    pub const OP_PUSHBYTES_7: All = All {code: 0x07};
57    /// Push the next 8 bytes as an array onto the stack
58    pub const OP_PUSHBYTES_8: All = All {code: 0x08};
59    /// Push the next 9 bytes as an array onto the stack
60    pub const OP_PUSHBYTES_9: All = All {code: 0x09};
61    /// Push the next 10 bytes as an array onto the stack
62    pub const OP_PUSHBYTES_10: All = All {code: 0x0a};
63    /// Push the next 11 bytes as an array onto the stack
64    pub const OP_PUSHBYTES_11: All = All {code: 0x0b};
65    /// Push the next 12 bytes as an array onto the stack
66    pub const OP_PUSHBYTES_12: All = All {code: 0x0c};
67    /// Push the next 13 bytes as an array onto the stack
68    pub const OP_PUSHBYTES_13: All = All {code: 0x0d};
69    /// Push the next 14 bytes as an array onto the stack
70    pub const OP_PUSHBYTES_14: All = All {code: 0x0e};
71    /// Push the next 15 bytes as an array onto the stack
72    pub const OP_PUSHBYTES_15: All = All {code: 0x0f};
73    /// Push the next 16 bytes as an array onto the stack
74    pub const OP_PUSHBYTES_16: All = All {code: 0x10};
75    /// Push the next 17 bytes as an array onto the stack
76    pub const OP_PUSHBYTES_17: All = All {code: 0x11};
77    /// Push the next 18 bytes as an array onto the stack
78    pub const OP_PUSHBYTES_18: All = All {code: 0x12};
79    /// Push the next 19 bytes as an array onto the stack
80    pub const OP_PUSHBYTES_19: All = All {code: 0x13};
81    /// Push the next 20 bytes as an array onto the stack
82    pub const OP_PUSHBYTES_20: All = All {code: 0x14};
83    /// Push the next 21 bytes as an array onto the stack
84    pub const OP_PUSHBYTES_21: All = All {code: 0x15};
85    /// Push the next 22 bytes as an array onto the stack
86    pub const OP_PUSHBYTES_22: All = All {code: 0x16};
87    /// Push the next 23 bytes as an array onto the stack
88    pub const OP_PUSHBYTES_23: All = All {code: 0x17};
89    /// Push the next 24 bytes as an array onto the stack
90    pub const OP_PUSHBYTES_24: All = All {code: 0x18};
91    /// Push the next 25 bytes as an array onto the stack
92    pub const OP_PUSHBYTES_25: All = All {code: 0x19};
93    /// Push the next 26 bytes as an array onto the stack
94    pub const OP_PUSHBYTES_26: All = All {code: 0x1a};
95    /// Push the next 27 bytes as an array onto the stack
96    pub const OP_PUSHBYTES_27: All = All {code: 0x1b};
97    /// Push the next 28 bytes as an array onto the stack
98    pub const OP_PUSHBYTES_28: All = All {code: 0x1c};
99    /// Push the next 29 bytes as an array onto the stack
100    pub const OP_PUSHBYTES_29: All = All {code: 0x1d};
101    /// Push the next 30 bytes as an array onto the stack
102    pub const OP_PUSHBYTES_30: All = All {code: 0x1e};
103    /// Push the next 31 bytes as an array onto the stack
104    pub const OP_PUSHBYTES_31: All = All {code: 0x1f};
105    /// Push the next 32 bytes as an array onto the stack
106    pub const OP_PUSHBYTES_32: All = All {code: 0x20};
107    /// Push the next 33 bytes as an array onto the stack
108    pub const OP_PUSHBYTES_33: All = All {code: 0x21};
109    /// Push the next 34 bytes as an array onto the stack
110    pub const OP_PUSHBYTES_34: All = All {code: 0x22};
111    /// Push the next 35 bytes as an array onto the stack
112    pub const OP_PUSHBYTES_35: All = All {code: 0x23};
113    /// Push the next 36 bytes as an array onto the stack
114    pub const OP_PUSHBYTES_36: All = All {code: 0x24};
115    /// Push the next 37 bytes as an array onto the stack
116    pub const OP_PUSHBYTES_37: All = All {code: 0x25};
117    /// Push the next 38 bytes as an array onto the stack
118    pub const OP_PUSHBYTES_38: All = All {code: 0x26};
119    /// Push the next 39 bytes as an array onto the stack
120    pub const OP_PUSHBYTES_39: All = All {code: 0x27};
121    /// Push the next 40 bytes as an array onto the stack
122    pub const OP_PUSHBYTES_40: All = All {code: 0x28};
123    /// Push the next 41 bytes as an array onto the stack
124    pub const OP_PUSHBYTES_41: All = All {code: 0x29};
125    /// Push the next 42 bytes as an array onto the stack
126    pub const OP_PUSHBYTES_42: All = All {code: 0x2a};
127    /// Push the next 43 bytes as an array onto the stack
128    pub const OP_PUSHBYTES_43: All = All {code: 0x2b};
129    /// Push the next 44 bytes as an array onto the stack
130    pub const OP_PUSHBYTES_44: All = All {code: 0x2c};
131    /// Push the next 45 bytes as an array onto the stack
132    pub const OP_PUSHBYTES_45: All = All {code: 0x2d};
133    /// Push the next 46 bytes as an array onto the stack
134    pub const OP_PUSHBYTES_46: All = All {code: 0x2e};
135    /// Push the next 47 bytes as an array onto the stack
136    pub const OP_PUSHBYTES_47: All = All {code: 0x2f};
137    /// Push the next 48 bytes as an array onto the stack
138    pub const OP_PUSHBYTES_48: All = All {code: 0x30};
139    /// Push the next 49 bytes as an array onto the stack
140    pub const OP_PUSHBYTES_49: All = All {code: 0x31};
141    /// Push the next 50 bytes as an array onto the stack
142    pub const OP_PUSHBYTES_50: All = All {code: 0x32};
143    /// Push the next 51 bytes as an array onto the stack
144    pub const OP_PUSHBYTES_51: All = All {code: 0x33};
145    /// Push the next 52 bytes as an array onto the stack
146    pub const OP_PUSHBYTES_52: All = All {code: 0x34};
147    /// Push the next 53 bytes as an array onto the stack
148    pub const OP_PUSHBYTES_53: All = All {code: 0x35};
149    /// Push the next 54 bytes as an array onto the stack
150    pub const OP_PUSHBYTES_54: All = All {code: 0x36};
151    /// Push the next 55 bytes as an array onto the stack
152    pub const OP_PUSHBYTES_55: All = All {code: 0x37};
153    /// Push the next 56 bytes as an array onto the stack
154    pub const OP_PUSHBYTES_56: All = All {code: 0x38};
155    /// Push the next 57 bytes as an array onto the stack
156    pub const OP_PUSHBYTES_57: All = All {code: 0x39};
157    /// Push the next 58 bytes as an array onto the stack
158    pub const OP_PUSHBYTES_58: All = All {code: 0x3a};
159    /// Push the next 59 bytes as an array onto the stack
160    pub const OP_PUSHBYTES_59: All = All {code: 0x3b};
161    /// Push the next 60 bytes as an array onto the stack
162    pub const OP_PUSHBYTES_60: All = All {code: 0x3c};
163    /// Push the next 61 bytes as an array onto the stack
164    pub const OP_PUSHBYTES_61: All = All {code: 0x3d};
165    /// Push the next 62 bytes as an array onto the stack
166    pub const OP_PUSHBYTES_62: All = All {code: 0x3e};
167    /// Push the next 63 bytes as an array onto the stack
168    pub const OP_PUSHBYTES_63: All = All {code: 0x3f};
169    /// Push the next 64 bytes as an array onto the stack
170    pub const OP_PUSHBYTES_64: All = All {code: 0x40};
171    /// Push the next 65 bytes as an array onto the stack
172    pub const OP_PUSHBYTES_65: All = All {code: 0x41};
173    /// Push the next 66 bytes as an array onto the stack
174    pub const OP_PUSHBYTES_66: All = All {code: 0x42};
175    /// Push the next 67 bytes as an array onto the stack
176    pub const OP_PUSHBYTES_67: All = All {code: 0x43};
177    /// Push the next 68 bytes as an array onto the stack
178    pub const OP_PUSHBYTES_68: All = All {code: 0x44};
179    /// Push the next 69 bytes as an array onto the stack
180    pub const OP_PUSHBYTES_69: All = All {code: 0x45};
181    /// Push the next 70 bytes as an array onto the stack
182    pub const OP_PUSHBYTES_70: All = All {code: 0x46};
183    /// Push the next 71 bytes as an array onto the stack
184    pub const OP_PUSHBYTES_71: All = All {code: 0x47};
185    /// Push the next 72 bytes as an array onto the stack
186    pub const OP_PUSHBYTES_72: All = All {code: 0x48};
187    /// Push the next 73 bytes as an array onto the stack
188    pub const OP_PUSHBYTES_73: All = All {code: 0x49};
189    /// Push the next 74 bytes as an array onto the stack
190    pub const OP_PUSHBYTES_74: All = All {code: 0x4a};
191    /// Push the next 75 bytes as an array onto the stack
192    pub const OP_PUSHBYTES_75: All = All {code: 0x4b};
193    /// Read the next byte as N; push the next N bytes as an array onto the stack
194    pub const OP_PUSHDATA1: All = All {code: 0x4c};
195    /// Read the next 2 bytes as N; push the next N bytes as an array onto the stack
196    pub const OP_PUSHDATA2: All = All {code: 0x4d};
197    /// Read the next 4 bytes as N; push the next N bytes as an array onto the stack
198    pub const OP_PUSHDATA4: All = All {code: 0x4e};
199    /// Push the array [0x81] onto the stack
200    pub const OP_PUSHNUM_NEG1: All = All {code: 0x4f};
201    /// Synonym for OP_RETURN
202    pub const OP_RESERVED: All = All {code: 0x50};
203    /// Push the array [0x01] onto the stack
204    pub const OP_PUSHNUM_1: All = All {code: 0x51};
205    /// Push the array [0x02] onto the stack
206    pub const OP_PUSHNUM_2: All = All {code: 0x52};
207    /// Push the array [0x03] onto the stack
208    pub const OP_PUSHNUM_3: All = All {code: 0x53};
209    /// Push the array [0x04] onto the stack
210    pub const OP_PUSHNUM_4: All = All {code: 0x54};
211    /// Push the array [0x05] onto the stack
212    pub const OP_PUSHNUM_5: All = All {code: 0x55};
213    /// Push the array [0x06] onto the stack
214    pub const OP_PUSHNUM_6: All = All {code: 0x56};
215    /// Push the array [0x07] onto the stack
216    pub const OP_PUSHNUM_7: All = All {code: 0x57};
217    /// Push the array [0x08] onto the stack
218    pub const OP_PUSHNUM_8: All = All {code: 0x58};
219    /// Push the array [0x09] onto the stack
220    pub const OP_PUSHNUM_9: All = All {code: 0x59};
221    /// Push the array [0x0a] onto the stack
222    pub const OP_PUSHNUM_10: All = All {code: 0x5a};
223    /// Push the array [0x0b] onto the stack
224    pub const OP_PUSHNUM_11: All = All {code: 0x5b};
225    /// Push the array [0x0c] onto the stack
226    pub const OP_PUSHNUM_12: All = All {code: 0x5c};
227    /// Push the array [0x0d] onto the stack
228    pub const OP_PUSHNUM_13: All = All {code: 0x5d};
229    /// Push the array [0x0e] onto the stack
230    pub const OP_PUSHNUM_14: All = All {code: 0x5e};
231    /// Push the array [0x0f] onto the stack
232    pub const OP_PUSHNUM_15: All = All {code: 0x5f};
233    /// Push the array [0x10] onto the stack
234    pub const OP_PUSHNUM_16: All = All {code: 0x60};
235    /// Does nothing
236    pub const OP_NOP: All = All {code: 0x61};
237    /// Synonym for OP_RETURN
238    pub const OP_VER: All = All {code: 0x62};
239    /// Pop and execute the next statements if a nonzero element was popped
240    pub const OP_IF: All = All {code: 0x63};
241    /// Pop and execute the next statements if a zero element was popped
242    pub const OP_NOTIF: All = All {code: 0x64};
243    /// Fail the script unconditionally, does not even need to be executed
244    pub const OP_VERIF: All = All {code: 0x65};
245    /// Fail the script unconditionally, does not even need to be executed
246    pub const OP_VERNOTIF: All = All {code: 0x66};
247    /// Execute statements if those after the previous OP_IF were not, and vice-versa.
248    /// If there is no previous OP_IF, this acts as a RETURN.
249    pub const OP_ELSE: All = All {code: 0x67};
250    /// Pop and execute the next statements if a zero element was popped
251    pub const OP_ENDIF: All = All {code: 0x68};
252    /// If the top value is zero or the stack is empty, fail; otherwise, pop the stack
253    pub const OP_VERIFY: All = All {code: 0x69};
254    /// Fail the script immediately. (Must be executed.)
255    pub const OP_RETURN: All = All {code: 0x6a};
256    /// Pop one element from the main stack onto the alt stack
257    pub const OP_TOALTSTACK: All = All {code: 0x6b};
258    /// Pop one element from the alt stack onto the main stack
259    pub const OP_FROMALTSTACK: All = All {code: 0x6c};
260    /// Drops the top two stack items
261    pub const OP_2DROP: All = All {code: 0x6d};
262    /// Duplicates the top two stack items as AB -> ABAB
263    pub const OP_2DUP: All = All {code: 0x6e};
264    /// Duplicates the two three stack items as ABC -> ABCABC
265    pub const OP_3DUP: All = All {code: 0x6f};
266    /// Copies the two stack items of items two spaces back to
267    /// the front, as xxAB -> ABxxAB
268    pub const OP_2OVER: All = All {code: 0x70};
269    /// Moves the two stack items four spaces back to the front,
270    /// as xxxxAB -> ABxxxx
271    pub const OP_2ROT: All = All {code: 0x71};
272    /// Swaps the top two pairs, as ABCD -> CDAB
273    pub const OP_2SWAP: All = All {code: 0x72};
274    /// Duplicate the top stack element unless it is zero
275    pub const OP_IFDUP: All = All {code: 0x73};
276    /// Push the current number of stack items onto the stack
277    pub const OP_DEPTH: All = All {code: 0x74};
278    /// Drops the top stack item
279    pub const OP_DROP: All = All {code: 0x75};
280    /// Duplicates the top stack item
281    pub const OP_DUP: All = All {code: 0x76};
282    /// Drops the second-to-top stack item
283    pub const OP_NIP: All = All {code: 0x77};
284    /// Copies the second-to-top stack item, as xA -> AxA
285    pub const OP_OVER: All = All {code: 0x78};
286    /// Pop the top stack element as N. Copy the Nth stack element to the top
287    pub const OP_PICK: All = All {code: 0x79};
288    /// Pop the top stack element as N. Move the Nth stack element to the top
289    pub const OP_ROLL: All = All {code: 0x7a};
290    /// Rotate the top three stack items, as [top next1 next2] -> [next2 top next1]
291    pub const OP_ROT: All = All {code: 0x7b};
292    /// Swap the top two stack items
293    pub const OP_SWAP: All = All {code: 0x7c};
294    /// Copy the top stack item to before the second item, as [top next] -> [top next top]
295    pub const OP_TUCK: All = All {code: 0x7d};
296    /// Fail the script unconditionally, does not even need to be executed
297    pub const OP_CAT: All = All {code: 0x7e};
298    /// Fail the script unconditionally, does not even need to be executed
299    pub const OP_SUBSTR: All = All {code: 0x7f};
300    /// Fail the script unconditionally, does not even need to be executed
301    pub const OP_LEFT: All = All {code: 0x80};
302    /// Fail the script unconditionally, does not even need to be executed
303    pub const OP_RIGHT: All = All {code: 0x81};
304    /// Pushes the length of the top stack item onto the stack
305    pub const OP_SIZE: All = All {code: 0x82};
306    /// Fail the script unconditionally, does not even need to be executed
307    pub const OP_INVERT: All = All {code: 0x83};
308    /// Fail the script unconditionally, does not even need to be executed
309    pub const OP_AND: All = All {code: 0x84};
310    /// Fail the script unconditionally, does not even need to be executed
311    pub const OP_OR: All = All {code: 0x85};
312    /// Fail the script unconditionally, does not even need to be executed
313    pub const OP_XOR: All = All {code: 0x86};
314    /// Pushes 1 if the inputs are exactly equal, 0 otherwise
315    pub const OP_EQUAL: All = All {code: 0x87};
316    /// Returns success if the inputs are exactly equal, failure otherwise
317    pub const OP_EQUALVERIFY: All = All {code: 0x88};
318    /// Synonym for OP_RETURN
319    pub const OP_RESERVED1: All = All {code: 0x89};
320    /// Synonym for OP_RETURN
321    pub const OP_RESERVED2: All = All {code: 0x8a};
322    /// Increment the top stack element in place
323    pub const OP_1ADD: All = All {code: 0x8b};
324    /// Decrement the top stack element in place
325    pub const OP_1SUB: All = All {code: 0x8c};
326    /// Fail the script unconditionally, does not even need to be executed
327    pub const OP_2MUL: All = All {code: 0x8d};
328    /// Fail the script unconditionally, does not even need to be executed
329    pub const OP_2DIV: All = All {code: 0x8e};
330    /// Multiply the top stack item by -1 in place
331    pub const OP_NEGATE: All = All {code: 0x8f};
332    /// Absolute value the top stack item in place
333    pub const OP_ABS: All = All {code: 0x90};
334    /// Map 0 to 1 and everything else to 0, in place
335    pub const OP_NOT: All = All {code: 0x91};
336    /// Map 0 to 0 and everything else to 1, in place
337    pub const OP_0NOTEQUAL: All = All {code: 0x92};
338    /// Pop two stack items and push their sum
339    pub const OP_ADD: All = All {code: 0x93};
340    /// Pop two stack items and push the second minus the top
341    pub const OP_SUB: All = All {code: 0x94};
342    /// Fail the script unconditionally, does not even need to be executed
343    pub const OP_MUL: All = All {code: 0x95};
344    /// Fail the script unconditionally, does not even need to be executed
345    pub const OP_DIV: All = All {code: 0x96};
346    /// Fail the script unconditionally, does not even need to be executed
347    pub const OP_MOD: All = All {code: 0x97};
348    /// Fail the script unconditionally, does not even need to be executed
349    pub const OP_LSHIFT: All = All {code: 0x98};
350    /// Fail the script unconditionally, does not even need to be executed
351    pub const OP_RSHIFT: All = All {code: 0x99};
352    /// Pop the top two stack items and push 1 if both are nonzero, else push 0
353    pub const OP_BOOLAND: All = All {code: 0x9a};
354    /// Pop the top two stack items and push 1 if either is nonzero, else push 0
355    pub const OP_BOOLOR: All = All {code: 0x9b};
356    /// Pop the top two stack items and push 1 if both are numerically equal, else push 0
357    pub const OP_NUMEQUAL: All = All {code: 0x9c};
358    /// Pop the top two stack items and return success if both are numerically equal, else return failure
359    pub const OP_NUMEQUALVERIFY: All = All {code: 0x9d};
360    /// Pop the top two stack items and push 0 if both are numerically equal, else push 1
361    pub const OP_NUMNOTEQUAL: All = All {code: 0x9e};
362    /// Pop the top two items; push 1 if the second is less than the top, 0 otherwise
363    pub const OP_LESSTHAN : All = All {code: 0x9f};
364    /// Pop the top two items; push 1 if the second is greater than the top, 0 otherwise
365    pub const OP_GREATERTHAN : All = All {code: 0xa0};
366    /// Pop the top two items; push 1 if the second is <= the top, 0 otherwise
367    pub const OP_LESSTHANOREQUAL : All = All {code: 0xa1};
368    /// Pop the top two items; push 1 if the second is >= the top, 0 otherwise
369    pub const OP_GREATERTHANOREQUAL : All = All {code: 0xa2};
370    /// Pop the top two items; push the smaller
371    pub const OP_MIN: All = All {code: 0xa3};
372    /// Pop the top two items; push the larger
373    pub const OP_MAX: All = All {code: 0xa4};
374    /// Pop the top three items; if the top is >= the second and < the third, push 1, otherwise push 0
375    pub const OP_WITHIN: All = All {code: 0xa5};
376    /// Pop the top stack item and push its RIPEMD160 hash
377    pub const OP_RIPEMD160: All = All {code: 0xa6};
378    /// Pop the top stack item and push its SHA1 hash
379    pub const OP_SHA1: All = All {code: 0xa7};
380    /// Pop the top stack item and push its SHA256 hash
381    pub const OP_SHA256: All = All {code: 0xa8};
382    /// Pop the top stack item and push its RIPEMD(SHA256) hash
383    pub const OP_HASH160: All = All {code: 0xa9};
384    /// Pop the top stack item and push its SHA256(SHA256) hash
385    pub const OP_HASH256: All = All {code: 0xaa};
386    /// Ignore this and everything preceding when deciding what to sign when signature-checking
387    pub const OP_CODESEPARATOR: All = All {code: 0xab};
388    /// https://en.bitcoin.it/wiki/OP_CHECKSIG pushing 1/0 for success/failure
389    pub const OP_CHECKSIG: All = All {code: 0xac};
390    /// https://en.bitcoin.it/wiki/OP_CHECKSIG returning success/failure
391    pub const OP_CHECKSIGVERIFY: All = All {code: 0xad};
392    /// Pop N, N pubkeys, M, M signatures, a dummy (due to bug in reference code), and verify that all M signatures are valid.
393    /// Push 1 for "all valid", 0 otherwise
394    pub const OP_CHECKMULTISIG: All = All {code: 0xae};
395    /// Like the above but return success/failure
396    pub const OP_CHECKMULTISIGVERIFY: All = All {code: 0xaf};
397    /// Does nothing
398    pub const OP_NOP1: All = All {code: 0xb0};
399    /// https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki
400    pub const OP_CLTV: All = All {code: 0xb1};
401    /// https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki
402    pub const OP_CSV: All = All {code: 0xb2};
403    /// Does nothing
404    pub const OP_NOP4: All = All {code: 0xb3};
405    /// Does nothing
406    pub const OP_NOP5: All = All {code: 0xb4};
407    /// Does nothing
408    pub const OP_NOP6: All = All {code: 0xb5};
409    /// Does nothing
410    pub const OP_NOP7: All = All {code: 0xb6};
411    /// Does nothing
412    pub const OP_NOP8: All = All {code: 0xb7};
413    /// Does nothing
414    pub const OP_NOP9: All = All {code: 0xb8};
415    /// Does nothing
416    pub const OP_NOP10: All = All {code: 0xb9};
417    // Every other opcode acts as OP_RETURN
418    /// Synonym for OP_RETURN
419    pub const OP_RETURN_186: All = All {code: 0xba};
420    /// Synonym for OP_RETURN
421    pub const OP_RETURN_187: All = All {code: 0xbb};
422    /// Synonym for OP_RETURN
423    pub const OP_RETURN_188: All = All {code: 0xbc};
424    /// Synonym for OP_RETURN
425    pub const OP_RETURN_189: All = All {code: 0xbd};
426    /// Synonym for OP_RETURN
427    pub const OP_RETURN_190: All = All {code: 0xbe};
428    /// Synonym for OP_RETURN
429    pub const OP_RETURN_191: All = All {code: 0xbf};
430    /// Synonym for OP_RETURN
431    pub const OP_RETURN_192: All = All {code: 0xc0};
432    /// Synonym for OP_RETURN
433    pub const OP_RETURN_193: All = All {code: 0xc1};
434    /// Synonym for OP_RETURN
435    pub const OP_RETURN_194: All = All {code: 0xc2};
436    /// Synonym for OP_RETURN
437    pub const OP_RETURN_195: All = All {code: 0xc3};
438    /// Synonym for OP_RETURN
439    pub const OP_RETURN_196: All = All {code: 0xc4};
440    /// Synonym for OP_RETURN
441    pub const OP_RETURN_197: All = All {code: 0xc5};
442    /// Synonym for OP_RETURN
443    pub const OP_RETURN_198: All = All {code: 0xc6};
444    /// Synonym for OP_RETURN
445    pub const OP_RETURN_199: All = All {code: 0xc7};
446    /// Synonym for OP_RETURN
447    pub const OP_RETURN_200: All = All {code: 0xc8};
448    /// Synonym for OP_RETURN
449    pub const OP_RETURN_201: All = All {code: 0xc9};
450    /// Synonym for OP_RETURN
451    pub const OP_RETURN_202: All = All {code: 0xca};
452    /// Synonym for OP_RETURN
453    pub const OP_RETURN_203: All = All {code: 0xcb};
454    /// Synonym for OP_RETURN
455    pub const OP_RETURN_204: All = All {code: 0xcc};
456    /// Synonym for OP_RETURN
457    pub const OP_RETURN_205: All = All {code: 0xcd};
458    /// Synonym for OP_RETURN
459    pub const OP_RETURN_206: All = All {code: 0xce};
460    /// Synonym for OP_RETURN
461    pub const OP_RETURN_207: All = All {code: 0xcf};
462    /// Synonym for OP_RETURN
463    pub const OP_RETURN_208: All = All {code: 0xd0};
464    /// Synonym for OP_RETURN
465    pub const OP_RETURN_209: All = All {code: 0xd1};
466    /// Synonym for OP_RETURN
467    pub const OP_RETURN_210: All = All {code: 0xd2};
468    /// Synonym for OP_RETURN
469    pub const OP_RETURN_211: All = All {code: 0xd3};
470    /// Synonym for OP_RETURN
471    pub const OP_RETURN_212: All = All {code: 0xd4};
472    /// Synonym for OP_RETURN
473    pub const OP_RETURN_213: All = All {code: 0xd5};
474    /// Synonym for OP_RETURN
475    pub const OP_RETURN_214: All = All {code: 0xd6};
476    /// Synonym for OP_RETURN
477    pub const OP_RETURN_215: All = All {code: 0xd7};
478    /// Synonym for OP_RETURN
479    pub const OP_RETURN_216: All = All {code: 0xd8};
480    /// Synonym for OP_RETURN
481    pub const OP_RETURN_217: All = All {code: 0xd9};
482    /// Synonym for OP_RETURN
483    pub const OP_RETURN_218: All = All {code: 0xda};
484    /// Synonym for OP_RETURN
485    pub const OP_RETURN_219: All = All {code: 0xdb};
486    /// Synonym for OP_RETURN
487    pub const OP_RETURN_220: All = All {code: 0xdc};
488    /// Synonym for OP_RETURN
489    pub const OP_RETURN_221: All = All {code: 0xdd};
490    /// Synonym for OP_RETURN
491    pub const OP_RETURN_222: All = All {code: 0xde};
492    /// Synonym for OP_RETURN
493    pub const OP_RETURN_223: All = All {code: 0xdf};
494    /// Synonym for OP_RETURN
495    pub const OP_RETURN_224: All = All {code: 0xe0};
496    /// Synonym for OP_RETURN
497    pub const OP_RETURN_225: All = All {code: 0xe1};
498    /// Synonym for OP_RETURN
499    pub const OP_RETURN_226: All = All {code: 0xe2};
500    /// Synonym for OP_RETURN
501    pub const OP_RETURN_227: All = All {code: 0xe3};
502    /// Synonym for OP_RETURN
503    pub const OP_RETURN_228: All = All {code: 0xe4};
504    /// Synonym for OP_RETURN
505    pub const OP_RETURN_229: All = All {code: 0xe5};
506    /// Synonym for OP_RETURN
507    pub const OP_RETURN_230: All = All {code: 0xe6};
508    /// Synonym for OP_RETURN
509    pub const OP_RETURN_231: All = All {code: 0xe7};
510    /// Synonym for OP_RETURN
511    pub const OP_RETURN_232: All = All {code: 0xe8};
512    /// Synonym for OP_RETURN
513    pub const OP_RETURN_233: All = All {code: 0xe9};
514    /// Synonym for OP_RETURN
515    pub const OP_RETURN_234: All = All {code: 0xea};
516    /// Synonym for OP_RETURN
517    pub const OP_RETURN_235: All = All {code: 0xeb};
518    /// Synonym for OP_RETURN
519    pub const OP_RETURN_236: All = All {code: 0xec};
520    /// Synonym for OP_RETURN
521    pub const OP_RETURN_237: All = All {code: 0xed};
522    /// Synonym for OP_RETURN
523    pub const OP_RETURN_238: All = All {code: 0xee};
524    /// Synonym for OP_RETURN
525    pub const OP_RETURN_239: All = All {code: 0xef};
526    /// Synonym for OP_RETURN
527    pub const OP_RETURN_240: All = All {code: 0xf0};
528    /// Synonym for OP_RETURN
529    pub const OP_RETURN_241: All = All {code: 0xf1};
530    /// Synonym for OP_RETURN
531    pub const OP_RETURN_242: All = All {code: 0xf2};
532    /// Synonym for OP_RETURN
533    pub const OP_RETURN_243: All = All {code: 0xf3};
534    /// Synonym for OP_RETURN
535    pub const OP_RETURN_244: All = All {code: 0xf4};
536    /// Synonym for OP_RETURN
537    pub const OP_RETURN_245: All = All {code: 0xf5};
538    /// Synonym for OP_RETURN
539    pub const OP_RETURN_246: All = All {code: 0xf6};
540    /// Synonym for OP_RETURN
541    pub const OP_RETURN_247: All = All {code: 0xf7};
542    /// Synonym for OP_RETURN
543    pub const OP_RETURN_248: All = All {code: 0xf8};
544    /// Synonym for OP_RETURN
545    pub const OP_RETURN_249: All = All {code: 0xf9};
546    /// Synonym for OP_RETURN
547    pub const OP_RETURN_250: All = All {code: 0xfa};
548    /// Synonym for OP_RETURN
549    pub const OP_RETURN_251: All = All {code: 0xfb};
550    /// Synonym for OP_RETURN
551    pub const OP_RETURN_252: All = All {code: 0xfc};
552    /// Synonym for OP_RETURN
553    pub const OP_RETURN_253: All = All {code: 0xfd};
554    /// Synonym for OP_RETURN
555    pub const OP_RETURN_254: All = All {code: 0xfe};
556    /// Synonym for OP_RETURN
557    pub const OP_RETURN_255: All = All {code: 0xff};
558}
559
560impl fmt::Debug for All {
561    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
562        f.write_str("OP_")?;
563        match *self {
564            All {code: x} if x <= 75 => write!(f, "PUSHBYTES_{}", self.code),
565            all::OP_PUSHDATA1 => write!(f, "PUSHDATA1"),
566            all::OP_PUSHDATA2 => write!(f, "PUSHDATA2"),
567            all::OP_PUSHDATA4 => write!(f, "PUSHDATA4"),
568            all::OP_PUSHNUM_NEG1 => write!(f, "PUSHNUM_NEG1"),
569            all::OP_RESERVED => write!(f, "RESERVED"),
570            All {code: x} if x >= all::OP_PUSHNUM_1.code && x <= all::OP_PUSHNUM_16.code => write!(f, "PUSHNUM_{}", x - all::OP_PUSHNUM_1.code + 1),
571            all::OP_NOP => write!(f, "NOP"),
572            all::OP_VER => write!(f, "VER"),
573            all::OP_IF => write!(f, "IF"),
574            all::OP_NOTIF => write!(f, "NOTIF"),
575            all::OP_VERIF => write!(f, "VERIF"),
576            all::OP_VERNOTIF => write!(f, "VERNOTIF"),
577            all::OP_ELSE => write!(f, "ELSE"),
578            all::OP_ENDIF => write!(f, "ENDIF"),
579            all::OP_VERIFY => write!(f, "VERIFY"),
580            all::OP_RETURN => write!(f, "RETURN"),
581            all::OP_TOALTSTACK => write!(f, "TOALTSTACK"),
582            all::OP_FROMALTSTACK => write!(f, "FROMALTSTACK"),
583            all::OP_2DROP => write!(f, "2DROP"),
584            all::OP_2DUP => write!(f, "2DUP"),
585            all::OP_3DUP => write!(f, "3DUP"),
586            all::OP_2OVER => write!(f, "2OVER"),
587            all::OP_2ROT => write!(f, "2ROT"),
588            all::OP_2SWAP => write!(f, "2SWAP"),
589            all::OP_IFDUP => write!(f, "IFDUP"),
590            all::OP_DEPTH => write!(f, "DEPTH"),
591            all::OP_DROP => write!(f, "DROP"),
592            all::OP_DUP => write!(f, "DUP"),
593            all::OP_NIP => write!(f, "NIP"),
594            all::OP_OVER => write!(f, "OVER"),
595            all::OP_PICK => write!(f, "PICK"),
596            all::OP_ROLL => write!(f, "ROLL"),
597            all::OP_ROT => write!(f, "ROT"),
598            all::OP_SWAP => write!(f, "SWAP"),
599            all::OP_TUCK => write!(f, "TUCK"),
600            all::OP_CAT => write!(f, "CAT"),
601            all::OP_SUBSTR => write!(f, "SUBSTR"),
602            all::OP_LEFT => write!(f, "LEFT"),
603            all::OP_RIGHT => write!(f, "RIGHT"),
604            all::OP_SIZE => write!(f, "SIZE"),
605            all::OP_INVERT => write!(f, "INVERT"),
606            all::OP_AND => write!(f, "AND"),
607            all::OP_OR => write!(f, "OR"),
608            all::OP_XOR => write!(f, "XOR"),
609            all::OP_EQUAL => write!(f, "EQUAL"),
610            all::OP_EQUALVERIFY => write!(f, "EQUALVERIFY"),
611            all::OP_RESERVED1 => write!(f, "RESERVED1"),
612            all::OP_RESERVED2 => write!(f, "RESERVED2"),
613            all::OP_1ADD => write!(f, "1ADD"),
614            all::OP_1SUB => write!(f, "1SUB"),
615            all::OP_2MUL => write!(f, "2MUL"),
616            all::OP_2DIV => write!(f, "2DIV"),
617            all::OP_NEGATE => write!(f, "NEGATE"),
618            all::OP_ABS => write!(f, "ABS"),
619            all::OP_NOT => write!(f, "NOT"),
620            all::OP_0NOTEQUAL => write!(f, "0NOTEQUAL"),
621            all::OP_ADD => write!(f, "ADD"),
622            all::OP_SUB => write!(f, "SUB"),
623            all::OP_MUL => write!(f, "MUL"),
624            all::OP_DIV => write!(f, "DIV"),
625            all::OP_MOD => write!(f, "MOD"),
626            all::OP_LSHIFT => write!(f, "LSHIFT"),
627            all::OP_RSHIFT => write!(f, "RSHIFT"),
628            all::OP_BOOLAND => write!(f, "BOOLAND"),
629            all::OP_BOOLOR => write!(f, "BOOLOR"),
630            all::OP_NUMEQUAL => write!(f, "NUMEQUAL"),
631            all::OP_NUMEQUALVERIFY => write!(f, "NUMEQUALVERIFY"),
632            all::OP_NUMNOTEQUAL => write!(f, "NUMNOTEQUAL"),
633            all::OP_LESSTHAN  => write!(f, "LESSTHAN"),
634            all::OP_GREATERTHAN  => write!(f, "GREATERTHAN"),
635            all::OP_LESSTHANOREQUAL  => write!(f, "LESSTHANOREQUAL"),
636            all::OP_GREATERTHANOREQUAL  => write!(f, "GREATERTHANOREQUAL"),
637            all::OP_MIN => write!(f, "MIN"),
638            all::OP_MAX => write!(f, "MAX"),
639            all::OP_WITHIN => write!(f, "WITHIN"),
640            all::OP_RIPEMD160 => write!(f, "RIPEMD160"),
641            all::OP_SHA1 => write!(f, "SHA1"),
642            all::OP_SHA256 => write!(f, "SHA256"),
643            all::OP_HASH160 => write!(f, "HASH160"),
644            all::OP_HASH256 => write!(f, "HASH256"),
645            all::OP_CODESEPARATOR => write!(f, "CODESEPARATOR"),
646            all::OP_CHECKSIG => write!(f, "CHECKSIG"),
647            all::OP_CHECKSIGVERIFY => write!(f, "CHECKSIGVERIFY"),
648            all::OP_CHECKMULTISIG => write!(f, "CHECKMULTISIG"),
649            all::OP_CHECKMULTISIGVERIFY => write!(f, "CHECKMULTISIGVERIFY"),
650            all::OP_CLTV => write!(f, "CLTV"),
651            all::OP_CSV => write!(f, "CSV"),
652            All {code: x} if x >= all::OP_NOP1.code && x <= all::OP_NOP10.code => write!(f, "NOP{}", x - all::OP_NOP1.code + 1),
653            All {code: x} => write!(f, "RETURN_{}", x),
654        }
655    }
656}
657
658impl All {
659    /// Classifies an Opcode into a broad class
660    #[inline]
661    pub fn classify(self) -> Class {
662        // 17 opcodes
663        if self == all::OP_VERIF || self == all::OP_VERNOTIF ||
664           self == all::OP_CAT || self == all::OP_SUBSTR ||
665           self == all::OP_LEFT || self == all::OP_RIGHT ||
666           self == all::OP_INVERT || self == all::OP_AND ||
667           self == all::OP_OR || self == all::OP_XOR ||
668           self == all::OP_2MUL || self == all::OP_2DIV ||
669           self == all::OP_MUL || self == all::OP_DIV || self == all::OP_MOD ||
670           self == all::OP_LSHIFT || self == all::OP_RSHIFT {
671            Class::IllegalOp
672        // 11 opcodes
673        } else if self == all::OP_NOP ||
674                  (all::OP_NOP1.code <= self.code &&
675                   self.code <= all::OP_NOP10.code) {
676            Class::NoOp
677        // 75 opcodes
678        } else if self == all::OP_RESERVED || self == all::OP_VER || self == all::OP_RETURN ||
679                  self == all::OP_RESERVED1 || self == all::OP_RESERVED2 ||
680                  self.code >= all::OP_RETURN_186.code {
681            Class::ReturnOp
682        // 1 opcode
683        } else if self == all::OP_PUSHNUM_NEG1 {
684            Class::PushNum(-1)
685        // 16 opcodes
686        } else if all::OP_PUSHNUM_1.code <= self.code &&
687                  self.code <= all::OP_PUSHNUM_16.code {
688            Class::PushNum(1 + self.code as i32 - all::OP_PUSHNUM_1.code as i32)
689        // 76 opcodes
690        } else if self.code <= all::OP_PUSHBYTES_75.code {
691            Class::PushBytes(self.code as u32)
692        // 60 opcodes
693        } else {
694            Class::Ordinary(Ordinary::try_from_all(self).unwrap())
695        }
696    }
697
698    /// Encode as a byte
699    #[inline]
700    pub fn into_u8(self) -> u8 {
701        self.code
702    }
703}
704
705impl From<u8> for All {
706    #[inline]
707    fn from(b: u8) -> All {
708        All {code: b}
709    }
710}
711
712
713display_from_debug!(All);
714
715#[cfg(feature = "serde")]
716impl serde::Serialize for All {
717    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
718    where
719        S: serde::Serializer,
720    {
721        serializer.serialize_str(&self.to_string())
722    }
723}
724
725/// Empty stack is also FALSE
726pub static OP_FALSE: All = all::OP_PUSHBYTES_0;
727/// Number 1 is also TRUE
728pub static OP_TRUE: All = all::OP_PUSHNUM_1;
729/// previously called OP_NOP2
730pub static OP_NOP2: All = all::OP_CLTV;
731/// previously called OP_NOP3
732pub static OP_NOP3: All = all::OP_CSV;
733
734/// Broad categories of opcodes with similar behavior
735#[derive(Copy, Clone, PartialEq, Eq, Debug)]
736pub enum Class {
737    /// Pushes the given number onto the stack
738    PushNum(i32),
739    /// Pushes the given number of bytes onto the stack
740    PushBytes(u32),
741    /// Fails the script if executed
742    ReturnOp,
743    /// Fails the script even if not executed
744    IllegalOp,
745    /// Does nothing
746    NoOp,
747    /// Any opcode not covered above
748    Ordinary(Ordinary)
749}
750
751display_from_debug!(Class);
752
753#[cfg(feature = "serde")]
754impl serde::Serialize for Class {
755    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
756    where
757        S: serde::Serializer,
758    {
759        serializer.serialize_str(&self.to_string())
760    }
761}
762
763macro_rules! ordinary_opcode {
764    ($($op:ident),*) => (
765        #[repr(u8)]
766        #[doc(hidden)]
767        #[derive(Copy, Clone, PartialEq, Eq, Debug)]
768        pub enum Ordinary {
769            $( $op = all::$op.code ),*
770        }
771
772        impl Ordinary {
773            /// Try to create from an All
774            pub fn try_from_all(b: All) -> Option<Self> {
775                match b {
776                    $( all::$op => { Some(Ordinary::$op) } ),*
777                    _ => None,
778                }
779            }
780        }
781    );
782}
783
784// "Ordinary" opcodes -- should be 60 of these
785ordinary_opcode! {
786    // pushdata
787    OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4,
788    // control flow
789    OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF, OP_VERIFY,
790    // stack
791    OP_TOALTSTACK, OP_FROMALTSTACK,
792    OP_2DROP, OP_2DUP, OP_3DUP, OP_2OVER, OP_2ROT, OP_2SWAP,
793    OP_DROP, OP_DUP, OP_NIP, OP_OVER, OP_PICK, OP_ROLL, OP_ROT, OP_SWAP, OP_TUCK,
794    OP_IFDUP, OP_DEPTH, OP_SIZE,
795    // equality
796    OP_EQUAL, OP_EQUALVERIFY,
797    // arithmetic
798    OP_1ADD, OP_1SUB, OP_NEGATE, OP_ABS, OP_NOT, OP_0NOTEQUAL,
799    OP_ADD, OP_SUB, OP_BOOLAND, OP_BOOLOR,
800    OP_NUMEQUAL, OP_NUMEQUALVERIFY, OP_NUMNOTEQUAL, OP_LESSTHAN,
801    OP_GREATERTHAN, OP_LESSTHANOREQUAL, OP_GREATERTHANOREQUAL,
802    OP_MIN, OP_MAX, OP_WITHIN,
803    // crypto
804    OP_RIPEMD160, OP_SHA1, OP_SHA256, OP_HASH160, OP_HASH256,
805    OP_CODESEPARATOR, OP_CHECKSIG, OP_CHECKSIGVERIFY,
806    OP_CHECKMULTISIG, OP_CHECKMULTISIGVERIFY
807}
808
809impl Ordinary {
810    /// Encode as a byte
811    #[inline]
812    pub fn into_u8(self) -> u8 {
813      self as u8
814  }
815}
816
817#[cfg(test)]
818mod tests {
819    use std::collections::HashSet;
820
821    use super::*;
822
823    macro_rules! roundtrip {
824        ($unique:expr, $op:ident) => {
825            assert_eq!(all::$op, All::from(all::$op.into_u8()));
826
827            let s1 = format!("{}", all::$op);
828            let s2 = format!("{:?}", all::$op);
829            assert_eq!(s1, s2);
830            assert_eq!(s1, stringify!($op));
831            assert!($unique.insert(s1));
832        }
833    }
834
835    #[test]
836    fn str_roundtrip() {
837        let mut unique = HashSet::new();
838        roundtrip!(unique, OP_PUSHBYTES_0);
839        roundtrip!(unique, OP_PUSHBYTES_1);
840        roundtrip!(unique, OP_PUSHBYTES_2);
841        roundtrip!(unique, OP_PUSHBYTES_3);
842        roundtrip!(unique, OP_PUSHBYTES_4);
843        roundtrip!(unique, OP_PUSHBYTES_5);
844        roundtrip!(unique, OP_PUSHBYTES_6);
845        roundtrip!(unique, OP_PUSHBYTES_7);
846        roundtrip!(unique, OP_PUSHBYTES_8);
847        roundtrip!(unique, OP_PUSHBYTES_9);
848        roundtrip!(unique, OP_PUSHBYTES_10);
849        roundtrip!(unique, OP_PUSHBYTES_11);
850        roundtrip!(unique, OP_PUSHBYTES_12);
851        roundtrip!(unique, OP_PUSHBYTES_13);
852        roundtrip!(unique, OP_PUSHBYTES_14);
853        roundtrip!(unique, OP_PUSHBYTES_15);
854        roundtrip!(unique, OP_PUSHBYTES_16);
855        roundtrip!(unique, OP_PUSHBYTES_17);
856        roundtrip!(unique, OP_PUSHBYTES_18);
857        roundtrip!(unique, OP_PUSHBYTES_19);
858        roundtrip!(unique, OP_PUSHBYTES_20);
859        roundtrip!(unique, OP_PUSHBYTES_21);
860        roundtrip!(unique, OP_PUSHBYTES_22);
861        roundtrip!(unique, OP_PUSHBYTES_23);
862        roundtrip!(unique, OP_PUSHBYTES_24);
863        roundtrip!(unique, OP_PUSHBYTES_25);
864        roundtrip!(unique, OP_PUSHBYTES_26);
865        roundtrip!(unique, OP_PUSHBYTES_27);
866        roundtrip!(unique, OP_PUSHBYTES_28);
867        roundtrip!(unique, OP_PUSHBYTES_29);
868        roundtrip!(unique, OP_PUSHBYTES_30);
869        roundtrip!(unique, OP_PUSHBYTES_31);
870        roundtrip!(unique, OP_PUSHBYTES_32);
871        roundtrip!(unique, OP_PUSHBYTES_33);
872        roundtrip!(unique, OP_PUSHBYTES_34);
873        roundtrip!(unique, OP_PUSHBYTES_35);
874        roundtrip!(unique, OP_PUSHBYTES_36);
875        roundtrip!(unique, OP_PUSHBYTES_37);
876        roundtrip!(unique, OP_PUSHBYTES_38);
877        roundtrip!(unique, OP_PUSHBYTES_39);
878        roundtrip!(unique, OP_PUSHBYTES_40);
879        roundtrip!(unique, OP_PUSHBYTES_41);
880        roundtrip!(unique, OP_PUSHBYTES_42);
881        roundtrip!(unique, OP_PUSHBYTES_43);
882        roundtrip!(unique, OP_PUSHBYTES_44);
883        roundtrip!(unique, OP_PUSHBYTES_45);
884        roundtrip!(unique, OP_PUSHBYTES_46);
885        roundtrip!(unique, OP_PUSHBYTES_47);
886        roundtrip!(unique, OP_PUSHBYTES_48);
887        roundtrip!(unique, OP_PUSHBYTES_49);
888        roundtrip!(unique, OP_PUSHBYTES_50);
889        roundtrip!(unique, OP_PUSHBYTES_51);
890        roundtrip!(unique, OP_PUSHBYTES_52);
891        roundtrip!(unique, OP_PUSHBYTES_53);
892        roundtrip!(unique, OP_PUSHBYTES_54);
893        roundtrip!(unique, OP_PUSHBYTES_55);
894        roundtrip!(unique, OP_PUSHBYTES_56);
895        roundtrip!(unique, OP_PUSHBYTES_57);
896        roundtrip!(unique, OP_PUSHBYTES_58);
897        roundtrip!(unique, OP_PUSHBYTES_59);
898        roundtrip!(unique, OP_PUSHBYTES_60);
899        roundtrip!(unique, OP_PUSHBYTES_61);
900        roundtrip!(unique, OP_PUSHBYTES_62);
901        roundtrip!(unique, OP_PUSHBYTES_63);
902        roundtrip!(unique, OP_PUSHBYTES_64);
903        roundtrip!(unique, OP_PUSHBYTES_65);
904        roundtrip!(unique, OP_PUSHBYTES_66);
905        roundtrip!(unique, OP_PUSHBYTES_67);
906        roundtrip!(unique, OP_PUSHBYTES_68);
907        roundtrip!(unique, OP_PUSHBYTES_69);
908        roundtrip!(unique, OP_PUSHBYTES_70);
909        roundtrip!(unique, OP_PUSHBYTES_71);
910        roundtrip!(unique, OP_PUSHBYTES_72);
911        roundtrip!(unique, OP_PUSHBYTES_73);
912        roundtrip!(unique, OP_PUSHBYTES_74);
913        roundtrip!(unique, OP_PUSHBYTES_75);
914        roundtrip!(unique, OP_PUSHDATA1);
915        roundtrip!(unique, OP_PUSHDATA2);
916        roundtrip!(unique, OP_PUSHDATA4);
917        roundtrip!(unique, OP_PUSHNUM_NEG1);
918        roundtrip!(unique, OP_RESERVED);
919        roundtrip!(unique, OP_PUSHNUM_1);
920        roundtrip!(unique, OP_PUSHNUM_2);
921        roundtrip!(unique, OP_PUSHNUM_3);
922        roundtrip!(unique, OP_PUSHNUM_4);
923        roundtrip!(unique, OP_PUSHNUM_5);
924        roundtrip!(unique, OP_PUSHNUM_6);
925        roundtrip!(unique, OP_PUSHNUM_7);
926        roundtrip!(unique, OP_PUSHNUM_8);
927        roundtrip!(unique, OP_PUSHNUM_9);
928        roundtrip!(unique, OP_PUSHNUM_10);
929        roundtrip!(unique, OP_PUSHNUM_11);
930        roundtrip!(unique, OP_PUSHNUM_12);
931        roundtrip!(unique, OP_PUSHNUM_13);
932        roundtrip!(unique, OP_PUSHNUM_14);
933        roundtrip!(unique, OP_PUSHNUM_15);
934        roundtrip!(unique, OP_PUSHNUM_16);
935        roundtrip!(unique, OP_NOP);
936        roundtrip!(unique, OP_VER);
937        roundtrip!(unique, OP_IF);
938        roundtrip!(unique, OP_NOTIF);
939        roundtrip!(unique, OP_VERIF);
940        roundtrip!(unique, OP_VERNOTIF);
941        roundtrip!(unique, OP_ELSE);
942        roundtrip!(unique, OP_ENDIF);
943        roundtrip!(unique, OP_VERIFY);
944        roundtrip!(unique, OP_RETURN);
945        roundtrip!(unique, OP_TOALTSTACK);
946        roundtrip!(unique, OP_FROMALTSTACK);
947        roundtrip!(unique, OP_2DROP);
948        roundtrip!(unique, OP_2DUP);
949        roundtrip!(unique, OP_3DUP);
950        roundtrip!(unique, OP_2OVER);
951        roundtrip!(unique, OP_2ROT);
952        roundtrip!(unique, OP_2SWAP);
953        roundtrip!(unique, OP_IFDUP);
954        roundtrip!(unique, OP_DEPTH);
955        roundtrip!(unique, OP_DROP);
956        roundtrip!(unique, OP_DUP);
957        roundtrip!(unique, OP_NIP);
958        roundtrip!(unique, OP_OVER);
959        roundtrip!(unique, OP_PICK);
960        roundtrip!(unique, OP_ROLL);
961        roundtrip!(unique, OP_ROT);
962        roundtrip!(unique, OP_SWAP);
963        roundtrip!(unique, OP_TUCK);
964        roundtrip!(unique, OP_CAT);
965        roundtrip!(unique, OP_SUBSTR);
966        roundtrip!(unique, OP_LEFT);
967        roundtrip!(unique, OP_RIGHT);
968        roundtrip!(unique, OP_SIZE);
969        roundtrip!(unique, OP_INVERT);
970        roundtrip!(unique, OP_AND);
971        roundtrip!(unique, OP_OR);
972        roundtrip!(unique, OP_XOR);
973        roundtrip!(unique, OP_EQUAL);
974        roundtrip!(unique, OP_EQUALVERIFY);
975        roundtrip!(unique, OP_RESERVED1);
976        roundtrip!(unique, OP_RESERVED2);
977        roundtrip!(unique, OP_1ADD);
978        roundtrip!(unique, OP_1SUB);
979        roundtrip!(unique, OP_2MUL);
980        roundtrip!(unique, OP_2DIV);
981        roundtrip!(unique, OP_NEGATE);
982        roundtrip!(unique, OP_ABS);
983        roundtrip!(unique, OP_NOT);
984        roundtrip!(unique, OP_0NOTEQUAL);
985        roundtrip!(unique, OP_ADD);
986        roundtrip!(unique, OP_SUB);
987        roundtrip!(unique, OP_MUL);
988        roundtrip!(unique, OP_DIV);
989        roundtrip!(unique, OP_MOD);
990        roundtrip!(unique, OP_LSHIFT);
991        roundtrip!(unique, OP_RSHIFT);
992        roundtrip!(unique, OP_BOOLAND);
993        roundtrip!(unique, OP_BOOLOR);
994        roundtrip!(unique, OP_NUMEQUAL);
995        roundtrip!(unique, OP_NUMEQUALVERIFY);
996        roundtrip!(unique, OP_NUMNOTEQUAL);
997        roundtrip!(unique, OP_LESSTHAN );
998        roundtrip!(unique, OP_GREATERTHAN );
999        roundtrip!(unique, OP_LESSTHANOREQUAL );
1000        roundtrip!(unique, OP_GREATERTHANOREQUAL );
1001        roundtrip!(unique, OP_MIN);
1002        roundtrip!(unique, OP_MAX);
1003        roundtrip!(unique, OP_WITHIN);
1004        roundtrip!(unique, OP_RIPEMD160);
1005        roundtrip!(unique, OP_SHA1);
1006        roundtrip!(unique, OP_SHA256);
1007        roundtrip!(unique, OP_HASH160);
1008        roundtrip!(unique, OP_HASH256);
1009        roundtrip!(unique, OP_CODESEPARATOR);
1010        roundtrip!(unique, OP_CHECKSIG);
1011        roundtrip!(unique, OP_CHECKSIGVERIFY);
1012        roundtrip!(unique, OP_CHECKMULTISIG);
1013        roundtrip!(unique, OP_CHECKMULTISIGVERIFY);
1014        roundtrip!(unique, OP_NOP1);
1015        roundtrip!(unique, OP_CLTV);
1016        roundtrip!(unique, OP_CSV);
1017        roundtrip!(unique, OP_NOP4);
1018        roundtrip!(unique, OP_NOP5);
1019        roundtrip!(unique, OP_NOP6);
1020        roundtrip!(unique, OP_NOP7);
1021        roundtrip!(unique, OP_NOP8);
1022        roundtrip!(unique, OP_NOP9);
1023        roundtrip!(unique, OP_NOP10);
1024        roundtrip!(unique, OP_RETURN_186);
1025        roundtrip!(unique, OP_RETURN_187);
1026        roundtrip!(unique, OP_RETURN_188);
1027        roundtrip!(unique, OP_RETURN_189);
1028        roundtrip!(unique, OP_RETURN_190);
1029        roundtrip!(unique, OP_RETURN_191);
1030        roundtrip!(unique, OP_RETURN_192);
1031        roundtrip!(unique, OP_RETURN_193);
1032        roundtrip!(unique, OP_RETURN_194);
1033        roundtrip!(unique, OP_RETURN_195);
1034        roundtrip!(unique, OP_RETURN_196);
1035        roundtrip!(unique, OP_RETURN_197);
1036        roundtrip!(unique, OP_RETURN_198);
1037        roundtrip!(unique, OP_RETURN_199);
1038        roundtrip!(unique, OP_RETURN_200);
1039        roundtrip!(unique, OP_RETURN_201);
1040        roundtrip!(unique, OP_RETURN_202);
1041        roundtrip!(unique, OP_RETURN_203);
1042        roundtrip!(unique, OP_RETURN_204);
1043        roundtrip!(unique, OP_RETURN_205);
1044        roundtrip!(unique, OP_RETURN_206);
1045        roundtrip!(unique, OP_RETURN_207);
1046        roundtrip!(unique, OP_RETURN_208);
1047        roundtrip!(unique, OP_RETURN_209);
1048        roundtrip!(unique, OP_RETURN_210);
1049        roundtrip!(unique, OP_RETURN_211);
1050        roundtrip!(unique, OP_RETURN_212);
1051        roundtrip!(unique, OP_RETURN_213);
1052        roundtrip!(unique, OP_RETURN_214);
1053        roundtrip!(unique, OP_RETURN_215);
1054        roundtrip!(unique, OP_RETURN_216);
1055        roundtrip!(unique, OP_RETURN_217);
1056        roundtrip!(unique, OP_RETURN_218);
1057        roundtrip!(unique, OP_RETURN_219);
1058        roundtrip!(unique, OP_RETURN_220);
1059        roundtrip!(unique, OP_RETURN_221);
1060        roundtrip!(unique, OP_RETURN_222);
1061        roundtrip!(unique, OP_RETURN_223);
1062        roundtrip!(unique, OP_RETURN_224);
1063        roundtrip!(unique, OP_RETURN_225);
1064        roundtrip!(unique, OP_RETURN_226);
1065        roundtrip!(unique, OP_RETURN_227);
1066        roundtrip!(unique, OP_RETURN_228);
1067        roundtrip!(unique, OP_RETURN_229);
1068        roundtrip!(unique, OP_RETURN_230);
1069        roundtrip!(unique, OP_RETURN_231);
1070        roundtrip!(unique, OP_RETURN_232);
1071        roundtrip!(unique, OP_RETURN_233);
1072        roundtrip!(unique, OP_RETURN_234);
1073        roundtrip!(unique, OP_RETURN_235);
1074        roundtrip!(unique, OP_RETURN_236);
1075        roundtrip!(unique, OP_RETURN_237);
1076        roundtrip!(unique, OP_RETURN_238);
1077        roundtrip!(unique, OP_RETURN_239);
1078        roundtrip!(unique, OP_RETURN_240);
1079        roundtrip!(unique, OP_RETURN_241);
1080        roundtrip!(unique, OP_RETURN_242);
1081        roundtrip!(unique, OP_RETURN_243);
1082        roundtrip!(unique, OP_RETURN_244);
1083        roundtrip!(unique, OP_RETURN_245);
1084        roundtrip!(unique, OP_RETURN_246);
1085        roundtrip!(unique, OP_RETURN_247);
1086        roundtrip!(unique, OP_RETURN_248);
1087        roundtrip!(unique, OP_RETURN_249);
1088        roundtrip!(unique, OP_RETURN_250);
1089        roundtrip!(unique, OP_RETURN_251);
1090        roundtrip!(unique, OP_RETURN_252);
1091        roundtrip!(unique, OP_RETURN_253);
1092        roundtrip!(unique, OP_RETURN_254);
1093        roundtrip!(unique, OP_RETURN_255);
1094        assert_eq!(unique.len(), 256);
1095    }
1096}
1097