What changed, and why it matters
This commit renames Bitcoin script opcode constants to shorter names (for example, OP_PUSHNUM_1 becomes OP_1) and keeps the old names as deprecated aliases. It also changes how these opcodes are serialized to JSON, so any software that exchanges opcode names with this library may need to update its expected strings. There is no direct security flaw in the code change itself, but it is a breaking API/serialization change that could surprise downstream users.
Treat this as a compatibility/API change rather than a vulnerability. Downstream projects using rust-bitcoin's serde serialization for opcodes should update their expected opcode name strings and migrate from OP_PUSHNUM_* to OP_1..OP_16/OP_1NEGATE. Monitor for any unexpected deserialization failures after upgrading.
Security signals we found
Breaking serde serialization format change noted by the vendor
Deprecated public API constants retained as aliases to avoid immediate breakage
No change to opcode byte values or script execution semantics
Evidence from the diff
The patch introduces terse opcode identifiers (OP_1 through OP_16 and OP_1NEGATE) matching Bitcoin Core naming, deprecates the previous OP_PUSHNUM_* names via #[deprecated] aliases, and updates Display/serde serialization to emit the new names. The opcode byte values (0x4f-0x60) and classification logic are unchanged. Tests and serde regression fixtures are updated to use the new names. The commit message explicitly notes this is a breaking change for serde serialization because it uses the exact constant names as serialized strings.
Changed components
bitcoin/src/blockdata/opcodes.rsprimitives/src/opcodes.rsbitcoin/tests/serde_opcodes.rsInspect captured patch +191 / −87
diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs
index 57715765..46503b4d 100644
--- a/bitcoin/src/blockdata/opcodes.rs
+++ b/bitcoin/src/blockdata/opcodes.rs
@@ -58,6 +58,58 @@ macro_rules! all_opcodes {
pub const OP_NOP2: Opcode = OP_CLTV;
/// Previously called OP_NOP3.
pub const OP_NOP3: Opcode = OP_CSV;
+
+ /// Push the array `0x81` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_1NEGATE instead")]
+ pub const OP_PUSHNUM_NEG1: Opcode = OP_1NEGATE;
+ /// Push the array `0x01` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_1 instead")]
+ pub const OP_PUSHNUM_1: Opcode = OP_1;
+ /// Push the array `0x02` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_2 instead")]
+ pub const OP_PUSHNUM_2: Opcode = OP_2;
+ /// Push the array `0x03` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_3 instead")]
+ pub const OP_PUSHNUM_3: Opcode = OP_3;
+ /// Push the array `0x04` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_4 instead")]
+ pub const OP_PUSHNUM_4: Opcode = OP_4;
+ /// Push the array `0x05` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_5 instead")]
+ pub const OP_PUSHNUM_5: Opcode = OP_5;
+ /// Push the array `0x06` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_6 instead")]
+ pub const OP_PUSHNUM_6: Opcode = OP_6;
+ /// Push the array `0x07` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_7 instead")]
+ pub const OP_PUSHNUM_7: Opcode = OP_7;
+ /// Push the array `0x08` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_8 instead")]
+ pub const OP_PUSHNUM_8: Opcode = OP_8;
+ /// Push the array `0x09` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_9 instead")]
+ pub const OP_PUSHNUM_9: Opcode = OP_9;
+ /// Push the array `0x0a` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_10 instead")]
+ pub const OP_PUSHNUM_10: Opcode = OP_10;
+ /// Push the array `0x0b` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_11 instead")]
+ pub const OP_PUSHNUM_11: Opcode = OP_11;
+ /// Push the array `0x0c` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_12 instead")]
+ pub const OP_PUSHNUM_12: Opcode = OP_12;
+ /// Push the array `0x0d` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_13 instead")]
+ pub const OP_PUSHNUM_13: Opcode = OP_13;
+ /// Push the array `0x0e` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_14 instead")]
+ pub const OP_PUSHNUM_14: Opcode = OP_14;
+ /// Push the array `0x0f` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_15 instead")]
+ pub const OP_PUSHNUM_15: Opcode = OP_15;
+ /// Push the array `0x10` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_16 instead")]
+ pub const OP_PUSHNUM_16: Opcode = OP_16;
}
impl fmt::Display for Opcode {
@@ -152,24 +204,24 @@ all_opcodes! {
OP_PUSHDATA1 => 0x4c, "Read the next byte as N; push the next N bytes as an array onto the stack.";
OP_PUSHDATA2 => 0x4d, "Read the next 2 bytes as N; push the next N bytes as an array onto the stack.";
OP_PUSHDATA4 => 0x4e, "Read the next 4 bytes as N; push the next N bytes as an array onto the stack.";
- OP_PUSHNUM_NEG1 => 0x4f, "Push the array `0x81` onto the stack.";
+ OP_1NEGATE => 0x4f, "Push the array `0x81` onto the stack.";
OP_RESERVED => 0x50, "Synonym for `OP_RETURN`.";
- OP_PUSHNUM_1 => 0x51, "Push the array `0x01` onto the stack.";
- OP_PUSHNUM_2 => 0x52, "Push the array `0x02` onto the stack.";
- OP_PUSHNUM_3 => 0x53, "Push the array `0x03` onto the stack.";
- OP_PUSHNUM_4 => 0x54, "Push the array `0x04` onto the stack.";
- OP_PUSHNUM_5 => 0x55, "Push the array `0x05` onto the stack.";
- OP_PUSHNUM_6 => 0x56, "Push the array `0x06` onto the stack.";
- OP_PUSHNUM_7 => 0x57, "Push the array `0x07` onto the stack.";
- OP_PUSHNUM_8 => 0x58, "Push the array `0x08` onto the stack.";
- OP_PUSHNUM_9 => 0x59, "Push the array `0x09` onto the stack.";
- OP_PUSHNUM_10 => 0x5a, "Push the array `0x0a` onto the stack.";
- OP_PUSHNUM_11 => 0x5b, "Push the array `0x0b` onto the stack.";
- OP_PUSHNUM_12 => 0x5c, "Push the array `0x0c` onto the stack.";
- OP_PUSHNUM_13 => 0x5d, "Push the array `0x0d` onto the stack.";
- OP_PUSHNUM_14 => 0x5e, "Push the array `0x0e` onto the stack.";
- OP_PUSHNUM_15 => 0x5f, "Push the array `0x0f` onto the stack.";
- OP_PUSHNUM_16 => 0x60, "Push the array `0x10` onto the stack.";
+ OP_1 => 0x51, "Push the array `0x01` onto the stack.";
+ OP_2 => 0x52, "Push the array `0x02` onto the stack.";
+ OP_3 => 0x53, "Push the array `0x03` onto the stack.";
+ OP_4 => 0x54, "Push the array `0x04` onto the stack.";
+ OP_5 => 0x55, "Push the array `0x05` onto the stack.";
+ OP_6 => 0x56, "Push the array `0x06` onto the stack.";
+ OP_7 => 0x57, "Push the array `0x07` onto the stack.";
+ OP_8 => 0x58, "Push the array `0x08` onto the stack.";
+ OP_9 => 0x59, "Push the array `0x09` onto the stack.";
+ OP_10 => 0x5a, "Push the array `0x0a` onto the stack.";
+ OP_11 => 0x5b, "Push the array `0x0b` onto the stack.";
+ OP_12 => 0x5c, "Push the array `0x0c` onto the stack.";
+ OP_13 => 0x5d, "Push the array `0x0d` onto the stack.";
+ OP_14 => 0x5e, "Push the array `0x0e` onto the stack.";
+ OP_15 => 0x5f, "Push the array `0x0f` onto the stack.";
+ OP_16 => 0x60, "Push the array `0x10` onto the stack.";
OP_NOP => 0x61, "Does nothing.";
OP_VER => 0x62, "Synonym for `OP_RETURN`.";
OP_IF => 0x63, "Pop and execute the next statements if a nonzero element was popped.";
@@ -397,7 +449,7 @@ impl Opcode {
| (OP_CHECKMULTISIGVERIFY, ClassifyContext::TapScript) => Class::ReturnOp,
// 1 opcode of PushNum class
- (OP_PUSHNUM_NEG1, _) => Class::PushNum(-1),
+ (OP_1NEGATE, _) => Class::PushNum(-1),
// 16 opcodes of PushNum class
(op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code =>
@@ -719,24 +771,24 @@ mod tests {
roundtrip!(unique, OP_PUSHDATA1);
roundtrip!(unique, OP_PUSHDATA2);
roundtrip!(unique, OP_PUSHDATA4);
- roundtrip!(unique, OP_PUSHNUM_NEG1);
+ roundtrip!(unique, OP_1NEGATE);
roundtrip!(unique, OP_RESERVED);
- roundtrip!(unique, OP_PUSHNUM_1);
- roundtrip!(unique, OP_PUSHNUM_2);
- roundtrip!(unique, OP_PUSHNUM_3);
- roundtrip!(unique, OP_PUSHNUM_4);
- roundtrip!(unique, OP_PUSHNUM_5);
- roundtrip!(unique, OP_PUSHNUM_6);
- roundtrip!(unique, OP_PUSHNUM_7);
- roundtrip!(unique, OP_PUSHNUM_8);
- roundtrip!(unique, OP_PUSHNUM_9);
- roundtrip!(unique, OP_PUSHNUM_10);
- roundtrip!(unique, OP_PUSHNUM_11);
- roundtrip!(unique, OP_PUSHNUM_12);
- roundtrip!(unique, OP_PUSHNUM_13);
- roundtrip!(unique, OP_PUSHNUM_14);
- roundtrip!(unique, OP_PUSHNUM_15);
- roundtrip!(unique, OP_PUSHNUM_16);
+ roundtrip!(unique, OP_1);
+ roundtrip!(unique, OP_2);
+ roundtrip!(unique, OP_3);
+ roundtrip!(unique, OP_4);
+ roundtrip!(unique, OP_5);
+ roundtrip!(unique, OP_6);
+ roundtrip!(unique, OP_7);
+ roundtrip!(unique, OP_8);
+ roundtrip!(unique, OP_9);
+ roundtrip!(unique, OP_10);
+ roundtrip!(unique, OP_11);
+ roundtrip!(unique, OP_12);
+ roundtrip!(unique, OP_13);
+ roundtrip!(unique, OP_14);
+ roundtrip!(unique, OP_15);
+ roundtrip!(unique, OP_16);
roundtrip!(unique, OP_NOP);
roundtrip!(unique, OP_VER);
roundtrip!(unique, OP_IF);
diff --git a/bitcoin/tests/serde_opcodes.rs b/bitcoin/tests/serde_opcodes.rs
index cf84bfbc..a94d3f96 100644
--- a/bitcoin/tests/serde_opcodes.rs
+++ b/bitcoin/tests/serde_opcodes.rs
@@ -99,24 +99,24 @@ fn serde_regression_opcodes() {
OP_PUSHDATA1,
OP_PUSHDATA2,
OP_PUSHDATA4,
- OP_PUSHNUM_NEG1,
+ OP_1NEGATE,
OP_RESERVED,
- OP_PUSHNUM_1,
- OP_PUSHNUM_2,
- OP_PUSHNUM_3,
- OP_PUSHNUM_4,
- OP_PUSHNUM_5,
- OP_PUSHNUM_6,
- OP_PUSHNUM_7,
- OP_PUSHNUM_8,
- OP_PUSHNUM_9,
- OP_PUSHNUM_10,
- OP_PUSHNUM_11,
- OP_PUSHNUM_12,
- OP_PUSHNUM_13,
- OP_PUSHNUM_14,
- OP_PUSHNUM_15,
- OP_PUSHNUM_16,
+ OP_1,
+ OP_2,
+ OP_3,
+ OP_4,
+ OP_5,
+ OP_6,
+ OP_7,
+ OP_8,
+ OP_9,
+ OP_10,
+ OP_11,
+ OP_12,
+ OP_13,
+ OP_14,
+ OP_15,
+ OP_16,
OP_NOP,
OP_VER,
OP_IF,
diff --git a/primitives/src/opcodes.rs b/primitives/src/opcodes.rs
index 09a97f17..dc983dc5 100644
--- a/primitives/src/opcodes.rs
+++ b/primitives/src/opcodes.rs
@@ -60,6 +60,58 @@ macro_rules! all_opcodes {
pub const OP_NOP2: Opcode = OP_CLTV;
/// Previously called `OP_NOP3`.
pub const OP_NOP3: Opcode = OP_CSV;
+
+ /// Push the array `0x81` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_1NEGATE instead")]
+ pub const OP_PUSHNUM_NEG1: Opcode = OP_1NEGATE;
+ /// Push the array `0x01` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_1 instead")]
+ pub const OP_PUSHNUM_1: Opcode = OP_1;
+ /// Push the array `0x02` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_2 instead")]
+ pub const OP_PUSHNUM_2: Opcode = OP_2;
+ /// Push the array `0x03` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_3 instead")]
+ pub const OP_PUSHNUM_3: Opcode = OP_3;
+ /// Push the array `0x04` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_4 instead")]
+ pub const OP_PUSHNUM_4: Opcode = OP_4;
+ /// Push the array `0x05` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_5 instead")]
+ pub const OP_PUSHNUM_5: Opcode = OP_5;
+ /// Push the array `0x06` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_6 instead")]
+ pub const OP_PUSHNUM_6: Opcode = OP_6;
+ /// Push the array `0x07` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_7 instead")]
+ pub const OP_PUSHNUM_7: Opcode = OP_7;
+ /// Push the array `0x08` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_8 instead")]
+ pub const OP_PUSHNUM_8: Opcode = OP_8;
+ /// Push the array `0x09` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_9 instead")]
+ pub const OP_PUSHNUM_9: Opcode = OP_9;
+ /// Push the array `0x0a` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_10 instead")]
+ pub const OP_PUSHNUM_10: Opcode = OP_10;
+ /// Push the array `0x0b` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_11 instead")]
+ pub const OP_PUSHNUM_11: Opcode = OP_11;
+ /// Push the array `0x0c` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_12 instead")]
+ pub const OP_PUSHNUM_12: Opcode = OP_12;
+ /// Push the array `0x0d` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_13 instead")]
+ pub const OP_PUSHNUM_13: Opcode = OP_13;
+ /// Push the array `0x0e` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_14 instead")]
+ pub const OP_PUSHNUM_14: Opcode = OP_14;
+ /// Push the array `0x0f` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_15 instead")]
+ pub const OP_PUSHNUM_15: Opcode = OP_15;
+ /// Push the array `0x10` onto the stack.
+ #[deprecated(since = "TBD", note = "use OP_16 instead")]
+ pub const OP_PUSHNUM_16: Opcode = OP_16;
}
impl fmt::Display for Opcode {
@@ -154,24 +206,24 @@ all_opcodes! {
OP_PUSHDATA1 => 0x4c, "Read the next byte as N; push the next N bytes as an array onto the stack.";
OP_PUSHDATA2 => 0x4d, "Read the next 2 bytes as N; push the next N bytes as an array onto the stack.";
OP_PUSHDATA4 => 0x4e, "Read the next 4 bytes as N; push the next N bytes as an array onto the stack.";
- OP_PUSHNUM_NEG1 => 0x4f, "Push the array `0x81` onto the stack.";
+ OP_1NEGATE => 0x4f, "Push the array `0x81` onto the stack.";
OP_RESERVED => 0x50, "Synonym for `OP_RETURN`.";
- OP_PUSHNUM_1 => 0x51, "Push the array `0x01` onto the stack.";
- OP_PUSHNUM_2 => 0x52, "Push the array `0x02` onto the stack.";
- OP_PUSHNUM_3 => 0x53, "Push the array `0x03` onto the stack.";
- OP_PUSHNUM_4 => 0x54, "Push the array `0x04` onto the stack.";
- OP_PUSHNUM_5 => 0x55, "Push the array `0x05` onto the stack.";
- OP_PUSHNUM_6 => 0x56, "Push the array `0x06` onto the stack.";
- OP_PUSHNUM_7 => 0x57, "Push the array `0x07` onto the stack.";
- OP_PUSHNUM_8 => 0x58, "Push the array `0x08` onto the stack.";
- OP_PUSHNUM_9 => 0x59, "Push the array `0x09` onto the stack.";
- OP_PUSHNUM_10 => 0x5a, "Push the array `0x0a` onto the stack.";
- OP_PUSHNUM_11 => 0x5b, "Push the array `0x0b` onto the stack.";
- OP_PUSHNUM_12 => 0x5c, "Push the array `0x0c` onto the stack.";
- OP_PUSHNUM_13 => 0x5d, "Push the array `0x0d` onto the stack.";
- OP_PUSHNUM_14 => 0x5e, "Push the array `0x0e` onto the stack.";
- OP_PUSHNUM_15 => 0x5f, "Push the array `0x0f` onto the stack.";
- OP_PUSHNUM_16 => 0x60, "Push the array `0x10` onto the stack.";
+ OP_1 => 0x51, "Push the array `0x01` onto the stack.";
+ OP_2 => 0x52, "Push the array `0x02` onto the stack.";
+ OP_3 => 0x53, "Push the array `0x03` onto the stack.";
+ OP_4 => 0x54, "Push the array `0x04` onto the stack.";
+ OP_5 => 0x55, "Push the array `0x05` onto the stack.";
+ OP_6 => 0x56, "Push the array `0x06` onto the stack.";
+ OP_7 => 0x57, "Push the array `0x07` onto the stack.";
+ OP_8 => 0x58, "Push the array `0x08` onto the stack.";
+ OP_9 => 0x59, "Push the array `0x09` onto the stack.";
+ OP_10 => 0x5a, "Push the array `0x0a` onto the stack.";
+ OP_11 => 0x5b, "Push the array `0x0b` onto the stack.";
+ OP_12 => 0x5c, "Push the array `0x0c` onto the stack.";
+ OP_13 => 0x5d, "Push the array `0x0d` onto the stack.";
+ OP_14 => 0x5e, "Push the array `0x0e` onto the stack.";
+ OP_15 => 0x5f, "Push the array `0x0f` onto the stack.";
+ OP_16 => 0x60, "Push the array `0x10` onto the stack.";
OP_NOP => 0x61, "Does nothing.";
OP_VER => 0x62, "Synonym for `OP_RETURN`.";
OP_IF => 0x63, "Pop and execute the next statements if a nonzero element was popped.";
@@ -399,7 +451,7 @@ impl Opcode {
| (OP_CHECKMULTISIGVERIFY, ClassifyContext::TapScript) => Class::ReturnOp,
// 1 opcode of PushNum class
- (OP_PUSHNUM_NEG1, _) => Class::PushNum(-1),
+ (OP_1NEGATE, _) => Class::PushNum(-1),
// 16 opcodes of PushNum class
(op, _) if op.code >= OP_PUSHNUM_1.code && op.code <= OP_PUSHNUM_16.code =>
@@ -727,24 +779,24 @@ mod tests {
roundtrip!(unique, OP_PUSHDATA1);
roundtrip!(unique, OP_PUSHDATA2);
roundtrip!(unique, OP_PUSHDATA4);
- roundtrip!(unique, OP_PUSHNUM_NEG1);
+ roundtrip!(unique, OP_1NEGATE);
roundtrip!(unique, OP_RESERVED);
- roundtrip!(unique, OP_PUSHNUM_1);
- roundtrip!(unique, OP_PUSHNUM_2);
- roundtrip!(unique, OP_PUSHNUM_3);
- roundtrip!(unique, OP_PUSHNUM_4);
- roundtrip!(unique, OP_PUSHNUM_5);
- roundtrip!(unique, OP_PUSHNUM_6);
- roundtrip!(unique, OP_PUSHNUM_7);
- roundtrip!(unique, OP_PUSHNUM_8);
- roundtrip!(unique, OP_PUSHNUM_9);
- roundtrip!(unique, OP_PUSHNUM_10);
- roundtrip!(unique, OP_PUSHNUM_11);
- roundtrip!(unique, OP_PUSHNUM_12);
- roundtrip!(unique, OP_PUSHNUM_13);
- roundtrip!(unique, OP_PUSHNUM_14);
- roundtrip!(unique, OP_PUSHNUM_15);
- roundtrip!(unique, OP_PUSHNUM_16);
+ roundtrip!(unique, OP_1);
+ roundtrip!(unique, OP_2);
+ roundtrip!(unique, OP_3);
+ roundtrip!(unique, OP_4);
+ roundtrip!(unique, OP_5);
+ roundtrip!(unique, OP_6);
+ roundtrip!(unique, OP_7);
+ roundtrip!(unique, OP_8);
+ roundtrip!(unique, OP_9);
+ roundtrip!(unique, OP_10);
+ roundtrip!(unique, OP_11);
+ roundtrip!(unique, OP_12);
+ roundtrip!(unique, OP_13);
+ roundtrip!(unique, OP_14);
+ roundtrip!(unique, OP_15);
+ roundtrip!(unique, OP_16);
roundtrip!(unique, OP_NOP);
roundtrip!(unique, OP_VER);
roundtrip!(unique, OP_IF);
Why this scored 21/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.