mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 13:25:49 +01:00
Fix hashtype check to correctly handle scala's conversion (#4487)
This commit is contained in:
parent
91a1c84a6f
commit
db63b286b3
2 changed files with 28 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue