Merge rust-bitcoin/rust-bitcoin#2949: OP_RETURN standardness check

15f6bacec9 api: Run just check-api (Ryan Breen)
9684d496bb Add is_standard_op_return (Ryan Breen)

Pull request description:

  This is the suggestion for #2292 to check OP_RETURN length

ACKs for top commit:
  apoelstra:
    ACK 15f6bacec9

Tree-SHA512: e346b5eff7cc40b98a08948c83cb5c064184541d819c37a977e432ec09df7f9e1a074f16a4df598142784bd875f1379e2b0848fe898923e4e12829f85b4c4520
This commit is contained in:
merge-script 2024-07-02 19:17:54 +00:00
commit db72ea8b32
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
5 changed files with 30 additions and 1 deletions

View File

@ -8209,6 +8209,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

View File

@ -7831,6 +7831,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

View File

@ -7182,6 +7182,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

View File

@ -349,7 +349,10 @@ impl Script {
&& self.0[1] == OP_PUSHBYTES_32.to_u8()
}
/// Check if this is an OP_RETURN output.
/// Check if this is a consensus-valid OP_RETURN output.
///
/// To validate if the OP_RETURN obeys Bitcoin Core's current standardness policy, use
/// [`is_standard_op_return()`](Self::is_standard_op_return) instead.
#[inline]
pub fn is_op_return(&self) -> bool {
match self.0.first() {
@ -358,6 +361,15 @@ impl Script {
}
}
/// Check if this is an OP_RETURN that obeys Bitcoin Core standardness policy.
///
/// What this function considers to be standard may change without warning pending Bitcoin Core
/// changes.
#[inline]
pub fn is_standard_op_return(&self) -> bool {
self.is_op_return() && self.0.len() <= 80
}
/// Checks whether a script is trivially known to have no satisfying input.
///
/// This method has potentially confusing semantics and an unclear purpose, so it's going to be

View File

@ -406,6 +406,20 @@ fn op_return_test() {
assert!(!ScriptBuf::from_hex("").unwrap().is_op_return());
}
#[test]
fn standard_op_return_test() {
assert!(ScriptBuf::from_hex("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87")
.unwrap()
.is_standard_op_return());
assert!(ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e")
.unwrap()
.is_standard_op_return());
assert!(!ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e21")
.unwrap()
.is_standard_op_return());
}
#[test]
fn multisig() {
// First multisig? 1-of-2