bitcoin_cash_base/
opcode.rs

1use num_derive::*;
2
3use lazy_static::lazy_static;
4use std::collections::HashMap;
5
6use crate::data_type::{BitcoinBoolean, BitcoinByteArray, BitcoinInteger, DataType};
7
8lazy_static! {
9    pub static ref MAP_NAME_TO_ENUM: HashMap<String, Opcode> = {
10        let mut map = HashMap::new();
11        map.insert("OP_0".to_string(), Opcode::OP_0);
12        map.insert("OP_1NEGATE".to_string(), Opcode::OP_1NEGATE);
13        for code in 0x51..Opcode::FIRST_UNDEFINED_OP_VALUE as u8 {
14            let opcode: Opcode = num::FromPrimitive::from_u8(code)
15                .unwrap_or_else(|| panic!("Invalid opcode {}", code));
16            map.insert(format!("{:?}", opcode), opcode);
17        }
18        map
19    };
20}
21
22#[derive(Clone, Debug, Copy, Eq, PartialEq)]
23pub enum StackItemDelta {
24    Untouched,
25    Added,
26    Changed,
27    Moved,
28    MovedIndirectly,
29    Observed,
30    Removed,
31}
32
33#[derive(Clone, Debug, Copy, Eq, PartialEq)]
34pub struct OpcodeBehavior {
35    pub input_types: &'static [DataType],
36    pub output_types: &'static [DataType],
37    pub output_order: Option<&'static [usize]>,
38    pub delta: &'static [StackItemDelta],
39}
40
41/// All opcodes which can be used in a Bitcoin Cash script.
42///
43/// Can be used in `#[bitcoin_cash::script]` functions.
44///
45/// ## Example
46/// ```
47/// use bitcoin_cash::{Opcode::*, Address, ByteArray, Hashed};
48/// struct Params {
49///   address: Address<'static>,
50/// }
51/// #[bitcoin_cash::script(P2pkhInputs)]
52/// fn p2pkh_script(params: &Params, signature: ByteArray, public_key: ByteArray) {
53///   OP_DUP(public_key);
54///   let pkh = OP_HASH160(public_key);
55///   let address = { params.address.hash().as_slice() };
56///   OP_EQUALVERIFY(pkh, address);
57///   OP_CHECKSIG(signature, public_key);
58/// }
59/// ```
60#[allow(non_camel_case_types)]
61#[derive(Clone, Debug, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, FromPrimitive)]
62pub enum Opcode {
63    /// ```text
64    /// OP_0() -> Integer
65    /// ```
66    ///
67    /// Pushes the integer 0 onto the stack.
68    ///
69    /// Usage:
70    /// ```
71    /// # use bitcoin_cash::Opcode::*;
72    /// # #[bitcoin_cash::script(DemoInputs)]
73    /// # fn demo(_: ()) {
74    /// let zero = OP_0;
75    /// let expected = 0;  // equivalent (and prefered) way to push numbers
76    /// OP_EQUALVERIFY(zero, expected);
77    /// # }
78    /// ```
79    OP_0 = 0x00,
80
81    /// Pushes the next byte number of bytes. Not to be used in `#[bitcoin_cash::script]` functions.
82    OP_PUSHDATA1 = 0x4c,
83
84    /// Pushes the next two byte number of bytes. Not to be used in `#[bitcoin_cash::script]` functions.
85    OP_PUSHDATA2 = 0x4d,
86
87    /// Pushes the next four byte number of bytes. Not to be used in `#[bitcoin_cash::script]` functions.
88    OP_PUSHDATA4 = 0x4e,
89
90    /// ```text
91    /// OP_1NEGATE() -> Integer
92    /// ```
93    ///
94    /// Pushes the integer -1 onto the stack.
95    ///
96    /// Usage:
97    /// ```
98    /// # use bitcoin_cash::Opcode::*;
99    /// # #[bitcoin_cash::script(DemoInputs)]
100    /// # fn demo(_: ()) {
101    /// // push -1
102    /// let minus_one = OP_1NEGATE;
103    ///
104    /// let expected = -1;  // equivalent (and prefered) way to push numbers
105    /// OP_EQUALVERIFY(minus_one, expected);
106    /// # }
107    /// ```
108    OP_1NEGATE = 0x4f,
109
110    /// Reserved opcode. Fails script if in executed branch immediately.
111    OP_RESERVED = 0x50,
112
113    /// ```text
114    /// OP_1() -> Integer
115    /// ```
116    ///
117    /// Pushes the integer 1 onto the stack.
118    ///
119    /// Usage:
120    /// ```
121    /// # use bitcoin_cash::Opcode::*;
122    /// # #[bitcoin_cash::script(DemoInputs)]
123    /// # fn demo(_: ()) {
124    /// // push 1
125    /// let one = OP_1;
126    ///
127    /// let expected = 1;  // equivalent (and prefered) way to push numbers
128    /// OP_EQUALVERIFY(one, expected);
129    /// # }
130    /// ```
131    OP_1 = 0x51,
132
133    /// ```text
134    /// OP_2() -> Integer
135    /// ```
136    ///
137    /// Pushes the integer 2 onto the stack.
138    ///
139    /// Usage:
140    /// ```
141    /// # use bitcoin_cash::Opcode::*;
142    /// # #[bitcoin_cash::script(DemoInputs)]
143    /// # fn demo(_: ()) {
144    /// // push 2
145    /// let two = OP_2;
146    ///
147    /// let expected = 2;  // equivalent (and prefered) way to push numbers
148    /// OP_EQUALVERIFY(two, expected);
149    /// # }
150    /// ```
151    OP_2 = 0x52,
152
153    /// ```text
154    /// OP_3() -> Integer
155    /// ```
156    ///
157    /// Pushes the integer 3 onto the stack.
158    ///
159    /// Usage:
160    /// ```
161    /// # use bitcoin_cash::Opcode::*;
162    /// # #[bitcoin_cash::script(DemoInputs)]
163    /// # fn demo(_: ()) {
164    /// // push 3
165    /// let three = OP_3;
166    ///
167    /// let expected = 3;  // equivalent (and prefered) way to push numbers
168    /// OP_EQUALVERIFY(three, expected);
169    /// # }
170    /// ```
171    OP_3 = 0x53,
172
173    /// ```text
174    /// OP_4() -> Integer
175    /// ```
176    ///
177    /// Pushes the integer 4 onto the stack.
178    ///
179    /// Usage:
180    /// ```
181    /// # use bitcoin_cash::Opcode::*;
182    /// # #[bitcoin_cash::script(DemoInputs)]
183    /// # fn demo(_: ()) {
184    /// // push 4
185    /// let four = OP_4;
186    ///
187    /// let expected = 4;  // equivalent (and prefered) way to push numbers
188    /// OP_EQUALVERIFY(four, expected);
189    /// # }
190    /// ```
191    OP_4 = 0x54,
192
193    /// ```text
194    /// OP_5() -> Integer
195    /// ```
196    ///
197    /// Pushes the integer 5 onto the stack.
198    ///
199    /// Usage:
200    /// ```
201    /// # use bitcoin_cash::Opcode::*;
202    /// # #[bitcoin_cash::script(DemoInputs)]
203    /// # fn demo(_: ()) {
204    /// // push 5
205    /// let five = OP_5;
206    ///
207    /// let expected = 5;  // equivalent (and prefered) way to push numbers
208    /// OP_EQUALVERIFY(five, expected);
209    /// # }
210    /// ```
211    OP_5 = 0x55,
212
213    /// ```text
214    /// OP_6() -> Integer
215    /// ```
216    ///
217    /// Pushes the integer 6 onto the stack.
218    ///
219    /// Usage:
220    /// ```
221    /// # use bitcoin_cash::Opcode::*;
222    /// # #[bitcoin_cash::script(DemoInputs)]
223    /// # fn demo(_: ()) {
224    /// // push 6
225    /// let six = OP_6;
226    ///
227    /// let expected = 6;  // equivalent (and prefered) way to push numbers
228    /// OP_EQUALVERIFY(six, expected);
229    /// # }
230    /// ```
231    OP_6 = 0x56,
232
233    /// ```text
234    /// OP_7() -> Integer
235    /// ```
236    ///
237    /// Pushes the integer 7 onto the stack.
238    ///
239    /// Usage:
240    /// ```
241    /// # use bitcoin_cash::Opcode::*;
242    /// # #[bitcoin_cash::script(DemoInputs)]
243    /// # fn demo(_: ()) {
244    /// // push 7
245    /// let seven = OP_7;
246    ///
247    /// let expected = 7;  // equivalent (and prefered) way to push numbers
248    /// OP_EQUALVERIFY(seven, expected);
249    /// # }
250    /// ```
251    OP_7 = 0x57,
252
253    /// ```text
254    /// OP_8() -> Integer
255    /// ```
256    ///
257    /// Pushes the integer 8 onto the stack.
258    ///
259    /// Usage:
260    /// ```
261    /// # use bitcoin_cash::Opcode::*;
262    /// # #[bitcoin_cash::script(DemoInputs)]
263    /// # fn demo(_: ()) {
264    /// // push 8
265    /// let eight = OP_8;
266    ///
267    /// let expected = 8;  // equivalent (and prefered) way to push numbers
268    /// OP_EQUALVERIFY(eight, expected);
269    /// # }
270    /// ```
271    OP_8 = 0x58,
272
273    /// ```text
274    /// OP_9() -> Integer
275    /// ```
276    ///
277    /// Pushes the integer 9 onto the stack.
278    ///
279    /// Usage:
280    /// ```
281    /// # use bitcoin_cash::Opcode::*;
282    /// # #[bitcoin_cash::script(DemoInputs)]
283    /// # fn demo(_: ()) {
284    /// // push 9
285    /// let nine = OP_9;
286    ///
287    /// let expected = 9;  // equivalent (and prefered) way to push numbers
288    /// OP_EQUALVERIFY(nine, expected);
289    /// # }
290    /// ```
291    OP_9 = 0x59,
292
293    /// ```text
294    /// OP_10() -> Integer
295    /// ```
296    ///
297    /// Pushes the integer 10 onto the stack.
298    ///
299    /// Usage:
300    /// ```
301    /// # use bitcoin_cash::Opcode::*;
302    /// # #[bitcoin_cash::script(DemoInputs)]
303    /// # fn demo(_: ()) {
304    /// // push 10
305    /// let ten = OP_10;
306    ///
307    /// let expected = 10;  // equivalent (and prefered) way to push numbers
308    /// OP_EQUALVERIFY(ten, expected);
309    /// # }
310    /// ```
311    OP_10 = 0x5a,
312
313    /// ```text
314    /// OP_11() -> Integer
315    /// ```
316    ///
317    /// Pushes the integer 11 onto the stack.
318    ///
319    /// Usage:
320    /// ```
321    /// # use bitcoin_cash::Opcode::*;
322    /// # #[bitcoin_cash::script(DemoInputs)]
323    /// # fn demo(_: ()) {
324    /// // push 11
325    /// let eleven = OP_11;
326    ///
327    /// let expected = 11;  // equivalent (and prefered) way to push numbers
328    /// OP_EQUALVERIFY(eleven, expected);
329    /// # }
330    /// ```
331    OP_11 = 0x5b,
332
333    /// ```text
334    /// OP_12() -> Integer
335    /// ```
336    ///
337    /// Pushes the integer 12 onto the stack.
338    ///
339    /// Usage:
340    /// ```
341    /// # use bitcoin_cash::Opcode::*;
342    /// # #[bitcoin_cash::script(DemoInputs)]
343    /// # fn demo(_: ()) {
344    /// // push 12
345    /// let twelve = OP_12;
346    ///
347    /// let expected = 12;  // equivalent (and prefered) way to push numbers
348    /// OP_EQUALVERIFY(twelve, expected);
349    /// # }
350    /// ```
351    OP_12 = 0x5c,
352
353    /// ```text
354    /// OP_13() -> Integer
355    /// ```
356    ///
357    /// Pushes the integer 13 onto the stack.
358    ///
359    /// Usage:
360    /// ```
361    /// # use bitcoin_cash::Opcode::*;
362    /// # #[bitcoin_cash::script(DemoInputs)]
363    /// # fn demo(_: ()) {
364    /// // push 13
365    /// let thirteen = OP_13;
366    ///
367    /// let expected = 13;  // equivalent (and prefered) way to push numbers
368    /// OP_EQUALVERIFY(thirteen, expected);
369    /// # }
370    /// ```
371    OP_13 = 0x5d,
372
373    /// ```text
374    /// OP_14() -> Integer
375    /// ```
376    ///
377    /// Pushes the integer 14 onto the stack.
378    ///
379    /// Usage:
380    /// ```
381    /// # use bitcoin_cash::Opcode::*;
382    /// # #[bitcoin_cash::script(DemoInputs)]
383    /// # fn demo(_: ()) {
384    /// // push 14
385    /// let fourteen = OP_14;
386    ///
387    /// let expected = 14;  // equivalent (and prefered) way to push numbers
388    /// OP_EQUALVERIFY(fourteen, expected);
389    /// # }
390    /// ```
391    OP_14 = 0x5e,
392
393    /// ```text
394    /// OP_15() -> Integer
395    /// ```
396    ///
397    /// Pushes the integer 15 onto the stack.
398    ///
399    /// Usage:
400    /// ```
401    /// # use bitcoin_cash::Opcode::*;
402    /// # #[bitcoin_cash::script(DemoInputs)]
403    /// # fn demo(_: ()) {
404    /// // push 15
405    /// let fiveteen = OP_15;
406    ///
407    /// let expected = 15;  // equivalent (and prefered) way to push numbers
408    /// OP_EQUALVERIFY(fiveteen, expected);
409    /// # }
410    /// ```
411    OP_15 = 0x5f,
412
413    /// ```text
414    /// OP_16() -> Integer
415    /// ```
416    ///
417    /// Pushes the integer 16 onto the stack.
418    ///
419    /// Usage:
420    /// ```
421    /// # use bitcoin_cash::Opcode::*;
422    /// # #[bitcoin_cash::script(DemoInputs)]
423    /// # fn demo(_: ()) {
424    /// // push 16
425    /// let sixteen = OP_16;
426    ///
427    /// let expected = 16;  // equivalent (and prefered) way to push numbers
428    /// OP_EQUALVERIFY(sixteen, expected);
429    /// # }
430    /// ```
431    OP_16 = 0x60,
432
433    /// ```text
434    /// OP_NOP() -> ()
435    /// ```
436    ///
437    /// Does nothing.
438    ///
439    /// Usage:
440    /// ```
441    /// # use bitcoin_cash::Opcode::*;
442    /// # #[bitcoin_cash::script(DemoInputs)]
443    /// # fn demo(_: ()) {
444    /// // do nothing
445    /// OP_NOP();
446    /// # }
447    /// ```
448    OP_NOP = 0x61,
449
450    /// Reserved opcode. Fails script if in executed branch immediately.
451    OP_VER = 0x62,
452
453    /// ```text
454    /// OP_IF(condition: bool) -> ()
455    /// ```
456    ///
457    /// Creates a branch (`OP_IF`/`OP_ELSE`/`OP_ENDIF` construct) that will only execute
458    /// if `condition` is true and will execute the alternative branch otherwise.
459    ///
460    /// Usage:
461    /// ```
462    /// # use bitcoin_cash::Opcode::*;
463    /// # #[bitcoin_cash::script(DemoInputs)]
464    /// # fn demo(_: ()) {
465    /// let condition = true;
466    ///
467    /// // branch on condition
468    /// OP_IF(condition); {
469    ///     let result = 5;
470    /// } OP_ELSE; {
471    ///     let result = 6;
472    /// } OP_ENDIF;
473    ///
474    /// let expected = 5;
475    /// OP_EQUALVERIFY(result, expected);
476    /// # }
477    /// ```
478    OP_IF = 0x63,
479
480    /// Opposite of OP_NOTIF. Currently not supported in `#[bitcoin_cash::script]` functions.
481    OP_NOTIF = 0x64,
482
483    /// Disabled opcode. Fails script immediately even if not in executed branch.
484    OP_VERIF = 0x65,
485
486    /// Disabled opcode. Fails script immediately even if not in executed branch.
487    OP_VERNOTIF = 0x66,
488
489    /// ```text
490    /// OP_ELSE() -> ()
491    /// ```
492    ///
493    /// Demarcates a branch (`OP_IF`/`OP_ELSE`/`OP_ENDIF` construct) that will only execute
494    /// if `condition` is true and will execute the alternative branch otherwise.
495    ///
496    /// Usage:
497    /// ```
498    /// # use bitcoin_cash::Opcode::*;
499    /// # #[bitcoin_cash::script(DemoInputs)]
500    /// # fn demo(_: ()) {
501    /// let condition = true;
502    ///
503    /// // branch on condition
504    /// OP_IF(condition); {
505    ///     let result = 5;
506    /// } OP_ELSE; {
507    ///     let result = 6;
508    /// } OP_ENDIF;
509    ///
510    /// let expected = 5;
511    /// OP_EQUALVERIFY(result, expected);
512    /// # }
513    /// ```
514    OP_ELSE = 0x67,
515
516    /// ```text
517    /// OP_ENDIF() -> ()
518    /// ```
519    ///
520    /// Ends a branch (`OP_IF`/`OP_ELSE`/`OP_ENDIF` construct) that will only execute
521    /// if `condition` is true and will execute the alternative branch otherwise.
522    ///
523    /// Usage:
524    /// ```
525    /// # use bitcoin_cash::Opcode::*;
526    /// # #[bitcoin_cash::script(DemoInputs)]
527    /// # fn demo(_: ()) {
528    /// let condition = true;
529    ///
530    /// // branch on condition
531    /// OP_IF(condition); {
532    ///     let result = 5;
533    /// } OP_ELSE; {
534    ///     let result = 6;
535    /// } OP_ENDIF;
536    ///
537    /// let expected = 5;
538    /// OP_EQUALVERIFY(result, expected);
539    /// # }
540    /// ```
541    OP_ENDIF = 0x68,
542
543    /// ```text
544    /// OP_VERIFY(condition: bool) -> ()
545    /// ```
546    ///
547    /// Marks transaction as invalid if `condition` is not true.
548    ///
549    /// Usage:
550    /// ```
551    /// # use bitcoin_cash::Opcode::*;
552    /// # #[bitcoin_cash::script(DemoInputs)]
553    /// # fn demo(_: ()) {
554    /// let condition = true;
555    ///
556    /// // verify condition
557    /// OP_VERIFY(condition);
558    /// # }
559    /// ```
560    OP_VERIFY = 0x69,
561
562    /// Fails execution of the script immediately. Used to attach data to transactions.
563    OP_RETURN = 0x6a,
564
565    /// ```text
566    /// OP_TOALTSTACK<T>(item: T) -> ()
567    /// ```
568    ///
569    /// Moves `item` to the top of the altstack.
570    ///
571    /// Usage:
572    /// ```
573    /// # use bitcoin_cash::Opcode::*;
574    /// # #[bitcoin_cash::script(DemoInputs)]
575    /// # fn demo(_: ()) {
576    /// let item = b"Bitcoin Cash";
577    ///
578    /// // move item to altstack
579    /// OP_TOALTSTACK(item);
580    ///
581    /// let expected = b"Bitcoin Cash";
582    /// OP_FROMALTSTACK(item);  // Note: retains name "item" on altstack
583    /// OP_EQUALVERIFY(expected, item);
584    /// # }
585    /// ```
586    OP_TOALTSTACK = 0x6b,
587
588    /// ```text
589    /// OP_FROMALTSTACK<T>(altitem: T) -> T
590    /// ```
591    ///
592    /// Moves the top item of the altstack to the main stack.
593    ///
594    /// Usage:
595    /// ```
596    /// # use bitcoin_cash::Opcode::*;
597    /// # #[bitcoin_cash::script(DemoInputs)]
598    /// # fn demo(_: ()) {
599    /// let item = b"Bitcoin Cash";
600    /// OP_TOALTSTACK(item);
601    /// let expected = b"Bitcoin Cash";
602    ///
603    /// // move item back to main stack
604    /// OP_FROMALTSTACK(item);  // Note: retains name "item" on main stack
605    ///
606    /// OP_EQUALVERIFY(expected, item);
607    /// # }
608    /// ```
609    OP_FROMALTSTACK = 0x6c,
610
611    /// ```text
612    /// OP_2DROP<T, U>(a: T, b: U) -> ()
613    /// ```
614    ///
615    /// Drops the two top stack items.
616    ///
617    /// ```text
618    /// a b ->
619    /// ```
620    ///
621    /// Usage:
622    /// ```
623    /// # use bitcoin_cash::Opcode::*;
624    /// # #[bitcoin_cash::script(DemoInputs)]
625    /// # fn demo(_: ()) {
626    /// let a = b"A";
627    /// let b = b"B";
628    /// let c = b"C";
629    ///
630    /// // drop b and c
631    /// OP_2DROP(b, c);
632    ///
633    /// let expected = b"A";
634    /// OP_EQUALVERIFY(a, expected);
635    /// # }
636    /// ```
637    OP_2DROP = 0x6d,
638
639    /// ```text
640    /// OP_2DUP<T, U>(a: T, b: U) -> (T, U, T, U)
641    /// ```
642    ///
643    /// Duplicates the top two stack items.
644    ///
645    /// ```text
646    /// a b -> a b a b
647    /// ```
648    ///
649    /// Usage:
650    /// ```
651    /// # use bitcoin_cash::Opcode::*;
652    /// # #[bitcoin_cash::script(DemoInputs)]
653    /// # fn demo(_: ()) {
654    /// let a = b"A";
655    /// let b = b"B";
656    ///
657    /// // duplicate a and b
658    /// OP_2DUP(a, b);  // Note: duplicated items retain name
659    ///
660    /// let expected = b"A";
661    /// OP_EQUALVERIFY(b, expected);
662    /// let expected = b"B";
663    /// OP_EQUALVERIFY(a, expected);
664    /// let expected = b"A";
665    /// OP_EQUALVERIFY(b, expected);
666    /// let expected = b"B";
667    /// OP_EQUALVERIFY(a, expected);
668    /// # }
669    /// ```
670    OP_2DUP = 0x6e,
671
672    /// ```text
673    /// OP_3DUP<T, U, V>(a: T, b: U, c: V) -> (T, U, V, T, U, V)
674    /// ```
675    ///
676    /// Duplicates the top two three items.
677    ///
678    /// ```text
679    /// a b c -> a b c a b c
680    /// ```
681    ///
682    /// Usage:
683    /// ```
684    /// # use bitcoin_cash::Opcode::*;
685    /// # #[bitcoin_cash::script(DemoInputs)]
686    /// # fn demo(_: ()) {
687    /// let a = b"A";
688    /// let b = b"B";
689    /// let c = b"C";
690    ///
691    /// // duplicate a, b and c
692    /// OP_3DUP(a, b, c);  // Note: duplicated items retain name
693    ///
694    /// let expected = b"C";
695    /// OP_EQUALVERIFY(c, expected);
696    /// let expected = b"B";
697    /// OP_EQUALVERIFY(b, expected);
698    /// let expected = b"A";
699    /// OP_EQUALVERIFY(a, expected);
700    /// let expected = b"C";
701    /// OP_EQUALVERIFY(c, expected);
702    /// let expected = b"B";
703    /// OP_EQUALVERIFY(b, expected);
704    /// let expected = b"A";
705    /// OP_EQUALVERIFY(a, expected);
706    /// # }
707    /// ```
708    OP_3DUP = 0x6f,
709
710    /// ```text
711    /// OP_2OVER<T, U, V, W>(a: T, b: U, c: V, d: W) -> (T, U, V, W, T, U)
712    /// ```
713    ///
714    /// Copies the pair of items two spaces back in the stack to the front.
715    ///
716    /// ```text
717    /// a b _ _ -> a b _ _ a b
718    /// ```
719    ///
720    /// Usage:
721    /// ```
722    /// # use bitcoin_cash::Opcode::*;
723    /// # #[bitcoin_cash::script(DemoInputs)]
724    /// # fn demo(_: ()) {
725    /// let a = b"A";
726    /// let b = b"B";
727    /// let c = b"C";
728    /// let d = b"D";
729    ///
730    /// // duplicate a and b
731    /// OP_2OVER(a, b, __, __);  // Note: duplicated items retain name
732    ///
733    /// let expected = b"B";
734    /// OP_EQUALVERIFY(b, expected);
735    /// let expected = b"A";
736    /// OP_EQUALVERIFY(a, expected);
737    /// let expected = b"D";
738    /// OP_EQUALVERIFY(d, expected);
739    /// let expected = b"C";
740    /// OP_EQUALVERIFY(c, expected);
741    /// let expected = b"B";
742    /// OP_EQUALVERIFY(b, expected);
743    /// let expected = b"A";
744    /// OP_EQUALVERIFY(a, expected);
745    /// # }
746    /// ```
747    OP_2OVER = 0x70,
748
749    /// ```text
750    /// OP_2ROT<T, U, V, W, X, Y>(a: T, b: U, c: V, d: W, e: X, f: Y) -> (V, W, X, Y, T, U)
751    /// ```
752    ///
753    /// The fifth and sixth items back are moved to the top of the stack.
754    ///
755    /// ```text
756    /// a b _ _ _ _ -> _ _ _ _ a b
757    /// ```
758    ///
759    /// Usage:
760    /// ```
761    /// # use bitcoin_cash::Opcode::*;
762    /// # #[bitcoin_cash::script(DemoInputs)]
763    /// # fn demo(_: ()) {
764    /// let a = b"A";
765    /// let b = b"B";
766    /// let c = b"C";
767    /// let d = b"D";
768    /// let e = b"E";
769    /// let f = b"F";
770    ///
771    /// // move a and b to the top
772    /// OP_2ROT(a, b, __, __, __, __);  // Note: moved items retain name
773    ///
774    /// let expected = b"B";
775    /// OP_EQUALVERIFY(b, expected);
776    /// let expected = b"A";
777    /// OP_EQUALVERIFY(a, expected);
778    /// let expected = b"F";
779    /// OP_EQUALVERIFY(f, expected);
780    /// let expected = b"E";
781    /// OP_EQUALVERIFY(e, expected);
782    /// let expected = b"D";
783    /// OP_EQUALVERIFY(d, expected);
784    /// let expected = b"C";
785    /// OP_EQUALVERIFY(c, expected);
786    /// # }
787    /// ```
788    OP_2ROT = 0x71,
789
790    /// ```text
791    /// OP_2SWAP<T, U, V, W>(a: T, b: U, c: V, d: W) -> (V, W, T, U)
792    /// ```
793    ///
794    /// Swaps the top two pairs of items.
795    ///
796    /// ```text
797    /// a b c d -> c d a b
798    /// ```
799    ///
800    /// Usage:
801    /// ```
802    /// # use bitcoin_cash::Opcode::*;
803    /// # #[bitcoin_cash::script(DemoInputs)]
804    /// # fn demo(_: ()) {
805    /// let a = b"A";
806    /// let b = b"B";
807    /// let c = b"C";
808    /// let d = b"D";
809    ///
810    /// // swap a and b with c and d
811    /// OP_2SWAP(a, b, c, d);  // Note: moved items retain name
812    ///
813    /// let expected = b"B";
814    /// OP_EQUALVERIFY(b, expected);
815    /// let expected = b"A";
816    /// OP_EQUALVERIFY(a, expected);
817    /// let expected = b"D";
818    /// OP_EQUALVERIFY(d, expected);
819    /// let expected = b"C";
820    /// OP_EQUALVERIFY(c, expected);
821    /// # }
822    /// ```
823    OP_2SWAP = 0x72,
824
825    /// If the top stack value is true, duplicate it. Not to be used in `#[bitcoin_cash::script]` functions.
826    OP_IFDUP = 0x73,
827
828    /// ```text
829    /// OP_DEPTH() -> Integer
830    /// ```
831    ///
832    /// Returns the number of stack items.
833    ///
834    /// Usage:
835    /// ```
836    /// # use bitcoin_cash::Opcode::*;
837    /// # #[bitcoin_cash::script(DemoInputs)]
838    /// # fn demo(_: ()) {
839    /// let a = b"A";
840    /// let b = b"B";
841    /// let c = b"C";
842    ///
843    /// // number of items on the stack
844    /// let n = OP_DEPTH();
845    ///
846    /// let expected = 3;
847    /// OP_EQUALVERIFY(n, expected);
848    /// # }
849    /// ```
850    OP_DEPTH = 0x74,
851
852    /// ```text
853    /// OP_DROP<T>(a: T) -> ()
854    /// ```
855    ///
856    /// Drops the top stack item.
857    ///
858    /// ```text
859    /// a ->
860    /// ```
861    ///
862    /// Usage:
863    /// ```
864    /// # use bitcoin_cash::Opcode::*;
865    /// # #[bitcoin_cash::script(DemoInputs)]
866    /// # fn demo(_: ()) {
867    /// let a = b"A";
868    /// let b = b"B";
869    ///
870    /// // drop b
871    /// OP_DROP(b);
872    ///
873    /// let expected = b"A";
874    /// OP_EQUALVERIFY(a, expected);
875    /// # }
876    /// ```
877    OP_DROP = 0x75,
878
879    /// ```text
880    /// OP_DUP<T>(a: T) -> (T, T)
881    /// ```
882    ///
883    /// Duplicates the top stack item.
884    ///
885    /// ```text
886    /// a -> a a
887    /// ```
888    ///
889    /// Usage:
890    /// ```
891    /// # use bitcoin_cash::Opcode::*;
892    /// # #[bitcoin_cash::script(DemoInputs)]
893    /// # fn demo(_: ()) {
894    /// let a = b"A";
895    ///
896    /// // drop b and c
897    /// OP_DUP(a);  // Note: duplicated item retains name
898    ///
899    /// let expected = b"A";
900    /// OP_EQUALVERIFY(a, expected);
901    /// let expected = b"A";
902    /// OP_EQUALVERIFY(a, expected);
903    /// # }
904    /// ```
905    OP_DUP = 0x76,
906
907    /// ```text
908    /// OP_NIP<T, U>(a: T, b: U) -> T
909    /// ```
910    ///
911    /// Removes the second-to-top stack item.
912    ///
913    /// ```text
914    /// a b -> b
915    /// ```
916    ///
917    /// Usage:
918    /// ```
919    /// # use bitcoin_cash::Opcode::*;
920    /// # #[bitcoin_cash::script(DemoInputs)]
921    /// # fn demo(_: ()) {
922    /// let a = b"A";
923    /// let b = b"B";
924    ///
925    /// // drop a
926    /// OP_NIP(a, __);
927    ///
928    /// let expected = b"B";
929    /// OP_EQUALVERIFY(b, expected);
930    /// # }
931    /// ```
932    OP_NIP = 0x77,
933
934    /// ```text
935    /// OP_OVER<T, U>(a: T, b: U) -> (T, U, T)
936    /// ```
937    ///
938    /// Copies the second-to-top stack item to the top of the stack.
939    ///
940    /// ```text
941    /// a b -> a b a
942    /// ```
943    ///
944    /// Usage:
945    /// ```
946    /// # use bitcoin_cash::Opcode::*;
947    /// # #[bitcoin_cash::script(DemoInputs)]
948    /// # fn demo(_: ()) {
949    /// let a = b"A";
950    /// let b = b"B";
951    ///
952    /// // copy a
953    /// OP_OVER(a, __);  // Note: duplicated item retains name
954    ///
955    /// let expected = b"A";
956    /// OP_EQUALVERIFY(a, expected);
957    /// let expected = b"B";
958    /// OP_EQUALVERIFY(b, expected);
959    /// let expected = b"A";
960    /// OP_EQUALVERIFY(a, expected);
961    /// # }
962    /// ```
963    OP_OVER = 0x78,
964
965    /// ```text
966    /// OP_PICK<T>(n: Integer) -> T
967    /// ```
968    ///
969    /// The item `n` back in the stack is copied to the top.
970    ///
971    /// ```text
972    /// xₙ ... x₂ x₁ x₀ <n> -> xₙ ... x₂ x₁ x₀ xₙ
973    /// ```
974    ///
975    /// Usage:
976    /// ```
977    /// # use bitcoin_cash::Opcode::*;
978    /// # #[bitcoin_cash::script(DemoInputs)]
979    /// # fn demo(_: ()) {
980    /// let a = b"A";
981    /// let b = b"B";
982    ///
983    /// // calculate depth of a
984    /// let depth_a = depth_of(a);
985    /// // copy a
986    /// OP_PICK(depth_a);  // Note: duplicated item retains name
987    ///
988    /// let expected = b"A";
989    /// OP_EQUALVERIFY(a, expected);
990    /// let expected = b"B";
991    /// OP_EQUALVERIFY(b, expected);
992    /// let expected = b"A";
993    /// OP_EQUALVERIFY(a, expected);
994    /// # }
995    /// ```
996    OP_PICK = 0x79,
997
998    /// ```text
999    /// OP_ROLL<T>(n: Integer) -> T
1000    /// ```
1001    ///
1002    /// The item `n` back in the stack is moved to the top.
1003    ///
1004    /// ```text
1005    /// xₙ ... x₂ x₁ x₀ <n> -> xₙ₋₁ ... x₂ x₁ x₀ xₙ
1006    /// ```
1007    ///
1008    /// Usage:
1009    /// ```
1010    /// # use bitcoin_cash::Opcode::*;
1011    /// # #[bitcoin_cash::script(DemoInputs)]
1012    /// # fn demo(_: ()) {
1013    /// let a = b"A";
1014    /// let b = b"B";
1015    ///
1016    /// // calculate depth of a
1017    /// let depth_a = depth_of(a);
1018    /// // move a to the top of the stack
1019    /// OP_ROLL(depth_a);  // Note: moved item retains name
1020    ///
1021    /// let expected = b"A";
1022    /// OP_EQUALVERIFY(a, expected);
1023    /// let expected = b"B";
1024    /// OP_EQUALVERIFY(b, expected);
1025    /// # }
1026    /// ```
1027    OP_ROLL = 0x7a,
1028
1029    /// ```text
1030    /// OP_ROT<T, U, V>(a: T, b: U, c: V) -> (U, V, T)
1031    /// ```
1032    ///
1033    /// The third-to-top item is moved to the top.
1034    ///
1035    /// ```text
1036    /// a b c -> b c a
1037    /// ```
1038    ///
1039    /// Usage:
1040    /// ```
1041    /// # use bitcoin_cash::Opcode::*;
1042    /// # #[bitcoin_cash::script(DemoInputs)]
1043    /// # fn demo(_: ()) {
1044    /// let a = b"A";
1045    /// let b = b"B";
1046    /// let c = b"C";
1047    ///
1048    /// // move a to the top
1049    /// OP_ROT(a, __, __);
1050    ///
1051    /// let expected = b"A";
1052    /// OP_EQUALVERIFY(a, expected);
1053    /// let expected = b"C";
1054    /// OP_EQUALVERIFY(c, expected);
1055    /// let expected = b"B";
1056    /// OP_EQUALVERIFY(b, expected);
1057    /// # }
1058    /// ```
1059    OP_ROT = 0x7b,
1060
1061    /// ```text
1062    /// OP_SWAP<T, U>(a: T, b: U) -> (U, T)
1063    /// ```
1064    ///
1065    /// The top two items on the stack are swapped.
1066    ///
1067    /// ```text
1068    /// a b -> b a
1069    /// ```
1070    ///
1071    /// Usage:
1072    /// ```
1073    /// # use bitcoin_cash::Opcode::*;
1074    /// # #[bitcoin_cash::script(DemoInputs)]
1075    /// # fn demo(_: ()) {
1076    /// let a = b"A";
1077    /// let b = b"B";
1078    ///
1079    /// // swap a and b
1080    /// OP_SWAP(a, b);
1081    ///
1082    /// let expected = b"A";
1083    /// OP_EQUALVERIFY(a, expected);
1084    /// let expected = b"B";
1085    /// OP_EQUALVERIFY(b, expected);
1086    /// # }
1087    /// ```
1088    OP_SWAP = 0x7c,
1089
1090    /// ```text
1091    /// OP_TUCK<T, U>(a: T, b: U) -> (U, T, U)
1092    /// ```
1093    ///
1094    /// The item at the top of the stack is copied and inserted before the second-to-top item.
1095    ///
1096    /// ```text
1097    /// a b -> b a b
1098    /// ```
1099    ///
1100    /// Usage:
1101    /// ```
1102    /// # use bitcoin_cash::Opcode::*;
1103    /// # #[bitcoin_cash::script(DemoInputs)]
1104    /// # fn demo(_: ()) {
1105    /// let a = b"A";
1106    /// let b = b"B";
1107    ///
1108    /// // insert b before a
1109    /// OP_TUCK(__, b);
1110    ///
1111    /// let expected = b"B";
1112    /// OP_EQUALVERIFY(b, expected);
1113    /// let expected = b"A";
1114    /// OP_EQUALVERIFY(a, expected);
1115    /// let expected = b"B";
1116    /// OP_EQUALVERIFY(b, expected);
1117    /// # }
1118    /// ```
1119    OP_TUCK = 0x7d,
1120
1121    /// ```text
1122    /// OP_CAT(left: ByteArray, right: ByteArray) -> ByteArray
1123    /// ```
1124    ///
1125    /// Concatenates two byte sequences.
1126    ///
1127    /// Usage:
1128    /// ```
1129    /// # use bitcoin_cash::Opcode::*;
1130    /// # #[bitcoin_cash::script(DemoInputs)]
1131    /// # fn demo(_: ()) {
1132    /// let a = b"Bitcoin";
1133    /// let b = b"Cash";
1134    ///
1135    /// // concatenate a and b
1136    /// let ab = OP_CAT(a, b);
1137    ///
1138    /// let expected = b"BitcoinCash";
1139    /// OP_EQUALVERIFY(ab, expected);
1140    /// # }
1141    /// ```
1142    OP_CAT = 0x7e,
1143
1144    /// ```text
1145    /// OP_SPLIT(array: ByteArray, split_index: Integer) -> (ByteArray, ByteArray)
1146    /// ```
1147    ///
1148    /// Split `array` at `split_index`.
1149    ///
1150    /// Usage:
1151    /// ```
1152    /// # use bitcoin_cash::Opcode::*;
1153    /// # #[bitcoin_cash::script(DemoInputs)]
1154    /// # fn demo(_: ()) {
1155    /// let array = b"BitcoinCash";
1156    /// let split_index = 7;
1157    ///
1158    /// // split array at index 7
1159    /// let (a, b) = OP_SPLIT(array, split_index);
1160    ///
1161    /// let expected = b"Cash";
1162    /// OP_EQUALVERIFY(b, expected);
1163    /// let expected = b"Bitcoin";
1164    /// OP_EQUALVERIFY(a, expected);
1165    /// # }
1166    /// ```
1167    OP_SPLIT = 0x7f,
1168
1169    /// ```text
1170    /// OP_NUM2BIN(num: Integer, n_bytes: Integer) -> ByteArray
1171    /// ```
1172    ///
1173    /// Convert `num`into a byte sequence of size `n_bytes`, taking account of
1174    /// the sign bit. The byte sequence produced uses little-endian encoding.
1175    ///
1176    /// Usage:
1177    /// ```
1178    /// # use bitcoin_cash::Opcode::*;
1179    /// # #[bitcoin_cash::script(DemoInputs)]
1180    /// # fn demo(_: ()) {
1181    /// let num = 0x1337;
1182    /// let n_bytes = 2;
1183    ///
1184    /// // encode num as 2 bytes
1185    /// let num2le = OP_NUM2BIN(num, n_bytes);
1186    ///
1187    /// let expected = b"\x37\x13";
1188    /// OP_EQUALVERIFY(num2le, expected);
1189    /// # }
1190    /// ```
1191    OP_NUM2BIN = 0x80,
1192
1193    /// ```text
1194    /// OP_BIN2NUM(array: ByteArray) -> Integer
1195    /// ```
1196    ///
1197    /// Convert `array` into a numeric value, including minimal encoding.
1198    /// `array` must encode the value in little-endian encoding.
1199    ///
1200    /// Usage:
1201    /// ```
1202    /// # use bitcoin_cash::Opcode::*;
1203    /// # #[bitcoin_cash::script(DemoInputs)]
1204    /// # fn demo(_: ()) {
1205    /// let num_encoded = b"\x37\x13";
1206    ///
1207    /// // decode num_encoded
1208    /// let num = OP_BIN2NUM(num_encoded);
1209    ///
1210    /// let expected = 0x1337;
1211    /// OP_EQUALVERIFY(num, expected);
1212    /// # }
1213    /// ```
1214    OP_BIN2NUM = 0x81,
1215
1216    /// ```text
1217    /// OP_SIZE(array: ByteArray) -> (ByteArray, Integer)
1218    /// ```
1219    ///
1220    /// Returns the byte length of `array`, retaining `array`.
1221    ///
1222    /// Usage:
1223    /// ```
1224    /// # use bitcoin_cash::Opcode::*;
1225    /// # #[bitcoin_cash::script(DemoInputs)]
1226    /// # fn demo(_: ()) {
1227    /// let array = b"BitcoinCash";
1228    ///
1229    /// // calculate size of array
1230    /// let (__, size) = OP_SIZE(array);
1231    ///
1232    /// let expected = 11;
1233    /// OP_EQUALVERIFY(size, expected);
1234    /// let expected = b"BitcoinCash";
1235    /// OP_EQUALVERIFY(array, expected);
1236    /// # }
1237    /// ```
1238    OP_SIZE = 0x82,
1239
1240    /// Disabled opcode. Fails script immediately even if not in executed branch.
1241    OP_INVERT = 0x83,
1242
1243    /// ```text
1244    /// OP_AND(a: ByteArray, b: ByteArray) -> ByteArray
1245    /// ```
1246    ///
1247    /// Boolean AND between each bit of `a` and `b`.
1248    ///
1249    /// The two operands must be the same size.
1250    ///
1251    /// Usage:
1252    /// ```
1253    /// # use bitcoin_cash::Opcode::*;
1254    /// # #[bitcoin_cash::script(DemoInputs)]
1255    /// # fn demo(_: ()) {
1256    /// let a = b"\x0103";
1257    /// let b = b"\x0302";
1258    ///
1259    /// // calculate a & b
1260    /// let bits = OP_AND(a, b);
1261    ///
1262    /// let expected = b"\x0102";
1263    /// OP_EQUALVERIFY(bits, expected);
1264    /// # }
1265    /// ```
1266    OP_AND = 0x84,
1267
1268    /// ```text
1269    /// OP_OR(a: ByteArray, b: ByteArray) -> ByteArray
1270    /// ```
1271    ///
1272    /// Boolean OR between each bit of `a` and `b`.
1273    ///
1274    /// The two operands must be the same size.
1275    ///
1276    /// Usage:
1277    /// ```
1278    /// # use bitcoin_cash::Opcode::*;
1279    /// # #[bitcoin_cash::script(DemoInputs)]
1280    /// # fn demo(_: ()) {
1281    /// let a = b"\x0103";
1282    /// let b = b"\x0201";
1283    ///
1284    /// // calculate a | b
1285    /// let bits = OP_OR(a, b);
1286    ///
1287    /// let expected = b"\x0203";
1288    /// OP_EQUALVERIFY(bits, expected);
1289    /// # }
1290    /// ```
1291    OP_OR = 0x85,
1292
1293    /// ```text
1294    /// OP_XOR(a: ByteArray, b: ByteArray) -> ByteArray
1295    /// ```
1296    ///
1297    /// Boolean XOR between each bit of `a` and `b`.
1298    ///
1299    /// The two operands must be the same size.
1300    ///
1301    /// Usage:
1302    /// ```
1303    /// # use bitcoin_cash::Opcode::*;
1304    /// # #[bitcoin_cash::script(DemoInputs)]
1305    /// # fn demo(_: ()) {
1306    /// let a = b"\x0103";
1307    /// let b = b"\x0302";
1308    ///
1309    /// // calculate a ^ b
1310    /// let bits = OP_XOR(a, b);
1311    ///
1312    /// let expected = b"\x0201";
1313    /// OP_EQUALVERIFY(bits, expected);
1314    /// # }
1315    /// ```
1316    OP_XOR = 0x86,
1317
1318    /// ```text
1319    /// OP_EQUAL<T>(a: T, b: T) -> bool
1320    /// ```
1321    ///
1322    /// Returns whether `a == b`.
1323    ///
1324    /// Usage:
1325    /// ```
1326    /// # use bitcoin_cash::Opcode::*;
1327    /// # #[bitcoin_cash::script(DemoInputs)]
1328    /// # fn demo(_: ()) {
1329    /// let a = b"BitcoinCash";
1330    /// let b = b"BitcoinCash";
1331    ///
1332    /// // check if a == b
1333    /// let is_equal = OP_EQUAL(a, b);
1334    ///
1335    /// OP_VERIFY(is_equal);
1336    /// # }
1337    /// ```
1338    OP_EQUAL = 0x87,
1339
1340    /// ```text
1341    /// OP_EQUALVERIFY<T>(a: T, b: T) -> ()
1342    /// ```
1343    ///
1344    /// Verifies that `a == b`.
1345    ///
1346    /// Usage:
1347    /// ```
1348    /// # use bitcoin_cash::Opcode::*;
1349    /// # #[bitcoin_cash::script(DemoInputs)]
1350    /// # fn demo(_: ()) {
1351    /// let a = b"BitcoinCash";
1352    /// let b = b"BitcoinCash";
1353    ///
1354    /// // verify that a == b
1355    /// OP_EQUALVERIFY(a, b);
1356    /// # }
1357    /// ```
1358    OP_EQUALVERIFY = 0x88,
1359
1360    /// Reserved opcode. Fails script if in executed branch immediately.
1361    OP_RESERVED1 = 0x89,
1362
1363    /// Reserved opcode. Fails script if in executed branch immediately.
1364    OP_RESERVED2 = 0x8a,
1365
1366    /// ```text
1367    /// OP_1ADD(a: Integer) -> Integer
1368    /// ```
1369    ///
1370    /// Calculates `a + 1`.
1371    ///
1372    /// Usage:
1373    /// ```
1374    /// # use bitcoin_cash::Opcode::*;
1375    /// # #[bitcoin_cash::script(DemoInputs)]
1376    /// # fn demo(_: ()) {
1377    /// let a = 7;
1378    ///
1379    /// // calculate a + 1
1380    /// let result = OP_1ADD(a);
1381    ///
1382    /// let expected = 8;
1383    /// OP_EQUALVERIFY(result, expected);
1384    /// # }
1385    /// ```
1386    OP_1ADD = 0x8b,
1387
1388    /// ```text
1389    /// OP_1SUB(a: Integer) -> Integer
1390    /// ```
1391    ///
1392    /// Calculates `a - 1`.
1393    ///
1394    /// Usage:
1395    /// ```
1396    /// # use bitcoin_cash::Opcode::*;
1397    /// # #[bitcoin_cash::script(DemoInputs)]
1398    /// # fn demo(_: ()) {
1399    /// let a = 7;
1400    ///
1401    /// // calculate a - 1
1402    /// let result = OP_1SUB(a);
1403    ///
1404    /// let expected = 6;
1405    /// OP_EQUALVERIFY(result, expected);
1406    /// # }
1407    /// ```
1408    OP_1SUB = 0x8c,
1409
1410    /// Disabled opcode. Fails script immediately even if not in executed branch.
1411    OP_2MUL = 0x8d,
1412
1413    /// Disabled opcode. Fails script immediately even if not in executed branch.
1414    OP_2DIV = 0x8e,
1415
1416    /// ```text
1417    /// OP_NEGATE(a: Integer) -> Integer
1418    /// ```
1419    ///
1420    /// Calculates `-a`.
1421    ///
1422    /// Usage:
1423    /// ```
1424    /// # use bitcoin_cash::Opcode::*;
1425    /// # #[bitcoin_cash::script(DemoInputs)]
1426    /// # fn demo(_: ()) {
1427    /// let a = 7;
1428    ///
1429    /// // calculate -a
1430    /// let result = OP_NEGATE(a);
1431    ///
1432    /// let expected = -7;
1433    /// OP_EQUALVERIFY(result, expected);
1434    /// # }
1435    /// ```
1436    OP_NEGATE = 0x8f,
1437
1438    /// ```text
1439    /// OP_ABS(a: Integer) -> Integer
1440    /// ```
1441    ///
1442    /// Calculates `abs(a)`.
1443    ///
1444    /// Usage:
1445    /// ```
1446    /// # use bitcoin_cash::Opcode::*;
1447    /// # #[bitcoin_cash::script(DemoInputs)]
1448    /// # fn demo(_: ()) {
1449    /// let a = -7;
1450    ///
1451    /// // calculate abs(a)
1452    /// let result = OP_ABS(a);
1453    ///
1454    /// let expected = 7;
1455    /// OP_EQUALVERIFY(result, expected);
1456    /// # }
1457    /// ```
1458    OP_ABS = 0x90,
1459
1460    /// ```text
1461    /// OP_NOT(a: Integer) -> Integer
1462    /// ```
1463    ///
1464    /// Calculates `!a`.
1465    ///
1466    /// Usage:
1467    /// ```
1468    /// # use bitcoin_cash::Opcode::*;
1469    /// # #[bitcoin_cash::script(DemoInputs)]
1470    /// # fn demo(_: ()) {
1471    /// let a = false;
1472    ///
1473    /// // calculate !a
1474    /// let result = OP_NOT(a);
1475    ///
1476    /// OP_VERIFY(result);
1477    /// # }
1478    /// ```
1479    OP_NOT = 0x91,
1480
1481    /// ```text
1482    /// OP_0NOTEQUAL(a: Integer) -> bool
1483    /// ```
1484    ///
1485    /// Calculates `a != 0`.
1486    ///
1487    /// Usage:
1488    /// ```
1489    /// # use bitcoin_cash::Opcode::*;
1490    /// # #[bitcoin_cash::script(DemoInputs)]
1491    /// # fn demo(_: ()) {
1492    /// let a = 7;
1493    ///
1494    /// // calculate a != 0
1495    /// let result = OP_0NOTEQUAL(a);
1496    ///
1497    /// OP_VERIFY(result);
1498    /// # }
1499    /// ```
1500    OP_0NOTEQUAL = 0x92,
1501
1502    /// ```text
1503    /// OP_ADD(a: Integer, b: Integer) -> Integer
1504    /// ```
1505    ///
1506    /// Calculates `a + b`.
1507    ///
1508    /// Usage:
1509    /// ```
1510    /// # use bitcoin_cash::Opcode::*;
1511    /// # #[bitcoin_cash::script(DemoInputs)]
1512    /// # fn demo(_: ()) {
1513    /// let a = 7;
1514    /// let b = 3;
1515    ///
1516    /// // calculate a + b
1517    /// let result = OP_ADD(a, b);
1518    ///
1519    /// let expected = 10;
1520    /// OP_EQUALVERIFY(result, expected);
1521    /// # }
1522    /// ```
1523    OP_ADD = 0x93,
1524
1525    /// ```text
1526    /// OP_SUB(a: Integer, b: Integer) -> Integer
1527    /// ```
1528    ///
1529    /// Calculates `a - b`.
1530    ///
1531    /// Usage:
1532    /// ```
1533    /// # use bitcoin_cash::Opcode::*;
1534    /// # #[bitcoin_cash::script(DemoInputs)]
1535    /// # fn demo(_: ()) {
1536    /// let a = 7;
1537    /// let b = 3;
1538    ///
1539    /// // calculate a - b
1540    /// let result = OP_SUB(a, b);
1541    ///
1542    /// let expected = 4;
1543    /// OP_EQUALVERIFY(result, expected);
1544    /// # }
1545    /// ```
1546    OP_SUB = 0x94,
1547
1548    /// Disabled opcode. Fails script immediately even if not in executed branch.
1549    OP_MUL = 0x95,
1550
1551    /// ```text
1552    /// OP_DIV(a: Integer, b: Integer) -> Integer
1553    /// ```
1554    ///
1555    /// Calculates `a / b`, truncating the fraction part.
1556    ///
1557    /// Usage:
1558    /// ```
1559    /// # use bitcoin_cash::Opcode::*;
1560    /// # #[bitcoin_cash::script(DemoInputs)]
1561    /// # fn demo(_: ()) {
1562    /// let a = 7;
1563    /// let b = 3;
1564    ///
1565    /// // calculate a / b
1566    /// let result = OP_DIV(a, b);
1567    ///
1568    /// let expected = 2;
1569    /// OP_EQUALVERIFY(result, expected);
1570    /// # }
1571    /// ```
1572    OP_DIV = 0x96,
1573
1574    /// ```text
1575    /// OP_MOD(a: Integer, b: Integer) -> Integer
1576    /// ```
1577    ///
1578    /// Calculates `a % b` (a modulo b).
1579    ///
1580    /// Usage:
1581    /// ```
1582    /// # use bitcoin_cash::Opcode::*;
1583    /// # #[bitcoin_cash::script(DemoInputs)]
1584    /// # fn demo(_: ()) {
1585    /// let a = 7;
1586    /// let b = 3;
1587    ///
1588    /// // calculate a % b
1589    /// let result = OP_MOD(a, b);
1590    ///
1591    /// let expected = 1;
1592    /// OP_EQUALVERIFY(result, expected);
1593    /// # }
1594    /// ```
1595    OP_MOD = 0x97,
1596
1597    /// Disabled opcode. Fails script immediately even if not in executed branch.
1598    OP_LSHIFT = 0x98,
1599
1600    /// Disabled opcode. Fails script immediately even if not in executed branch.
1601    OP_RSHIFT = 0x99,
1602
1603    /// ```text
1604    /// OP_BOOLAND(a: bool, b: bool) -> bool
1605    /// ```
1606    ///
1607    /// Calculates `a && b`, boolean AND (∧).
1608    ///
1609    /// Usage:
1610    /// ```
1611    /// # use bitcoin_cash::Opcode::*;
1612    /// # #[bitcoin_cash::script(DemoInputs)]
1613    /// # fn demo(_: ()) {
1614    /// let a = false;
1615    /// let b = true;
1616    ///
1617    /// // calculate a && b
1618    /// let result = OP_BOOLAND(a, b);
1619    ///
1620    /// let expected = false;
1621    /// OP_EQUALVERIFY(result, expected);
1622    /// # }
1623    /// ```
1624    OP_BOOLAND = 0x9a,
1625
1626    /// ```text
1627    /// OP_BOOLOR(a: bool, b: bool) -> bool
1628    /// ```
1629    ///
1630    /// Calculates `a || b`, boolean OR (∨).
1631    ///
1632    /// Usage:
1633    /// ```
1634    /// # use bitcoin_cash::Opcode::*;
1635    /// # #[bitcoin_cash::script(DemoInputs)]
1636    /// # fn demo(_: ()) {
1637    /// let a = false;
1638    /// let b = true;
1639    ///
1640    /// // calculate a || b
1641    /// let result = OP_BOOLOR(a, b);
1642    ///
1643    /// OP_VERIFY(result);
1644    /// # }
1645    /// ```
1646    OP_BOOLOR = 0x9b,
1647
1648    /// ```text
1649    /// OP_NUMEQUAL(a: Integer, b: Integer) -> bool
1650    /// ```
1651    ///
1652    /// Calculates `a == b`.
1653    ///
1654    /// Usage:
1655    /// ```
1656    /// # use bitcoin_cash::Opcode::*;
1657    /// # #[bitcoin_cash::script(DemoInputs)]
1658    /// # fn demo(_: ()) {
1659    /// let a = 7;
1660    /// let b = 7;
1661    ///
1662    /// // check if a == b
1663    /// let is_equal = OP_NUMEQUAL(a, b);
1664    ///
1665    /// OP_VERIFY(is_equal);
1666    /// # }
1667    /// ```
1668    OP_NUMEQUAL = 0x9c,
1669
1670    /// ```text
1671    /// OP_NUMEQUALVERIFY(a: Integer, b: Integer) -> ()
1672    /// ```
1673    ///
1674    /// Verifies that `a == b`.
1675    ///
1676    /// Usage:
1677    /// ```
1678    /// # use bitcoin_cash::Opcode::*;
1679    /// # #[bitcoin_cash::script(DemoInputs)]
1680    /// # fn demo(_: ()) {
1681    /// let a = 7;
1682    /// let b = 7;
1683    ///
1684    /// // verify that a == b
1685    /// OP_NUMEQUALVERIFY(a, b);
1686    /// # }
1687    /// ```
1688    OP_NUMEQUALVERIFY = 0x9d,
1689
1690    /// ```text
1691    /// OP_NUMNOTEQUAL(a: Integer, b: Integer) -> bool
1692    /// ```
1693    ///
1694    /// Calculates `a != b`.
1695    ///
1696    /// Usage:
1697    /// ```
1698    /// # use bitcoin_cash::Opcode::*;
1699    /// # #[bitcoin_cash::script(DemoInputs)]
1700    /// # fn demo(_: ()) {
1701    /// let a = 7;
1702    /// let b = 9;
1703    ///
1704    /// // check if a == b
1705    /// let is_not_equal = OP_NUMNOTEQUAL(a, b);
1706    ///
1707    /// OP_VERIFY(is_not_equal);
1708    /// # }
1709    /// ```
1710    OP_NUMNOTEQUAL = 0x9e,
1711
1712    /// ```text
1713    /// OP_LESSTHAN(a: Integer, b: Integer) -> bool
1714    /// ```
1715    ///
1716    /// Calculates `a < b`.
1717    ///
1718    /// Usage:
1719    /// ```
1720    /// # use bitcoin_cash::Opcode::*;
1721    /// # #[bitcoin_cash::script(DemoInputs)]
1722    /// # fn demo(_: ()) {
1723    /// let a = 7;
1724    /// let b = 9;
1725    ///
1726    /// // check if a < b
1727    /// let is_less = OP_LESSTHAN(a, b);
1728    ///
1729    /// OP_VERIFY(is_less);
1730    /// # }
1731    /// ```
1732    OP_LESSTHAN = 0x9f,
1733
1734    /// ```text
1735    /// OP_GREATERTHAN(a: Integer, b: Integer) -> bool
1736    /// ```
1737    ///
1738    /// Calculates `a > b`.
1739    ///
1740    /// Usage:
1741    /// ```
1742    /// # use bitcoin_cash::Opcode::*;
1743    /// # #[bitcoin_cash::script(DemoInputs)]
1744    /// # fn demo(_: ()) {
1745    /// let a = 11;
1746    /// let b = 9;
1747    ///
1748    /// // check if a > b
1749    /// let is_greater = OP_GREATERTHAN(a, b);
1750    ///
1751    /// OP_VERIFY(is_greater);
1752    /// # }
1753    /// ```
1754    OP_GREATERTHAN = 0xa0,
1755
1756    /// ```text
1757    /// OP_LESSTHANOREQUAL(a: Integer, b: Integer) -> bool
1758    /// ```
1759    ///
1760    /// Calculates `a <= b`.
1761    ///
1762    /// Usage:
1763    /// ```
1764    /// # use bitcoin_cash::Opcode::*;
1765    /// # #[bitcoin_cash::script(DemoInputs)]
1766    /// # fn demo(_: ()) {
1767    /// let a = 7;
1768    /// let b = 7;
1769    ///
1770    /// // check if a <= b
1771    /// let is_at_most = OP_LESSTHANOREQUAL(a, b);
1772    ///
1773    /// OP_VERIFY(is_at_most);
1774    /// # }
1775    /// ```
1776    OP_LESSTHANOREQUAL = 0xa1,
1777
1778    /// ```text
1779    /// OP_GREATERTHANOREQUAL(a: Integer, b: Integer) -> bool
1780    /// ```
1781    ///
1782    /// Calculates `a >= b`.
1783    ///
1784    /// Usage:
1785    /// ```
1786    /// # use bitcoin_cash::Opcode::*;
1787    /// # #[bitcoin_cash::script(DemoInputs)]
1788    /// # fn demo(_: ()) {
1789    /// let a = 9;
1790    /// let b = 9;
1791    ///
1792    /// // check if a >= b
1793    /// let is_at_least = OP_GREATERTHANOREQUAL(a, b);
1794    ///
1795    /// OP_VERIFY(is_at_least);
1796    /// # }
1797    /// ```
1798    OP_GREATERTHANOREQUAL = 0xa2,
1799
1800    /// ```text
1801    /// OP_MIN(a: Integer, b: Integer) -> bool
1802    /// ```
1803    ///
1804    /// Calculates `min(a, b)`, the lesser of `a` and `b`.
1805    ///
1806    /// Usage:
1807    /// ```
1808    /// # use bitcoin_cash::Opcode::*;
1809    /// # #[bitcoin_cash::script(DemoInputs)]
1810    /// # fn demo(_: ()) {
1811    /// let a = 3;
1812    /// let b = 9;
1813    ///
1814    /// // calculate min(a, b)
1815    /// let result = OP_MIN(a, b);
1816    ///
1817    /// let expected = 3;
1818    /// OP_EQUALVERIFY(result, expected);
1819    /// # }
1820    /// ```
1821    OP_MIN = 0xa3,
1822
1823    /// ```text
1824    /// OP_MAX(a: Integer, b: Integer) -> bool
1825    /// ```
1826    ///
1827    /// Calculates `max(a, b)`, the greater of `a` and `b`.
1828    ///
1829    /// Usage:
1830    /// ```
1831    /// # use bitcoin_cash::Opcode::*;
1832    /// # #[bitcoin_cash::script(DemoInputs)]
1833    /// # fn demo(_: ()) {
1834    /// let a = 3;
1835    /// let b = 9;
1836    ///
1837    /// // calculate max(a, b)
1838    /// let result = OP_MAX(a, b);
1839    ///
1840    /// let expected = 9;
1841    /// OP_EQUALVERIFY(result, expected);
1842    /// # }
1843    /// ```
1844    OP_MAX = 0xa4,
1845
1846    /// ```text
1847    /// OP_WITHIN(a: Integer, min: Integer, max: Integer) -> bool
1848    /// ```
1849    ///
1850    /// Calculates `a >= min && a <= max`.
1851    ///
1852    /// Usage:
1853    /// ```
1854    /// # use bitcoin_cash::Opcode::*;
1855    /// # #[bitcoin_cash::script(DemoInputs)]
1856    /// # fn demo(_: ()) {
1857    /// let a = 3;
1858    /// let min = 1;
1859    /// let max = 9;
1860    ///
1861    /// // calculate if a is within min and max
1862    /// let result = OP_WITHIN(a, min, max);
1863    ///
1864    /// OP_VERIFY(result);
1865    /// # }
1866    /// ```
1867    OP_WITHIN = 0xa5,
1868
1869    /// ```text
1870    /// OP_RIPEMD160(array: ByteArray) -> ByteArray
1871    /// ```
1872    ///
1873    /// Hashes `array` using RIPEMD-160.
1874    ///
1875    /// Usage:
1876    /// ```
1877    /// # use hex_literal::hex;
1878    /// # use bitcoin_cash::Opcode::*;
1879    /// # #[bitcoin_cash::script(DemoInputs)]
1880    /// # fn demo(_: ()) {
1881    /// let array = b"BitcoinCash";
1882    ///
1883    /// // calculate ripemd160(array)
1884    /// let hash = OP_RIPEMD160(array);
1885    ///
1886    /// let expected = hex!("0d2aa57463e5fac82f97f496ed98525fbec71c4c");
1887    /// OP_EQUALVERIFY(hash, expected);
1888    /// # }
1889    /// ```
1890    OP_RIPEMD160 = 0xa6,
1891
1892    /// ```text
1893    /// OP_SHA1(array: ByteArray) -> ByteArray
1894    /// ```
1895    ///
1896    /// Hashes `array` using SHA-1.
1897    ///
1898    /// Usage:
1899    /// ```
1900    /// # use hex_literal::hex;
1901    /// # use bitcoin_cash::Opcode::*;
1902    /// # #[bitcoin_cash::script(DemoInputs)]
1903    /// # fn demo(_: ()) {
1904    /// let array = b"BitcoinCash";
1905    ///
1906    /// // calculates sha1(array)
1907    /// let hash = OP_SHA1(array);
1908    ///
1909    /// let expected = hex!("a7a1986ab925f4d8a81fc0da1352c780ad2f5fe1");
1910    /// OP_EQUALVERIFY(hash, expected);
1911    /// # }
1912    /// ```
1913    OP_SHA1 = 0xa7,
1914
1915    /// ```text
1916    /// OP_SHA256(array: ByteArray) -> ByteArray
1917    /// ```
1918    ///
1919    /// Hashes `array` using SHA-256.
1920    ///
1921    /// Usage:
1922    /// ```
1923    /// # use hex_literal::hex;
1924    /// # use bitcoin_cash::Opcode::*;
1925    /// # #[bitcoin_cash::script(DemoInputs)]
1926    /// # fn demo(_: ()) {
1927    /// let array = b"BitcoinCash";
1928    ///
1929    /// // calculates sha256(array)
1930    /// let hash = OP_SHA256(array);
1931    ///
1932    /// let expected = hex!("78e015aa460c0a5be71fe4618c72898200a45a20f9bd7048398971babc3b372b");
1933    /// OP_EQUALVERIFY(hash, expected);
1934    /// # }
1935    /// ```
1936    OP_SHA256 = 0xa8,
1937
1938    /// ```text
1939    /// OP_HASH160(array: ByteArray) -> ByteArray
1940    /// ```
1941    ///
1942    /// Hashes `array` using first SHA-256 and then RIPEMD-160.
1943    ///
1944    /// Usage:
1945    /// ```
1946    /// # use hex_literal::hex;
1947    /// # use bitcoin_cash::Opcode::*;
1948    /// # #[bitcoin_cash::script(DemoInputs)]
1949    /// # fn demo(_: ()) {
1950    /// let array = b"BitcoinCash";
1951    ///
1952    /// // calculates ripemd160(sha256(array))
1953    /// let hash = OP_HASH160(array);
1954    ///
1955    /// let expected = hex!("29e99ecb43b5a4c19aa2b05c7d6fc439bca5f023");
1956    /// OP_EQUALVERIFY(hash, expected);
1957    /// # }
1958    /// ```
1959    OP_HASH160 = 0xa9,
1960
1961    /// ```text
1962    /// OP_HASH256(array: ByteArray) -> ByteArray
1963    /// ```
1964    ///
1965    /// Hashes `array` twice using SHA-256.
1966    ///
1967    /// Usage:
1968    /// ```
1969    /// # use hex_literal::hex;
1970    /// # use bitcoin_cash::Opcode::*;
1971    /// # #[bitcoin_cash::script(DemoInputs)]
1972    /// # fn demo(_: ()) {
1973    /// let array = b"BitcoinCash";
1974    ///
1975    /// // calculates sha256(sha256(array))
1976    /// let hash = OP_HASH256(array);
1977    ///
1978    /// let expected = hex!("575d8ad02159b76cf2beda18c4ccb9bdb9a7ac894506d97e319c9e5c3096ca37");
1979    /// OP_EQUALVERIFY(hash, expected);
1980    /// # }
1981    /// ```
1982    OP_HASH256 = 0xaa,
1983
1984    /// ```text
1985    /// OP_CODESEPARATOR() -> ()
1986    /// ```
1987    ///
1988    /// Makes `OP_CHECK(MULTI)SIG(VERIFY)` set `scriptCode` to everything after
1989    /// the most recently-executed `OP_CODESEPARATOR` when computing the sighash.
1990    ///
1991    /// Usage:
1992    /// ```
1993    /// # use bitcoin_cash::Opcode::*;
1994    /// # #[bitcoin_cash::script(DemoInputs)]
1995    /// # fn demo(_: ()) {
1996    /// let array = b"BitcoinCash";
1997    ///
1998    /// // removes "BitcoinCash" from scriptCode
1999    /// OP_CODESEPARATOR();
2000    /// # }
2001    /// ```
2002    OP_CODESEPARATOR = 0xab,
2003
2004    /// ```text
2005    /// OP_CHECKSIG(public_key: ByteArray, signature: ByteArray) -> bool
2006    /// ```
2007    ///
2008    /// The last byte (=sighash type) of `signature` is removed.
2009    /// The sighash for this input is calculated based on the sighash type.
2010    /// The truncated signature used by `OP_CHECKSIG` must be a valid ECDSA or
2011    /// Schnorr signature for that hash and `public_key`. If it is valid, 1 is
2012    /// returned, if it is empty, 0 is returned, otherwise the operation fails.
2013    ///
2014    /// Usage:
2015    /// ```
2016    /// # use hex_literal::hex;
2017    /// # use bitcoin_cash::{Opcode::*, ByteArray};
2018    /// #[bitcoin_cash::script(P2PKInputs)]
2019    /// fn p2pk(_: (), signature: ByteArray) {
2020    ///   let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519");
2021    ///
2022    ///   // check if `signature` signs current sighash for `public_key`
2023    ///   let success = OP_CHECKSIG(signature, public_key);
2024    /// }
2025    /// ```
2026    OP_CHECKSIG = 0xac,
2027
2028    /// ```text
2029    /// OP_CHECKSIGVERIFY(public_key: ByteArray, signature: ByteArray) -> ()
2030    /// ```
2031    ///
2032    /// The last byte (=sighash type) of `signature` is removed.
2033    /// The sighash for this input is calculated based on the sighash type.
2034    /// Verifies the truncated signature used by `OP_CHECKSIGVERIFY` is a
2035    /// valid ECDSA or Schnorr signature for that hash and `public_key`.
2036    ///
2037    /// Usage:
2038    /// ```
2039    /// # use hex_literal::hex;
2040    /// # use bitcoin_cash::{Opcode::*, ByteArray};
2041    /// #[bitcoin_cash::script(P2PKInputs)]
2042    /// fn p2pk(_: (), signature: ByteArray) {
2043    ///   let public_key = hex!("0201961ef44067e870a9b1684041929caffad57eae6bbc79dd785320d53231f519");
2044    ///
2045    ///   // verify `signature` signs current sighash for `public_key`
2046    ///   OP_CHECKSIGVERIFY(signature, public_key);
2047    /// }
2048    /// ```
2049    OP_CHECKSIGVERIFY = 0xad,
2050
2051    /// Performs a multisig check. Not to be used in `#[bitcoin_cash::script]` functions.
2052    OP_CHECKMULTISIG = 0xae,
2053
2054    /// Verifies a multisig check. Not to be used in `#[bitcoin_cash::script]` functions.
2055    OP_CHECKMULTISIGVERIFY = 0xaf,
2056
2057    /// ```text
2058    /// OP_NOP1() -> ()
2059    /// ```
2060    ///
2061    /// Does nothing.
2062    ///
2063    /// Usage:
2064    /// ```
2065    /// # use bitcoin_cash::Opcode::*;
2066    /// # #[bitcoin_cash::script(DemoInputs)]
2067    /// # fn demo(_: ()) {
2068    /// // do nothing
2069    /// OP_NOP1();
2070    /// # }
2071    /// ```
2072    OP_NOP1 = 0xb0,
2073
2074    /// ```text
2075    /// OP_CHECKLOCKTIMEVERIFY(locktime: Integer) -> Integer
2076    /// ```
2077    ///
2078    /// Marks transaction as invalid if the top stack item is greater than the transaction's
2079    /// `nLockTime` field, otherwise script evaluation continues as though an `OP_NOP` was
2080    /// executed. Transaction is also invalid if
2081    ///
2082    /// 1. the stack is empty or
2083    /// 2. the top stack item is negative or
2084    /// 3. the top stack item is greater than or equal to 500000000 while the transaction's
2085    ///    `nLockTime` field is less than 500000000, or vice versa or
2086    /// 4. the input's nSequence field is equal to 0xffffffff.
2087    ///
2088    /// The precise semantics are described in BIP65.
2089    ///
2090    /// Usage:
2091    /// ```
2092    /// # use bitcoin_cash::Opcode::*;
2093    /// # #[bitcoin_cash::script(DemoInputs)]
2094    /// # fn demo(_: ()) {
2095    /// let locktime = 400_000;
2096    ///
2097    /// // verify locktime
2098    /// OP_CHECKLOCKTIMEVERIFY(locktime);
2099    ///
2100    /// let expected = 400_000;
2101    /// OP_EQUALVERIFY(locktime, expected);
2102    /// # }
2103    /// ```
2104    OP_CHECKLOCKTIMEVERIFY = 0xb1,
2105
2106    /// ```text
2107    /// OP_CHECKSEQUENCEVERIFY(sequence: Integer) -> Integer
2108    /// ```
2109    ///
2110    /// Marks transaction as invalid if the relative lock time of the input
2111    /// (enforced by BIP68 with `nSequence`) is not equal to or longer than
2112    /// the value of the top stack item. The precise semantics are described
2113    /// in BIP112.
2114    ///
2115    /// Usage:
2116    /// ```
2117    /// # use bitcoin_cash::Opcode::*;
2118    /// # #[bitcoin_cash::script(DemoInputs)]
2119    /// # fn demo(_: ()) {
2120    /// let sequence = 1000;
2121    ///
2122    /// // verify input age
2123    /// OP_CHECKSEQUENCEVERIFY(sequence);
2124    ///
2125    /// let expected = 1000;
2126    /// OP_EQUALVERIFY(sequence, expected);
2127    /// # }
2128    /// ```
2129    OP_CHECKSEQUENCEVERIFY = 0xb2,
2130
2131    /// ```text
2132    /// OP_NOP4() -> ()
2133    /// ```
2134    ///
2135    /// Does nothing.
2136    ///
2137    /// Usage:
2138    /// ```
2139    /// # use bitcoin_cash::Opcode::*;
2140    /// # #[bitcoin_cash::script(DemoInputs)]
2141    /// # fn demo(_: ()) {
2142    /// // do nothing
2143    /// OP_NOP4();
2144    /// # }
2145    /// ```
2146    OP_NOP4 = 0xb3,
2147
2148    /// ```text
2149    /// OP_NOP5() -> ()
2150    /// ```
2151    ///
2152    /// Does nothing.
2153    ///
2154    /// Usage:
2155    /// ```
2156    /// # use bitcoin_cash::Opcode::*;
2157    /// # #[bitcoin_cash::script(DemoInputs)]
2158    /// # fn demo(_: ()) {
2159    /// // do nothing
2160    /// OP_NOP5();
2161    /// # }
2162    /// ```
2163    OP_NOP5 = 0xb4,
2164
2165    /// ```text
2166    /// OP_NOP6() -> ()
2167    /// ```
2168    ///
2169    /// Does nothing.
2170    ///
2171    /// Usage:
2172    /// ```
2173    /// # use bitcoin_cash::Opcode::*;
2174    /// # #[bitcoin_cash::script(DemoInputs)]
2175    /// # fn demo(_: ()) {
2176    /// // do nothing
2177    /// OP_NOP6();
2178    /// # }
2179    /// ```
2180    OP_NOP6 = 0xb5,
2181
2182    /// ```text
2183    /// OP_NOP7() -> ()
2184    /// ```
2185    ///
2186    /// Does nothing.
2187    ///
2188    /// Usage:
2189    /// ```
2190    /// # use bitcoin_cash::Opcode::*;
2191    /// # #[bitcoin_cash::script(DemoInputs)]
2192    /// # fn demo(_: ()) {
2193    /// // do nothing
2194    /// OP_NOP7();
2195    /// # }
2196    /// ```
2197    OP_NOP7 = 0xb6,
2198
2199    /// ```text
2200    /// OP_NOP8() -> ()
2201    /// ```
2202    ///
2203    /// Does nothing.
2204    ///
2205    /// Usage:
2206    /// ```
2207    /// # use bitcoin_cash::Opcode::*;
2208    /// # #[bitcoin_cash::script(DemoInputs)]
2209    /// # fn demo(_: ()) {
2210    /// // do nothing
2211    /// OP_NOP8();
2212    /// # }
2213    /// ```
2214    OP_NOP8 = 0xb7,
2215
2216    /// ```text
2217    /// OP_NOP9() -> ()
2218    /// ```
2219    ///
2220    /// Does nothing.
2221    ///
2222    /// Usage:
2223    /// ```
2224    /// # use bitcoin_cash::Opcode::*;
2225    /// # #[bitcoin_cash::script(DemoInputs)]
2226    /// # fn demo(_: ()) {
2227    /// // do nothing
2228    /// OP_NOP9();
2229    /// # }
2230    /// ```
2231    OP_NOP9 = 0xb8,
2232
2233    /// ```text
2234    /// OP_NOP10() -> ()
2235    /// ```
2236    ///
2237    /// Does nothing.
2238    ///
2239    /// Usage:
2240    /// ```
2241    /// # use bitcoin_cash::Opcode::*;
2242    /// # #[bitcoin_cash::script(DemoInputs)]
2243    /// # fn demo(_: ()) {
2244    /// // do nothing
2245    /// OP_NOP10();
2246    /// # }
2247    /// ```
2248    OP_NOP10 = 0xb9,
2249
2250    /// ```text
2251    /// OP_CHECKDATASIG(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> bool
2252    /// ```
2253    ///
2254    /// Checks whether `signature` is a valid ECDSA or Schnorr signature for `sha256(message)` and `public_key`.
2255    ///
2256    /// Usage:
2257    /// ```
2258    /// # use hex_literal::hex;
2259    /// # use bitcoin_cash::Opcode::*;
2260    /// # #[bitcoin_cash::script(DemoInputs)]
2261    /// # fn demo(_: ()) {
2262    /// let signature = [
2263    ///     hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(),
2264    ///     hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(),
2265    /// ].concat();
2266    /// let message = b"BitcoinCash";
2267    /// let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496");
2268    ///
2269    /// let is_valid_sig = OP_CHECKDATASIG(signature, message, public_key);
2270    /// # }
2271    /// ```
2272    OP_CHECKDATASIG = 0xba,
2273
2274    /// ```text
2275    /// OP_CHECKDATASIGVERIFY(signature: ByteArray, message: ByteArray, public_key: ByteArray) -> ()
2276    /// ```
2277    ///
2278    /// Verifies that `signature` is a valid ECDSA or Schnorr signature for `sha256(message)` and `public_key`.
2279    ///
2280    /// Usage:
2281    /// ```
2282    /// # use hex_literal::hex;
2283    /// # use bitcoin_cash::Opcode::*;
2284    /// # #[bitcoin_cash::script(DemoInputs)]
2285    /// # fn demo(_: ()) {
2286    /// let signature = [
2287    ///     hex!("3045022100f560a6e928ec52e77801a3ea4cbfbe6d89d1fff77a8d2ed00c457af278ae54").as_ref(),
2288    ///     hex!("01022015cc2b1c92b53cef6afd10e5e5fa33eb66b9d13d82d970a4a951b6e7f1903509").as_ref(),
2289    /// ].concat();
2290    /// let message = b"BitcoinCash";
2291    /// let public_key = hex!("0350be375c6e807988a5f575c9776e271e19a79f64681bcfe6a1affde9a5444496");
2292    ///
2293    /// OP_CHECKDATASIGVERIFY(signature, message, public_key);
2294    /// # }
2295    /// ```
2296    OP_CHECKDATASIGVERIFY = 0xbb,
2297
2298    /// ```text
2299    /// OP_REVERSEBYTES(array: ByteArray) -> ByteArray
2300    /// ```
2301    ///
2302    /// Reverse `array`.
2303    ///
2304    /// Usage:
2305    /// ```
2306    /// # use bitcoin_cash::Opcode::*;
2307    /// # #[bitcoin_cash::script(DemoInputs)]
2308    /// # fn demo(_: ()) {
2309    /// let array = b"BitcoinCash";
2310    ///
2311    /// // reverse array
2312    /// let reversed = OP_REVERSEBYTES(array);
2313    ///
2314    /// let expected = b"hsaCnioctiB";
2315    /// OP_EQUALVERIFY(reversed, expected);
2316    /// # }
2317    /// ```
2318    OP_REVERSEBYTES = 0xbc,
2319
2320    /// The first op_code value after all defined opcodes
2321    FIRST_UNDEFINED_OP_VALUE,
2322}
2323
2324/// Internal module used for type checking.
2325///
2326/// Functions only push mock data.
2327pub mod func {
2328    #![allow(non_snake_case)]
2329    #![allow(unused_variables)]
2330
2331    use super::*;
2332
2333    pub fn FIRST<T>(item1: T, item2: T) -> T {
2334        item1
2335    }
2336
2337    pub fn SECOND<T>(item1: T, item2: T) -> T {
2338        item2
2339    }
2340
2341    pub fn OP_1NEGATE() -> BitcoinInteger {
2342        BitcoinInteger(0)
2343    }
2344    pub fn OP_0() -> BitcoinInteger {
2345        BitcoinInteger(0)
2346    }
2347    pub fn OP_1() -> BitcoinInteger {
2348        BitcoinInteger(0)
2349    }
2350    pub fn OP_2() -> BitcoinInteger {
2351        BitcoinInteger(0)
2352    }
2353    pub fn OP_3() -> BitcoinInteger {
2354        BitcoinInteger(0)
2355    }
2356    pub fn OP_4() -> BitcoinInteger {
2357        BitcoinInteger(0)
2358    }
2359    pub fn OP_5() -> BitcoinInteger {
2360        BitcoinInteger(0)
2361    }
2362    pub fn OP_6() -> BitcoinInteger {
2363        BitcoinInteger(0)
2364    }
2365    pub fn OP_7() -> BitcoinInteger {
2366        BitcoinInteger(0)
2367    }
2368    pub fn OP_8() -> BitcoinInteger {
2369        BitcoinInteger(0)
2370    }
2371    pub fn OP_9() -> BitcoinInteger {
2372        BitcoinInteger(0)
2373    }
2374    pub fn OP_10() -> BitcoinInteger {
2375        BitcoinInteger(0)
2376    }
2377    pub fn OP_11() -> BitcoinInteger {
2378        BitcoinInteger(0)
2379    }
2380    pub fn OP_12() -> BitcoinInteger {
2381        BitcoinInteger(0)
2382    }
2383    pub fn OP_13() -> BitcoinInteger {
2384        BitcoinInteger(0)
2385    }
2386    pub fn OP_14() -> BitcoinInteger {
2387        BitcoinInteger(0)
2388    }
2389    pub fn OP_15() -> BitcoinInteger {
2390        BitcoinInteger(0)
2391    }
2392    pub fn OP_16() -> BitcoinInteger {
2393        BitcoinInteger(0)
2394    }
2395
2396    pub fn OP_NOP() {}
2397    pub fn OP_NOP1() {}
2398    pub fn OP_NOP4() {}
2399    pub fn OP_NOP5() {}
2400    pub fn OP_NOP6() {}
2401    pub fn OP_NOP7() {}
2402    pub fn OP_NOP8() {}
2403    pub fn OP_NOP9() {}
2404    pub fn OP_NOP10() {}
2405
2406    pub fn OP_IF<T>(stack_item: T) {}
2407    pub fn OP_ELSE() {}
2408    pub fn OP_ENDIF() {}
2409    pub fn OP_VERIFY<T>(stack_item: T) {}
2410
2411    pub fn OP_TOALTSTACK<T>(stack_item: T) -> T {
2412        stack_item
2413    }
2414    pub fn OP_FROMALTSTACK<T>(alt_stack_item: T) -> T {
2415        alt_stack_item
2416    }
2417    pub fn OP_2DROP<T, U>(item1: T, item2: U) {}
2418    pub fn OP_2DUP<T: Clone, U: Clone>(item1: T, item2: U) -> (T, U, T, U) {
2419        (item1.clone(), item2.clone(), item1, item2)
2420    }
2421    pub fn OP_3DUP<T: Clone, U: Clone, V: Clone>(
2422        item1: T,
2423        item2: U,
2424        item3: V,
2425    ) -> (T, U, V, T, U, V) {
2426        (
2427            item1.clone(),
2428            item2.clone(),
2429            item3.clone(),
2430            item1,
2431            item2,
2432            item3,
2433        )
2434    }
2435    pub fn OP_2OVER<T: Clone, U: Clone, V, W>(
2436        item1: T,
2437        item2: U,
2438        item3: V,
2439        item4: W,
2440    ) -> (T, U, V, W, T, U) {
2441        (item1.clone(), item2.clone(), item3, item4, item1, item2)
2442    }
2443    pub fn OP_2ROT<T, U, V, W, X, Y>(
2444        item1: T,
2445        item2: U,
2446        item3: V,
2447        item4: W,
2448        item5: X,
2449        item6: Y,
2450    ) -> (V, W, X, Y, T, U) {
2451        (item3, item4, item5, item6, item1, item2)
2452    }
2453    pub fn OP_2SWAP<T, U, V, W>(item1: T, item2: U, item3: V, item4: W) -> (V, W, T, U) {
2454        (item3, item4, item1, item2)
2455    }
2456    pub fn OP_DEPTH() -> BitcoinInteger {
2457        BitcoinInteger(0)
2458    }
2459    pub fn OP_DROP<T>(item: T) {}
2460    pub fn OP_DUP<T: Clone>(item: T) -> (T, T) {
2461        (item.clone(), item)
2462    }
2463    pub fn OP_NIP<T, U>(item1: T, item2: U) -> U {
2464        item2
2465    }
2466    pub fn OP_OVER<T: Clone, U>(item1: T, item2: U) -> (T, U, T) {
2467        (item1.clone(), item2, item1)
2468    }
2469    pub fn OP_PICK(depth: BitcoinInteger) {}
2470    pub fn OP_ROLL(depth: BitcoinInteger) {}
2471    pub fn OP_ROT<T, U, V>(item1: T, item2: U, item3: V) -> (U, V, T) {
2472        (item2, item3, item1)
2473    }
2474    pub fn OP_SWAP<T, U>(item1: T, item2: U) -> (U, T) {
2475        (item2, item1)
2476    }
2477    pub fn OP_TUCK<T, U: Clone>(item1: T, item2: U) -> (U, T, U) {
2478        (item2.clone(), item1, item2)
2479    }
2480    pub fn OP_RETURN() {}
2481
2482    pub fn OP_CAT(left: BitcoinByteArray, right: BitcoinByteArray) -> BitcoinByteArray {
2483        BitcoinByteArray(b"MOCK".as_ref().into())
2484    }
2485    pub fn OP_SPLIT(
2486        array: BitcoinByteArray,
2487        split_idx: BitcoinInteger,
2488    ) -> (BitcoinByteArray, BitcoinByteArray) {
2489        (
2490            BitcoinByteArray(b"left".as_ref().into()),
2491            BitcoinByteArray(b"right".as_ref().into()),
2492        )
2493    }
2494    pub fn OP_NUM2BIN(num: BitcoinInteger, byte_size: BitcoinInteger) -> BitcoinByteArray {
2495        BitcoinByteArray(b"MOCK".as_ref().into())
2496    }
2497    pub fn OP_BIN2NUM(array: BitcoinByteArray) -> BitcoinInteger {
2498        BitcoinInteger(0)
2499    }
2500    pub fn OP_SIZE(array: BitcoinByteArray) -> (BitcoinByteArray, BitcoinInteger) {
2501        (array, BitcoinInteger(0))
2502    }
2503    pub fn OP_AND(array1: BitcoinByteArray, array2: BitcoinByteArray) -> BitcoinByteArray {
2504        BitcoinByteArray(b"MOCK".as_ref().into())
2505    }
2506    pub fn OP_OR(array1: BitcoinByteArray, array2: BitcoinByteArray) -> BitcoinByteArray {
2507        BitcoinByteArray(b"MOCK".as_ref().into())
2508    }
2509    pub fn OP_XOR(array1: BitcoinByteArray, array2: BitcoinByteArray) -> BitcoinByteArray {
2510        BitcoinByteArray(b"MOCK".as_ref().into())
2511    }
2512    pub fn OP_EQUAL<T>(item1: T, item2: T) -> BitcoinBoolean {
2513        BitcoinBoolean(true)
2514    }
2515    pub fn OP_EQUALVERIFY<T>(item1: T, item2: T) {}
2516
2517    pub fn OP_1ADD(num: BitcoinInteger) -> BitcoinInteger {
2518        BitcoinInteger(0)
2519    }
2520    pub fn OP_1SUB(num: BitcoinInteger) -> BitcoinInteger {
2521        BitcoinInteger(0)
2522    }
2523    pub fn OP_NEGATE(num: BitcoinInteger) -> BitcoinInteger {
2524        BitcoinInteger(0)
2525    }
2526    pub fn OP_ABS(num: BitcoinInteger) -> BitcoinInteger {
2527        BitcoinInteger(0)
2528    }
2529    pub fn OP_NOT(boolean: BitcoinBoolean) -> BitcoinBoolean {
2530        BitcoinBoolean(true)
2531    }
2532    pub fn OP_0NOTEQUAL(num: BitcoinInteger) -> BitcoinBoolean {
2533        BitcoinBoolean(true)
2534    }
2535    pub fn OP_ADD(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2536        BitcoinInteger(0)
2537    }
2538    pub fn OP_SUB(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2539        BitcoinInteger(0)
2540    }
2541    pub fn OP_DIV(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2542        BitcoinInteger(0)
2543    }
2544    pub fn OP_MOD(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2545        BitcoinInteger(0)
2546    }
2547    pub fn OP_BOOLAND(boolean1: BitcoinBoolean, boolean2: BitcoinBoolean) -> BitcoinBoolean {
2548        BitcoinBoolean(true)
2549    }
2550    pub fn OP_BOOLOR(boolean1: BitcoinBoolean, boolean2: BitcoinBoolean) -> BitcoinBoolean {
2551        BitcoinBoolean(true)
2552    }
2553    pub fn OP_NUMEQUAL(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2554        BitcoinBoolean(true)
2555    }
2556    pub fn OP_NUMEQUALVERIFY(num1: BitcoinInteger, num2: BitcoinInteger) {}
2557    pub fn OP_NUMNOTEQUAL(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2558        BitcoinBoolean(true)
2559    }
2560    pub fn OP_LESSTHAN(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2561        BitcoinBoolean(true)
2562    }
2563    pub fn OP_GREATERTHAN(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2564        BitcoinBoolean(true)
2565    }
2566    pub fn OP_LESSTHANOREQUAL(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2567        BitcoinBoolean(true)
2568    }
2569    pub fn OP_GREATERTHANOREQUAL(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinBoolean {
2570        BitcoinBoolean(true)
2571    }
2572    pub fn OP_MIN(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2573        BitcoinInteger(0)
2574    }
2575    pub fn OP_MAX(num1: BitcoinInteger, num2: BitcoinInteger) -> BitcoinInteger {
2576        BitcoinInteger(0)
2577    }
2578    pub fn OP_WITHIN(
2579        num1: BitcoinInteger,
2580        num_min: BitcoinInteger,
2581        num_max: BitcoinInteger,
2582    ) -> BitcoinBoolean {
2583        BitcoinBoolean(true)
2584    }
2585    pub fn OP_RIPEMD160(array: BitcoinByteArray) -> BitcoinByteArray {
2586        BitcoinByteArray(b"MOCK".as_ref().into())
2587    }
2588    pub fn OP_SHA1(array: BitcoinByteArray) -> BitcoinByteArray {
2589        BitcoinByteArray(b"MOCK".as_ref().into())
2590    }
2591    pub fn OP_SHA256(array: BitcoinByteArray) -> BitcoinByteArray {
2592        BitcoinByteArray(b"MOCK".as_ref().into())
2593    }
2594    pub fn OP_HASH160(array: BitcoinByteArray) -> BitcoinByteArray {
2595        BitcoinByteArray(b"MOCK".as_ref().into())
2596    }
2597    pub fn OP_HASH256(array: BitcoinByteArray) -> BitcoinByteArray {
2598        BitcoinByteArray(b"MOCK".as_ref().into())
2599    }
2600    pub fn OP_CODESEPARATOR() {}
2601    pub fn OP_CHECKSIG(sig: BitcoinByteArray, pubkey: BitcoinByteArray) -> BitcoinBoolean {
2602        BitcoinBoolean(true)
2603    }
2604    pub fn OP_CHECKSIGVERIFY(sig: BitcoinByteArray, pubkey: BitcoinByteArray) {}
2605    pub fn OP_CHECKLOCKTIMEVERIFY(locktime: BitcoinInteger) -> BitcoinInteger {
2606        BitcoinInteger(0)
2607    }
2608    pub fn OP_CHECKSEQUENCEVERIFY(sequence: BitcoinInteger) -> BitcoinInteger {
2609        BitcoinInteger(0)
2610    }
2611    pub fn OP_CHECKDATASIG(
2612        sig: BitcoinByteArray,
2613        data: BitcoinByteArray,
2614        pubkey: BitcoinByteArray,
2615    ) -> BitcoinBoolean {
2616        BitcoinBoolean(true)
2617    }
2618    pub fn OP_CHECKDATASIGVERIFY(
2619        sig: BitcoinByteArray,
2620        data: BitcoinByteArray,
2621        pubkey: BitcoinByteArray,
2622    ) {
2623    }
2624    pub fn OP_REVERSEBYTES(array: BitcoinByteArray) -> BitcoinByteArray {
2625        BitcoinByteArray(b"MOCK".as_ref().into())
2626    }
2627}
2628
2629impl Opcode {
2630    pub fn is_disabled(self) -> bool {
2631        use Opcode::*;
2632        match self {
2633            OP_RESERVED | OP_RESERVED1 | OP_RESERVED2 | OP_MUL | OP_2MUL | OP_2DIV | OP_INVERT
2634            | OP_LSHIFT | OP_RSHIFT | OP_VER | OP_VERIF | OP_VERNOTIF => true,
2635            _ => false,
2636        }
2637    }
2638
2639    pub fn retains_input(self) -> bool {
2640        use Opcode::*;
2641        match self {
2642            OP_SIZE | OP_CHECKLOCKTIMEVERIFY | OP_CHECKSEQUENCEVERIFY => true,
2643            _ => false,
2644        }
2645    }
2646
2647    pub fn behavior(self) -> OpcodeBehavior {
2648        use DataType::*;
2649        use Opcode::*;
2650        use StackItemDelta::*;
2651        fn o(
2652            input_types: &'static [DataType],
2653            output_types: &'static [DataType],
2654            output_order: &'static [usize],
2655            delta: &'static [StackItemDelta],
2656        ) -> OpcodeBehavior {
2657            OpcodeBehavior {
2658                input_types,
2659                output_types,
2660                output_order: Some(output_order),
2661                delta,
2662            }
2663        }
2664        fn u(
2665            input_types: &'static [DataType],
2666            output_types: &'static [DataType],
2667            delta: &'static [StackItemDelta],
2668        ) -> OpcodeBehavior {
2669            OpcodeBehavior {
2670                input_types,
2671                output_types,
2672                output_order: None,
2673                delta,
2674            }
2675        }
2676        const T: DataType = Generic;
2677        match self {
2678            OP_VERIFY => u(&[Boolean], &[], &[]),
2679
2680            OP_2DROP => o(&[T, T], &[], &[], &[]),
2681            OP_2DUP => o(
2682                &[T, T],
2683                &[T, T, T, T],
2684                &[0, 1, 0, 1],
2685                &[Observed, Observed, Added, Added],
2686            ),
2687            OP_3DUP => o(
2688                &[T, T, T],
2689                &[T, T, T, T, T, T],
2690                &[0, 1, 2, 0, 1, 2],
2691                &[Observed, Observed, Observed, Added, Added, Added],
2692            ),
2693            OP_2OVER => o(
2694                &[T, T, T, T],
2695                &[T, T, T, T, T, T],
2696                &[0, 1, 2, 3, 0, 1],
2697                &[Observed, Observed, Untouched, Untouched, Added, Added],
2698            ),
2699            OP_2ROT => o(
2700                &[T, T, T, T, T, T],
2701                &[T, T, T, T, T, T],
2702                &[2, 3, 4, 5, 0, 1],
2703                &[
2704                    MovedIndirectly,
2705                    MovedIndirectly,
2706                    MovedIndirectly,
2707                    MovedIndirectly,
2708                    Moved,
2709                    Moved,
2710                ],
2711            ),
2712            OP_2SWAP => o(
2713                &[T, T, T, T],
2714                &[T, T, T, T],
2715                &[2, 3, 0, 1],
2716                &[MovedIndirectly, MovedIndirectly, Moved, Moved],
2717            ),
2718            OP_DEPTH => o(&[], &[Integer], &[0], &[Added]),
2719            OP_DROP => o(&[T], &[], &[], &[]),
2720            OP_DUP => o(&[T], &[T, T], &[0, 0], &[Observed, Added]),
2721            OP_NIP => o(&[T, T], &[T], &[1], &[MovedIndirectly]),
2722            OP_OVER => o(
2723                &[T, T],
2724                &[T, T, T],
2725                &[0, 1, 0],
2726                &[Observed, Untouched, Added],
2727            ),
2728            OP_PICK => u(&[Integer], &[T], &[Added]),
2729            OP_ROLL => u(&[Integer], &[T], &[Moved]),
2730            OP_ROT => o(
2731                &[T, T, T],
2732                &[T, T, T],
2733                &[1, 2, 0],
2734                &[MovedIndirectly, MovedIndirectly, Moved],
2735            ),
2736            OP_SWAP => o(&[T, T], &[T, T], &[1, 0], &[MovedIndirectly, Moved]),
2737            OP_TUCK => o(
2738                &[T, T],
2739                &[T, T, T],
2740                &[1, 0, 1],
2741                &[Added, MovedIndirectly, MovedIndirectly],
2742            ),
2743
2744            OP_CAT => u(
2745                &[ByteArray(None), ByteArray(None)],
2746                &[ByteArray(None)],
2747                &[Changed],
2748            ),
2749            OP_SPLIT => u(
2750                &[ByteArray(None), Integer],
2751                &[ByteArray(None), ByteArray(None)],
2752                &[Changed, Changed],
2753            ),
2754            OP_NUM2BIN => u(&[Integer, Integer], &[ByteArray(None)], &[Changed]),
2755            OP_BIN2NUM => u(&[ByteArray(None)], &[Integer], &[Changed]),
2756            OP_SIZE => u(
2757                &[ByteArray(None)],
2758                &[ByteArray(None), Integer],
2759                &[Observed, Added],
2760            ),
2761
2762            OP_AND => u(
2763                &[ByteArray(None), ByteArray(None)],
2764                &[ByteArray(None)],
2765                &[Changed],
2766            ),
2767            OP_OR => u(
2768                &[ByteArray(None), ByteArray(None)],
2769                &[ByteArray(None)],
2770                &[Changed],
2771            ),
2772            OP_XOR => u(
2773                &[ByteArray(None), ByteArray(None)],
2774                &[ByteArray(None)],
2775                &[Changed],
2776            ),
2777            OP_EQUAL => u(&[T, T], &[Boolean], &[Changed]),
2778            OP_EQUALVERIFY => u(&[T, T], &[], &[]),
2779
2780            OP_1ADD => u(&[Integer], &[Integer], &[Changed]),
2781            OP_1SUB => u(&[Integer], &[Integer], &[Changed]),
2782            OP_NEGATE => u(&[Integer], &[Integer], &[Changed]),
2783            OP_ABS => u(&[Integer], &[Integer], &[Changed]),
2784            OP_NOT => u(&[Boolean], &[Boolean], &[Changed]),
2785            OP_0NOTEQUAL => u(&[Integer], &[Boolean], &[Changed]),
2786
2787            OP_ADD => u(&[Integer, Integer], &[Integer], &[Changed]),
2788            OP_SUB => u(&[Integer, Integer], &[Integer], &[Changed]),
2789            OP_DIV => u(&[Integer, Integer], &[Integer], &[Changed]),
2790            OP_MOD => u(&[Integer, Integer], &[Integer], &[Changed]),
2791            OP_BOOLAND => u(&[Boolean, Boolean], &[Boolean], &[Changed]),
2792            OP_BOOLOR => u(&[Boolean, Boolean], &[Boolean], &[Changed]),
2793            OP_NUMEQUAL => u(&[Integer, Integer], &[Boolean], &[Changed]),
2794            OP_NUMEQUALVERIFY => u(&[Integer, Integer], &[], &[]),
2795            OP_NUMNOTEQUAL => u(&[Integer, Integer], &[Boolean], &[Changed]),
2796            OP_LESSTHAN => u(&[Integer, Integer], &[Boolean], &[Changed]),
2797            OP_GREATERTHAN => u(&[Integer, Integer], &[Boolean], &[Changed]),
2798            OP_LESSTHANOREQUAL => u(&[Integer, Integer], &[Boolean], &[Changed]),
2799            OP_GREATERTHANOREQUAL => u(&[Integer, Integer], &[Boolean], &[Changed]),
2800            OP_MIN => u(&[Integer, Integer], &[Integer], &[Changed]),
2801            OP_MAX => u(&[Integer, Integer], &[Integer], &[Changed]),
2802            OP_WITHIN => u(&[Integer, Integer, Integer], &[Boolean], &[Changed]),
2803
2804            OP_RIPEMD160 => u(&[ByteArray(None)], &[ByteArray(Some(20))], &[Changed]),
2805            OP_SHA1 => u(&[ByteArray(None)], &[ByteArray(Some(20))], &[Changed]),
2806            OP_SHA256 => u(&[ByteArray(None)], &[ByteArray(Some(32))], &[Changed]),
2807            OP_HASH160 => u(&[ByteArray(None)], &[ByteArray(Some(20))], &[Changed]),
2808            OP_HASH256 => u(&[ByteArray(None)], &[ByteArray(Some(32))], &[Changed]),
2809            OP_CHECKSIG => u(&[ByteArray(None), ByteArray(None)], &[Boolean], &[Changed]),
2810            OP_CHECKSIGVERIFY => u(&[ByteArray(None), ByteArray(None)], &[], &[Changed]),
2811
2812            OP_CHECKDATASIG => u(
2813                &[ByteArray(None), ByteArray(None), ByteArray(None)],
2814                &[Boolean],
2815                &[Changed],
2816            ),
2817            OP_CHECKDATASIGVERIFY => u(
2818                &[ByteArray(None), ByteArray(None), ByteArray(None)],
2819                &[],
2820                &[],
2821            ),
2822            OP_REVERSEBYTES => u(&[ByteArray(None)], &[ByteArray(None)], &[Changed]),
2823            OP_0 | OP_1NEGATE | OP_1 | OP_2 | OP_3 | OP_4 | OP_5 | OP_6 | OP_7 | OP_8 | OP_9
2824            | OP_10 | OP_11 | OP_12 | OP_13 | OP_14 | OP_15 | OP_16 => u(&[], &[Integer], &[Added]),
2825
2826            OP_IF => u(&[T], &[], &[]),
2827            OP_ELSE => u(&[], &[], &[]),
2828            OP_ENDIF => u(&[], &[], &[]),
2829
2830            OP_TOALTSTACK => u(&[T], &[], &[]),
2831            OP_FROMALTSTACK => u(&[], &[T], &[Added]),
2832
2833            OP_CHECKLOCKTIMEVERIFY => u(&[Integer], &[Integer], &[Observed]),
2834            OP_CHECKSEQUENCEVERIFY => u(&[Integer], &[Integer], &[Observed]),
2835
2836            OP_IFDUP | OP_CHECKMULTISIG | OP_CHECKMULTISIGVERIFY => {
2837                panic!("Opcode behavior cannot be expressed in OpcodeBehavior")
2838            }
2839
2840            opcode if opcode.is_disabled() => panic!("Opcode is disabled"),
2841
2842            _ => u(&[], &[], &[]),
2843        }
2844    }
2845}