From 83bce905a1b359c595999907fd856e16863009b3 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Mon, 2 May 2016 14:16:04 -0500 Subject: [PATCH] Fixing a couple bugs in setting ScriptUnknownError instead of ScriptErrorMinimalData --- .../bitcoins/script/arithmetic/ArithmeticInterpreter.scala | 6 +++--- .../org/bitcoins/script/crypto/CryptoInterpreter.scala | 4 ++-- .../scala/org/bitcoins/script/stack/StackInterpreter.scala | 2 +- .../script/arithmetic/ArithmeticInterpreterTest.scala | 2 +- .../org/bitcoins/script/stack/StackInterpreterTest.scala | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreter.scala b/src/main/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreter.scala index ca1872bac0..431c0dd121 100644 --- a/src/main/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreter.scala +++ b/src/main/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreter.scala @@ -281,7 +281,7 @@ trait ArithmeticInterpreter extends ControlOperationsInterpreter { !BitcoinScriptUtil.isShortestEncoding(b) || !BitcoinScriptUtil.isShortestEncoding(a))) { logger.error("The constant you gave us is not encoded in the shortest way possible") - ScriptProgram(program, ScriptErrorMinimalData) + ScriptProgram(program, ScriptErrorUnknownError) } else if (isLargerThan4Bytes(c) || isLargerThan4Bytes(b) || isLargerThan4Bytes(a)) { //pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here //https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002 @@ -369,7 +369,7 @@ trait ArithmeticInterpreter extends ControlOperationsInterpreter { case (x : ScriptNumber, y : ScriptNumber) => if (ScriptFlagUtil.requireMinimalData(program.flags) && (!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(y))) { logger.error("The constant you gave us is not encoded in the shortest way possible") - ScriptProgram(program, ScriptErrorMinimalData) + ScriptProgram(program, ScriptErrorUnknownError) } else if (isLargerThan4Bytes(x) || isLargerThan4Bytes(y)) { //pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here //https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002 @@ -420,7 +420,7 @@ trait ArithmeticInterpreter extends ControlOperationsInterpreter { if (ScriptFlagUtil.requireMinimalData(program.flags) && (!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(y))) { logger.error("The constant you gave us is not encoded in the shortest way possible") - ScriptProgram(program, ScriptErrorMinimalData) + ScriptProgram(program, ScriptErrorUnknownError) } else if (isLargerThan4Bytes(x) || isLargerThan4Bytes(y)) { //pretty sure that an error is thrown inside of CScriptNum which in turn is caught by interpreter.cpp here //https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002 diff --git a/src/main/scala/org/bitcoins/script/crypto/CryptoInterpreter.scala b/src/main/scala/org/bitcoins/script/crypto/CryptoInterpreter.scala index 93dc56c6c1..cc3a7be4b2 100644 --- a/src/main/scala/org/bitcoins/script/crypto/CryptoInterpreter.scala +++ b/src/main/scala/org/bitcoins/script/crypto/CryptoInterpreter.scala @@ -170,7 +170,7 @@ trait CryptoInterpreter extends ControlOperationsInterpreter with BitcoinSLogger ScriptProgram(program,ScriptErrorPubKeyCount) } else if (ScriptFlagUtil.requireMinimalData(program.flags) && !nPossibleSignatures.isShortestEncoding) { logger.error("The required signatures and the possible signatures must be encoded as the shortest number possible") - ScriptProgram(program, ScriptErrorMinimalData) + ScriptProgram(program, ScriptErrorUnknownError) } else if (program.stack.size < 2) { logger.error("We need at least 2 operations on the stack") ScriptProgram(program,ScriptErrorInvalidStackOperation) @@ -179,7 +179,7 @@ trait CryptoInterpreter extends ControlOperationsInterpreter with BitcoinSLogger if (ScriptFlagUtil.requireMinimalData(program.flags) && !mRequiredSignatures.isShortestEncoding) { logger.error("The required signatures val must be the shortest encoding as possible") - return ScriptProgram(program,ScriptErrorMinimalData) + return ScriptProgram(program,ScriptErrorUnknownError) } if (mRequiredSignatures < ScriptNumber.zero) { diff --git a/src/main/scala/org/bitcoins/script/stack/StackInterpreter.scala b/src/main/scala/org/bitcoins/script/stack/StackInterpreter.scala index 7346bfcc5c..2aee8410d5 100644 --- a/src/main/scala/org/bitcoins/script/stack/StackInterpreter.scala +++ b/src/main/scala/org/bitcoins/script/stack/StackInterpreter.scala @@ -381,7 +381,7 @@ trait StackInterpreter extends BitcoinSLogger { case Success(n) => op(n) case Failure(_) => logger.error("Script number was not minimally encoded") - ScriptProgram(program,ScriptErrorMinimalData) + ScriptProgram(program,ScriptErrorUnknownError) } } diff --git a/src/test/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreterTest.scala b/src/test/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreterTest.scala index f1a806f1e1..b76401ca55 100644 --- a/src/test/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreterTest.scala +++ b/src/test/scala/org/bitcoins/script/arithmetic/ArithmeticInterpreterTest.scala @@ -478,7 +478,7 @@ class ArithmeticInterpreterTest extends FlatSpec with MustMatchers with Arithmet val program = ScriptProgram(TestUtil.testProgramExecutionInProgress, stack,script) val newProgram = opWithin(program) newProgram.isInstanceOf[ExecutedScriptProgram] must be (true) - newProgram.asInstanceOf[ExecutedScriptProgram].error must be (Some(ScriptErrorMinimalData)) + newProgram.asInstanceOf[ExecutedScriptProgram].error must be (Some(ScriptErrorUnknownError)) } it must "mark the script as invalid for OP_WITHIN if one of the numbers is larger than 4 bytes" in { diff --git a/src/test/scala/org/bitcoins/script/stack/StackInterpreterTest.scala b/src/test/scala/org/bitcoins/script/stack/StackInterpreterTest.scala index 5cb3c50f73..35d4a83865 100644 --- a/src/test/scala/org/bitcoins/script/stack/StackInterpreterTest.scala +++ b/src/test/scala/org/bitcoins/script/stack/StackInterpreterTest.scala @@ -214,7 +214,7 @@ class StackInterpreterTest extends FlatSpec with MustMatchers with StackInterpre val newProgram = opRoll(program) newProgram.isInstanceOf[ExecutedScriptProgram] must be (true) - newProgram.asInstanceOf[ExecutedScriptProgram].error must be (Some(ScriptErrorMinimalData)) + newProgram.asInstanceOf[ExecutedScriptProgram].error must be (Some(ScriptErrorUnknownError)) } it must "evaluate an OP_ROT correctly" in {