Skip to content

Commit c240a27

Browse files
committed
Merge rust-bitcoin#4928: Make pushnum opcodes more terse
95ea71f Use new OP_x variants (for x in 1-16) (Tobin C. Harding) 85f9b10 Add terse opcodes for 1-16 and neg (Tobin C. Harding) 89795ff opcodes: Fix incorrect docs (Tobin C. Harding) 9b3ebb6 Move opcode aliases to all module (Tobin C. Harding) 74ef48c Change opcodes from static to const (Tobin C. Harding) Pull request description: Use `OP_1` instead of `OP_PUSHNUM_1` (for all values 1-16 inclusive). This is a breaking change to `serde` serialization since we use the exact letters of the consts when serializin Fix rust-bitcoin#4924 ACKs for top commit: apoelstra: ACK 95ea71f; successfully ran local tests shinghim: ACK 95ea71f Tree-SHA512: a190e625d03b28cfb8f7678a40d18cc8cdd10b18bac23b147ea3f63f751a29e49f658f4addf13d8d4d513cae9dfaa3c555f3fba064144b0d0687b151f4f99394
2 parents d1453ce + 95ea71f commit c240a27

File tree

8 files changed

+285
-181
lines changed

8 files changed

+285
-181
lines changed

bitcoin/src/blockdata/opcodes.rs

Lines changed: 122 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,70 @@ macro_rules! all_opcodes {
4747
#[doc = $doc]
4848
pub const $op: Opcode = Opcode { code: $val};
4949
)*
50-
}
5150

