Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Fix script check (#647)
Browse files Browse the repository at this point in the history
* fix script check

* optimize code

* format

Co-authored-by: Luchuan <luchuan@neo.org>
  • Loading branch information
Tommo-L and Luchuan authored Aug 12, 2020
1 parent b8ca802 commit 59da501
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 is 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
Expand Down

0 comments on commit 59da501

Please sign in to comment.