From d537c8017ac0c2ec1b1d2d5a604a78aab705ef2f Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 26 Apr 2013 13:50:30 +0200 Subject: [PATCH] Script: fix bug, OP_0/OP_FALSE is not invalid. --- core/src/main/java/com/google/bitcoin/script/Script.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/script/Script.java b/core/src/main/java/com/google/bitcoin/script/Script.java index 744231ce..ade8e4fc 100644 --- a/core/src/main/java/com/google/bitcoin/script/Script.java +++ b/core/src/main/java/com/google/bitcoin/script/Script.java @@ -591,7 +591,10 @@ public class Script { continue; switch(opcode) { - //case OP_0: dont know why this isnt also here in the reference client + case OP_0: + // This is also OP_FALSE (they are both zero). + stack.add(new byte[]{0}); + break; case OP_1NEGATE: stack.add(Utils.reverseBytes(Utils.encodeMPI(BigInteger.ONE.negate(), false))); break; @@ -1014,7 +1017,7 @@ public class Script { break; default: - throw new ScriptException("Script used a reserved Op Code"); + throw new ScriptException("Script used a reserved opcode " + opcode); } } @@ -1163,7 +1166,7 @@ public class Script { throw new ScriptException("Stack empty at end of script execution."); if (!castToBool(stack.pollLast())) - throw new ScriptException("Script resulted in a non-true stack"); + throw new ScriptException("Script resulted in a non-true stack: " + stack); // P2SH is pay to script hash. It means that the scriptPubKey has a special form which is a valid // program but it has "useless" form that if evaluated as a normal program always returns true.