52-
/// Push an empty array onto the stack.
53-
pub static OP_0: Opcode = OP_PUSHBYTES_0;
54-
/// Empty stack is also FALSE.
55-
pub static OP_FALSE: Opcode = OP_PUSHBYTES_0;
56-
/// Number 1 is also TRUE.
57-
pub static OP_TRUE: Opcode = OP_PUSHNUM_1;
58-
/// Previously called OP_NOP2.
59-
pub static OP_NOP2: Opcode = OP_CLTV;
60-
/// Previously called OP_NOP3.
61-
pub static OP_NOP3: Opcode = OP_CSV;
51+
/// Push an empty array onto the stack.
52+
pub const OP_0: Opcode = OP_PUSHBYTES_0;
53+
/// Empty stack is also FALSE.
54+
pub const OP_FALSE: Opcode = OP_PUSHBYTES_0;
55+
/// Number 1 is also TRUE.
56+
pub const OP_TRUE: Opcode = OP_1;
57+
/// Previously called OP_NOP2.
58+
pub const OP_NOP2: Opcode = OP_CLTV;
59+
/// Previously called OP_NOP3.
60+
pub const OP_NOP3: Opcode = OP_CSV;
61+
62+
/// Push the array `0x81` onto the stack.
63+
#[deprecated(since = "TBD", note = "use OP_1NEGATE instead")]
64+
pub const OP_PUSHNUM_NEG1: Opcode = OP_1NEGATE;
65+
/// Push the array `0x01` onto the stack.
66+
#[deprecated(since = "TBD", note = "use OP_1 instead")]
67+
pub const OP_PUSHNUM_1: Opcode = OP_1;
68+
/// Push the array `0x02` onto the stack.
69+
#[deprecated(since = "TBD", note = "use OP_2 instead")]
70+
pub const OP_PUSHNUM_2: Opcode = OP_2;
71+
/// Push the array `0x03` onto the stack.
72+
#[deprecated(since = "TBD", note = "use OP_3 instead")]
73+
pub const OP_PUSHNUM_3: Opcode = OP_3;
74+
/// Push the array `0x04` onto the stack.
75+
#[deprecated(since = "TBD", note = "use OP_4 instead")]
76+
pub const OP_PUSHNUM_4: Opcode = OP_4;
77+
/// Push the array `0x05` onto the stack.
78+
#[deprecated(since = "TBD", note = "use OP_5 instead")]
79+
pub const OP_PUSHNUM_5: Opcode = OP_5;
80+
/// Push the array `0x06` onto the stack.
81+
#[deprecated(since = "TBD", note = "use OP_6 instead")]
82+
pub const OP_PUSHNUM_6: Opcode = OP_6;
83+
/// Push the array `0x07` onto the stack.
84+
#[deprecated(since = "TBD", note = "use OP_7 instead")]
85+
pub const OP_PUSHNUM_7: Opcode = OP_7;
86+
/// Push the array `0x08` onto the stack.
87+
#[deprecated(since = "TBD", note = "use OP_8 instead")]
88+
pub const OP_PUSHNUM_8: Opcode = OP_8;
89+
/// Push the array `0x09` onto the stack.
90+
#[deprecated(since = "TBD", note = "use OP_9 instead")]
91+
pub const OP_PUSHNUM_9: Opcode = OP_9;
92+
/// Push the array `0x0a` onto the stack.
93+
#[deprecated(since = "TBD", note = "use OP_10 instead")]
94+
pub const OP_PUSHNUM_10: Opcode = OP_10;
95+
/// Push the array `0x0b` onto the stack.
96+
#[deprecated(since = "TBD", note = "use OP_11 instead")]
97+
pub const OP_PUSHNUM_11: Opcode = OP_11;
98+
/// Push the array `0x0c` onto the stack.
99+
#[deprecated(since = "TBD", note = "use OP_12 instead")]
100+
pub const OP_PUSHNUM_12: Opcode = OP_12;
101+
/// Push the array `0x0d` onto the stack.
102+
#[deprecated(since = "TBD", note = "use OP_13 instead")]
103+
pub const OP_PUSHNUM_13: Opcode = OP_13;
104+
/// Push the array `0x0e` onto the stack.
105+
#[deprecated(since = "TBD", note = "use OP_14 instead")]
106+
pub const OP_PUSHNUM_14: Opcode = OP_14;
107+
/// Push the array `0x0f` onto the stack.
108+
#[deprecated(since = "TBD", note = "use OP_15 instead")]
109+
pub const OP_PUSHNUM_15: Opcode = OP_15;
110+
/// Push the array `0x10` onto the stack.
111+
#[deprecated(since = "TBD", note = "use OP_16 instead")]
112+
pub const OP_PUSHNUM_16: Opcode = OP_16;
113+
}
62114

