From 466f161e0bb27a2d04a0b5321449b9916aa6afaa Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Thu, 18 Feb 2021 23:32:35 +0100 Subject: [PATCH] transaction: document why we mask sighash types with 0x9f Signed-off-by: Antoine Poinsot Co-Authored-by: sanket1729 --- src/blockdata/transaction.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index 27f61142..8448c991 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -675,7 +675,12 @@ impl SigHashType { /// Reads a 4-byte uint32 as a sighash type pub fn from_u32(n: u32) -> SigHashType { - match n & 0x9f { + // In Bitcoin Core, the SignatureHash function will mask the (int32) value with + // 0x1f to (apparently) deactivate ACP when checking for SINGLE and NONE bits. + // We however want to be matching also against on ACP-masked ALL, SINGLE, and NONE. + // So here we re-activate ACP. + let mask = 0x1f | 0x80; + match n & mask { // "real" sighashes 0x01 => SigHashType::All, 0x02 => SigHashType::None,