-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVM simulator with internal/external storage, to allow the simulation and validation of state of expected interaction with any smart contract. Current implementation working with a single contract, Note, some opcodes are not implemented and overall requires further testing. Also small utilities to identify if a contract implements specific function selectors, simple approach.
- Loading branch information
1 parent
ba7c7cc
commit f576f66
Showing
23 changed files
with
2,835 additions
and
985 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Nethereum.BlockchainProcessing/BlockStorage/Entities/TransactionLog.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Numerics; | ||
using System.Threading.Tasks; | ||
|
||
namespace Nethereum.EVM | ||
{ | ||
public interface INodeDataService | ||
{ | ||
Task<BigInteger> GetBalanceAsync(byte[] address); | ||
Task<byte[]> GetCodeAsync(byte[] address); | ||
Task<byte[]> GetBlockHashAsync(BigInteger blockNumber); | ||
Task<byte[]> GetStorageAtAsync(byte[] address, BigInteger position); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Nethereum.Hex.HexConvertors.Extensions; | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
|
||
namespace Nethereum.EVM | ||
{ | ||
public class InternalStorageState | ||
{ | ||
public Dictionary<string, Dictionary<BigInteger, byte[]>> Storage { get; protected set; } | ||
|
||
public InternalStorageState() | ||
{ | ||
Storage = new Dictionary<string, Dictionary<BigInteger, byte[]>>(); | ||
} | ||
public bool ContainsKey(string address, BigInteger key) | ||
{ | ||
address = address.ToLower(); | ||
return Storage.ContainsKey(address) && Storage[address].ContainsKey(key); | ||
} | ||
|
||
public void UpsertValue(string address, BigInteger key, byte[] value) | ||
{ | ||
address = address.ToLower(); | ||
if(!Storage.ContainsKey(address)) | ||
{ | ||
Storage.Add(address, new Dictionary<BigInteger, byte[]>()); | ||
} | ||
|
||
if (!Storage[address].ContainsKey(key)) | ||
{ | ||
Storage[address].Add(key, value); | ||
} | ||
else | ||
{ | ||
Storage[address][key] = value; | ||
} | ||
} | ||
|
||
public byte[] GetValue(string address, BigInteger key) | ||
{ | ||
address = address.ToLower(); | ||
if (ContainsKey(address, key)) | ||
{ | ||
return Storage[address][key]; | ||
} | ||
return null; | ||
} | ||
|
||
public Dictionary<BigInteger, byte[]> GetStorage(string address) | ||
{ | ||
address = address.ToLower(); | ||
if (!Storage.ContainsKey(address.ToLower())) return null; | ||
return Storage[address]; | ||
} | ||
|
||
public Dictionary<string, string> GetContractStorageAsHex(string address) | ||
{ | ||
address = address.ToLower(); | ||
var storage = GetStorage(address); | ||
if (storage == null) return null; | ||
var dictionary = new Dictionary<string, string>(); | ||
foreach (var item in storage) | ||
{ | ||
if (item.Value != null) { | ||
dictionary.Add(item.Key.ToString(), item.Value.ToHex()); | ||
} | ||
} | ||
return dictionary; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard1.6</TargetFramework> | ||
<AssemblyName>Nethereum.EVM</AssemblyName> | ||
<PackageId>Nethereum.EVM</PackageId> | ||
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion> | ||
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
</PropertyGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
<PropertyGroup> | ||
<Description>Nethereum.EVM EVM simulator (WIP) and Bytecode utils</Description> | ||
<AssemblyTitle>Nethereum.EVM</AssemblyTitle> | ||
<Version>0.2.0</Version> | ||
<TargetFrameworks>$(DefaultFrameworks)</TargetFrameworks> | ||
<AssemblyName>Nethereum.EVM</AssemblyName> | ||
<PackageId>Nethereum.EVM</PackageId> | ||
<PackageTags>Netherum;Ethereum;Blockchain;</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Nethereum.ABI\Nethereum.ABI.csproj" /> | ||
<ProjectReference Include="..\Nethereum.Hex\Nethereum.Hex.csproj" /> | ||
<ProjectReference Include="..\Nethereum.RPC\Nethereum.RPC.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.