Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mode to disable backward jumps on Neo AppEngine 3 #837

Closed
Closed
Changes from 2 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
26 changes: 25 additions & 1 deletion neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public partial class ApplicationEngine : ExecutionEngine
public const long GasFree = 0;
private readonly long gas_amount;
private readonly bool testMode;
// limited mode (disallow backward jumps and recursive calls)
private readonly bool isLimited;
private readonly RandomAccessStack<UInt160> hashes = new RandomAccessStack<UInt160>();
private readonly List<NotifyEventArgs> notifications = new List<NotifyEventArgs>();
private readonly List<IDisposable> disposables = new List<IDisposable>();
Expand All @@ -29,10 +31,11 @@ public partial class ApplicationEngine : ExecutionEngine
public IReadOnlyList<NotifyEventArgs> Notifications => notifications;
internal Dictionary<UInt160, int> InvocationCounter { get; } = new Dictionary<UInt160, int>();

public ApplicationEngine(TriggerType trigger, IVerifiable container, Snapshot snapshot, long gas, bool testMode = false)
public ApplicationEngine(TriggerType trigger, IVerifiable container, Snapshot snapshot, long gas, bool testMode = false, bool isLimited = false)
{
this.gas_amount = GasFree + gas;
this.testMode = testMode;
this.isLimited = isLimited;
this.Trigger = trigger;
this.ScriptContainer = container;
this.Snapshot = snapshot;
Expand Down Expand Up @@ -81,6 +84,27 @@ protected override bool PreExecuteInstruction()
{
if (CurrentContext.InstructionPointer >= CurrentContext.Script.Length)
return true;

Instruction instruction = CurrentContext.CurrentInstruction;
switch(instruction.OpCode)
{
case OpCode.JMP:
case OpCode.JMPIF:
case OpCode.JMPIFNOT:
case OpCode.CALL:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With syscall, you can jump to your own contract again

Copy link
Contributor Author

@igormcoelho igormcoelho Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what we've been talking, most syscalls will probably be disabled on verification. In my opinion now, only crypto stuff and block header information should be available... no appcalls, no storage, ... so it will be fast as a bullet and state independent.

{
if(isLimited)
{
// no backwards jump in limited mode
if(instruction.TokenI16 <= 0)
{
return false;
}
}
break;
}
}

return AddGas(OpCodePrices[CurrentContext.CurrentInstruction.OpCode]);
}

Expand Down