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

Turing-incomplete mode #1741

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
14 changes: 12 additions & 2 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ internal void LoadContext(ExecutionContext context, int initialPosition)
LoadContext(context);
}

public ExecutionContext LoadScript(Script script, CallFlags callFlags)
public ExecutionContext LoadScript(Script script, CallFlags callFlags, bool turingComplete = true)
{
ExecutionContext context = LoadScript(script);
context.GetState<ExecutionContextState>().CallFlags = callFlags;
ExecutionContextState state = context.GetState<ExecutionContextState>();
if (!turingComplete && callFlags.HasFlag(CallFlags.AllowCall))
{
throw new ArgumentException("Combine AllowCall and turingComplete it's not allowed");
}
state.CallFlags = callFlags;
state.TuringComplete = turingComplete;
return context;
}

Expand Down Expand Up @@ -223,6 +229,10 @@ protected override void OnSysCall(uint method)

protected override void PreExecuteInstruction()
{
ExecutionContextState state = CurrentContext.GetState<ExecutionContextState>();
if (!state.TuringComplete)
if (CurrentContext.CurrentInstruction.OpCode >= OpCode.JMP && CurrentContext.CurrentInstruction.OpCode <= OpCode.CALLA)
throw new InvalidOperationException();
if (CurrentContext.InstructionPointer < CurrentContext.Script.Length)
AddGas(OpCodePrices[CurrentContext.CurrentInstruction.OpCode]);
}
Expand Down
2 changes: 2 additions & 0 deletions src/neo/SmartContract/ExecutionContextState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ internal class ExecutionContextState
/// Execution context rights
/// </summary>
public CallFlags CallFlags { get; set; } = CallFlags.All;

public bool TuringComplete { get; set; } = true;
}
}
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, StoreView snap
using (ApplicationEngine engine = new ApplicationEngine(TriggerType.Verification, verifiable, snapshot, gas))
{
engine.LoadScript(verification, CallFlags.ReadOnly).InstructionPointer = offset;
engine.LoadScript(verifiable.Witnesses[i].InvocationScript, CallFlags.None);
engine.LoadScript(verifiable.Witnesses[i].InvocationScript, CallFlags.None, turingComplete: false);
if (engine.Execute() == VMState.FAULT) return false;
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) return false;
gas -= engine.GasConsumed;
Expand Down