Add crate private opcode and other constants
What changed, and why it matters
This commit simply copies a few internal Bitcoin script constants (specific byte values used in transaction scripts) into a lower-level crate module. It does not change any public behavior, fix a bug, or alter how data is validated. There is no security relevance visible in the change itself.
No security action needed. Review as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds crate-private pub(crate) constants: OP_PUSHBYTES_2, OP_PUSHBYTES_20, OP_PUSHBYTES_32 in primitives/src/opcodes.rs, and P2A_PROGRAM in primitives/src/script/mod.rs. These are gated behind the alloc feature where appropriate and are not exposed publicly. The commit message frames this as a code-organization step to make values available in primitives that currently live elsewhere.
Changed components
primitives/src/opcodes.rsprimitives/src/script/mod.rsInspect captured patch +15 / −0
diff --git a/primitives/src/opcodes.rs b/primitives/src/opcodes.rs
index d4d8be09..1c94a080 100644
--- a/primitives/src/opcodes.rs
+++ b/primitives/src/opcodes.rs
@@ -166,6 +166,18 @@ pub(crate) const OP_PUSHDATA4: u8 = 0x4e;
/// Push an empty array onto the stack.
pub(crate) const OP_PUSHBYTES_0: Opcode = Opcode::from_u8(0x00);
+/// Push the next 2 bytes as an array onto the stack.
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHBYTES_2: Opcode = Opcode::from_u8(0x02);
+
+/// Push the next 20 bytes as an array onto the stack.
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHBYTES_20: Opcode = Opcode::from_u8(0x14);
+
+/// Push the next 32 bytes as an array onto the stack.
+#[cfg(feature = "alloc")]
+pub(crate) const OP_PUSHBYTES_32: Opcode = Opcode::from_u8(0x20);
+
/// Format a byte as a script opcode.
#[cfg(feature = "alloc")]
pub(crate) fn fmt_opcode(op: u8, f: &mut fmt::Formatter) -> fmt::Result {
diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs
index b71692d7..cb9f4f0a 100644
--- a/primitives/src/script/mod.rs
+++ b/primitives/src/script/mod.rs
@@ -90,6 +90,9 @@ pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520;
/// The maximum allowed redeem script size of the witness script.
pub const MAX_WITNESS_SCRIPT_SIZE: usize = 10_000;
+/// The P2A program which is given by 0x4e73.
+pub(crate) const P2A_PROGRAM: [u8; 2] = [78, 115];
+
/// Generates P2WSH-type of scriptPubkey with a given [`WitnessVersion`] and the program bytes.
/// Does not do any checks on version or program length.
///
Why this scored 15/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.