mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-25 07:17:32 +01:00
Fixing a couple bugs in setting ScriptUnknownError instead of ScriptErrorMinimalData
This commit is contained in:
parent
01b9aaf077
commit
83bce905a1
5 changed files with 8 additions and 8 deletions
|
@ -281,7 +281,7 @@ trait ArithmeticInterpreter extends ControlOperationsInterpreter {
|
||||||
!BitcoinScriptUtil.isShortestEncoding(b) || !BitcoinScriptUtil.isShortestEncoding(a))) {
|
!BitcoinScriptUtil.isShortestEncoding(b) || !BitcoinScriptUtil.isShortestEncoding(a))) {
|
||||||
|
|
||||||
logger.error("The constant you gave us is not encoded in the shortest way possible")
|
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)) {
|
} 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
|
//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
|
//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) =>
|
case (x : ScriptNumber, y : ScriptNumber) =>
|
||||||
if (ScriptFlagUtil.requireMinimalData(program.flags) && (!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(y))) {
|
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")
|
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)) {
|
} 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
|
//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
|
//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) &&
|
if (ScriptFlagUtil.requireMinimalData(program.flags) &&
|
||||||
(!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(y))) {
|
(!BitcoinScriptUtil.isShortestEncoding(x) || !BitcoinScriptUtil.isShortestEncoding(y))) {
|
||||||
logger.error("The constant you gave us is not encoded in the shortest way possible")
|
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)) {
|
} 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
|
//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
|
//https://github.com/bitcoin/bitcoin/blob/master/src/script/interpreter.cpp#L999-L1002
|
||||||
|
|
|
@ -170,7 +170,7 @@ trait CryptoInterpreter extends ControlOperationsInterpreter with BitcoinSLogger
|
||||||
ScriptProgram(program,ScriptErrorPubKeyCount)
|
ScriptProgram(program,ScriptErrorPubKeyCount)
|
||||||
} else if (ScriptFlagUtil.requireMinimalData(program.flags) && !nPossibleSignatures.isShortestEncoding) {
|
} 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")
|
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) {
|
} else if (program.stack.size < 2) {
|
||||||
logger.error("We need at least 2 operations on the stack")
|
logger.error("We need at least 2 operations on the stack")
|
||||||
ScriptProgram(program,ScriptErrorInvalidStackOperation)
|
ScriptProgram(program,ScriptErrorInvalidStackOperation)
|
||||||
|
@ -179,7 +179,7 @@ trait CryptoInterpreter extends ControlOperationsInterpreter with BitcoinSLogger
|
||||||
|
|
||||||
if (ScriptFlagUtil.requireMinimalData(program.flags) && !mRequiredSignatures.isShortestEncoding) {
|
if (ScriptFlagUtil.requireMinimalData(program.flags) && !mRequiredSignatures.isShortestEncoding) {
|
||||||
logger.error("The required signatures val must be the shortest encoding as possible")
|
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) {
|
if (mRequiredSignatures < ScriptNumber.zero) {
|
||||||
|
|
|
@ -381,7 +381,7 @@ trait StackInterpreter extends BitcoinSLogger {
|
||||||
case Success(n) => op(n)
|
case Success(n) => op(n)
|
||||||
case Failure(_) =>
|
case Failure(_) =>
|
||||||
logger.error("Script number was not minimally encoded")
|
logger.error("Script number was not minimally encoded")
|
||||||
ScriptProgram(program,ScriptErrorMinimalData)
|
ScriptProgram(program,ScriptErrorUnknownError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -478,7 +478,7 @@ class ArithmeticInterpreterTest extends FlatSpec with MustMatchers with Arithmet
|
||||||
val program = ScriptProgram(TestUtil.testProgramExecutionInProgress, stack,script)
|
val program = ScriptProgram(TestUtil.testProgramExecutionInProgress, stack,script)
|
||||||
val newProgram = opWithin(program)
|
val newProgram = opWithin(program)
|
||||||
newProgram.isInstanceOf[ExecutedScriptProgram] must be (true)
|
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 {
|
it must "mark the script as invalid for OP_WITHIN if one of the numbers is larger than 4 bytes" in {
|
||||||
|
|
|
@ -214,7 +214,7 @@ class StackInterpreterTest extends FlatSpec with MustMatchers with StackInterpre
|
||||||
val newProgram = opRoll(program)
|
val newProgram = opRoll(program)
|
||||||
|
|
||||||
newProgram.isInstanceOf[ExecutedScriptProgram] must be (true)
|
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 {
|
it must "evaluate an OP_ROT correctly" in {
|
||||||
|
|
Loading…
Add table
Reference in a new issue