transaction: document why we mask sighash types with 0x9f

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Co-Authored-by: sanket1729 <sanket1729@gmail.com>
This commit is contained in:
Antoine Poinsot 2021-02-18 23:32:35 +01:00
parent 7f73d5f7db
commit 466f161e0b
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
1 changed files with 6 additions and 1 deletions

View File

@ -675,7 +675,12 @@ impl SigHashType {
/// Reads a 4-byte uint32 as a sighash type /// Reads a 4-byte uint32 as a sighash type
pub fn from_u32(n: u32) -> SigHashType { 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 // "real" sighashes
0x01 => SigHashType::All, 0x01 => SigHashType::All,
0x02 => SigHashType::None, 0x02 => SigHashType::None,