From: CryptoManiac Date: Sat, 22 Aug 2015 17:44:52 +0000 (+0300) Subject: Remove if block of checking disabled opcodes X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=7665d065797814e219e8f7162fa5c00c97de0d2c Remove if block of checking disabled opcodes --- diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index 9936f72..fb22fff 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -993,7 +993,7 @@ namespace Novacoin if (nDepth >= 0) { StringBuilder sb = new StringBuilder(); - sb.AppendFormat("stacktop() : positive depth ({0})", nDepth); + sb.AppendFormat("stacktop() : positive depth ({0}) has no sense.", nDepth); throw new StackMachineException(sb.ToString()); } @@ -1001,7 +1001,7 @@ namespace Novacoin if (nStackElement < 0) { StringBuilder sb = new StringBuilder(); - sb.AppendFormat("stacktop() : nDepth={0} exceeds real stack depth", nDepth); + sb.AppendFormat("stacktop() : nDepth={0} exceeds real stack depth ({1})", nDepth, stack.Count); throw new StackMachineException(sb.ToString()); } @@ -1024,7 +1024,9 @@ namespace Novacoin { // Can be negative zero if (i == value.Length - 1 && value[i] == 0x80) + { return false; + } return true; } @@ -1055,7 +1057,6 @@ namespace Novacoin ByteQueue pbegincodehash = script.GetByteQUeue(); opcodetype opcode; - IEnumerable vchPushValue; List vfExec = new List(); List> altstack = new List>(); @@ -1085,38 +1086,51 @@ namespace Novacoin // // Read instruction // - if (!GetOp(ref pc, out opcode, out vchPushValue)) + IEnumerable pushArg; + if (!GetOp(ref pc, out opcode, out pushArg)) + { return false; - if (vchPushValue.Count() > 520) // Check against MAX_SCRIPT_ELEMENT_SIZE + } + + if (pushArg.Count() > 520) // Check against MAX_SCRIPT_ELEMENT_SIZE + { return false; + } + if (opcode > opcodetype.OP_16 && ++nOpCount > 201) + { return false; - - if (opcode == opcodetype.OP_CAT || - opcode == opcodetype.OP_SUBSTR || - opcode == opcodetype.OP_LEFT || - opcode == opcodetype.OP_RIGHT || - opcode == opcodetype.OP_INVERT || - opcode == opcodetype.OP_AND || - opcode == opcodetype.OP_OR || - opcode == opcodetype.OP_XOR || - opcode == opcodetype.OP_2MUL || - opcode == opcodetype.OP_2DIV || - opcode == opcodetype.OP_MUL || - opcode == opcodetype.OP_DIV || - opcode == opcodetype.OP_MOD || - opcode == opcodetype.OP_LSHIFT || - opcode == opcodetype.OP_RSHIFT) - return false; // Disabled opcodes. + } if (fExec && 0 <= opcode && opcode <= opcodetype.OP_PUSHDATA4) { - stack.Add(vchPushValue); + // Push argument to stack + stack.Add(pushArg); } else if (fExec || (opcodetype.OP_IF <= opcode && opcode <= opcodetype.OP_ENDIF)) switch (opcode) { // + // Disabled opcodes + // + case opcodetype.OP_CAT: + case opcodetype.OP_SUBSTR: + case opcodetype.OP_LEFT: + case opcodetype.OP_RIGHT: + case opcodetype.OP_INVERT: + case opcodetype.OP_AND: + case opcodetype.OP_OR: + case opcodetype.OP_XOR: + case opcodetype.OP_2MUL: + case opcodetype.OP_2DIV: + case opcodetype.OP_MUL: + case opcodetype.OP_DIV: + case opcodetype.OP_MOD: + case opcodetype.OP_LSHIFT: + case opcodetype.OP_RSHIFT: + return false; + + // // Push value // case opcodetype.OP_1NEGATE: