Fixing bug in serialization for p2sh signature

This commit is contained in:
Chris Stewart 2016-11-18 16:46:13 -06:00
parent a83b04e63b
commit eb2beb9b69
4 changed files with 11 additions and 8 deletions

View File

@ -80,7 +80,9 @@ trait TransactionSignatureChecker extends BitcoinSLogger {
}
val hashTypeByte = if (signature.bytes.nonEmpty) signature.bytes.last else 0x00.toByte
val hashType = HashType(Seq(0.toByte, 0.toByte, 0.toByte, hashTypeByte))
val hashForSignature = TransactionSignatureSerializer.hashForSignature(txSignatureComponent,hashType)
val hashForSignature = TransactionSignatureSerializer.hashForSignature(txSignatureComponent.transaction,
txSignatureComponent.inputIndex,
sigsRemovedScript, hashType)
logger.info("Hash for signature: " + BitcoinSUtil.encodeHex(hashForSignature.bytes))
val isValid = pubKey.verify(hashForSignature,signature)
if (isValid) SignatureValidationSuccess else SignatureValidationFailureIncorrectSignatures

View File

@ -330,8 +330,9 @@ object ScriptProgram {
/** Creates a fresh instance of [[org.bitcoins.core.script.PreExecutionScriptProgram]] */
def apply(transaction: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32, flags: Seq[ScriptFlag]): PreExecutionScriptProgram = {
val t = TransactionSignatureComponent(transaction,inputIndex,scriptPubKey, flags)
ScriptProgram(t)
val t = TransactionSignatureComponent(transaction,inputIndex,scriptPubKey,flags)
val script = t.scriptSignature.asm
PreExecutionScriptProgramImpl(t,Nil,script.toList,script.toList,Nil,t.flags)
}
/**

View File

@ -164,7 +164,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
else if (evaluated.stackTopIsFalse) ScriptProgram(evaluated,ScriptErrorEvalFalse)
else evaluated
case Right(err) =>
val program = ScriptProgram(witnessTxSigComponent)
val program = ScriptProgram.toExecutionInProgress(ScriptProgram(witnessTxSigComponent))
ScriptProgram(program,err)
}
case UnassignedWitness =>

View File

@ -28,7 +28,7 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
//use this to represent a single test case from script_valid.json
val lines =
/* val lines =
"""
| [ [
[
@ -42,8 +42,8 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
"OK",
"Basic P2WSH"
]]
""".stripMargin
//val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
""".stripMargin*/
val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
val json = lines.parseJson
val testCasesOpt : Seq[Option[CoreTestCase]] = json.convertTo[Seq[Option[CoreTestCase]]]
val testCases : Seq[CoreTestCase] = testCasesOpt.flatten