Fix hashtype check to correctly handle scala's conversion (#4487)

This commit is contained in:
benthecarman 2022-07-11 06:40:40 -05:00 committed by GitHub
parent 91a1c84a6f
commit db63b286b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 13 deletions

View file

@ -94,10 +94,8 @@ trait TransactionSignatureChecker {
)
//bip341 restricts valid hash types: https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#common-signature-message
val invalidHashType = {
!(hashType.byte <= 0x03.toByte || (hashType.byte >= 0x81.toByte && hashType.byte <= 0x83.toByte))
}
if (invalidHashType) {
val validHashType = checkTaprootHashType(hashType)
if (!validHashType) {
ScriptErrorSchnorrSigHashType
} else {
val hash =
@ -109,6 +107,19 @@ trait TransactionSignatureChecker {
}
}
// (hash_type <= 0x03 || (hash_type >= 0x81 && hash_type <= 0x83))
private val validTaprootHashTypes: Vector[Byte] = Vector(0x00.toByte,
0x01.toByte,
0x02.toByte,
0x03.toByte,
0x81.toByte,
0x82.toByte,
0x83.toByte)
def checkTaprootHashType(hashType: HashType): Boolean = {
validTaprootHashTypes.contains(hashType.byte)
}
/** Checks the signature of a scriptSig in the spending transaction against the
* given scriptPubKey & explicitly given public key
* This is useful for instances of non standard scriptSigs

View file

@ -231,15 +231,19 @@ sealed abstract class CryptoInterpreter {
}
helperE match {
case Right(helper) =>
val result = TransactionSignatureChecker.checkSigTapscript(
txSignatureComponent = program.txSignatureComponent,
pubKey = helper.pubKey.schnorrPublicKey,
signature = helper.signature,
hashType = helper.hashType,
taprootOptions = program.taprootSerializationOptions,
flags = program.flags
)
Right(result)
val validHashType =
TransactionSignatureChecker.checkTaprootHashType(helper.hashType)
if (validHashType) {
val result = TransactionSignatureChecker.checkSigTapscript(
txSignatureComponent = program.txSignatureComponent,
pubKey = helper.pubKey.schnorrPublicKey,
signature = helper.signature,
hashType = helper.hashType,
taprootOptions = program.taprootSerializationOptions,
flags = program.flags
)
Right(result)
} else Left(ScriptErrorSchnorrSigHashType)
case Left(err) => Left(err)
}
}