Implementing generator for p2sh(p2wsh) transactions

This commit is contained in:
Chris Stewart 2016-12-13 13:31:15 -06:00
parent 202c5df832
commit b542961ed9
3 changed files with 8 additions and 3 deletions

View File

@ -140,7 +140,6 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
val redeemScript = ScriptPubKey(c.bytes ++ redeemScriptBytes)
redeemScript match {
case w : WitnessScriptPubKey =>
logger.error("Witness scriptPubKey")
val pushOp = BitcoinScriptUtil.calculatePushOp(redeemScriptBytes)
val expectedScriptBytes = pushOp.flatMap(_.bytes) ++ redeemScriptBytes
val flags = scriptPubKeyExecutedProgram.flags
@ -148,7 +147,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
if (segwitEnabled && (scriptSig.asmBytes == expectedScriptBytes)) {
// The scriptSig must be _exactly_ a single push of the redeemScript. Otherwise we
// reintroduce malleability.
logger.error("redeem script was witness script pubkey, segwit was enabled, scriptSig was single push of redeemScript")
logger.info("redeem script was witness script pubkey, segwit was enabled, scriptSig was single push of redeemScript")
executeSegWitScript(scriptPubKeyExecutedProgram,w)
} else if (segwitEnabled && (scriptSig.asmBytes != expectedScriptBytes)) {
logger.error("Segwit was enabled, but p2sh redeem script was malleated")

View File

@ -130,4 +130,11 @@ class TransactionSignatureCreatorSpec extends Properties("TransactionSignatureCr
result == ScriptOk
}
property("generate a valid signature from a p2sh(p2wsh) witness tranasction") =
Prop.forAllNoShrink(TransactionGenerators.signedP2SHP2WSHTransaction) { case (wtxSigComponent, privKeys) =>
val program = ScriptProgram(wtxSigComponent)
val result = ScriptInterpreter.run(program)
if (result != ScriptOk) logger.warn("Result: " + result)
result == ScriptOk
}
}

View File

@ -144,5 +144,4 @@ class TransactionSignatureCreatorTest extends FlatSpec with MustMatchers with Bi
result must be (ScriptOk)
}
}