What changed, and why it matters
This change is purely a code organization cleanup. It moves a handful of Bitcoin script opcode aliases (like OP_0, OP_TRUE, OP_NOP2) from outside a module into the 'all' submodule so that a wildcard import picks them up. No behavior of the library changes, and there is no security fix or vulnerability here.
No security action needed. Treat as a normal refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit relocates opcode alias constants (OP_0, OP_FALSE, OP_TRUE, OP_NOP2, OP_NOP3) inside the all_opcodes! macro’s generated all module in both bitcoin/src/blockdata/opcodes.rs and primitives/src/opcodes.rs. Existing call sites in tests are updated from opcodes::OP_NOP3 to opcodes::all::OP_NOP3 and bitcoin::opcodes::OP_0 to bitcoin::opcodes::all::OP_0. This is an API ergonomics change, not a functional or security patch.
Changed components
bitcoin/src/blockdata/opcodes.rsprimitives/src/opcodes.rsInspect captured patch +25 / −25
diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs
index 8cd6e417..e00e4098 100644
--- a/bitcoin/src/blockdata/opcodes.rs
+++ b/bitcoin/src/blockdata/opcodes.rs
@@ -47,18 +47,18 @@ macro_rules! all_opcodes {
#[doc = $doc]
pub const $op: Opcode = Opcode { code: $val};
)*
- }
- /// Push an empty array onto the stack.
- pub const OP_0: Opcode = OP_PUSHBYTES_0;
- /// Empty stack is also FALSE.
- pub const OP_FALSE: Opcode = OP_PUSHBYTES_0;
- /// Number 1 is also TRUE.
- pub const OP_TRUE: Opcode = OP_PUSHNUM_1;
- /// Previously called OP_NOP2.
- pub const OP_NOP2: Opcode = OP_CLTV;
- /// Previously called OP_NOP3.
- pub const OP_NOP3: Opcode = OP_CSV;
+ /// Push an empty array onto the stack.
+ pub const OP_0: Opcode = OP_PUSHBYTES_0;
+ /// Empty stack is also FALSE.
+ pub const OP_FALSE: Opcode = OP_PUSHBYTES_0;
+ /// Number 1 is also TRUE.
+ pub const OP_TRUE: Opcode = OP_PUSHNUM_1;
+ /// Previously called OP_NOP2.
+ pub const OP_NOP2: Opcode = OP_CLTV;
+ /// Previously called OP_NOP3.
+ pub const OP_NOP3: Opcode = OP_CSV;
+ }
impl fmt::Display for Opcode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
diff --git a/bitcoin/src/blockdata/script/tests.rs b/bitcoin/src/blockdata/script/tests.rs
index 16ae1729..67cf18b3 100644
--- a/bitcoin/src/blockdata/script/tests.rs
+++ b/bitcoin/src/blockdata/script/tests.rs
@@ -747,7 +747,7 @@ fn iterator() {
assert_eq!(
v_min,
- vec![(0, Instruction::PushBytes([105].as_ref())), (2, Instruction::Op(opcodes::OP_NOP3))]
+ vec![(0, Instruction::PushBytes([105].as_ref())), (2, Instruction::Op(opcodes::all::OP_NOP3))]
);
assert_eq!(v_nonmin.unwrap_err(), Error::NonMinimalPush);
@@ -756,7 +756,7 @@ fn iterator() {
v_nonmin_alt,
vec![
(0, Instruction::PushBytes([105, 0].as_ref())),
- (3, Instruction::Op(opcodes::OP_NOP3))
+ (3, Instruction::Op(opcodes::all::OP_NOP3))
]
);
diff --git a/bitcoin/tests/bip_174.rs b/bitcoin/tests/bip_174.rs
index 7b1bab9a..124e58d7 100644
--- a/bitcoin/tests/bip_174.rs
+++ b/bitcoin/tests/bip_174.rs
@@ -7,7 +7,7 @@ use bitcoin::amount::{Amount, Denomination};
use bitcoin::bip32::{Fingerprint, IntoDerivationPath, KeySource, Xpriv, Xpub};
use bitcoin::consensus::encode::{deserialize, serialize_hex};
use bitcoin::hex::FromHex;
-use bitcoin::opcodes::OP_0;
+use bitcoin::opcodes::all::OP_0;
use bitcoin::psbt::{Psbt, PsbtSighashType};
use bitcoin::script::{PushBytes, ScriptBuf, ScriptBufExt as _};
use bitcoin::secp256k1::Secp256k1;
diff --git a/primitives/src/opcodes.rs b/primitives/src/opcodes.rs
index d1b77c0d..80d595cc 100644
--- a/primitives/src/opcodes.rs
+++ b/primitives/src/opcodes.rs
@@ -49,18 +49,18 @@ macro_rules! all_opcodes {
#[doc = $doc]
pub const $op: Opcode = Opcode { code: $val};
)*
- }
- /// Push an empty array onto the stack.
- pub const OP_0: Opcode = OP_PUSHBYTES_0;
- /// Empty stack is also `FALSE`.
- pub const OP_FALSE: Opcode = OP_PUSHBYTES_0;
- /// Number 1 is also TRUE.
- pub const OP_TRUE: Opcode = OP_PUSHNUM_1;
- /// Previously called `OP_NOP2`.
- pub const OP_NOP2: Opcode = OP_CLTV;
- /// Previously called `OP_NOP3`.
- pub const OP_NOP3: Opcode = OP_CSV;
+ /// Push an empty array onto the stack.
+ pub const OP_0: Opcode = OP_PUSHBYTES_0;
+ /// Empty stack is also `FALSE`.
+ pub const OP_FALSE: Opcode = OP_PUSHBYTES_0;
+ /// Number 1 is also TRUE.
+ pub const OP_TRUE: Opcode = OP_PUSHNUM_1;
+ /// Previously called `OP_NOP2`.
+ pub const OP_NOP2: Opcode = OP_CLTV;
+ /// Previously called `OP_NOP3`.
+ pub const OP_NOP3: Opcode = OP_CSV;
+ }
impl fmt::Display for Opcode {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
Why this scored 20/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.