From 9ec9adc71d3e292b08ec25e53597762796cbfde8 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Thu, 20 Feb 2025 17:59:12 +0100 Subject: [PATCH] Add a note about Electrum's script hashes The Electrum protocol uses hashes of `script_pubkey` that might look similar to the ones we have in the crate and could be confused. This change notes that to hopefully avoid the confusion. Resolves https://github.com/rust-bitcoin/rust-bitcoin/discussions/3997 --- primitives/src/script/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs index 6f90337a9..6e784e1bb 100644 --- a/primitives/src/script/mod.rs +++ b/primitives/src/script/mod.rs @@ -33,9 +33,18 @@ pub const MAX_REDEEM_SCRIPT_SIZE: usize = 520; pub const MAX_WITNESS_SCRIPT_SIZE: usize = 10_000; hashes::hash_newtype! { - /// A hash of Bitcoin Script bytecode. + /// A 160-bit hash of Bitcoin Script bytecode. + /// + /// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that + /// uses 256-bit hash and hashes a semantically different script. Thus, this type cannot + /// represent it. pub struct ScriptHash(hash160::Hash); - /// SegWit version of a Bitcoin Script bytecode hash. + + /// SegWit (256-bit) version of a Bitcoin Script bytecode hash. + /// + /// Note: there is another "script hash" object in bitcoin ecosystem (Electrum protocol) that + /// looks similar to this one also being SHA256, however, they hash semantically different + /// scripts and have reversed representations, so this type cannot be used for both. pub struct WScriptHash(sha256::Hash); }