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

master-2.x changes since Feb 2, 2018 #3

Open
wants to merge 66 commits into
base: last-known-2.x-update
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
80ea35d
add `Map` to NeoVM (#28)
erikzhang Feb 26, 2018
b1338d4
`TryGetValue` instead of `ContainsKey` and `Get` (#31)
shargon Feb 27, 2018
64f71bd
add new opcode `VERIFY`
Apr 10, 2018
f014d93
avoid exceptions from `Neo.VM.Types.*.Equals()`
May 3, 2018
e2f3b1a
make `ExecutionEngine.Service` be public
erikzhang Jun 14, 2018
79c3aad
Stack Isolation (#39)
erikzhang Jun 24, 2018
bedaaa3
documentation for opcodes in English (#42)
igormcoelho Jul 26, 2018
59f3e66
Fix bug in AltStack replication in compatibility mode
Aug 14, 2018
25723de
change version to v2.3.1
erikzhang Aug 15, 2018
ab74c36
Clone struct when picking item from array or map.
erikzhang Aug 20, 2018
1874219
Using loops to solve the problem of recursive stack overflow (#48)
erikzhang Aug 27, 2018
ab5f939
Revert 49 fixes/pickitem (#52)
erikzhang Sep 10, 2018
9d06c0f
change version to v2.3.1.1
erikzhang Sep 10, 2018
94a91ae
convert string to `StackItem`
erikzhang Sep 21, 2018
e074f00
hashing interop names to uint32 (#61)
igormcoelho Oct 21, 2018
7f5b76b
Added extra dictionary mapping from string -> uint (#62)
igormcoelho Nov 16, 2018
76cf461
change version to v2.3.2
erikzhang Nov 16, 2018
248d77f
Make NeoVM portable (#67)
erikzhang Nov 23, 2018
532e0c6
change version to v2.3.3
erikzhang Nov 27, 2018
43b357d
add `GetInterface<T>()`
erikzhang Nov 27, 2018
4046c89
Prevent exception on last Instruction (#69)
shargon Dec 1, 2018
45e1e95
Add SafeReadBytes from VM (#71)
igormcoelho Dec 10, 2018
48bea34
Add travis and reorder ut folders (#74)
shargon Jan 11, 2019
0675aa1
Cache ScriptHash (#76)
shargon Jan 11, 2019
f93471a
Documentation for Stack Isolation (#79)
igormcoelho Jan 29, 2019
fabeb9f
Proposal of VM-UT (#80)
shargon Feb 28, 2019
080da7c
Move VM Limits to NeoVM (#75)
shargon Mar 5, 2019
ce3091b
Add an implicit conversion to `Script`
erikzhang Mar 6, 2019
b2f12fa
Change version to v2.4.0
erikzhang Mar 6, 2019
8dd5a1f
More unit tests (#81)
shargon Mar 7, 2019
6a993a2
Make `ExecutionEngine.LoadScript()` be `protected virtual` (#83)
erikzhang Mar 7, 2019
2e5981c
Remove `FlagsAttribute` from `VMState` (#84)
erikzhang Mar 10, 2019
41724f6
Fixes possible DOS in `StackItem.GetBoolean()` (#87)
erikzhang Mar 20, 2019
c552114
Check for negative count in NEWARRAY/NEWSTRUCT (#90)
ixje Mar 22, 2019
0e5cb85
Update readme (#92)
shargon Mar 25, 2019
f93ad20
Allow to convert a Struct from Array (#91)
shargon Mar 26, 2019
663e9c8
Add `PreExecuteInstruction()` and `PostExecuteInstruction()` virtual …
erikzhang Mar 26, 2019
e615bf5
Implement PICKITEM for ByteArray (#98)
erikzhang Mar 27, 2019
c45330e
Improve the performance of NeoVM (#95)
erikzhang Mar 27, 2019
bfb68c8
Add class `Instruction` to simplify `ExecutionEngine` (#102)
erikzhang Mar 28, 2019
ea8d2dc
Small optimization (#105)
shargon Mar 29, 2019
58152f8
Move breakpoints logic to other class (#106)
shargon Mar 30, 2019
8db80d4
Use ReadOnlySpan and ReadOnlyMemory for reducing memory copy (#104)
erikzhang Apr 1, 2019
fd9533f
Add `TokenString` and `TokenU32` to `Instruction`
erikzhang Apr 1, 2019
c38bacf
Revert "Use ReadOnlySpan and ReadOnlyMemory for reducing memory copy …
erikzhang Apr 1, 2019
cea98bf
Unify CheckStackSize for PICKITEM (#107)
shargon Apr 1, 2019
e827772
fixes `JMP*`
erikzhang Apr 2, 2019
17d58f6
change version to v2.4.1
erikzhang Apr 4, 2019
63437a3
Small optimizations (#111)
shargon Apr 7, 2019
6679ec7
Add Coverals to neo-vm (#110)
shargon Apr 7, 2019
16a2473
ScriptBuilder unit tests (#113)
shargon Apr 8, 2019
fbc276e
Allow to compress syscalls api methods (#114)
shargon Apr 8, 2019
6b31afc
Debugger unit testing (#115)
shargon Apr 9, 2019
3c18bc9
Unit test for RandomAccessStack (#116)
shargon Apr 9, 2019
07aa32b
APPCALL and TAILCALL unit tests (#117)
shargon Apr 10, 2019
cf869a7
Fix breakpoints on StepOver and StepOut (#119)
shargon Apr 11, 2019
f0f8090
Optimize Instructions cache (#120)
shargon Apr 11, 2019
1bc4546
Revert the restrictions of NUMEQUAL and NUMNOTEQUAL (#126)
erikzhang Apr 13, 2019
86dfba6
Fixes CALL_I (#131)
erikzhang Apr 18, 2019
fb5d6c9
Fix .travis
erikzhang Apr 20, 2019
0d13635
Revert some checks for 2.x (#140)
shargon Apr 29, 2019
38c5dc0
Fixes GetEntryScriptHash and GetCallingScriptHash (2.x) (#138)
erikzhang May 2, 2019
cd5c3d0
change version to v2.4.2
erikzhang May 3, 2019
e9b0e6a
Revert "Fixes GetEntryScriptHash and GetCallingScriptHash (2.x) (#138…
erikzhang May 15, 2019
15170c4
Add nuget license metadata into project file.
erikzhang May 22, 2019
30e9d57
Update ExecutionEngine.cs (#205)
shargon Dec 4, 2019
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
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: csharp

os:
- linux
- osx

dist: bionic
osx_image: xcode9.1

mono: none
dotnet: 2.1.300

before_install:
- cd tests/neo-vm.Tests
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ulimit -n 2048; fi

script:
- dotnet restore
- find * -name *.csproj | xargs -I % dotnet add % package coverlet.msbuild
- dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=opencover

after_success:
# After all tests OK, Send CodeDov report
- echo "Test Success - Branch($TRAVIS_BRANCH) Pull Request($TRAVIS_PULL_REQUEST) Tag($TRAVIS_TAG)"
- bash <(curl -s https://codecov.io/bash) -v
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
<p align="center">
<img
src="https://neo-cdn.azureedge.net/images/neo_logo.svg"
width="250px">
</p>

<p align="center">
<a href='https://coveralls.io/github/neo-project/neo-vm?branch=master'>
<img src='https://coveralls.io/repos/github/neo-project/neo-vm/badge.svg?branch=master' alt='Coverage Status' />
</a>
<a href="https://travis-ci.org/neo-project/neo-vm">
<img src="https://travis-ci.org/neo-project/neo-vm.svg?branch=master">
</a>
<a href="https://github.com/neo-project/neo-vm/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
</a>

</p>

# NEO Virtual Machine

This is the virtual machine of NEO: **NeoVM**.
Expand Down
12 changes: 12 additions & 0 deletions neo-vm.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0F08E36C-9F1
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "neo-vm", "src\neo-vm\neo-vm.csproj", "{6A621185-36A9-4E1A-8D3D-462D19503E32}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{210DA31B-019E-48CE-9498-D56A7987C4E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "neo-vm.Tests", "tests\neo-vm.Tests\neo-vm.Tests.csproj", "{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,11 +21,19 @@ Global
{6A621185-36A9-4E1A-8D3D-462D19503E32}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6A621185-36A9-4E1A-8D3D-462D19503E32}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6A621185-36A9-4E1A-8D3D-462D19503E32}.Release|Any CPU.Build.0 = Release|Any CPU
{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6A621185-36A9-4E1A-8D3D-462D19503E32} = {0F08E36C-9F18-423D-8F8C-C8C2FACF00F7}
{56063C9E-49B3-4CE2-96C5-E5F7ECACC5FC} = {210DA31B-019E-48CE-9498-D56A7987C4E6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F8AC7AA8-85DE-4A98-9B58-BA08AB813C99}
EndGlobalSection
EndGlobal
84 changes: 84 additions & 0 deletions src/neo-vm/Debugger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections.Generic;

namespace Neo.VM
{
public class Debugger
{
private readonly ExecutionEngine engine;
private readonly Dictionary<byte[], HashSet<uint>> break_points = new Dictionary<byte[], HashSet<uint>>(new HashComparer());

public Debugger(ExecutionEngine engine)
{
this.engine = engine;
}

public void AddBreakPoint(byte[] script_hash, uint position)
{
if (!break_points.TryGetValue(script_hash, out HashSet<uint> hashset))
{
hashset = new HashSet<uint>();
break_points.Add(script_hash, hashset);
}
hashset.Add(position);
}

public void Execute()
{
engine.State &= ~VMState.BREAK;
while (!engine.State.HasFlag(VMState.HALT) && !engine.State.HasFlag(VMState.FAULT) && !engine.State.HasFlag(VMState.BREAK))
{
ExecuteAndCheckBreakPoints();
}
}

private void ExecuteAndCheckBreakPoints()
{
engine.ExecuteNext();
if (engine.State == VMState.NONE && engine.InvocationStack.Count > 0 && break_points.Count > 0)
{
if (break_points.TryGetValue(engine.CurrentContext.ScriptHash, out HashSet<uint> hashset) && hashset.Contains((uint)engine.CurrentContext.InstructionPointer))
engine.State = VMState.BREAK;
}
}

public bool RemoveBreakPoint(byte[] script_hash, uint position)
{
if (!break_points.TryGetValue(script_hash, out HashSet<uint> hashset)) return false;
if (!hashset.Remove(position)) return false;
if (hashset.Count == 0) break_points.Remove(script_hash);
return true;
}

public void StepInto()
{
if (engine.State.HasFlag(VMState.HALT) || engine.State.HasFlag(VMState.FAULT)) return;
engine.ExecuteNext();
if (engine.State == VMState.NONE)
engine.State = VMState.BREAK;
}

public void StepOut()
{
engine.State &= ~VMState.BREAK;
int c = engine.InvocationStack.Count;
while (!engine.State.HasFlag(VMState.HALT) && !engine.State.HasFlag(VMState.FAULT) && !engine.State.HasFlag(VMState.BREAK) && engine.InvocationStack.Count >= c)
ExecuteAndCheckBreakPoints();
if (engine.State == VMState.NONE)
engine.State = VMState.BREAK;
}

public void StepOver()
{
if (engine.State.HasFlag(VMState.HALT) || engine.State.HasFlag(VMState.FAULT)) return;
engine.State &= ~VMState.BREAK;
int c = engine.InvocationStack.Count;
do
{
ExecuteAndCheckBreakPoints();
}
while (!engine.State.HasFlag(VMState.HALT) && !engine.State.HasFlag(VMState.FAULT) && !engine.State.HasFlag(VMState.BREAK) && engine.InvocationStack.Count > c);
if (engine.State == VMState.NONE)
engine.State = VMState.BREAK;
}
}
}
89 changes: 56 additions & 33 deletions src/neo-vm/ExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -1,62 +1,85 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;

namespace Neo.VM
{
public class ExecutionContext : IDisposable
public class ExecutionContext
{
private ExecutionEngine engine;
public readonly byte[] Script;
public readonly bool PushOnly;
internal readonly BinaryReader OpReader;
internal readonly HashSet<uint> BreakPoints;
/// <summary>
/// Number of items to be returned
/// </summary>
public int RVCount { get; }

public int InstructionPointer
/// <summary>
/// Script
/// </summary>
public Script Script { get; }

/// <summary>
/// Evaluation stack
/// </summary>
public RandomAccessStack<StackItem> EvaluationStack { get; } = new RandomAccessStack<StackItem>();

/// <summary>
/// Alternative stack
/// </summary>
public RandomAccessStack<StackItem> AltStack { get; } = new RandomAccessStack<StackItem>();

/// <summary>
/// Instruction pointer
/// </summary>
public int InstructionPointer { get; set; }

public Instruction CurrentInstruction
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
return (int)OpReader.BaseStream.Position;
return GetInstruction(InstructionPointer);
}
set
}

/// <summary>
/// Next instruction
/// </summary>
public Instruction NextInstruction
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
OpReader.BaseStream.Seek(value, SeekOrigin.Begin);
return GetInstruction(InstructionPointer + CurrentInstruction.Size);
}
}

public OpCode NextInstruction => (OpCode)Script[OpReader.BaseStream.Position];

private byte[] _script_hash = null;
/// <summary>
/// Cached script hash
/// </summary>
public byte[] ScriptHash
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
if (_script_hash == null)
_script_hash = engine.Crypto.Hash160(Script);
return _script_hash;
return Script.ScriptHash;
}
}

internal ExecutionContext(ExecutionEngine engine, byte[] script, bool push_only, HashSet<uint> break_points = null)
/// <summary>
/// Constructor
/// </summary>
/// <param name="script">Script</param>
/// <param name="rvcount">Number of items to be returned</param>
internal ExecutionContext(Script script, int rvcount)
{
this.engine = engine;
this.RVCount = rvcount;
this.Script = script;
this.PushOnly = push_only;
this.OpReader = new BinaryReader(new MemoryStream(script, false));
this.BreakPoints = break_points ?? new HashSet<uint>();
}

public ExecutionContext Clone()
{
return new ExecutionContext(engine, Script, PushOnly, BreakPoints)
{
InstructionPointer = InstructionPointer
};
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Instruction GetInstruction(int ip) => Script.GetInstruction(ip);

public void Dispose()
internal bool MoveNext()
{
OpReader.Dispose();
InstructionPointer += CurrentInstruction.Size;
return InstructionPointer < Script.Length;
}
}
}
Loading