Skip to content

Commit db72ea8

Browse files
committed
Merge rust-bitcoin#2949: OP_RETURN standardness check
15f6bac api: Run just check-api (Ryan Breen) 9684d49 Add is_standard_op_return (Ryan Breen) Pull request description: This is the suggestion for rust-bitcoin#2292 to check OP_RETURN length ACKs for top commit: apoelstra: ACK 15f6bac Tree-SHA512: e346b5eff7cc40b98a08948c83cb5c064184541d819c37a977e432ec09df7f9e1a074f16a4df598142784bd875f1379e2b0848fe898923e4e12829f85b4c4520
2 parents e1b357c + 15f6bac commit db72ea8

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

api/bitcoin/all-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8209,6 +8209,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
82098209
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
82108210
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
82118211
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
8212+
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
82128213
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
82138214
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
82148215
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

api/bitcoin/default-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7831,6 +7831,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
78317831
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
78327832
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
78337833
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
7834+
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
78347835
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
78357836
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
78367837
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

api/bitcoin/no-features.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7182,6 +7182,7 @@ pub fn bitcoin::blockdata::script::Script::is_p2wpkh(&self) -> bool
71827182
pub fn bitcoin::blockdata::script::Script::is_p2wsh(&self) -> bool
71837183
pub fn bitcoin::blockdata::script::Script::is_provably_unspendable(&self) -> bool
71847184
pub fn bitcoin::blockdata::script::Script::is_push_only(&self) -> bool
7185+
pub fn bitcoin::blockdata::script::Script::is_standard_op_return(&self) -> bool
71857186
pub fn bitcoin::blockdata::script::Script::is_witness_program(&self) -> bool
71867187
pub fn bitcoin::blockdata::script::Script::len(&self) -> usize
71877188
pub fn bitcoin::blockdata::script::Script::minimal_non_dust(&self) -> bitcoin_units::amount::Amount

bitcoin/src/blockdata/script/borrowed.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,10 @@ impl Script {
349349
&& self.0[1] == OP_PUSHBYTES_32.to_u8()
350350
}
351351

352-
/// Check if this is an OP_RETURN output.
352+
/// Check if this is a consensus-valid OP_RETURN output.
353+
///
354+
/// To validate if the OP_RETURN obeys Bitcoin Core's current standardness policy, use
355+
/// [`is_standard_op_return()`](Self::is_standard_op_return) instead.
353356
#[inline]
354357
pub fn is_op_return(&self) -> bool {
355358
match self.0.first() {
@@ -358,6 +361,15 @@ impl Script {
358361
}
359362
}
360363

364+
/// Check if this is an OP_RETURN that obeys Bitcoin Core standardness policy.
365+
///
366+
/// What this function considers to be standard may change without warning pending Bitcoin Core
367+
/// changes.
368+
#[inline]
369+
pub fn is_standard_op_return(&self) -> bool {
370+
self.is_op_return() && self.0.len() <= 80
371+
}
372+
361373
/// Checks whether a script is trivially known to have no satisfying input.
362374
///
363375
/// This method has potentially confusing semantics and an unclear purpose, so it's going to be

bitcoin/src/blockdata/script/tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,20 @@ fn op_return_test() {
406406
assert!(!ScriptBuf::from_hex("").unwrap().is_op_return());
407407
}
408408

409+
#[test]
410+
fn standard_op_return_test() {
411+
assert!(ScriptBuf::from_hex("6aa9149eb21980dc9d413d8eac27314938b9da920ee53e87")
412+
.unwrap()
413+
.is_standard_op_return());
414+
assert!(ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e")
415+
.unwrap()
416+
.is_standard_op_return());
417+
418+
assert!(!ScriptBuf::from_hex("6a48656c6c6f2c2074686973206973206d7920666972737420636f6e747269627574696f6e20746f207275737420626974636f696e2e20506c6561736520617070726f7665206d79205052206672656e21")
419+
.unwrap()
420+
.is_standard_op_return());
421+
}
422+
409423
#[test]
410424
fn multisig() {
411425
// First multisig? 1-of-2

0 commit comments

Comments
 (0)