();
23 | }
24 |
25 | public AstUserDefinedTypeName(AstNode node) : this(node.Node) { }
26 | #endregion
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionJumpDest.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
8 | {
9 | public class InstructionJumpDest : InstructionBase
10 | {
11 | #region Constructors
12 | ///
13 | /// Our default constructor, reads the opcode/operand information from the provided stream.
14 | ///
15 | public InstructionJumpDest(MeadowEVM evm) : base(evm) { }
16 | #endregion
17 |
18 | #region Functions
19 | public override void Execute()
20 | {
21 | // This does nothing other than mark the destination of a jump to act as a security layer against exploits.
22 | ExecutionState.JumpedLastInstruction = false;
23 | }
24 | #endregion
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc/Types/Debugging/ExecutionTraceException.cs:
--------------------------------------------------------------------------------
1 | using Meadow.JsonRpc.JsonConverters;
2 | using Newtonsoft.Json;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Meadow.JsonRpc.Types.Debugging
8 | {
9 | public class ExecutionTraceException
10 | {
11 | #region Properties
12 | ///
13 | /// DATA, variable length, a string representing the exception message.
14 | ///
15 | [JsonProperty("exception")]
16 | public string Message { get; set; }
17 | ///
18 | /// INTEGER, 32-bit, nullable, represents the trace index (if any) at which this occurred. Is null if the exception occurred outside of VM execution.
19 | ///
20 | [JsonProperty("traceIndex"), JsonConverter(typeof(JsonRpcHexConverter))]
21 | public int? TraceIndex { get; set; }
22 | #endregion
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionHalt.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Text;
6 |
7 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
8 | {
9 | public class InstructionHalt : InstructionBase
10 | {
11 | #region Constructors
12 | ///
13 | /// Our default constructor, reads the opcode/operand information from the provided stream.
14 | ///
15 | public InstructionHalt(MeadowEVM evm) : base(evm) { }
16 | #endregion
17 |
18 | #region Functions
19 | public override void Execute()
20 | {
21 | // We'll want to return with a blank result, our remaining gas, and a status indicating whether we should revert.
22 | Return(new EVMExecutionResult(EVM, null, true));
23 | }
24 | #endregion
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Block Information/InstructionBlockCoinbase.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types;
2 | using Meadow.EVM.EVM.Execution;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Numerics;
7 | using System.Text;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Block_Information
10 | {
11 | public class InstructionBlockCoinbase : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionBlockCoinbase(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // We'll push our coinbase address
24 | Stack.Push(EVM.State.CurrentBlock.Header.Coinbase);
25 | }
26 | #endregion
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Block Information/InstructionBlockGasLimit.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types;
2 | using Meadow.EVM.EVM.Execution;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Numerics;
7 | using System.Text;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Block_Information
10 | {
11 | public class InstructionBlockGasLimit : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionBlockGasLimit(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // We push our gas limit onto the stack.
24 | Stack.Push(EVM.State.CurrentBlock.Header.GasLimit);
25 | }
26 | #endregion
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Block Information/InstructionBlockNumber.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types;
2 | using Meadow.EVM.EVM.Execution;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Numerics;
7 | using System.Text;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Block_Information
10 | {
11 | public class InstructionBlockNumber : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionBlockNumber(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // We push our block number onto the stack.
24 | Stack.Push(EVM.State.CurrentBlock.Header.BlockNumber);
25 | }
26 | #endregion
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Block Information/InstructionBlockTimestamp.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types;
2 | using Meadow.EVM.EVM.Execution;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Numerics;
7 | using System.Text;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Block_Information
10 | {
11 | public class InstructionBlockTimestamp : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionBlockTimestamp(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // We push our timestamp onto the stack.
24 | Stack.Push(EVM.State.CurrentBlock.Header.Timestamp);
25 | }
26 | #endregion
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.TestApp/Contracts/MultifileInheritedContract.sol:
--------------------------------------------------------------------------------
1 |
2 | import "./MultifileInheritableContract.sol";
3 |
4 | pragma solidity ^0.4.11;
5 |
6 |
7 | contract MultifileInheritedContract is MultifileInheritableContract {
8 |
9 | function MultifileInheritedContract() payable { }
10 |
11 | /**
12 | * @dev Transfers the current balance to the owner and terminates the contract.
13 | */
14 | function destroy() onlyOwner {
15 | selfdestruct(owner);
16 | }
17 |
18 | function destroyAndSend(address _recipient) onlyOwner {
19 | selfdestruct(_recipient);
20 | }
21 |
22 | function testFunction() public {
23 | uint test = 7;
24 | if(test == 8)
25 | test = 1;
26 | else if(test == 7)
27 | test = 2;
28 | else
29 | test = 3;
30 | }
31 |
32 | function testFunctionWithInheritedModifier() onlyOwner {
33 | uint test = 7;
34 | if(test == 8)
35 | test = 1;
36 | else if(test == 7)
37 | test = 2;
38 | else
39 | test = 3;
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Block Information/InstructionBlockDifficulty.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types;
2 | using Meadow.EVM.EVM.Execution;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Numerics;
7 | using System.Text;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Block_Information
10 | {
11 | public class InstructionBlockDifficulty : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionBlockDifficulty(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // We push our difficulty onto the stack.
24 | Stack.Push(EVM.State.CurrentBlock.Header.Difficulty);
25 | }
26 | #endregion
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.DebugSolSources/Meadow.DebugSolSources.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.1
6 | true
7 | true
8 | meadow-debugsol
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen/Util.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Text;
5 |
6 | namespace Meadow.SolCodeGen
7 | {
8 | static class Util
9 | {
10 | public static string GetRelativeFilePath(string solSourceDir, string absolutePath)
11 | {
12 | if (string.IsNullOrEmpty(solSourceDir))
13 | {
14 | return absolutePath;
15 | }
16 |
17 | if (absolutePath.StartsWith(solSourceDir, StringComparison.OrdinalIgnoreCase))
18 | {
19 | absolutePath = absolutePath.Substring(solSourceDir.Length).TrimStart(new[] { '\\', '/' });
20 | }
21 | else if (Path.IsPathRooted(absolutePath))
22 | {
23 | throw new Exception($"Unexpected source file path from solc output: {absolutePath}, source dir: {solSourceDir}");
24 | }
25 |
26 | return absolutePath;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionAdd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionAdd : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionAdd(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Add two unsigned words off of the top of the stack.
23 | BigInteger result = Stack.Pop() + Stack.Pop();
24 |
25 | // Push the result onto the stack.
26 | Stack.Push(result);
27 | }
28 | #endregion
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Meadow.Networking/Extensions/IPAddressExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Net;
4 | using System.Text;
5 |
6 | namespace Meadow.Networking.Extensions
7 | {
8 | public static class IPAddressExtensions
9 | {
10 | #region Functions
11 | ///
12 | /// Obtains the IP address as a string, compatible for use in a URI (IPv6 addresses enclosed in square brackets).
13 | /// Reference: https://tools.ietf.org/html/rfc2732
14 | ///
15 | /// The IP address to format as a string.
16 | /// Returns the IP address as a string, compatible for use in a Uri.
17 | public static string ToUriCompatibleString(this IPAddress address)
18 | {
19 | return address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 ? $"[{address}]" : address.ToString();
20 | }
21 | #endregion
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/System Operations/InstructionInvalid.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Definitions;
2 | using Meadow.EVM.Exceptions;
3 | using Meadow.EVM.EVM.Execution;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Numerics;
8 | using System.Text;
9 |
10 | namespace Meadow.EVM.EVM.Instructions.System_Operations
11 | {
12 | public class InstructionInvalid : InstructionBase
13 | {
14 | #region Constructors
15 | ///
16 | /// Our default constructor, reads the opcode/operand information from the provided stream.
17 | ///
18 | public InstructionInvalid(MeadowEVM evm) : base(evm) { }
19 | #endregion
20 |
21 | #region Functions
22 | public override void Execute()
23 | {
24 | // Throw our invalid instruction exception
25 | throw new EVMException($"{Opcode.ToString()} instruction hit!");
26 | }
27 | #endregion
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionMultiply.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionMultiply : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionMultiply(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Multiply two unsigned words off of the top of the stack.
23 | BigInteger result = Stack.Pop() * Stack.Pop();
24 |
25 | // Push the result onto the stack.
26 | Stack.Push(result);
27 | }
28 | #endregion
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/Contracts/ExceptionContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | contract ExceptionContract {
4 |
5 | address[] public addressArray;
6 |
7 | constructor(bool _throwOnConstructor) public {
8 | assert(!_throwOnConstructor);
9 | }
10 |
11 | function outOfBoundArrayAccess() returns(bool) {
12 | address someAddr = addressArray[4];
13 | return true;
14 | }
15 |
16 | function doRevert() {
17 | revert("do revert hit");
18 | }
19 |
20 | function doRequire() {
21 | bool thingDidWork = false;
22 | require(thingDidWork, "thing did not work");
23 | }
24 |
25 | function doAssert() {
26 | bool thingDidWork = false;
27 | assert(thingDidWork);
28 | }
29 |
30 | function doThrow() {
31 | throw;
32 | }
33 |
34 | function entryFunction() {
35 | nextFunction();
36 | }
37 |
38 | function nextFunction() {
39 | anotherFunc();
40 | }
41 |
42 | function anotherFunc() {
43 | lastFunc();
44 | }
45 |
46 | function lastFunc() {
47 | doAssert();
48 | }
49 |
50 |
51 |
52 | }
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/GlobalSetup.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Diagnostics;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | [assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)]
10 |
11 | namespace Meadow.UnitTestTemplate.Test
12 | {
13 | [TestClass]
14 | public static class GlobalSetup
15 | {
16 | [AssemblyInitialize]
17 | public static async Task Init(TestContext testContext)
18 | {
19 | Global.HideSolidityFromReport("mocks", "IgnoreContract.sol");
20 | await Task.CompletedTask;
21 | }
22 |
23 | [AssemblyCleanup]
24 | public static async Task Cleanup()
25 | {
26 | await Global.GenerateCoverageReport();
27 | }
28 |
29 | public static void Main(string[] args)
30 | {
31 | Global.Launch();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Views/CoverageHeader.cshtml:
--------------------------------------------------------------------------------
1 | @using Meadow.CoverageReport.Models;
2 | @using System.Globalization;
3 |
4 | @model CoverageStats
5 |
6 |
17 |
18 |
19 |
20 | @Model.LineCoveragePercent%
21 | Lines
22 | @Model.LineCoveredCount/@Model.LineCount
23 |
24 | @Model.BranchCoveragePercent%
25 | Branches
26 | @Model.BranchCoveredCount/@Model.BranchCount
27 |
28 | @Model.FunctionCoveragePercent%
29 | Functions
30 | @Model.FunctionCoveredCount/@Model.FunctionCount
31 |
32 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/Debugging/Tracing/ExecutionTraceException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Meadow.EVM.Debugging.Tracing
6 | {
7 | public class ExecutionTraceException
8 | {
9 | #region Properties
10 | ///
11 | /// The index in our which indicates the point in execution where the occurred.
12 | ///
13 | public int? TraceIndex { get; }
14 | ///
15 | /// The exception that occurred during execution.
16 | ///
17 | public Exception Exception { get; }
18 | #endregion
19 |
20 | #region Constructors
21 | public ExecutionTraceException(int? traceIndex, Exception exception)
22 | {
23 | // Set our properties
24 | TraceIndex = traceIndex;
25 | Exception = exception;
26 | }
27 | #endregion
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/pwsh_testing/Contracts/ErrorContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | /// @title Error Generating Contract (Testing)
4 | /// @author David Pokora
5 | /// @notice This is a contract used to generate errors to test EVM exception tracing, etc.
6 | /// @dev
7 | contract ErrorContract
8 | {
9 | /// @notice Our default contructor
10 | constructor() public
11 | {
12 |
13 | }
14 |
15 | /// @notice Raises a simple error directly in this call.
16 | function testSimpleError()
17 | {
18 | assert(false);
19 | }
20 |
21 | function doAssert()
22 | {
23 | assert(false);
24 | }
25 |
26 | function doRevert()
27 | {
28 | require(false, "some require message");
29 | }
30 |
31 | function doThrow(){
32 | throw;
33 | }
34 |
35 | /// @notice Raises an error indirectly through another call.
36 | function testIndirectError()
37 | {
38 | // Call another function to generate the error.
39 | testSimpleError();
40 | }
41 |
42 | /// @notice The fallback function
43 | function() public
44 | {
45 |
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/src/Meadow.DebugExampleTests/GlobalSetup.cs:
--------------------------------------------------------------------------------
1 | using Meadow.UnitTestTemplate;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Diagnostics;
6 | using System.Reflection;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | [assembly: Parallelize(Workers = 1, Scope = ExecutionScope.MethodLevel)]
11 |
12 | namespace Meadow.DebugExampleTests
13 | {
14 | [TestClass]
15 | public static class GlobalSetup
16 | {
17 | [AssemblyInitialize]
18 | public static async Task Init(TestContext testContext)
19 | {
20 | Global.HideSolidityFromReport("mocks", "IgnoreContract.sol");
21 | await Task.CompletedTask;
22 | }
23 |
24 | [AssemblyCleanup]
25 | public static async Task Cleanup()
26 | {
27 | await Global.GenerateCoverageReport();
28 | }
29 |
30 | public static void Main(string[] args)
31 | {
32 | Global.Launch();
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.TestNode.Test.App/Contracts/ErrorContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | /// @title Error Generating Contract (Testing)
4 | /// @author David Pokora
5 | /// @notice This is a contract used to generate errors to test EVM exception tracing, etc.
6 | /// @dev
7 | contract ErrorContract
8 | {
9 | /// @notice Our default contructor
10 | constructor() public
11 | {
12 |
13 | }
14 |
15 | /// @notice Raises a simple error directly in this call.
16 | function testSimpleError()
17 | {
18 | assert(false);
19 | }
20 |
21 | function doAssert()
22 | {
23 | assert(false);
24 | }
25 |
26 | function doRevert()
27 | {
28 | require(false, "some require message");
29 | }
30 |
31 | function doThrow(){
32 | throw;
33 | }
34 |
35 | /// @notice Raises an error indirectly through another call.
36 | function testIndirectError()
37 | {
38 | // Call another function to generate the error.
39 | testSimpleError();
40 | }
41 |
42 | /// @notice The fallback function
43 | function() public
44 | {
45 |
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/src/pwsh_testing/Contracts/MultifileInheritedContract.sol:
--------------------------------------------------------------------------------
1 |
2 | import "./MultifileInheritableContract.sol";
3 |
4 | pragma solidity ^0.4.11;
5 |
6 |
7 | contract MultifileInheritedContract is MultifileInheritableContract {
8 |
9 | function MultifileInheritedContract() payable { }
10 |
11 | /**
12 | * @dev Transfers the current balance to the owner and terminates the contract.
13 | */
14 | function destroy() onlyOwner {
15 | selfdestruct(owner);
16 | }
17 |
18 | function destroyAndSend(address _recipient) onlyOwner {
19 | selfdestruct(_recipient);
20 | }
21 |
22 | function testFunction() public {
23 | uint test = 7;
24 | if(test == 8)
25 | test = 1;
26 | else if(test == 7)
27 | test = 2;
28 | else
29 | test = 3;
30 | }
31 |
32 | function testFunctionWithInheritedModifier() onlyOwner {
33 | uint test = 7;
34 | if(test == 8)
35 | test = 1;
36 | else if(test == 7)
37 | test = 2;
38 | else
39 | test = 3;
40 | }
41 |
42 | function testInheritedAssertThrow()
43 | {
44 | testAssertIndirect();
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Meadow.DebugSolSources/ProcessArgs.cs:
--------------------------------------------------------------------------------
1 | using McMaster.Extensions.CommandLineUtils;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Meadow.DebugSolSources
7 | {
8 | class ProcessArgs
9 | {
10 | [Option("-d|--directory", "Directory of the .sol source files.", CommandOptionType.SingleValue)]
11 | public string Directory { get; }
12 |
13 | [Option("-e|--entry", "The contract entry point in the form of 'ContractName.FunctionName'", CommandOptionType.SingleValue)]
14 | public string Entry { get; }
15 |
16 | [Option("-f|--singleFile", "A single solidity file to debug.", CommandOptionType.SingleValue)]
17 | public string SingleFile { get; }
18 |
19 | public static ProcessArgs Parse(string[] args)
20 | {
21 | var app = new CommandLineApplication(throwOnUnexpectedArg: true);
22 | app.Conventions.UseDefaultConventions();
23 | app.Parse(args);
24 | return app.Model;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Meadow.TestNode.Test.App/Contracts/MultifileInheritedContract.sol:
--------------------------------------------------------------------------------
1 |
2 | import "./MultifileInheritableContract.sol";
3 |
4 | pragma solidity ^0.4.11;
5 |
6 |
7 | contract MultifileInheritedContract is MultifileInheritableContract {
8 |
9 | function MultifileInheritedContract() payable { }
10 |
11 | /**
12 | * @dev Transfers the current balance to the owner and terminates the contract.
13 | */
14 | function destroy() onlyOwner {
15 | selfdestruct(owner);
16 | }
17 |
18 | function destroyAndSend(address _recipient) onlyOwner {
19 | selfdestruct(_recipient);
20 | }
21 |
22 | function testFunction() public {
23 | uint test = 7;
24 | if(test == 8)
25 | test = 1;
26 | else if(test == 7)
27 | test = 2;
28 | else
29 | test = 3;
30 | }
31 |
32 | function testFunctionWithInheritedModifier() onlyOwner {
33 | uint test = 7;
34 | if(test == 8)
35 | test = 1;
36 | else if(test == 7)
37 | test = 2;
38 | else
39 | test = 3;
40 | }
41 |
42 | function testInheritedAssertThrow()
43 | {
44 | testAssertIndirect();
45 | }
46 | }
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/UnderlyingTypes/VarInt.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Core.AbiEncoding;
2 | using Meadow.Core.Utils;
3 | using Meadow.CoverageReport.AstTypes;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes
9 | {
10 | public class VarInt : VarBase
11 | {
12 | #region Constructors
13 | public VarInt(string typeString) : base(typeString)
14 | {
15 | // Obtain our size in bytes
16 | int sizeBytes = VarParser.GetIntegerSizeInBytes(BaseType, GenericType);
17 |
18 | // Initialize our bounds
19 | InitializeBounds(1, sizeBytes);
20 | }
21 | #endregion
22 |
23 | #region Functions
24 | public override object ParseData(Memory data)
25 | {
26 | // Read an signed integer of the specified size
27 | return BigIntegerConverter.GetBigInteger(data.Span, true, SizeBytes);
28 | }
29 | #endregion
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/UnderlyingTypes/VarUInt.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Core.EthTypes;
2 | using Meadow.Core.Utils;
3 | using Meadow.CoverageReport.AstTypes;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes
9 | {
10 | public class VarUInt : VarBase
11 | {
12 | #region Constructors
13 | public VarUInt(string typeString) : base(typeString)
14 | {
15 | // Obtain our size in bytes
16 | int sizeBytes = VarParser.GetIntegerSizeInBytes(BaseType, GenericType);
17 |
18 | // Initialize our bounds
19 | InitializeBounds(1, sizeBytes);
20 | }
21 | #endregion
22 |
23 | #region Functions
24 | public override object ParseData(Memory data)
25 | {
26 | // Read an unsigned integer of the specified size
27 | return BigIntegerConverter.GetBigInteger(data.Span, false, SizeBytes);
28 | }
29 | #endregion
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionIsZero.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionIsZero : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionIsZero(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop();
24 | BigInteger result = a == 0 ? 1 : 0;
25 |
26 | // Push the result onto the stack.
27 | Stack.Push(result);
28 | }
29 | #endregion
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen/CodeGenerators/SolcOutputHelperGenerator.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Contract;
2 | using Meadow.Core.Utils;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Meadow.SolCodeGen.CodeGenerators
8 | {
9 | class SolcOutputHelperGenerator : GeneratorBase
10 | {
11 | readonly byte[] _codebaseHash;
12 |
13 | public SolcOutputHelperGenerator(byte[] codebaseHash, string @namespace) : base(@namespace)
14 | {
15 | _codebaseHash = codebaseHash;
16 | }
17 |
18 | protected override string GenerateUsingDeclarations()
19 | {
20 | var hashHex = HexUtil.GetHexFromBytes(_codebaseHash);
21 | var sourceAttrTypeName = typeof(GeneratedSolcDataAttribute).FullName;
22 | var assemblyAttr = $"[assembly: {sourceAttrTypeName}(\"{hashHex}\")]";
23 | return assemblyAttr;
24 | }
25 |
26 | protected override string GenerateClassDef()
27 | {
28 | return string.Empty;
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM.Test/Meadow.EVM.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 |
11 |
12 | all
13 | runtime; build; native; contentfiles; analyzers
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Meadow.Core.Test/Meadow.Core.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 | all
11 | runtime; build; native; contentfiles; analyzers
12 |
13 |
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/AstTypes/AstElementaryTypeName.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Meadow.CoverageReport.AstTypes
8 | {
9 | public class AstElementaryTypeName : AstNode
10 | {
11 | #region Properties
12 | ///
13 | /// The name of our type.
14 | ///
15 | public string Name { get; }
16 | ///
17 | /// The descriptions for this type.
18 | ///
19 | public AstTypeDescriptions TypeDescriptions { get; }
20 | #endregion
21 |
22 | #region Constructor
23 | public AstElementaryTypeName(JObject node) : base(node)
24 | {
25 | // Set our properties
26 | Name = node.SelectToken("name")?.Value();
27 | TypeDescriptions = new AstTypeDescriptions(node);
28 | }
29 |
30 | public AstElementaryTypeName(AstNode node) : this(node.Node) { }
31 | #endregion
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionMod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionMod : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionMod(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Modulo divide the two unsigned words off of the top of the stack.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = b == 0 ? 0 : a % b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.Core/Utils/MiscExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Text;
5 |
6 | namespace System
7 | {
8 | public static class DeconstructExtensions
9 | {
10 | public static void Deconstruct(
11 | this KeyValuePair p,
12 | out TKey key,
13 | out TValue value)
14 | {
15 | key = p.Key;
16 | value = p.Value;
17 | }
18 |
19 | }
20 |
21 | public static class ListExtensions
22 | {
23 | public static void AddRange(this List list, params T[] items)
24 | {
25 | list.AddRange(items);
26 | }
27 | }
28 |
29 | public static class SpanExtensions
30 | {
31 | public static Span AsByteSpan(this TFrom[] arr) where TFrom :
32 | #if LANG_7_3
33 | unmanaged
34 | #else
35 | struct
36 | #endif
37 | {
38 | return MemoryMarshal.Cast(arr.AsSpan());
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionDivide.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionDivide : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionDivide(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Divide the two unsigned words off of the top of the stack.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = b == 0 ? 0 : a / b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.Contract.Test/Meadow.Contract.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 | all
11 | runtime; build; native; contentfiles; analyzers
12 |
13 |
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Meadow.Core/RlpEncoding/RLPByteArray.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Meadow.Core.RlpEncoding
6 | {
7 | ///
8 | /// Represents a byte array which can be RLP serialized.
9 | ///
10 | public class RLPByteArray : RLPItem
11 | {
12 | #region Properties
13 | ///
14 | /// The embedded raw data inside of this RLP item.
15 | ///
16 | public Memory Data { get; set; }
17 | #endregion
18 |
19 | #region Constructors
20 | ///
21 | /// Default constructor, initializes with a null data array.
22 | ///
23 | public RLPByteArray() { }
24 | ///
25 | /// Initializes an RLP byte array with the given data.
26 | ///
27 | /// The data to set for our RLP item.
28 | public RLPByteArray(Memory data)
29 | {
30 | Data = data;
31 | }
32 | #endregion
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionSubtract.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionSubtract : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionSubtract(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Subtract two unsigned words off of the top of the stack from eachother.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a - b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionSignedDivide.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionSignedDivide : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionSignedDivide(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Divide the two signed words off of the top of the stack.
23 | BigInteger a = Stack.Pop(true);
24 | BigInteger b = Stack.Pop(true);
25 | BigInteger result = b == 0 ? 0 : a / b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionEqual.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionEqual : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionEqual(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a == b ? 1 : 0;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionOr.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionOr : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionOr(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Perform a bitwise OR on the first two items we pop off the stack and push the result back onto the stack.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a | b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Environment/InstructionBalance.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.Data_Types.Addressing;
8 | using Meadow.EVM.EVM.Execution;
9 |
10 | namespace Meadow.EVM.EVM.Instructions.Environment
11 | {
12 | public class InstructionBalance : InstructionBase
13 | {
14 | #region Constructors
15 | ///
16 | /// Our default constructor, reads the opcode/operand information from the provided stream.
17 | ///
18 | public InstructionBalance(MeadowEVM evm) : base(evm) { }
19 | #endregion
20 |
21 | #region Functions
22 | public override void Execute()
23 | {
24 | // Obtain our address
25 | Address address = Stack.Pop();
26 |
27 | // Obtain our balance and push it to the stack.
28 | BigInteger balance = EVM.State.GetBalance(address);
29 | Stack.Push(balance);
30 | }
31 | #endregion
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/pwsh_testing/Contracts/OtherContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 |
4 | contract OtherContract {
5 |
6 | event DataEvent(uint _int1, uint _int2, uint indexed _int3, string _str, uint indexed _int7, address[] _addrs, bytes _bytes, string _mystr);
7 |
8 | event TestEvent(address indexed _addr, uint64 indexed _id, uint _val, uint _timestamp);
9 |
10 |
11 | function emitDataEvent(uint _int1, uint _int2, uint _int3) public {
12 | address[] memory addrs = new address[](12);
13 | for (uint i = 0; i < 12; i++) {
14 | addrs[i] = address(i);
15 | }
16 | bytes memory b = new bytes(9);
17 | b[3] = byte(3);
18 |
19 | emit DataEvent(_int1, _int2, _int3,
20 | "All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log.",
21 | 7, addrs, b, "another string that should be hashed since its indexed");
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport.Test/Meadow.CoverageReport.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 | all
11 | runtime; build; native; contentfiles; analyzers
12 |
13 |
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionAnd.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionAnd : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionAnd(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Perform a bitwise AND on the first two items we pop off the stack and push the result back onto the stack.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a & b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionLessThan.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionLessThan : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionLessThan(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a < b ? 1 : 0;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionXor.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionXor : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionXor(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Perform a bitwise XOR on the first two items we pop off the stack and push the result back onto the stack.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a ^ b;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc.Client.Test/Meadow.JsonRpc.Client.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 | all
11 | runtime; build; native; contentfiles; analyzers
12 |
13 |
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionGreaterThan.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionGreaterThan : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionGreaterThan(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop();
24 | BigInteger b = Stack.Pop();
25 | BigInteger result = a > b ? 1 : 0;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.TestNode.Test.App/Contracts/OtherContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 |
4 | contract OtherContract {
5 |
6 | event DataEvent(uint _int1, uint _int2, uint indexed _int3, string _str, uint indexed _int7, address[] _addrs, bytes _bytes, string _mystr);
7 |
8 | event TestEvent(address indexed _addr, uint64 indexed _id, uint _val, uint _timestamp);
9 |
10 |
11 | function emitDataEvent(uint _int1, uint _int2, uint _int3) public {
12 | address[] memory addrs = new address[](12);
13 | for (uint i = 0; i < 12; i++) {
14 | addrs[i] = address(i);
15 | }
16 | bytes memory b = new bytes(9);
17 | b[3] = byte(3);
18 |
19 | emit DataEvent(_int1, _int2, _int3,
20 | "All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log.",
21 | 7, addrs, b, "another string that should be hashed since its indexed");
22 | }
23 |
24 | }
--------------------------------------------------------------------------------
/src/pwsh_testing/Contracts/MultifileInheritableContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.11;
2 |
3 | contract MultifileInheritableContract {
4 |
5 | address public owner;
6 |
7 | /**
8 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender
9 | * account.
10 | */
11 | function MultifileInheritableContract() {
12 | owner = msg.sender;
13 | }
14 |
15 |
16 | /**
17 | * @dev Throws if called by any account other than the owner.
18 | */
19 | modifier onlyOwner() {
20 | require(msg.sender == owner);
21 | _;
22 | }
23 |
24 |
25 | /**
26 | * @dev Allows the current owner to transfer control of the contract to a newOwner.
27 | * @param newOwner The address to transfer ownership to.
28 | */
29 | function transferOwnership(address newOwner) onlyOwner {
30 | require(newOwner != address(0));
31 | owner = newOwner;
32 | }
33 |
34 | // Test Callstack through multiple contracts and indirect calls.
35 | function testThrowAssert() public {
36 | assert(false);
37 | }
38 | function testAssertIndirect() public {
39 | testThrowAssert();
40 | }
41 | }
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/UnderlyingTypes/VarBoolean.cs:
--------------------------------------------------------------------------------
1 | using Meadow.CoverageReport.AstTypes;
2 | using Meadow.CoverageReport.Debugging.Variables.Enums;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Text;
6 |
7 | namespace Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes
8 | {
9 | public class VarBoolean : VarBase
10 | {
11 | #region Constructors
12 | public VarBoolean(string typeString) : base(typeString)
13 | {
14 | // Initialize our bounds
15 | InitializeBounds(1, 1);
16 | }
17 | #endregion
18 |
19 | #region Functions
20 | public override object ParseData(Memory data)
21 | {
22 | // If there is no data, return false
23 | if (data.Length == 0)
24 | {
25 | return false;
26 | }
27 | else
28 | {
29 | // Otherwise the boolean is parsed from the first byte.
30 | return data.Span[data.Length - 1] != 0;
31 | }
32 | }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc.Server/Meadow.JsonRpc.Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | true
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc/JsonConverters/JsonRpcSerializer.cs:
--------------------------------------------------------------------------------
1 | using Meadow.JsonRpc.JsonConverters;
2 | using Newtonsoft.Json;
3 |
4 | namespace Meadow.JsonRpc.JsonConverters
5 | {
6 | public static class JsonRpcSerializer
7 | {
8 | public static readonly JsonSerializerSettings Settings;
9 | public static readonly JsonSerializer Serializer;
10 | public static readonly JsonConverter[] Converters = new JsonConverter[]
11 | {
12 | new AddressHexJsonConverter(),
13 | new DataHexJsonConverter(),
14 | new HashHexJsonConverter(),
15 | new UInt256HexJsonConverter(),
16 | new JsonRpcHexConverter()
17 | };
18 |
19 | static JsonRpcSerializer()
20 | {
21 | Settings = new JsonSerializerSettings();
22 | Settings.DefaultValueHandling = DefaultValueHandling.Ignore;
23 |
24 | foreach (var converter in Converters)
25 | {
26 | Settings.Converters.Add(converter);
27 | }
28 |
29 | Serializer = JsonSerializer.CreateDefault(Settings);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.TestNode.Test.App/Contracts/MultifileInheritableContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.11;
2 |
3 | contract MultifileInheritableContract {
4 |
5 | address public owner;
6 |
7 | /**
8 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender
9 | * account.
10 | */
11 | function MultifileInheritableContract() {
12 | owner = msg.sender;
13 | }
14 |
15 |
16 | /**
17 | * @dev Throws if called by any account other than the owner.
18 | */
19 | modifier onlyOwner() {
20 | require(msg.sender == owner);
21 | _;
22 | }
23 |
24 |
25 | /**
26 | * @dev Allows the current owner to transfer control of the contract to a newOwner.
27 | * @param newOwner The address to transfer ownership to.
28 | */
29 | function transferOwnership(address newOwner) onlyOwner {
30 | require(newOwner != address(0));
31 | owner = newOwner;
32 | }
33 |
34 | // Test Callstack through multiple contracts and indirect calls.
35 | function testThrowAssert() public {
36 | assert(false);
37 | }
38 | function testAssertIndirect() public {
39 | testThrowAssert();
40 | }
41 | }
--------------------------------------------------------------------------------
/src/pwsh_testing/Contracts/VarAnalysisContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | /// @title Error Generating Contract (Testing)
4 | /// @author David Pokora
5 | /// @notice This is a contract used to generate errors to test EVM exception tracing, etc.
6 | /// @dev
7 | contract VarAnalysisContract
8 | {
9 | uint globalVal;
10 |
11 | /// @notice Our default contructor
12 | constructor() public
13 | {
14 | }
15 |
16 | enum TestEnum {FIRST,SECOND,THIRD}
17 |
18 | function updateStateValues()
19 | {
20 | uint x = 777;
21 | globalVal++;
22 | }
23 |
24 | function throwWithLocals()
25 | {
26 | address addr1 = 0x345ca3e014aaf5dca488057592ee47305d9b3e10;
27 | address addr2 = 0x7070707070707070707070707070707070707070;
28 | int x = -1;
29 | uint y = 0x1080;
30 | bool b1 = true;
31 | bool b2 = false;
32 | TestEnum enum1 = TestEnum.FIRST;
33 | TestEnum enum2 = TestEnum.SECOND;
34 | TestEnum enum3 = TestEnum.THIRD;
35 | assert(false);
36 |
37 | // This is never hit, these values should not be reflected when checking locals.
38 | TestEnum enum4 = TestEnum.FIRST;
39 | bool b3 = true;
40 | x = 7;
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionSignedLessThan.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionSignedLessThan : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionSignedLessThan(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop(true);
24 | BigInteger b = Stack.Pop(true);
25 | BigInteger result = a < b ? 1 : 0;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Environment/InstructionGasPrice.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.EVM.Execution;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Environment
10 | {
11 | public class InstructionGasPrice : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionGasPrice(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // Push the transaction's current gas price onto the stack.
24 | if (EVM.State.CurrentTransaction != null)
25 | {
26 | Stack.Push(EVM.State.CurrentTransaction.GasPrice);
27 | }
28 | else
29 | {
30 | Stack.Push(0);
31 | }
32 | }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Bitwise Logic/InstructionSignedGreaterThan.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Bitwise_Logic
9 | {
10 | public class InstructionSignedGreaterThan : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionSignedGreaterThan(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Checks that the assumed comparison is valid. If it is, return 1, otherwise return 0.
23 | BigInteger a = Stack.Pop(true);
24 | BigInteger b = Stack.Pop(true);
25 | BigInteger result = a > b ? 1 : 0;
26 |
27 | // Push the result onto the stack.
28 | Stack.Push(result);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Environment/InstructionOrigin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.EVM.Execution;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Environment
10 | {
11 | public class InstructionOrigin : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionOrigin(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // Push the origin address from the transaction to the stack.
24 | if (EVM.State.CurrentTransaction != null)
25 | {
26 | Stack.Push(EVM.State.CurrentTransaction.GetSenderAddress());
27 | }
28 | else
29 | {
30 | Stack.Push(0);
31 | }
32 | }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.TestApp/Contracts/FinalizableCrowdsale.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | import "./SafeMath.sol";
4 | import "./Ownable.sol";
5 | import "./TimedCrowdsale.sol";
6 |
7 |
8 | /**
9 | * @title FinalizableCrowdsale
10 | * @dev Extension of Crowdsale where an owner can do extra work
11 | * after finishing.
12 | */
13 | contract FinalizableCrowdsale is TimedCrowdsale, Ownable {
14 | using SafeMath for uint256;
15 |
16 | bool public isFinalized = false;
17 |
18 | event Finalized();
19 |
20 | /**
21 | * @dev Must be called after crowdsale ends, to do some extra finalization
22 | * work. Calls the contract's finalization function.
23 | */
24 | function finalize() onlyOwner public {
25 | require(!isFinalized);
26 | require(hasClosed());
27 |
28 | finalization();
29 | emit Finalized();
30 |
31 | isFinalized = true;
32 | }
33 |
34 | /**
35 | * @dev Can be overridden to add finalization logic. The overriding function
36 | * should call super.finalization() to ensure the chain of finalization is
37 | * executed entirely.
38 | */
39 | function finalization() internal {
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/Meadow.EVM.Test/TransactionRlpTests.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Core.RlpEncoding;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Numerics;
5 | using System.Text;
6 | using Xunit;
7 |
8 | namespace Meadow.EVM.Test
9 | {
10 | public class TransactionRlpTests
11 | {
12 | [Fact]
13 | public void RLPLogTest()
14 | {
15 | Meadow.EVM.Data_Types.Transactions.Log log = new Meadow.EVM.Data_Types.Transactions.Log((BigInteger)0x11223344, new List() { 3, 2, 1 }, new byte[] { 00, 77, 00, 77 });
16 | RLPItem item = log.Serialize();
17 | byte[] data = RLP.Encode(item);
18 | item = RLP.Decode(data);
19 | log.Deserialize(item);
20 | item = log.Serialize();
21 | byte[] data2 = RLP.Encode(item);
22 | Assert.True(data.ValuesEqual(data2));
23 | Assert.Equal(0x11223344, (BigInteger)log.Address);
24 | Assert.True(log.Topics.Count == 3 && log.Topics[0] == 3 && log.Topics[1] == 2 && log.Topics[2] == 1);
25 | Assert.True(log.Data.ValuesEqual(new byte[] { 00, 77, 00, 77 }));
26 | }
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Environment/InstructionReturnDataSize.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.Data_Types.Addressing;
8 | using Meadow.EVM.EVM.Execution;
9 |
10 | namespace Meadow.EVM.EVM.Instructions.Environment
11 | {
12 | public class InstructionReturnDataSize : InstructionBase
13 | {
14 | #region Constructors
15 | ///
16 | /// Our default constructor, reads the opcode/operand information from the provided stream.
17 | ///
18 | public InstructionReturnDataSize(MeadowEVM evm) : base(evm) { }
19 | #endregion
20 |
21 | #region Functions
22 | public override void Execute()
23 | {
24 | // Obtain our return data length
25 | int codeLength = ExecutionState.LastCallResult?.ReturnData == null ? 0 : ExecutionState.LastCallResult.ReturnData.Length;
26 |
27 | // Push the return data length to the stack.
28 | Stack.Push(codeLength);
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.Networking/Configuration/NetworkConfiguration.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Networking.Protocol.Addressing;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Net;
5 | using System.Text;
6 |
7 | namespace Meadow.Networking.Configuration
8 | {
9 | public class NetworkConfiguration
10 | {
11 | #region Properties
12 | public bool ListeningEnabled { get; set; }
13 | public IPAddress ListeningHost { get; set; }
14 | public ushort ListeningPort { get; set; }
15 |
16 | public List BootstrapNodes { get; set; }
17 | #endregion
18 |
19 | #region Constructors
20 | public NetworkConfiguration(bool defaultBootstrapServers = true)
21 | {
22 | // Initialize our properties with default values
23 | BootstrapNodes = new List();
24 |
25 | // Add our default bootstrap nodes
26 | if (defaultBootstrapServers)
27 | {
28 | // Add the bootstrap nodes.
29 | BootstrapNodes.AddRange(DefaultBootstrapNodes.MainNetNodes);
30 | }
31 | }
32 | #endregion
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Models/SourceFileLine.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using Newtonsoft.Json.Converters;
3 |
4 | namespace Meadow.CoverageReport.Models
5 | {
6 | public class SourceFileLine
7 | {
8 | public bool IsActive { get; set; }
9 | public bool IsUnreachable { get; set; }
10 | public int LineNumber { get; set; }
11 | public string LiteralSourceCodeLine { get; set; }
12 | public int ExecutionCount { get; set; }
13 | public bool IsCovered => ExecutionCount > 0;
14 |
15 | [JsonConverter(typeof(StringEnumConverter))]
16 | public BranchCoverageState BranchState { get; set; }
17 |
18 | [JsonConverter(typeof(StringEnumConverter))]
19 | public BranchType? BranchType { get; set; }
20 |
21 | public bool IsBranch { get; set; }
22 |
23 | [JsonIgnore]
24 | public SourceFileMap SourceFileMapParent { get; set; }
25 |
26 | public int Offset { get; set; }
27 | public int OffsetEnd => Offset + Length;
28 | public int Length { get; set; }
29 |
30 | [JsonIgnore]
31 | public AstNode[] CorrelatedAstNodes { get; set; }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionStorageLoad.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.Data_Types.Accounts;
2 | using Meadow.EVM.Data_Types.Addressing;
3 | using Meadow.EVM.EVM.Execution;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.IO;
7 | using System.Numerics;
8 | using System.Text;
9 |
10 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
11 | {
12 | public class InstructionStorageLoad : InstructionBase
13 | {
14 | #region Constructors
15 | ///
16 | /// Our default constructor, reads the opcode/operand information from the provided stream.
17 | ///
18 | public InstructionStorageLoad(MeadowEVM evm) : base(evm) { }
19 | #endregion
20 |
21 | #region Functions
22 | public override void Execute()
23 | {
24 | // Pop our key off of the stack.
25 | BigInteger key = Stack.Pop();
26 |
27 | // In our current account, check the storage for this key's value and push it to the stack.
28 | Stack.Push(EVM.State.GetStorageData(Message.To, key));
29 | }
30 | #endregion
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/UnderlyingTypes/VarFixedBytes.cs:
--------------------------------------------------------------------------------
1 | using Meadow.CoverageReport.AstTypes;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes
7 | {
8 | public class VarFixedBytes : VarBase
9 | {
10 | #region Constructors
11 | public VarFixedBytes(string typeString) : base(typeString)
12 | {
13 | // Determine the size of our fixed array.
14 | int sizeBytes = VarParser.GetFixedArraySizeInBytes(BaseType);
15 |
16 | // Initialize our bounds
17 | InitializeBounds(1, sizeBytes);
18 | }
19 | #endregion
20 |
21 | #region Functions
22 | public override object ParseData(Memory data)
23 | {
24 | // If our data is not the correct size, return an empty array
25 | if (data.Length < SizeBytes)
26 | {
27 | return default(Memory);
28 | }
29 |
30 | // Slice our data off.
31 | return data.Slice(0, SizeBytes);
32 | }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionMemoryStore.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Numerics;
6 | using System.Text;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
9 | {
10 | public class InstructionMemoryStore : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionMemoryStore(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Obtain the address at which to read memory from in our memory segment.
23 | BigInteger address = Stack.Pop();
24 |
25 | // Obtain our data to store
26 | BigInteger data = Stack.Pop();
27 |
28 | // Store our data in our memory segment at the given address
29 | Memory.Write((long)address, data);
30 | }
31 | #endregion
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/NestedBranchesTests.cs:
--------------------------------------------------------------------------------
1 | using Meadow.JsonRpc.Types;
2 | using Meadow.EVM.Data_Types;
3 | using Meadow.Core.Utils;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using System.Numerics;
6 | using System.Threading.Tasks;
7 | using Meadow.Contract;
8 |
9 | namespace Meadow.UnitTestTemplate.Test
10 | {
11 |
12 | [TestClass]
13 | public class NestedBranchesTests : ContractTest
14 | {
15 | NestedBranches _contract;
16 |
17 | protected override async Task BeforeEach()
18 | {
19 | _contract = await NestedBranches.New(RpcClient);
20 | }
21 |
22 | [TestMethod]
23 | public async Task NestedStructBranches()
24 | {
25 | Assert.IsTrue(await _contract.checkStructTree(555).Call());
26 | Assert.IsFalse(await _contract.checkStructTree(111).Call());
27 | }
28 |
29 | [TestMethod]
30 | public async Task SimpleIfStatement()
31 | {
32 | Assert.IsTrue(await _contract.simpleIfStatement(true).Call());
33 | Assert.IsFalse(await _contract.simpleIfStatement(false).Call());
34 | }
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc/RpcControllerExtensions.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Core.Utils;
2 | using System.Linq;
3 | using System.Reflection;
4 |
5 | namespace Meadow.JsonRpc
6 | {
7 | public static class RpcControllerExtensions
8 | {
9 | ///
10 | /// Returns a list of rpc methods that are not defined in the interface.
11 | ///
12 | public static RpcApiMethod[] GetUndefinedRpcMethods(this IRpcController controller)
13 | {
14 | var methodAttrs = controller
15 | .GetType()
16 | .GetInterfaces()
17 | .Concat(new[] { controller.GetType() })
18 | .Distinct()
19 | .SelectMany(t => t.GetMethods(BindingFlags.Public | BindingFlags.Instance))
20 | .Select(m => m.GetCustomAttribute(inherit: true))
21 | .Where(a => a != null)
22 | .Select(a => a.Method)
23 | .ToArray();
24 |
25 | var rpcDefs = EnumExtensions.GetValues();
26 | var undefined = rpcDefs.Except(methodAttrs).ToArray();
27 | return undefined;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/AstTypes/AstMappingTypeName.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json.Linq;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Meadow.CoverageReport.AstTypes
7 | {
8 | public class AstMappingTypeName : AstElementaryTypeName
9 | {
10 | #region Properties
11 | public AstElementaryTypeName KeyType { get; }
12 | public AstElementaryTypeName ValueType { get; }
13 | #endregion
14 |
15 | #region Constructor
16 | public AstMappingTypeName(JObject node) : base(node)
17 | {
18 | // Set our properties
19 | JToken keyType = node.SelectToken("keyType");
20 | if (keyType != null)
21 | {
22 | KeyType = Create((JObject)keyType);
23 | }
24 |
25 | JToken valueType = node.SelectToken("valueType");
26 | if (valueType != null)
27 | {
28 | ValueType = Create((JObject)valueType);
29 | }
30 | }
31 |
32 | public AstMappingTypeName(AstNode node) : this(node.Node) { }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionAddMod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 | using Meadow.Core.Utils;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
10 | {
11 | public class InstructionAddMod : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionAddMod(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // Modulo divide the two added unsigned words off of the top of the stack.
24 | BigInteger a = Stack.Pop();
25 | BigInteger b = Stack.Pop();
26 | BigInteger c = Stack.Pop();
27 | BigInteger result = c == 0 ? 0 : ((a + b) % c).CapOverflow();
28 |
29 | // Push the result onto the stack.
30 | Stack.Push(result);
31 | }
32 | #endregion
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/InheritanceTests.cs:
--------------------------------------------------------------------------------
1 | using Meadow.JsonRpc.Types;
2 | using Meadow.EVM.Data_Types;
3 | using Meadow.Core.Utils;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using System.Numerics;
6 | using System.Threading.Tasks;
7 | using Meadow.Contract;
8 |
9 | namespace Meadow.UnitTestTemplate.Test
10 | {
11 |
12 | [TestClass]
13 | public class InheritanceTests : ContractTest
14 | {
15 | InheritanceChild _contract;
16 |
17 | protected override async Task BeforeEach()
18 | {
19 | _contract = await InheritanceChild.New(RpcClient);
20 | }
21 |
22 | [TestMethod]
23 | public async Task FailModifier()
24 | {
25 | await _contract.testThing(5).ExpectRevertTransaction();
26 | }
27 |
28 | [TestMethod]
29 | public async Task SuperPass()
30 | {
31 | var num = await _contract.testThing(2).Call();
32 | Assert.AreEqual(3, num);
33 | }
34 |
35 | [TestMethod]
36 | public async Task SuperFail()
37 | {
38 | await _contract.testThing(0).ExpectRevertTransaction();
39 | }
40 | }
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionMemoryLoad.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Numerics;
6 | using System.Text;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
9 | {
10 | public class InstructionMemoryLoad : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionMemoryLoad(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Obtain the address at which to read memory from in our memory segment.
23 | BigInteger address = Stack.Pop();
24 |
25 | // Read a 256-bit integer from our memory segment and append it to stack
26 | BigInteger value = Memory.ReadBigInteger((long)address);
27 |
28 | // Push our value back onto the stack.
29 | Stack.Push(value);
30 | }
31 | #endregion
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.TestApp/Contracts/OtherContract.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 |
4 | contract OtherContract {
5 |
6 | event DataEvent(uint _int1, uint _int2, uint indexed _int3, string _str, uint indexed _int7, address[] _addrs, bytes _bytes, string _mystr);
7 |
8 | event TestEvent(address indexed _addr, uint64 indexed _id, uint _val, uint _timestamp);
9 |
10 | /// @notice The constructor
11 | constructor() public {
12 |
13 | }
14 |
15 | function emitDataEvent(uint _int1, uint _int2, uint _int3) public {
16 | address[] memory addrs = new address[](12);
17 | for (uint i = 0; i < 12; i++) {
18 | addrs[i] = address(i);
19 | }
20 | bytes memory b = new bytes(9);
21 | b[3] = byte(3);
22 |
23 | emit DataEvent(_int1, _int2, _int3,
24 | "All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log. All non-indexed arguments will be stored in the data part of the log.",
25 | 7, addrs, b, "another string that should be hashed since its indexed");
26 | }
27 |
28 | }
--------------------------------------------------------------------------------
/src/Meadow.Core/AccountDerivation/SystemRandomAccountDerivation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Security.Cryptography;
4 | using System.Text;
5 |
6 | namespace Meadow.Core.AccountDerivation
7 | {
8 | public class SystemRandomAccountDerivation : AccountDerivationBase
9 | {
10 | Action _getRandomBytes;
11 |
12 | public SystemRandomAccountDerivation(int? seed = null)
13 | {
14 | if (seed.HasValue)
15 | {
16 | var rnd = new Random(seed.Value);
17 | _getRandomBytes = bytes =>
18 | {
19 | rnd.NextBytes(bytes);
20 | };
21 | }
22 | else
23 | {
24 | var rnd = RandomNumberGenerator.Create();
25 | _getRandomBytes = bytes =>
26 | {
27 | rnd.GetBytes(bytes);
28 | };
29 | }
30 | }
31 |
32 | public override byte[] GeneratePrivateKey(uint accountIndex)
33 | {
34 | var data = new byte[32];
35 | _getRandomBytes(data);
36 | return data;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionMultiplyMod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 | using Meadow.Core.Utils;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
10 | {
11 | public class InstructionMultiplyMod : InstructionBase
12 | {
13 | #region Constructors
14 | ///
15 | /// Our default constructor, reads the opcode/operand information from the provided stream.
16 | ///
17 | public InstructionMultiplyMod(MeadowEVM evm) : base(evm) { }
18 | #endregion
19 |
20 | #region Functions
21 | public override void Execute()
22 | {
23 | // Modulo divide the two multiplied unsigned words off of the top of the stack.
24 | BigInteger a = Stack.Pop();
25 | BigInteger b = Stack.Pop();
26 | BigInteger c = Stack.Pop();
27 | BigInteger result = c == 0 ? 0 : ((a * b) % c).CapOverflow();
28 |
29 | // Push the result onto the stack.
30 | Stack.Push(result);
31 | }
32 | #endregion
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/System Operations/InstructionRevert.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Numerics;
6 | using System.Text;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.System_Operations
9 | {
10 | public class InstructionRevert : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionRevert(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Obtain the offset and size of the data to copy from memory as our result.
23 | BigInteger offset = Stack.Pop();
24 | BigInteger size = Stack.Pop();
25 |
26 | // We'll want to return with our read memory, our remaining gas, and indicating we wish to revert changes.
27 | Return(new EVMExecutionResult(EVM, Memory.ReadBytes((long)offset, (int)size), GasState.Gas, false));
28 | }
29 | #endregion
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Models/CoverageStats.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Meadow.CoverageReport.Models
6 | {
7 | public class CoverageStats
8 | {
9 | public int LineCount { get; set; }
10 | public int LineCoveredCount { get; set; }
11 | public double LineCoveragePercent => GetPercent(LineCount, LineCoveredCount);
12 |
13 | public int BranchCount { get; set; }
14 | public int BranchCoveredCount { get; set; }
15 | public double BranchCoveragePercent => GetPercent(BranchCount, BranchCoveredCount);
16 |
17 | public int FunctionCount { get; set; }
18 | public int FunctionCoveredCount { get; set; }
19 | public double FunctionCoveragePercent => GetPercent(FunctionCount, FunctionCoveredCount);
20 |
21 | static double GetPercent(int total, int hit)
22 | {
23 | if (total == 0 && hit == 0)
24 | {
25 | return 100;
26 | }
27 |
28 | if (hit == 0)
29 | {
30 | return 0;
31 | }
32 |
33 | return Math.Round((hit / (double)total) * 100, 2);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/System Operations/InstructionReturn.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Numerics;
6 | using System.Text;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.System_Operations
9 | {
10 | public class InstructionReturn : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionReturn(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Obtain the offset and size of the data to copy from memory as our result.
23 | BigInteger offset = Stack.Pop();
24 | BigInteger size = Stack.Pop();
25 |
26 | // We'll want to return with our read memory, our remaining gas, and indicating we don't wish to revert changes.
27 | Return(new EVMExecutionResult(EVM, Memory.ReadBytes((long)offset, (int)size), GasState.Gas, true));
28 | }
29 | #endregion
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc.Server.Proxy.Test/Meadow.JsonRpc.Server.Proxy.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 |
7 |
8 |
9 |
10 | all
11 | runtime; build; native; contentfiles; analyzers
12 |
13 |
14 |
15 |
16 | all
17 | runtime; build; native; contentfiles; analyzers
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen/ContractInfo.cs:
--------------------------------------------------------------------------------
1 | using SolcNet.DataDescription.Output;
2 |
3 | namespace Meadow.SolCodeGen
4 | {
5 | class ContractInfo
6 | {
7 | public readonly string SolFile;
8 | public readonly string ContractName;
9 | public readonly SolcNet.DataDescription.Output.Contract ContractOutput;
10 | public readonly byte[] Hash;
11 | public readonly string Bytecode;
12 |
13 | public ContractInfo(string solFile, string contractName, SolcNet.DataDescription.Output.Contract contractOutput, byte[] hash, string bytecode)
14 | {
15 | SolFile = solFile;
16 | ContractName = contractName;
17 | ContractOutput = contractOutput;
18 | Hash = hash;
19 | Bytecode = bytecode;
20 | }
21 |
22 | public void Deconstruct(out string solFile, out string contractName, out SolcNet.DataDescription.Output.Contract contractOuput, out byte[] hash, out string bytecode)
23 | {
24 | solFile = SolFile;
25 | contractName = ContractName;
26 | contractOuput = ContractOutput;
27 | hash = Hash;
28 | bytecode = Bytecode;
29 | }
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate/InternalTestState.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace Meadow.UnitTestTemplate
6 | {
7 | ///
8 | /// Provides information regarding the state of a test, as needed by this test framework.
9 | ///
10 | internal class InternalTestState
11 | {
12 | #region Properties
13 | ///
14 | /// Indicates if tests are working on/should be working on an external node.
15 | ///
16 | internal bool InExternalNodeContext { get; set; }
17 |
18 | ///
19 | /// Indicates the test start time.
20 | ///
21 | internal DateTimeOffset StartTime { get; set; }
22 | ///
23 | /// Indicates the test end time.
24 | ///
25 | internal DateTimeOffset EndTime { get; set; }
26 |
27 | ///
28 | /// Indicates whether test initialization occurred without error.
29 | ///
30 | internal bool InitializationSuccess { get; set; }
31 |
32 | internal string CustomDisplayName { get; set; }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.JsonRpc.Server.Proxy/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net;
3 | using System.Threading.Tasks;
4 |
5 | namespace Meadow.JsonRpc.Server.Proxy
6 | {
7 | class Program
8 | {
9 | static async Task Main(string[] args)
10 | {
11 | // TODO: command line args for port and host
12 |
13 | // Default ganache gui port.
14 | int targetServerPort = 7545;
15 |
16 | // Default to localhost.
17 | string host = IPAddress.Loopback.ToString();
18 |
19 | int proxyServerPort = 7117;
20 |
21 | string proxyUri = $"http://{IPAddress.Loopback}:{proxyServerPort}";
22 | string serverUri = $"http://{host}:{targetServerPort}";
23 |
24 | Console.WriteLine($"Proxying calls to server at {serverUri}");
25 |
26 | Console.WriteLine($"Launching server proxy, listening at {proxyUri}");
27 | var rpcServerProxy = new RpcServerProxy(new Uri(serverUri), proxyServerPort);
28 | await rpcServerProxy.StartServerAsync();
29 | Console.WriteLine("Server started and listening...");
30 |
31 | await rpcServerProxy.WaitForServerShutdownAsync();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.TestApp/Contracts/Ownable.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 |
4 | /**
5 | * @title Ownable
6 | * @dev The Ownable contract has an owner address, and provides basic authorization control
7 | * functions, this simplifies the implementation of "user permissions".
8 | */
9 | contract Ownable {
10 | address public owner;
11 |
12 |
13 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
14 |
15 |
16 | /**
17 | * @dev The Ownable constructor sets the original `owner` of the contract to the sender
18 | * account.
19 | */
20 | function Ownable() public {
21 | owner = msg.sender;
22 | }
23 |
24 | /**
25 | * @dev Throws if called by any account other than the owner.
26 | */
27 | modifier onlyOwner() {
28 | require(msg.sender == owner);
29 | _;
30 | }
31 |
32 | /**
33 | * @dev Allows the current owner to transfer control of the contract to a newOwner.
34 | * @param newOwner The address to transfer ownership to.
35 | */
36 | function transferOwnership(address newOwner) public onlyOwner {
37 | require(newOwner != address(0));
38 | emit OwnershipTransferred(owner, newOwner);
39 | owner = newOwner;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/Meadow.Core/EthTypes/FixedMxN.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Runtime.InteropServices;
4 | using System.Text;
5 |
6 | // Disabled, currently unused
7 |
8 | /*
9 | namespace Meadow.Core.EthTypes
10 | {
11 | public interface IFixedN
12 | {
13 | int Decimals { get; }
14 | }
15 |
16 | ///
17 | /// Where M represents the number of bits taken by the type
18 | /// and N represents how many decimal points are available.
19 | /// M must be divisible by 8 and goes from 8 to 256 bits.
20 | /// N must be between 0 and 80, inclusive. ufixed and fixed
21 | /// are aliases for ufixed128x19 and fixed128x19, respectively.
22 | ///
23 | [StructLayout(LayoutKind.Sequential)]
24 | public struct Fixed where M : struct where N : struct, IFixedN
25 | {
26 | readonly M Value;
27 |
28 | public int Decimals => default(N).Decimals;
29 |
30 |
31 | }
32 |
33 | [StructLayout(LayoutKind.Sequential)]
34 | public struct UFixed where M : struct where N : struct, IFixedN
35 | {
36 | readonly M Value;
37 |
38 | public int Decimals => default(N).Decimals;
39 |
40 |
41 | }
42 | }
43 | */
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Arithmetic/InstructionSignedMod.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.EVM.Execution;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Arithmetic
9 | {
10 | public class InstructionSignedMod : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionSignedMod(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Modulo divide the two signed words off of the top of the stack.
23 | BigInteger a = Stack.Pop(true);
24 | BigInteger b = Stack.Pop(true);
25 | BigInteger result = 0;
26 | if (a != 0)
27 | {
28 | result = a.Sign * (BigInteger.Abs(a) % BigInteger.Abs(b));
29 | }
30 |
31 | // Push the result onto the stack.
32 | Stack.Push(result);
33 | }
34 | #endregion
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Environment/InstructionExternalCodeSize.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.Data_Types.Addressing;
8 | using Meadow.EVM.EVM.Execution;
9 |
10 | namespace Meadow.EVM.EVM.Instructions.Environment
11 | {
12 | public class InstructionExternalCodeSize : InstructionBase
13 | {
14 | #region Constructors
15 | ///
16 | /// Our default constructor, reads the opcode/operand information from the provided stream.
17 | ///
18 | public InstructionExternalCodeSize(MeadowEVM evm) : base(evm) { }
19 | #endregion
20 |
21 | #region Functions
22 | public override void Execute()
23 | {
24 | // Obtain our external account address
25 | Address externalCodeAddress = Stack.Pop();
26 |
27 | // Obtain our code segment
28 | byte[] codeSegment = EVM.State.GetCodeSegment(externalCodeAddress);
29 |
30 | // Push the code size to the stack.
31 | Stack.Push(codeSegment.Length);
32 | }
33 | #endregion
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Control Flow and IO/InstructionMemoryStore8.cs:
--------------------------------------------------------------------------------
1 | using Meadow.EVM.EVM.Execution;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Numerics;
6 | using System.Text;
7 |
8 | namespace Meadow.EVM.EVM.Instructions.Control_Flow_and_IO
9 | {
10 | public class InstructionMemoryStore8 : InstructionBase
11 | {
12 | #region Constructors
13 | ///
14 | /// Our default constructor, reads the opcode/operand information from the provided stream.
15 | ///
16 | public InstructionMemoryStore8(MeadowEVM evm) : base(evm) { }
17 | #endregion
18 |
19 | #region Functions
20 | public override void Execute()
21 | {
22 | // Obtain the address at which to read memory from in our memory segment.
23 | BigInteger address = Stack.Pop();
24 |
25 | // Obtain our data to store
26 | BigInteger data = Stack.Pop();
27 | byte storeData = (byte)(data & 0xFF);
28 |
29 | // Store our data in our memory segment at the given address
30 | Memory.Write((long)address, storeData);
31 | }
32 | #endregion
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.VSCode.Debugger/src/logger.ts:
--------------------------------------------------------------------------------
1 | import * as vscode from "vscode";
2 | import * as util from 'util';
3 |
4 | export class Logger {
5 |
6 | private static outputChannel : vscode.OutputChannel = vscode.window.createOutputChannel("Meadow Solidity Debugger");
7 |
8 | private static _didShow: boolean = false;
9 |
10 | public static log(message: string, ...params: any[]): void {
11 | if (!this._didShow) {
12 | this._didShow = true;
13 | this.show();
14 | }
15 | this.outputChannel.appendLine(message);
16 | params.forEach(p => this.outputChannel.appendLine(util.inspect(p)));
17 |
18 | if (this._isDebugging) {
19 | console.log(message);
20 | params.forEach(p => console.log(p));
21 | }
22 | }
23 |
24 | public static show(): void {
25 | this.outputChannel.show();
26 | }
27 |
28 | private static _isDebugging: boolean;
29 |
30 | static init() {
31 | try {
32 | const isDebuggingRegex = /^--inspect(-brk)?=?/;
33 | const args = process.execArgv;
34 | this._isDebugging = args ? args.some(arg => isDebuggingRegex.test(arg)) : false;
35 | } catch { }
36 | }
37 | }
38 |
39 | Logger.init();
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/Pairing/UnderlyingVariableValuePair.cs:
--------------------------------------------------------------------------------
1 | using Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace Meadow.CoverageReport.Debugging.Variables.Pairing
7 | {
8 | ///
9 | /// Similar to but instead including the underlying variable object "" instead of a type.
10 | ///
11 | public struct UnderlyingVariableValuePair
12 | {
13 | #region Properties
14 | public readonly VarBase Variable;
15 | public readonly object Value;
16 | #endregion
17 |
18 | #region Constructor
19 | public UnderlyingVariableValuePair(VarBase variable, object value)
20 | {
21 | // Set our properties
22 | Variable = variable;
23 | Value = value;
24 | }
25 |
26 | public UnderlyingVariableValuePair(VariableValuePair variableValuePair)
27 | {
28 | // Set our properties
29 | Variable = variableValuePair.Variable.ValueParser;
30 | Value = variableValuePair.Value;
31 | }
32 | #endregion
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/Debugging/Variables/UnderlyingTypes/VarAddress.cs:
--------------------------------------------------------------------------------
1 | using Meadow.Core.EthTypes;
2 | using Meadow.CoverageReport.AstTypes;
3 | using Meadow.CoverageReport.Debugging.Variables.Enums;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Text;
7 |
8 | namespace Meadow.CoverageReport.Debugging.Variables.UnderlyingTypes
9 | {
10 | public class VarAddress : VarBase
11 | {
12 | #region Constructors
13 | public VarAddress(string typeString) : base(typeString)
14 | {
15 | // Initialize our bounds
16 | InitializeBounds(1, Address.SIZE);
17 | }
18 | #endregion
19 |
20 | #region Functions
21 | public override object ParseData(Memory data)
22 | {
23 | // If there is insufficient data, return a zero address.
24 | if (data.Length < Address.SIZE)
25 | {
26 | return new Address(new byte[Address.SIZE]);
27 | }
28 | else
29 | {
30 | // Otherwise the boolean is parsed from the first byte.
31 | return new Address(data.Slice(data.Length - Address.SIZE, Address.SIZE).ToArray());
32 | }
33 | }
34 | #endregion
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Meadow.TestNode.Host/ProcessArgs.cs:
--------------------------------------------------------------------------------
1 | using McMaster.Extensions.CommandLineUtils;
2 |
3 | namespace Meadow.TestNode.Host
4 | {
5 |
6 | class ProcessArgs
7 | {
8 | [Option("-p|--port", "TODO.", CommandOptionType.SingleValue)]
9 | public uint Port { get; } = 8747;
10 |
11 | [Option("-h|--host", "TODO", CommandOptionType.SingleValue)]
12 | public string Host { get; } = "127.0.0.1";
13 |
14 | [Option("-a|--account_count", "TODO", CommandOptionType.SingleValue)]
15 | public uint AccountCount { get; } = 100;
16 |
17 | [Option("-b|--account_balance", "TODO", CommandOptionType.SingleValue)]
18 | public uint AccountBalance { get; } = 1000;
19 |
20 | [Option("-m|--mnemonic", "TODO", CommandOptionType.SingleValue)]
21 | public string Mnemonic { get; }
22 |
23 | [Option("--proxy_node", "TODO", CommandOptionType.SingleValue)]
24 | public string Proxy { get; }
25 |
26 | public static ProcessArgs Parse(string[] args)
27 | {
28 | var app = new CommandLineApplication(throwOnUnexpectedArg: true);
29 | app.Conventions.UseDefaultConventions();
30 | app.Parse(args);
31 | return app.Model;
32 | }
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/Meadow.DebugAdapterServer/DebuggerTransport/NamedPipeServerDebuggerTransport.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using System.IO.Pipes;
3 |
4 | namespace Meadow.DebugAdapterServer.DebuggerTransport
5 | {
6 | public class NamedPipeServerDebuggerTransport : IDebuggerTransport
7 | {
8 | readonly NamedPipeServerStream _pipeServer;
9 |
10 | public Stream InputStream => _pipeServer;
11 | public Stream OutputStream => _pipeServer;
12 |
13 | public void Dispose()
14 | {
15 | try
16 | {
17 | if (_pipeServer.IsConnected)
18 | {
19 | _pipeServer.Disconnect();
20 | }
21 | }
22 | catch { }
23 |
24 | _pipeServer.Dispose();
25 | }
26 |
27 | public NamedPipeServerDebuggerTransport()
28 | {
29 | // Setup named pipe server.
30 | var debugSessionID = SolidityDebugger.SolidityDebugSessionID;
31 | _pipeServer = new NamedPipeServerStream(debugSessionID, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
32 |
33 | // Wait for debug adapter proxy to connect.
34 | _pipeServer.WaitForConnection();
35 | }
36 |
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/Meadow.EVM/EVM/Instructions/Stack/InstructionSwap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Numerics;
5 | using System.Text;
6 | using Meadow.EVM.Data_Types;
7 | using Meadow.EVM.EVM.Execution;
8 |
9 | namespace Meadow.EVM.EVM.Instructions.Stack
10 | {
11 | public class InstructionSwap : InstructionBase
12 | {
13 | #region Properties
14 | public uint SwapIndex { get; }
15 | #endregion
16 |
17 | #region Constructors
18 | ///
19 | /// Our default constructor, reads the opcode/operand information from the provided stream.
20 | ///
21 | public InstructionSwap(MeadowEVM evm) : base(evm)
22 | {
23 | // This class handles multiple swap operations (various indexes).
24 | // The opcodes are linear, so we can calculate the index based off opcode.
25 | SwapIndex = (uint)(Opcode - InstructionOpcode.SWAP1) + 1;
26 | }
27 | #endregion
28 |
29 | #region Functions
30 | public override void Execute()
31 | {
32 | // Swap the top item on the stack with the one at the provided index.
33 | Stack.Swap(SwapIndex);
34 | }
35 | #endregion
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/Meadow.UnitTestTemplate.Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp2.1
5 | false
6 | Meadow.UnitTestTemplate.Test.GlobalSetup
7 |
8 |
9 |
10 |
11 | all
12 | runtime; build; native; contentfiles; analyzers
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.TestApp/Contracts/CappedCrowdsale.sol:
--------------------------------------------------------------------------------
1 | pragma solidity ^0.4.21;
2 |
3 | import "./SafeMath.sol";
4 | import "./Crowdsale.sol";
5 |
6 |
7 | /**
8 | * @title CappedCrowdsale
9 | * @dev Crowdsale with a limit for total contributions.
10 | */
11 | contract CappedCrowdsale is Crowdsale {
12 | using SafeMath for uint256;
13 |
14 | uint256 public cap;
15 |
16 | /**
17 | * @dev Constructor, takes maximum amount of wei accepted in the crowdsale.
18 | * @param _cap Max amount of wei to be contributed
19 | */
20 | function CappedCrowdsale(uint256 _cap) public {
21 | require(_cap > 0);
22 | cap = _cap;
23 | }
24 |
25 | /**
26 | * @dev Checks whether the cap has been reached.
27 | * @return Whether the cap was reached
28 | */
29 | function capReached() public view returns (bool) {
30 | return weiRaised >= cap;
31 | }
32 |
33 | /**
34 | * @dev Extend parent behavior requiring purchase to respect the funding cap.
35 | * @param _beneficiary Token purchaser
36 | * @param _weiAmount Amount of wei contributed
37 | */
38 | function _preValidatePurchase(address _beneficiary, uint256 _weiAmount) internal {
39 | super._preValidatePurchase(_beneficiary, _weiAmount);
40 | require(weiRaised.add(_weiAmount) <= cap);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/Meadow.UnitTestTemplate.Test/TestsIgnoredContracts.cs:
--------------------------------------------------------------------------------
1 | using Meadow.JsonRpc.Types;
2 | using Meadow.EVM.Data_Types;
3 | using Meadow.Core.Utils;
4 | using Microsoft.VisualStudio.TestTools.UnitTesting;
5 | using System.Numerics;
6 | using System.Threading.Tasks;
7 | using Meadow.Contract;
8 |
9 | namespace Meadow.UnitTestTemplate.Test
10 | {
11 |
12 | [TestClass]
13 | public class TestsIgnoredContracts : ContractTest
14 | {
15 |
16 | protected override Task BeforeEach()
17 | {
18 | return Task.CompletedTask;
19 | }
20 |
21 | [TestMethod]
22 | public async Task MockContractFunction()
23 | {
24 | var contract = await MockContract.New(RpcClient);
25 | string testStr = "test string 1234";
26 | var resultStr = await contract.echoString(testStr).Call();
27 | Assert.AreEqual(testStr, resultStr);
28 | }
29 |
30 | [TestMethod]
31 | public async Task IgnoreContractFunction()
32 | {
33 | var contract = await IgnoreContract.New(RpcClient);
34 | string testStr = "test string 1234";
35 | var resultStr = await contract.echoString(testStr).Call();
36 | Assert.AreEqual(testStr, resultStr);
37 | }
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/src/Meadow.Cli/Help/Watch-Solidity.md:
--------------------------------------------------------------------------------
1 | # Watch-Solidity
2 |
3 | ## SYNOPSIS
4 | This Cmdlet lets Meadow.Cli look for active changes in your contracts.
5 |
6 | ## SYNTAX
7 |
8 | ### Watch Solidity Parameters
9 | ```
10 | Watch-Solidity []
11 | ```
12 |
13 | ## DESCRIPTION
14 | This Cmdlet allows Meadow.Cli watch for changes in your solidity contracts and respond live.
15 |
16 | ## EXAMPLES
17 |
18 | ### EXAMPLE 1
19 | Basic use
20 | ```powershell
21 | C:\PS> Watch-Solidity
22 | ```
23 |
24 | This examples shows how to start the file watcher so that Meadow.Cli can respond to changes in your contracts live.
25 |
26 | ## PARAMETERS
27 |
28 | ### \
29 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
30 |
31 | ## INPUTS
32 |
33 | ### None
34 |
35 |
36 | ## OUTPUTS
37 |
38 | ### None
39 |
40 |
41 | ## NOTES
42 |
43 | ## RELATED LINKS
44 |
45 | [Meadow Suite site link:](https://meadowsuite.com)
46 |
47 | [Hosho Group site link:](https://hosho.io)
48 |
49 |
50 | *Generated by: PowerShell HelpWriter 2018 v2.2.40*
51 |
--------------------------------------------------------------------------------
/src/Meadow.Core/AccountDerivation/AccountDerivationBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Meadow.Core.AccountDerivation
4 | {
5 | public delegate byte[] GenerateAccountKeyDelegate(uint accountIndex);
6 |
7 | public interface IAccountDerivation
8 | {
9 | byte[] GeneratePrivateKey(uint accountIndex);
10 | }
11 |
12 | public abstract class AccountDerivationBase : IAccountDerivation
13 | {
14 | public virtual byte[] Seed { get; set; }
15 |
16 | public abstract byte[] GeneratePrivateKey(uint accountIndex);
17 |
18 | class AccountDerivationFactory : AccountDerivationBase
19 | {
20 | GenerateAccountKeyDelegate _generateAccount;
21 |
22 | public AccountDerivationFactory(GenerateAccountKeyDelegate generateAccount)
23 | {
24 | _generateAccount = generateAccount;
25 | }
26 |
27 | public override byte[] GeneratePrivateKey(uint accountIndex)
28 | {
29 | return _generateAccount(accountIndex);
30 | }
31 | }
32 |
33 | public static IAccountDerivation Create(GenerateAccountKeyDelegate generateAccount)
34 | {
35 | return new AccountDerivationFactory(generateAccount);
36 | }
37 | }
38 |
39 |
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/Meadow.SolCodeGen.Test/Util.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 |
7 | namespace Meadow.SolCodeGen.Test
8 | {
9 | public static class Util
10 | {
11 | private static string _solutionDir;
12 |
13 | public static string FindSolutionDirectory()
14 | {
15 | if (_solutionDir != null)
16 | {
17 | return _solutionDir;
18 | }
19 |
20 | const string TEST_PROJ_DIR_NAME = "Meadow.SolCodeGen.Test";
21 |
22 | // Find the solution directory (start at this assembly directory and move up).
23 | var cwd = typeof(Integration).Assembly.Location;
24 | string checkDir = null;
25 | do
26 | {
27 | cwd = Path.GetDirectoryName(cwd);
28 | var children = Directory.GetDirectories(cwd, TEST_PROJ_DIR_NAME, SearchOption.TopDirectoryOnly);
29 | if (children.Any(p => p.EndsWith(TEST_PROJ_DIR_NAME, StringComparison.Ordinal)))
30 | {
31 | checkDir = cwd;
32 | }
33 | }
34 | while (checkDir == null);
35 |
36 | return _solutionDir = checkDir;
37 | }
38 |
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Meadow.CoverageReport/AnalysisResults.cs:
--------------------------------------------------------------------------------
1 | using SolcNet.DataDescription.Output;
2 | using System.Collections.Generic;
3 |
4 | namespace Meadow.CoverageReport
5 | {
6 | public class AnalysisResults
7 | {
8 | ///
9 | /// All nodes with no filtering.
10 | ///
11 | public AstNode[] FullNodeList { get; set; }
12 |
13 | ///
14 | /// All nodes that have a corresponding sourcemap entry.
15 | ///
16 | public AstNode[] ReachableNodes { get; set; }
17 |
18 | ///
19 | /// All nodes that represent executable source code
20 | ///
21 | public AstNode[] AllActiveNodes { get; set; }
22 |
23 | ///
24 | /// All nodes that have executable source code which are not compiled into the bytecode and thus are
25 | /// unreachable.
26 | ///
27 | public AstNode[] UnreachableNodes { get; set; }
28 |
29 | public AstNode[] FunctionNode { get; set; }
30 |
31 | public (AstNode Node, BranchType BranchType)[] BranchNodes { get; set; }
32 |
33 | public IReadOnlyDictionary<(string FileName, string ContractName, string BytecodeHash), (SourceMapEntry[] NonDeployed, SourceMapEntry[] Deployed)> SourceMaps;
34 |
35 | }
36 | }
37 |
--------------------------------------------------------------------------------