From fafaac036a318ac7965a093e349f0cd8e42ba4f9 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Wed, 12 Aug 2020 16:06:34 +0800 Subject: [PATCH 1/3] fix script check --- neo-cli/CLI/MainService.cs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index fb01dbadc..9c712cf98 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -269,23 +269,17 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, // Basic script checks - using (var engine = ApplicationEngine.Create(TriggerType.Application, null, null, 0, true)) + Script script = new Script(file.Script); + for(var i = 0; i < script.Length;) { - var context = engine.LoadScript(file.Script); + // Check bad opcodes - while (context.InstructionPointer <= context.Script.Length) + Instruction inst = script.GetInstruction(i); + if (inst == null || !Enum.IsDefined(typeof(OpCode), inst.OpCode)) { - // Check bad opcodes - - var ci = context.CurrentInstruction; - - if (ci == null || !Enum.IsDefined(typeof(OpCode), ci.OpCode)) - { - throw new FormatException($"OpCode not found at {context.InstructionPointer}-{((byte)ci.OpCode).ToString("x2")}"); - } - - context.InstructionPointer += ci.Size; + throw new FormatException($"OpCode not found at {i}-{((byte)inst.OpCode).ToString("x2")}"); } + i += inst.Size; } // Build script From c8c98c47b0d9a5451ec5f5a3e3fad231458102fb Mon Sep 17 00:00:00 2001 From: Luchuan Date: Wed, 12 Aug 2020 16:08:06 +0800 Subject: [PATCH 2/3] optimize code --- neo-cli/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 9c712cf98..88423c255 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -275,7 +275,7 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, // Check bad opcodes Instruction inst = script.GetInstruction(i); - if (inst == null || !Enum.IsDefined(typeof(OpCode), inst.OpCode)) + if (inst is null || !Enum.IsDefined(typeof(OpCode), inst.OpCode)) { throw new FormatException($"OpCode not found at {i}-{((byte)inst.OpCode).ToString("x2")}"); } From abf47907f8108ce2991a496daead23374ff63457 Mon Sep 17 00:00:00 2001 From: Luchuan Date: Wed, 12 Aug 2020 16:10:31 +0800 Subject: [PATCH 3/3] format --- neo-cli/CLI/MainService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neo-cli/CLI/MainService.cs b/neo-cli/CLI/MainService.cs index 88423c255..77ece39ac 100644 --- a/neo-cli/CLI/MainService.cs +++ b/neo-cli/CLI/MainService.cs @@ -270,7 +270,7 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, // Basic script checks Script script = new Script(file.Script); - for(var i = 0; i < script.Length;) + for (var i = 0; i < script.Length;) { // Check bad opcodes