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

Commit

Permalink
Revert "Fixes GetEntryScriptHash and GetCallingScriptHash (2.x) (#138)…
Browse files Browse the repository at this point in the history
…" (#157)

This reverts commit 38c5dc0.
  • Loading branch information
erikzhang authored May 15, 2019
1 parent cd5c3d0 commit e9b0e6a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
6 changes: 1 addition & 5 deletions src/neo-vm/ExecutionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ public byte[] ScriptHash
}
}

public byte[] CallingScriptHash { get; }

/// <summary>
/// Constructor
/// </summary>
/// <param name="script">Script</param>
/// <param name="callingScriptHash">Script hash of the calling script</param>
/// <param name="rvcount">Number of items to be returned</param>
internal ExecutionContext(Script script, byte[] callingScriptHash, int rvcount)
internal ExecutionContext(Script script, int rvcount)
{
this.RVCount = rvcount;
this.Script = script;
this.CallingScriptHash = callingScriptHash;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
25 changes: 12 additions & 13 deletions src/neo-vm/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public class ExecutionEngine : IDisposable
public RandomAccessStack<ExecutionContext> InvocationStack { get; } = new RandomAccessStack<ExecutionContext>();
public RandomAccessStack<StackItem> ResultStack { get; } = new RandomAccessStack<StackItem>();
public ExecutionContext CurrentContext => InvocationStack.Peek();
public byte[] EntryScriptHash { get; private set; }
public ExecutionContext CallingContext => InvocationStack.Count > 1 ? InvocationStack.Peek(1) : null;
public ExecutionContext EntryContext => InvocationStack.Peek(InvocationStack.Count - 1);
public VMState State { get; internal protected set; } = VMState.BREAK;

public ExecutionEngine(IScriptContainer container, ICrypto crypto, IScriptTable table = null, IInteropService service = null)
Expand Down Expand Up @@ -284,7 +285,7 @@ private bool ExecuteInstruction()
case OpCode.CALL:
{
if (!CheckMaxInvocationStack()) return false;
ExecutionContext context_call = LoadScript(context.Script, context.ScriptHash);
ExecutionContext context_call = LoadScript(context.Script);
context_call.InstructionPointer = context.InstructionPointer + instruction.TokenI16;
if (context_call.InstructionPointer < 0 || context_call.InstructionPointer > context_call.Script.Length) return false;
context.EvaluationStack.CopyTo(context_call.EvaluationStack);
Expand Down Expand Up @@ -327,7 +328,7 @@ private bool ExecuteInstruction()
{
script_hash = context.EvaluationStack.Pop().GetByteArray();
}
ExecutionContext context_new = LoadScriptByHash(script_hash, context.ScriptHash);
ExecutionContext context_new = LoadScriptByHash(script_hash);
if (context_new == null) return false;
context.EvaluationStack.CopyTo(context_new.EvaluationStack);
if (instruction.OpCode == OpCode.TAILCALL)
Expand Down Expand Up @@ -1170,7 +1171,7 @@ private bool ExecuteInstruction()
int rvcount = instruction.Operand[0];
int pcount = instruction.Operand[1];
if (context.EvaluationStack.Count < pcount) return false;
ExecutionContext context_call = LoadScript(context.Script, context.ScriptHash, rvcount);
ExecutionContext context_call = LoadScript(context.Script, rvcount);
context_call.InstructionPointer = context.InstructionPointer + instruction.TokenI16_1 + 2;
if (context_call.InstructionPointer < 0 || context_call.InstructionPointer > context_call.Script.Length) return false;
context.EvaluationStack.CopyTo(context_call.EvaluationStack, pcount);
Expand Down Expand Up @@ -1207,7 +1208,7 @@ private bool ExecuteInstruction()
script_hash = instruction.ReadBytes(2, 20);
}

ExecutionContext context_new = LoadScriptByHash(script_hash, context.ScriptHash, rvcount);
ExecutionContext context_new = LoadScriptByHash(script_hash, rvcount);
if (context_new == null) return false;
context.EvaluationStack.CopyTo(context_new.EvaluationStack, pcount);
if (instruction.OpCode == OpCode.CALL_ET || instruction.OpCode == OpCode.CALL_EDT)
Expand Down Expand Up @@ -1237,26 +1238,24 @@ private bool ExecuteInstruction()
return true;
}

public ExecutionContext LoadScript(byte[] script, byte[] callingScriptHash = null, int rvcount = -1)
public ExecutionContext LoadScript(byte[] script, int rvcount = -1)
{
return LoadScript(new Script(Crypto, script), callingScriptHash, rvcount);
return LoadScript(new Script(Crypto, script), rvcount);
}

protected virtual ExecutionContext LoadScript(Script script, byte[] callingScriptHash = null, int rvcount = -1)
protected virtual ExecutionContext LoadScript(Script script, int rvcount = -1)
{
ExecutionContext context = new ExecutionContext(script, callingScriptHash, rvcount);
if (EntryScriptHash is null)
EntryScriptHash = context.ScriptHash;
ExecutionContext context = new ExecutionContext(script, rvcount);
InvocationStack.Push(context);
return context;
}

private ExecutionContext LoadScriptByHash(byte[] hash, byte[] callingScriptHash, int rvcount = -1)
private ExecutionContext LoadScriptByHash(byte[] hash, int rvcount = -1)
{
if (table == null) return null;
byte[] script = table.GetScript(hash);
if (script == null) return null;
return LoadScript(new Script(hash, script), callingScriptHash, rvcount);
return LoadScript(new Script(hash, script), rvcount);
}

protected virtual bool PostExecuteInstruction(Instruction instruction)
Expand Down
2 changes: 1 addition & 1 deletion src/neo-vm/neo-vm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Copyright>2016-2019 The Neo Project</Copyright>
<AssemblyTitle>Neo.VM</AssemblyTitle>
<Description>Neo.VM</Description>
<Version>2.4.2</Version>
<Version>2.4.3</Version>
<Authors>The Neo Project</Authors>
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks>
<AssemblyName>Neo.VM</AssemblyName>
Expand Down
4 changes: 2 additions & 2 deletions tests/neo-vm.Tests/Types/InteropService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public bool Invoke(byte[] method, ExecutionEngine engine)
{
case "System.ExecutionEngine.GetEntryScriptHash":
{
engine.CurrentContext.EvaluationStack.Push(engine.EntryScriptHash);
engine.CurrentContext.EvaluationStack.Push(engine.EntryContext.ScriptHash);
return true;
}
case "System.ExecutionEngine.GetCallingScriptHash":
{
engine.CurrentContext.EvaluationStack.Push(engine.CurrentContext.CallingScriptHash ?? new byte[0]);
engine.CurrentContext.EvaluationStack.Push(engine.CallingContext.ScriptHash);
return true;
}
case "System.ExecutionEngine.GetExecutingScriptHash":
Expand Down

0 comments on commit e9b0e6a

Please sign in to comment.