63115
impl fmt::Display for Opcode {
64116
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
@@ -152,24 +204,24 @@ all_opcodes! {
152204
OP_PUSHDATA1 => 0x4c, "Read the next byte as N; push the next N bytes as an array onto the stack.";
153205
OP_PUSHDATA2 => 0x4d, "Read the next 2 bytes as N; push the next N bytes as an array onto the stack.";
154206
OP_PUSHDATA4 => 0x4e, "Read the next 4 bytes as N; push the next N bytes as an array onto the stack.";
155-
OP_PUSHNUM_NEG1 => 0x4f, "Push the array `0x81` onto the stack.";
207+
OP_1NEGATE => 0x4f, "Push the array `0x81` onto the stack.";
156208
OP_RESERVED => 0x50, "Synonym for `OP_RETURN`.";
157-
OP_PUSHNUM_1 => 0x51, "Push the array `0x01` onto the stack.";
158-
OP_PUSHNUM_2 => 0x52, "Push the array `0x02` onto the stack.";
159-
OP_PUSHNUM_3 => 0x53, "Push the array `0x03` onto the stack.";
160-
OP_PUSHNUM_4 => 0x54, "Push the array `0x04` onto the stack.";
161-
OP_PUSHNUM_5 => 0x55, "Push the array `0x05` onto the stack.";
162-
OP_PUSHNUM_6 => 0x56, "Push the array `0x06` onto the stack.";
163-
OP_PUSHNUM_7 => 0x57, "Push the array `0x07` onto the stack.";
164-
OP_PUSHNUM_8 => 0x58, "Push the array `0x08` onto the stack.";
165-
OP_PUSHNUM_9 => 0x59, "Push the array `0x09` onto the stack.";
166-
OP_PUSHNUM_10 => 0x5a, "Push the array `0x0a` onto the stack.";
167-
OP_PUSHNUM_11 => 0x5b, "Push the array `0x0b` onto the stack.";
168-
OP_PUSHNUM_12 => 0x5c, "Push the array `0x0c` onto the stack.";
169-
OP_PUSHNUM_13 => 0x5d, "Push the array `0x0d` onto the stack.";
170-
OP_PUSHNUM_14 => 0x5e, "Push the array `0x0e` onto the stack.";
171-
OP_PUSHNUM_15 => 0x5f, "Push the array `0x0f` onto the stack.";
172-
OP_PUSHNUM_16 => 0x60, "Push the array `0x10` onto the stack.";
209+
OP_1 => 0x51, "Push the array `0x01` onto the stack.";
210+
OP_2 => 0x52, "Push the array `0x02` onto the stack.";
211+
OP_3 => 0x53, "Push the array `0x03` onto the stack.";
212+
OP_4 => 0x54, "Push the array `0x04` onto the stack.";
213+
OP_5 => 0x55, "Push the array `0x05` onto the stack.";
214+
OP_6 => 0x56, "Push the array `0x06` onto the stack.";
215+
OP_7 => 0x57, "Push the array `0x07` onto the stack.";
216+
OP_8 => 0x58, "Push the array `0x08` onto the stack.";
217+
OP_9 => 0x59, "Push the array `0x09` onto the stack.";
218+
OP_10 => 0x5a, "Push the array `0x0a` onto the stack.";
219+
OP_11 => 0x5b, "Push the array `0x0b` onto the stack.";
220+
OP_12 => 0x5c, "Push the array `0x0c` onto the stack.";
221+
OP_13 => 0x5d, "Push the array `0x0d` onto the stack.";
222+
OP_14 => 0x5e, "Push the array `0x0e` onto the stack.";
223+
OP_15 => 0x5f, "Push the array `0x0f` onto the stack.";
224+
OP_16 => 0x60, "Push the array `0x10` onto the stack.";
173225
OP_NOP => 0x61, "Does nothing.";
174226
OP_VER => 0x62, "Synonym for `OP_RETURN`.";
175227
OP_IF => 0x63, "Pop and execute the next statements if a nonzero element was popped.";
@@ -397,11 +449,11 @@ impl Opcode {
397449
| (OP_CHECKMULTISIGVERIFY, ClassifyContext::TapScript) => Class::ReturnOp,
398450

399451
// 1 opcode of PushNum class
400-
(OP_PUSHNUM_NEG1, _) => Class::PushNum(-1),
452+
(OP_1NEGATE, _) => Class::PushNum(-1),
401453

402454
// 16 opcodes of PushNum class
403-
(op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code =>
404-
Class::PushNum(1 + self.code as i32 - OP_PUSHNUM_1.code as i32),
455+
(op, _) if op.code >= OP_1.code && op.code <= OP_16.code =>
456+
Class::PushNum(1 + self.code as i32 - OP_1.code as i32),
405457

406458
// 76 opcodes of PushBytes class
407459
(op, _) if op.code <= OP_PUSHBYTES_75.code => Class::PushBytes(self.code as u32),
@@ -415,7 +467,7 @@ impl Opcode {
415467
#[inline]
416468
pub const fn to_u8(self) -> u8 { self.code }
417469

418-
/// Encodes PUSHNUM [`Opcode`] as a `u8` representing its number (1-16).
470+
/// Decodes PUSHNUM [`Opcode`] as a `u8` representing its number (1-16).
419471
///
420472
/// Does not convert `OP_FALSE` to 0. Only `1` to `OP_PUSHNUM_16` are covered.
421473
///
@@ -425,8 +477,8 @@ impl Opcode {
425477
#[inline]
426478
#[must_use]
427479
pub const fn decode_pushnum(self) -> Option<u8> {
428-
const START: u8 = OP_PUSHNUM_1.code;
429-
const END: u8 = OP_PUSHNUM_16.code;
480+
const START: u8 = OP_1.code;
481+
const END: u8 = OP_16.code;
430482
match self.code {
431483
START..=END => Some(self.code - START + 1),
432484
_ => None,
@@ -575,11 +627,11 @@ mod tests {
575627
fn decode_pushnum() {
576628
// Test all possible opcodes
577629
// - Sanity check
578-
assert_eq!(OP_PUSHNUM_1.code, 0x51_u8);
579-
assert_eq!(OP_PUSHNUM_16.code, 0x60_u8);
630+
assert_eq!(OP_1.code, 0x51_u8);
631+
assert_eq!(OP_16.code, 0x60_u8);
580632
for i in 0x00..=0xff_u8 {
581633
let expected = match i {
582-
// OP_PUSHNUM_1 ..= OP_PUSHNUM_16
634+
// OP_1 ..= OP_16
583635
0x51..=0x60 => Some(i - 0x50),
584636
_ => None,
585637
};
@@ -589,22 +641,22 @@ mod tests {
589641
// Test the named opcode constants
590642
// - This is the OP right before PUSHNUMs start
591643
assert!(OP_RESERVED.decode_pushnum().is_none());
592-
assert_eq!(OP_PUSHNUM_1.decode_pushnum().expect("pushnum"), 1);
593-
assert_eq!(OP_PUSHNUM_2.decode_pushnum().expect("pushnum"), 2);
594-
assert_eq!(OP_PUSHNUM_3.decode_pushnum().expect("pushnum"), 3);
595-
assert_eq!(OP_PUSHNUM_4.decode_pushnum().expect("pushnum"), 4);
596-
assert_eq!(OP_PUSHNUM_5.decode_pushnum().expect("pushnum"), 5);
597-
assert_eq!(OP_PUSHNUM_6.decode_pushnum().expect("pushnum"), 6);
598-
assert_eq!(OP_PUSHNUM_7.decode_pushnum().expect("pushnum"), 7);
599-
assert_eq!(OP_PUSHNUM_8.decode_pushnum().expect("pushnum"), 8);
600-
assert_eq!(OP_PUSHNUM_9.decode_pushnum().expect("pushnum"), 9);
601-
assert_eq!(OP_PUSHNUM_10.decode_pushnum().expect("pushnum"), 10);
602-
assert_eq!(OP_PUSHNUM_11.decode_pushnum().expect("pushnum"), 11);
603-
assert_eq!(OP_PUSHNUM_12.decode_pushnum().expect("pushnum"), 12);
604-
assert_eq!(OP_PUSHNUM_13.decode_pushnum().expect("pushnum"), 13);
605-
assert_eq!(OP_PUSHNUM_14.decode_pushnum().expect("pushnum"), 14);
606-
assert_eq!(OP_PUSHNUM_15.decode_pushnum().expect("pushnum"), 15);
607-
assert_eq!(OP_PUSHNUM_16.decode_pushnum().expect("pushnum"), 16);
644+
assert_eq!(OP_1.decode_pushnum().expect("pushnum"), 1);
645+
assert_eq!(OP_2.decode_pushnum().expect("pushnum"), 2);
646+
assert_eq!(OP_3.decode_pushnum().expect("pushnum"), 3);
647+
assert_eq!(OP_4.decode_pushnum().expect("pushnum"), 4);
648+
assert_eq!(OP_5.decode_pushnum().expect("pushnum"), 5);
649+
assert_eq!(OP_6.decode_pushnum().expect("pushnum"), 6);
650+
assert_eq!(OP_7.decode_pushnum().expect("pushnum"), 7);
651+
assert_eq!(OP_8.decode_pushnum().expect("pushnum"), 8);
652+
assert_eq!(OP_9.decode_pushnum().expect("pushnum"), 9);
653+
assert_eq!(OP_10.decode_pushnum().expect("pushnum"), 10);
654+
assert_eq!(OP_11.decode_pushnum().expect("pushnum"), 11);
655+
assert_eq!(OP_12.decode_pushnum().expect("pushnum"), 12);
656+
assert_eq!(OP_13.decode_pushnum().expect("pushnum"), 13);
657+
assert_eq!(OP_14.decode_pushnum().expect("pushnum"), 14);
658+
assert_eq!(OP_15.decode_pushnum().expect("pushnum"), 15);
659+
assert_eq!(OP_16.decode_pushnum().expect("pushnum"), 16);
608660
// - This is the OP right after PUSHNUMs end
609661
assert!(OP_NOP.decode_pushnum().is_none());
610662
}
@@ -719,24 +771,24 @@ mod tests {
719771
roundtrip!(unique, OP_PUSHDATA1);
720772
roundtrip!(unique, OP_PUSHDATA2);
721773
roundtrip!(unique, OP_PUSHDATA4);
722-
roundtrip!(unique, OP_PUSHNUM_NEG1);
774+
roundtrip!(unique, OP_1NEGATE);
723775
roundtrip!(unique, OP_RESERVED);
724-
roundtrip!(unique, OP_PUSHNUM_1);
725-
roundtrip!(unique, OP_PUSHNUM_2);
726-
roundtrip!(unique, OP_PUSHNUM_3);
727-
roundtrip!(unique, OP_PUSHNUM_4);
728-
roundtrip!(unique, OP_PUSHNUM_5);
729-
roundtrip!(unique, OP_PUSHNUM_6);
730-
roundtrip!(unique, OP_PUSHNUM_7);
731-
roundtrip!(unique, OP_PUSHNUM_8);
732-
roundtrip!(unique, OP_PUSHNUM_9);
733-
roundtrip!(unique, OP_PUSHNUM_10);
734-
roundtrip!(unique, OP_PUSHNUM_11);
735-
roundtrip!(unique, OP_PUSHNUM_12);
736-
roundtrip!(unique, OP_PUSHNUM_13);
737-
roundtrip!(unique, OP_PUSHNUM_14);
738-
roundtrip!(unique, OP_PUSHNUM_15);
739-
roundtrip!(unique, OP_PUSHNUM_16);
776+
roundtrip!(unique, OP_1);
777+
roundtrip!(unique, OP_2);
778+
roundtrip!(unique, OP_3);
779+
roundtrip!(unique, OP_4);
780+
roundtrip!(unique, OP_5);
781+
roundtrip!(unique, OP_6);
782+
roundtrip!(unique, OP_7);
783+
roundtrip!(unique, OP_8);
784+
roundtrip!(unique, OP_9);
785+
roundtrip!(unique, OP_10);
786+
roundtrip!(unique, OP_11);
787+
roundtrip!(unique, OP_12);
788+
roundtrip!(unique, OP_13);
789+
roundtrip!(unique, OP_14);
790+
roundtrip!(unique, OP_15);
791+
roundtrip!(unique, OP_16);
740792
roundtrip!(unique, OP_NOP);
741793
roundtrip!(unique, OP_VER);
742794
roundtrip!(unique, OP_IF);

bitcoin/src/blockdata/script/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ impl<T> Builder<T> {
7878
let bytes = data.as_ref().as_bytes();
7979
if bytes.len() == 1 && (bytes[0] == 0x81 || bytes[0] <= 16) {
8080
match bytes[0] {
81-
0x81 => self.push_opcode(OP_PUSHNUM_NEG1),
81+
0x81 => self.push_opcode(OP_1NEGATE),
8282
0 => self.push_opcode(OP_PUSHBYTES_0),
83-
1..=16 => self.push_opcode(Opcode::from(bytes[0] + (OP_PUSHNUM_1.to_u8() - 1))),
83+
1..=16 => self.push_opcode(Opcode::from(bytes[0] + (OP_1.to_u8() - 1))),
8484
_ => self, // unreachable arm
8585
}
8686
} else {

bitcoin/src/blockdata/script/owned.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ internal_macros::define_extension_trait! {
6464
/// Does not check whether `n` is in the range of [-2^31 +1...2^31 -1].
6565
fn push_int_unchecked(&mut self, n: i64) {
6666
match n {
67-
-1 => self.push_opcode(OP_PUSHNUM_NEG1),
67+
-1 => self.push_opcode(OP_1NEGATE),
6868
0 => self.push_opcode(OP_PUSHBYTES_0),
69-
1..=16 => self.push_opcode(Opcode::from(n as u8 + (OP_PUSHNUM_1.to_u8() - 1))),
69+
1..=16 => self.push_opcode(Opcode::from(n as u8 + (OP_1.to_u8() - 1))),
7070
_ => self.push_int_non_minimal(n),
7171
}
7272
}
@@ -79,9 +79,9 @@ internal_macros::define_extension_trait! {
7979
let bytes = data.as_ref().as_bytes();
8080
if bytes.len() == 1 && (bytes[0] == 0x81 || bytes[0] <= 16) {
8181
match bytes[0] {
82-
0x81 => { self.push_opcode(OP_PUSHNUM_NEG1); },
82+
0x81 => { self.push_opcode(OP_1NEGATE); },
8383
0 => { self.push_opcode(OP_PUSHBYTES_0); },
84-
1..=16 => { self.push_opcode(Opcode::from(bytes[0] + (OP_PUSHNUM_1.to_u8() - 1))); },
84+
1..=16 => { self.push_opcode(Opcode::from(bytes[0] + (OP_1.to_u8() - 1))); },
8585
_ => {}, // unreachable arm
8686
}
8787
} else {

bitcoin/src/blockdata/script/tests.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ fn iterator() {
747747

748748
assert_eq!(
749749
v_min,
750-
vec![(0, Instruction::PushBytes([105].as_ref())), (2, Instruction::Op(opcodes::OP_NOP3))]
750+
vec![(0, Instruction::PushBytes([105].as_ref())), (2, Instruction::Op(opcodes::all::OP_NOP3))]
751751
);
752752

753753
assert_eq!(v_nonmin.unwrap_err(), Error::NonMinimalPush);
@@ -756,7 +756,7 @@ fn iterator() {
756756
v_nonmin_alt,
757757
vec![
758758
(0, Instruction::PushBytes([105, 0].as_ref())),
759-
(3, Instruction::Op(opcodes::OP_NOP3))
759+
(3, Instruction::Op(opcodes::all::OP_NOP3))
760760
]
761761
);
762762

@@ -858,34 +858,34 @@ fn script_get_sigop_count() {
858858
.push_slice([42; 20])
859859
.push_opcode(OP_EQUALVERIFY)
860860
.push_opcode(OP_CHECKSIGVERIFY)
861-
.push_opcode(OP_PUSHNUM_1)
861+
.push_opcode(OP_1)
862862
.into_script()
863863
.count_sigops(),
864864
1
865865
);
866866
let multi = Script::builder()
867-
.push_opcode(OP_PUSHNUM_1)
867+
.push_opcode(OP_1)
868868
.push_slice([3; 33])
869869
.push_slice([3; 33])
870870
.push_slice([3; 33])
871-
.push_opcode(OP_PUSHNUM_3)
871+
.push_opcode(OP_3)
872872
.push_opcode(OP_CHECKMULTISIG)
873873
.into_script();
874874
assert_eq!(multi.count_sigops(), 3);
875875
assert_eq!(multi.count_sigops_legacy(), 20);
876876
let multi_verify = Script::builder()
877-
.push_opcode(OP_PUSHNUM_1)
877+
.push_opcode(OP_1)
878878
.push_slice([3; 33])
879879
.push_slice([3; 33])
880880
.push_slice([3; 33])
881-
.push_opcode(OP_PUSHNUM_3)
881+
.push_opcode(OP_3)
882882
.push_opcode(OP_CHECKMULTISIGVERIFY)
883-
.push_opcode(OP_PUSHNUM_1)
883+
.push_opcode(OP_1)
884884
.into_script();
885885
assert_eq!(multi_verify.count_sigops(), 3);
886886
assert_eq!(multi_verify.count_sigops_legacy(), 20);
887887
let multi_nopushnum_pushdata = Script::builder()
888-
.push_opcode(OP_PUSHNUM_1)
888+
.push_opcode(OP_1)
889889
.push_slice([3; 33])
890890
.push_slice([3; 33])
891891
.push_slice([3; 33])
@@ -894,7 +894,7 @@ fn script_get_sigop_count() {
894894
assert_eq!(multi_nopushnum_pushdata.count_sigops(), 20);
895895
assert_eq!(multi_nopushnum_pushdata.count_sigops_legacy(), 20);
896896
let multi_nopushnum_op = Script::builder()
897-
.push_opcode(OP_PUSHNUM_1)
897+
.push_opcode(OP_1)
898898
.push_slice([3; 33])
899899
.push_slice([3; 33])
900900
.push_opcode(OP_DROP)
@@ -1017,10 +1017,10 @@ fn instruction_script_num_parse() {
10171017
];
10181018
let ops = [
10191019
(Instruction::Op(opcodes::all::OP_PUSHDATA4), None),
1020-
(Instruction::Op(opcodes::all::OP_PUSHNUM_NEG1), Some(-1)),
1020+
(Instruction::Op(opcodes::all::OP_1NEGATE), Some(-1)),
10211021
(Instruction::Op(opcodes::all::OP_RESERVED), None),
1022-
(Instruction::Op(opcodes::all::OP_PUSHNUM_1), Some(1)),
1023-
(Instruction::Op(opcodes::all::OP_PUSHNUM_16), Some(16)),
1022+
(Instruction::Op(opcodes::all::OP_1), Some(1)),
1023+
(Instruction::Op(opcodes::all::OP_16), Some(16)),
10241024
(Instruction::Op(opcodes::all::OP_NOP), None),
10251025
];
10261026
for (input, expected) in &push_bytes {

bitcoin/src/blockdata/script/witness_version.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl TryFrom<Opcode> for WitnessVersion {
122122
fn try_from(opcode: Opcode) -> Result<Self, Self::Error> {
123123
match opcode.to_u8() {
124124
0 => Ok(WitnessVersion::V0),
125-
version if version >= OP_PUSHNUM_1.to_u8() && version <= OP_PUSHNUM_16.to_u8() =>
126-
WitnessVersion::try_from(version - OP_PUSHNUM_1.to_u8() + 1),
125+
version if version >= OP_1.to_u8() && version <= OP_16.to_u8() =>
126+
WitnessVersion::try_from(version - OP_1.to_u8() + 1),
127127
invalid => Err(TryFromError { invalid }),
128128
}
129129
}
@@ -145,7 +145,7 @@ impl From<WitnessVersion> for Opcode {
145145
fn from(version: WitnessVersion) -> Opcode {
146146
match version {
147147
WitnessVersion::V0 => OP_PUSHBYTES_0,
148-
no => Opcode::from(OP_PUSHNUM_1.to_u8() + no.to_num() - 1),
148+
no => Opcode::from(OP_1.to_u8() + no.to_num() - 1),
149149
}
150150
}
151151
}

0 commit comments

Comments
 (0)