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

Fix script check #647

Merged
merged 3 commits into from
Aug 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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