diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs index e1fe91b78..a922d7313 100644 --- a/bitcoin/src/blockdata/script/borrowed.rs +++ b/bitcoin/src/blockdata/script/borrowed.rs @@ -12,7 +12,7 @@ use super::{ use crate::consensus::Encodable; use crate::opcodes::all::*; use crate::opcodes::{self, Opcode}; -use crate::policy::DUST_RELAY_TX_FEE; +use crate::policy::{DUST_RELAY_TX_FEE, MAX_OP_RETURN_RELAY}; use crate::prelude::{sink, DisplayHex, String, ToString}; use crate::taproot::{LeafVersion, TapLeafHash, TapLeafHashExt as _}; use crate::FeeRate; @@ -217,7 +217,7 @@ crate::internal_macros::define_extension_trait! { /// What this function considers to be standard may change without warning pending Bitcoin Core /// changes. #[inline] - fn is_standard_op_return(&self) -> bool { self.is_op_return() && self.len() <= 80 } + fn is_standard_op_return(&self) -> bool { self.is_op_return() && self.len() <= MAX_OP_RETURN_RELAY } /// Checks whether a script is trivially known to have no satisfying input. /// diff --git a/bitcoin/src/blockdata/script/tests.rs b/bitcoin/src/blockdata/script/tests.rs index 5a3409af6..7010bb19b 100644 --- a/bitcoin/src/blockdata/script/tests.rs +++ b/bitcoin/src/blockdata/script/tests.rs @@ -416,8 +416,10 @@ fn standard_op_return() { assert!(ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e") .unwrap() .is_standard_op_return()); - - assert!(!ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e21") + assert!(ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e21") + .unwrap() + .is_standard_op_return()); + assert!(!ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e21524f42") .unwrap() .is_standard_op_return()); } diff --git a/bitcoin/src/policy.rs b/bitcoin/src/policy.rs index 35c2dda8b..89eb08261 100644 --- a/bitcoin/src/policy.rs +++ b/bitcoin/src/policy.rs @@ -43,6 +43,9 @@ pub const DEFAULT_MIN_RELAY_TX_FEE: u32 = 1_000; /// mempools. pub const DEFAULT_MEMPOOL_EXPIRY: u32 = 336; +// 80 bytes of data, +1 for OP_RETURN, +2 for the pushdata opcodes. +pub(crate) const MAX_OP_RETURN_RELAY: usize = 83; + /// The virtual transaction size, as computed by default by bitcoind node. pub fn get_virtual_tx_size(weight: i64, n_sigops: i64) -> i64 { (cmp::max(weight, n_sigops * DEFAULT_BYTES_PER_SIGOP as i64) + WITNESS_SCALE_FACTOR as i64 - 1)