fix(script): account for data pushing opcodes in `is_standard_op_return`

While I believe the original commit used 80 bytes for the entire script as the limit,
Bitcoin Core as of [this commit](7a172c76d2/src/policy/policy.h)
will relay OP_RETURN outputs as long as the data itself is not above 80 bytes, meaning a script of maximum size 83 bytes should be standard.
This commit is contained in:
Rob N 2024-11-19 12:42:55 -10:00
parent c47a41a076
commit e0442782c8
No known key found for this signature in database
GPG Key ID: F4DD8F8486EC0F1F
3 changed files with 9 additions and 4 deletions

View File

@ -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.
///

View File

@ -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());
}

View File

@ -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)