diff --git a/src/main/scala/org/bitcoins/core/protocol/script/ScriptSignature.scala b/src/main/scala/org/bitcoins/core/protocol/script/ScriptSignature.scala index 72ff26d0c1..2e33cfcb74 100644 --- a/src/main/scala/org/bitcoins/core/protocol/script/ScriptSignature.scala +++ b/src/main/scala/org/bitcoins/core/protocol/script/ScriptSignature.scala @@ -190,6 +190,11 @@ object P2SHScriptSignature extends ScriptFactory[P2SHScriptSignature] { def fromAsm(asm: Seq[ScriptToken]): P2SHScriptSignature = { + //everything can be a P2SHScriptSignature, thus passing the trivially true function + //the most important thing to note is we cannot have a P2SHScriptSignature unless + //we have a P2SHScriptPubKey + //previously P2SHScriptSignature's redeem script had to be standard scriptPubKey's, this + //was removed in 0.11 or 0.12 of Bitcoin Core buildScript(asm, P2SHScriptSignatureImpl(_),{ _ => true}, "Given asm tokens are not a p2sh scriptSig, got: " + asm) } diff --git a/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala b/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala index 9a7e5d8fd7..cd37a20b77 100644 --- a/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala +++ b/src/main/scala/org/bitcoins/core/script/interpreter/ScriptInterpreter.scala @@ -112,7 +112,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con /** Helper function to actually run a p2sh script */ def run(p: ExecutedScriptProgram, stack : Seq[ScriptToken], s: ScriptPubKey): ExecutedScriptProgram = { - logger.info("Running p2sh script: " + stack) + logger.debug("Running p2sh script: " + stack) val p2shRedeemScriptProgram = ScriptProgram(p.txSignatureComponent,stack.tail, s.asm) if (ScriptFlagUtil.requirePushOnly(p2shRedeemScriptProgram.flags) && !BitcoinScriptUtil.isPushOnly(s.asm)) { @@ -202,7 +202,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con /** Helper function to run the post segwit execution checks */ def postSegWitProgramChecks(evaluated: ExecutedScriptProgram): ExecutedScriptProgram = { - logger.info("Stack after evaluating witness: " + evaluated.stack) + logger.debug("Stack after evaluating witness: " + evaluated.stack) if (evaluated.error.isDefined) evaluated else if (evaluated.stack.size != 1 || evaluated.stackTopIsFalse) ScriptProgram(evaluated,ScriptErrorEvalFalse) else evaluated @@ -497,8 +497,8 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con * Return true if witness was NOT used, return false if witness was used. */ private def hasUnexpectedWitness(program: ScriptProgram): Boolean = { val txSigComponent = program.txSignatureComponent - logger.info("TxSigComponent: " + txSigComponent) - val unexpectedWitenss = txSigComponent match { + logger.debug("TxSigComponent: " + txSigComponent) + val unexpectedWitness = txSigComponent match { case b : BaseTransactionSignatureComponent => b.transaction match { case wtx : WitnessTransaction => @@ -522,8 +522,8 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con !witnessedUsed } - if (unexpectedWitenss) logger.error("Found unexpected witness that was not used by the ScriptProgram: " + program) - unexpectedWitenss + if (unexpectedWitness) logger.error("Found unexpected witness that was not used by the ScriptProgram: " + program) + unexpectedWitness } } object ScriptInterpreter extends ScriptInterpreter \ No newline at end of file diff --git a/src/main/scala/org/bitcoins/core/serializers/transaction/RawTransactionWitnessParser.scala b/src/main/scala/org/bitcoins/core/serializers/transaction/RawTransactionWitnessParser.scala index 7328cf05e0..26a558870f 100644 --- a/src/main/scala/org/bitcoins/core/serializers/transaction/RawTransactionWitnessParser.scala +++ b/src/main/scala/org/bitcoins/core/serializers/transaction/RawTransactionWitnessParser.scala @@ -33,8 +33,6 @@ trait RawTransactionWitnessParser { val hex = witness.witnesses.map(_.hex).mkString hex } - - } object RawTransactionWitnessParser extends RawTransactionWitnessParser \ No newline at end of file diff --git a/src/main/scala/org/bitcoins/core/util/BitcoinScriptUtil.scala b/src/main/scala/org/bitcoins/core/util/BitcoinScriptUtil.scala index b5a09994e2..c85f917bec 100644 --- a/src/main/scala/org/bitcoins/core/util/BitcoinScriptUtil.scala +++ b/src/main/scala/org/bitcoins/core/util/BitcoinScriptUtil.scala @@ -276,9 +276,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger { def calculateScriptForChecking(txSignatureComponent: TransactionSignatureComponent, signature: ECDigitalSignature, script: Seq[ScriptToken]): Seq[ScriptToken] = { val scriptForChecking = calculateScriptForSigning(txSignatureComponent, script) - logger.info("sig for removal: " + signature) - logger.info("script: " + script) - logger.info("scriptWithSigRemoved: " + scriptForChecking) + logger.debug("sig for removal: " + signature) + logger.debug("script: " + script) + logger.debug("scriptWithSigRemoved: " + scriptForChecking) txSignatureComponent.sigVersion match { case SigVersionBase => removeSignatureFromScript(signature,scriptForChecking) case SigVersionWitnessV0 => @@ -351,7 +351,8 @@ trait BitcoinScriptUtil extends BitcoinSLogger { } /** Given a tx, scriptPubKey and the input index we are checking the tx, it derives the appropriate [[SignatureVersion]] to use */ - def parseSigVersion(tx: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32): SignatureVersion = scriptPubKey match { + @tailrec + final def parseSigVersion(tx: Transaction, scriptPubKey: ScriptPubKey, inputIndex: UInt32): SignatureVersion = scriptPubKey match { case _ : WitnessScriptPubKeyV0 | _: UnassignedWitnessScriptPubKey => SigVersionWitnessV0 case _: P2SHScriptPubKey => @@ -375,7 +376,9 @@ trait BitcoinScriptUtil extends BitcoinSLogger { def castToBool(token: ScriptToken): Boolean = { token.bytes.zipWithIndex.exists { case (b,index) => - b.toByte != 0 && !(b.toByte == 0x80.toByte && index == token.bytes.size - 1) + val byteNotZero = b.toByte != 0 + val lastByteNotNegativeZero = !(index == token.bytes.size - 1 && b.toByte == 0x80.toByte) + byteNotZero && lastByteNotNegativeZero } } } diff --git a/src/test/scala/org/bitcoins/core/script/ScriptProgramTest.scala b/src/test/scala/org/bitcoins/core/script/ScriptProgramTest.scala index a909415916..121aee9bc4 100644 --- a/src/test/scala/org/bitcoins/core/script/ScriptProgramTest.scala +++ b/src/test/scala/org/bitcoins/core/script/ScriptProgramTest.scala @@ -29,5 +29,4 @@ class ScriptProgramTest extends FlatSpec with MustMatchers { val program3 = ScriptProgram(program, List(ScriptNumber.negativeZero), ScriptProgram.Stack) program3.stackTopIsTrue must be (false) } - }