diff --git a/src/script/sighashtype.h b/src/script/sighashtype.h --- a/src/script/sighashtype.h +++ b/src/script/sighashtype.h @@ -20,7 +20,7 @@ }; /** - * Base signature hash types + * Base signature hash types nominally range from 0x00 to 0x1f. * Base sig hash types not defined in this enum may be used, but they will be * represented as UNSUPPORTED. See transaction * c99c49da4c38af669dea436d3e73780dfdb6c1ecf9958baa52960e8baee30e73 for an @@ -67,11 +67,17 @@ uint32_t getForkValue() const { return sigHash >> 8; } + // Checks whether baseType has supported value AND bit 0x20 is unset, i.e, + // make sure that (sigHash&0x3f) is either ALL, SINGLE, or NONE. bool isDefined() const { - auto baseType = + // While BaseSigHashType normally ranges from 0x00 to 0x1f, here + // lowBits ranges from 0x00 to 0x3f due to the narrowing conversion + // (BaseSigHashType is uint8_t, implicitly clipping forkID) and + // omission of bit 0x20 from the mask. + auto lowBits = BaseSigHashType(sigHash & ~(SIGHASH_FORKID | SIGHASH_ANYONECANPAY)); - return baseType >= BaseSigHashType::ALL && - baseType <= BaseSigHashType::SINGLE; + return lowBits >= BaseSigHashType::ALL && + lowBits <= BaseSigHashType::SINGLE; } bool hasForkId() const { return (sigHash & SIGHASH_FORKID) != 0; }