From ce55dd5b700f906c56717ea5157e59822e2520ea Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 20 Feb 2025 18:10:53 +0100 Subject: [PATCH] Make `ScriptHash` & `WScriptHash` obey sanity rule These were re-implementing hashing after the check rather than calling the `_unchecked` method, so this replaces the manual implementation with the method. --- primitives/src/script/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs index 6e784e1bb..4e698da25 100644 --- a/primitives/src/script/mod.rs +++ b/primitives/src/script/mod.rs @@ -69,7 +69,8 @@ impl ScriptHash { return Err(RedeemScriptSizeError { size: redeem_script.len() }); } - Ok(ScriptHash(hash160::Hash::hash(redeem_script.as_bytes()))) + // We've just checked the length + Ok(ScriptHash::from_script_unchecked(redeem_script)) } /// Constructs a new `ScriptHash` from any script irrespective of script size. @@ -99,7 +100,8 @@ impl WScriptHash { return Err(WitnessScriptSizeError { size: witness_script.len() }); } - Ok(WScriptHash(sha256::Hash::hash(witness_script.as_bytes()))) + // We've just checked the length + Ok(WScriptHash::from_script_unchecked(witness_script)) } /// Constructs a new `WScriptHash` from any script irrespective of script size.