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

Validate before deploy update #893

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions neo-cli/CLI/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;
using Neo.SmartContract.Manifest;

namespace Neo.CLI
{
internal static class Helper
Expand All @@ -22,5 +25,17 @@ public static bool IsYes(this string input)
}

public static string ToBase64String(this byte[] input) => System.Convert.ToBase64String(input);

public static void IsScriptValid(this ReadOnlyMemory<byte> script, ContractAbi abi)
{
try
{
SmartContract.Helper.Check(script.ToArray(), abi);
}
catch (Exception e)
{
throw new FormatException($"Bad Script or Manifest Format: {e.Message}");
}
}
}
}
29 changes: 2 additions & 27 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,8 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,
throw new FormatException("invalid data");
}


// Basic script checks

Script script = new Script(nef.Script);
for (var i = 0; i < script.Length;)
{
// Check bad opcodes

Instruction inst = script.GetInstruction(i);
if (inst is null || !Enum.IsDefined(typeof(OpCode), inst.OpCode))
{
throw new FormatException($"OpCode not found at {i}-{((byte)inst.OpCode).ToString("x2")}");
}
i += inst.Size;
}
nef.Script.IsScriptValid(manifest.Abi);

// Build script

Expand Down Expand Up @@ -320,19 +307,7 @@ private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string m
}

// Basic script checks

Script script = new Script(nef.Script);
for (var i = 0; i < script.Length;)
{
// Check bad opcodes

Instruction inst = script.GetInstruction(i);
if (inst is null || !Enum.IsDefined(typeof(OpCode), inst.OpCode))
{
throw new FormatException($"OpCode not found at {i}-{((byte)inst.OpCode).ToString("x2")}");
}
i += inst.Size;
}
nef.Script.IsScriptValid(manifest.Abi);

// Build script

Expand Down