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