Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync neo-core #414

Merged
merged 47 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0bc7234
update
Tommo-L Dec 24, 2020
663c607
reset
Tommo-L Dec 24, 2020
2f64647
CI01123
Tommo-L Dec 24, 2020
2a01c48
optimize
Tommo-L Dec 24, 2020
17d56c6
add ut
Tommo-L Dec 24, 2020
a501a06
Remove callback api
Tommo-L Dec 25, 2020
3917efa
Merge branch 'master' into sync_neo
Tommo-L Dec 28, 2020
65c2d37
Add more methods
shargon Jan 5, 2021
c29df40
Change to enum
shargon Jan 5, 2021
3ea7aa5
Merge branch 'master' into sync_neo
erikzhang Jan 6, 2021
12c45fc
sync to neo
Jan 7, 2021
953e023
Merge branch 'sync_neo' of https://github.com/Tommo-L/neo-devpack-dot…
Jan 7, 2021
163c893
fix
Jan 7, 2021
d73ee04
Fix compilation
shargon Jan 7, 2021
a3fb53d
Fix some UT
shargon Jan 7, 2021
16ec4b1
sync to neo
Jan 8, 2021
d232ab1
fix
Jan 8, 2021
2af846b
fix
Jan 8, 2021
35a58b5
Fix dynamic call
erikzhang Jan 10, 2021
1e49b04
Fix hashes and update nuget
shargon Jan 10, 2021
9adf4aa
Some fixes
shargon Jan 10, 2021
e05465a
More fixes
shargon Jan 10, 2021
61581b7
Fix Iterator
erikzhang Jan 10, 2021
d45fb3c
More Fixes
shargon Jan 10, 2021
bb38513
Fix deploy id
shargon Jan 10, 2021
4d39bec
Merge remote-tracking branch 'Tommo-L/sync_neo' into sync_neo
shargon Jan 10, 2021
4ceb1dc
Fix types
erikzhang Jan 10, 2021
9138e5f
Fix some UT
shargon Jan 11, 2021
784813b
Add ToBigInteger from ByteString
shargon Jan 11, 2021
7aae619
Fix InvocationCounter test
shargon Jan 11, 2021
ee341ad
More ut fixes
shargon Jan 11, 2021
395a835
Fix Iterator UT
shargon Jan 11, 2021
8febdf5
Fix Contract.Call UT
shargon Jan 11, 2021
72a253c
Fix UTs
shargon Jan 11, 2021
04919dd
Test Func
shargon Jan 11, 2021
c08f2cd
rename ToBigInteger to Parse
Tommo-L Jan 12, 2021
7b9a64f
add contract dynamic call
Tommo-L Jan 12, 2021
f04fc80
Fix UT
shargon Jan 12, 2021
1745ec3
Replace ToBigInteger to cast
shargon Jan 12, 2021
08f85b5
Replace ToBigInteger by BigInteger.Parse
shargon Jan 12, 2021
44e52f4
check type
shargon Jan 12, 2021
2138a96
Restore comment
shargon Jan 12, 2021
52eb0d2
Use last nuget
shargon Jan 12, 2021
a408bad
Add Parse overloads
shargon Jan 12, 2021
0963d10
Fix 1 arg call
shargon Jan 12, 2021
e110b33
Add Atoi
shargon Jan 12, 2021
aea745d
Test void return
shargon Jan 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 63 additions & 24 deletions src/Neo.Compiler.MSIL/MSIL/CctorSubVM.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo.Cryptography;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace Neo.Compiler.MSIL
Expand Down Expand Up @@ -191,28 +192,72 @@ public static bool Parse(ILMethod from, NeoModule to)
p2[i] = p1[i];
}
}
else if (m.DeclaringType.FullName == "System.Numerics.BigInteger" && m.Name == "op_Implicit")
else if (m.DeclaringType.FullName == "System.Numerics.BigInteger")
{
var type = m.Parameters[0].ParameterType.FullName;
if (type == "System.UInt64")
if (m.Name == "op_Implicit")
{
var p = (ulong)(long)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
else if (type == "System.UInt32")
{
var p = (ulong)(int)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
else if (type == "System.Int64")
{
var p = (long)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
var type = m.Parameters[0].ParameterType.FullName;
if (type == "System.UInt64")
{
var p = (ulong)(long)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
else if (type == "System.UInt32")
{
var p = (ulong)(int)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
else if (type == "System.Int64")
{
var p = (long)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
else
{
var p = (int)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
}
}
else
else if (m.Name == "Parse")
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
var p = (int)calcStack.Pop();
calcStack.Push(new System.Numerics.BigInteger(p).ToByteArray());
switch (calcStack.Count)
{
case 1:
{
var p = calcStack.Pop();
if (p is string pstr)
{
p = System.Numerics.BigInteger.Parse(pstr);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
calcStack.Push(p);
break;
}

throw new InvalidOperationException("Unsupported call to BigInteger.Parse");
}
case 2:
{
var s = calcStack.Pop();
var p = calcStack.Pop();
if (p is string pstr)
{
if (s is int)
{
p = System.Numerics.BigInteger.Parse(pstr, (NumberStyles)s);
calcStack.Push(p);
break;
}
else if (s is IFormatProvider)
{
p = System.Numerics.BigInteger.Parse(pstr, (IFormatProvider)s);
calcStack.Push(p);
break;
}
}

throw new InvalidOperationException("Unsupported call to BigInteger.Parse");
}
default: throw new InvalidOperationException("Unsupported call to BigInteger.Parse");
}
}
}
else
Expand Down Expand Up @@ -247,12 +292,6 @@ public static bool Parse(ILMethod from, NeoModule to)
if (reverse) hex = hex.Reverse().ToArray();
calcStack.Push(hex);
}
else if (attrname == "ToBigInteger")
{
var text = (string)calcStack.Pop();
var n = System.Numerics.BigInteger.Parse(text);
calcStack.Push(n);
}
}
if (attr.AttributeType.FullName == "Neo.SmartContract.Framework.SyscallAttribute")
{
Expand Down
15 changes: 14 additions & 1 deletion src/Neo.Compiler.MSIL/MSIL/Conv_Multi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -756,6 +757,13 @@ private int ConvertCall(OpCode src, NeoMethod to)
Insert1(VM.OpCode.SYSCALL, "", to, BitConverter.GetBytes(ApplicationEngine.System_Binary_Itoa));
return 0;
}
else if (src.tokenMethod == "System.Numerics.BigInteger System.Numerics.BigInteger::Parse(System.String)")
{
ConvertPushNumber(10, null, to); // Push Base
Convert1by1(VM.OpCode.SWAP, src, to); // Swap arguments
Insert1(VM.OpCode.SYSCALL, "", to, BitConverter.GetBytes(ApplicationEngine.System_Binary_Atoi));
return 0;
}
}

if (calltype == 0)
Expand Down Expand Up @@ -879,7 +887,7 @@ private int ConvertCall(OpCode src, NeoMethod to)
}
return 0;
}
else if (calltype == 4)
else if (calltype == 4) // is sdk contract call
{
if (defs.IsGetter
&& defs.CustomAttributes.Any(a => a.AttributeType.FullName == "Neo.SmartContract.Framework.ContractHashAttribute"))
Expand All @@ -892,6 +900,9 @@ private int ConvertCall(OpCode src, NeoMethod to)
ConvertPushNumber(pcount, null, to);
Convert1by1(VM.OpCode.PACK, null, to);

// Push CallFlag.All to the tail of stack
ConvertPushNumber((int)CallFlags.All, null, to);

// Push call method name, the first letter should be lowercase.
ConvertPushString(GetMethodName(defs.Body.Method), src, to);

Expand Down Expand Up @@ -923,8 +934,10 @@ private int ConvertCall(OpCode src, NeoMethod to)
}
else if (calltype == 6)
{
ConvertPushNumber((int)CallFlags.All, null, to); // add CallFlag
ConvertPushNumber(callpcount, src, to);
Convert1by1(VM.OpCode.ROLL, null, to);
Convert1by1(VM.OpCode.REVERSE4, null, to);
Convert1by1(VM.OpCode.SYSCALL, null, to, BitConverter.GetBytes(ApplicationEngine.System_Contract_Call));
}
else if (calltype == 3)
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.4.0" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="3.4.0" />
<PackageReference Include="Mono.Cecil" Version="0.11.2" />
<PackageReference Include="Neo" Version="3.0.0-CI01119" />
<PackageReference Include="Neo" Version="3.0.0-CI01149" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Neo.Compiler.MSIL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public static int Compile(Options options, ILogger log = null)
Compiler = "neon",
Version = Version.Parse(((AssemblyFileVersionAttribute)Assembly.GetAssembly(typeof(Program))
.GetCustomAttribute(typeof(AssemblyFileVersionAttribute))).Version).ToString(),
Tokens = Array.Empty<MethodToken>(),
Script = bytes
};
nef.CheckSum = NefFile.ComputeChecksum(nef);
Expand Down
11 changes: 11 additions & 0 deletions src/Neo.SmartContract.Framework/ByteString.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Numerics;

namespace Neo.SmartContract.Framework
{
public abstract class ByteString
Expand Down Expand Up @@ -25,5 +27,14 @@ public extern int Length

[OpCode(OpCode.CONVERT, StackItemType.ByteString)]
public static extern explicit operator ByteString(byte[] buffer);

[OpCode(OpCode.DUP)]
[OpCode(OpCode.ISNULL)]
[OpCode(OpCode.JMPIFNOT, "0x05")]
[OpCode(OpCode.PUSH0)]
[OpCode(OpCode.SWAP)]
[OpCode(OpCode.DROP)]
[OpCode(OpCode.CONVERT, StackItemType.Integer)]
public static extern explicit operator BigInteger(ByteString text);
}
}
6 changes: 3 additions & 3 deletions src/Neo.SmartContract.Framework/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public static byte ToByte(this int source)
[OpCode(OpCode.CAT)]
public extern static byte[] Concat(this byte[] first, byte[] second);

[OpCode(OpCode.CAT)]
public extern static byte[] Concat(this byte[] first, ByteString second);

[NonemitWithConvert(ConvertMethod.HexToBytes)]
public extern static byte[] HexToBytes(this string hex, bool reverse = false);

Expand Down Expand Up @@ -195,9 +198,6 @@ public static byte ToByte(this int source)
[NonemitWithConvert(ConvertMethod.ToScriptHash)]
public extern static UInt160 ToScriptHash(this string address);

[NonemitWithConvert(ConvertMethod.ToBigInteger)]
public extern static BigInteger ToBigInteger(this string text);

[Syscall("System.Binary.Serialize")]
public extern static byte[] Serialize(this object source);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public enum ConvertMethod
{
HexToBytes,
ToScriptHash,
ToBigInteger,
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Constructor)]
Expand Down
8 changes: 6 additions & 2 deletions src/Neo.SmartContract.Framework/OpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,17 @@ public enum OpCode : byte
/// </summary>
CALLA = 0x36,
/// <summary>
/// Calls the function which is described by the token.
/// </summary>
CALLT = 0x37,
/// <summary>
/// It turns the vm state to FAULT immediately, and cannot be caught.
/// </summary>
ABORT = 0x37,
ABORT = 0x38,
/// <summary>
/// Pop the top value of the stack, if it false, then exit vm execution and set vm state to FAULT.
/// </summary>
ASSERT = 0x38,
ASSERT = 0x39,
/// <summary>
/// Pop the top value of the stack, and throw it.
/// </summary>
Expand Down
12 changes: 7 additions & 5 deletions src/Neo.SmartContract.Framework/Services/Neo/CallFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ public enum CallFlags : byte
{
None = 0,

AllowModifyStates = 0b00000001,
AllowCall = 0b00000010,
AllowNotify = 0b00000100,
ReadStates = 0b00000001,
WriteStates = 0b00000010,
AllowCall = 0b00000100,
AllowNotify = 0b00001000,

ReadOnly = AllowCall | AllowNotify,
All = AllowModifyStates | AllowCall | AllowNotify
States = ReadStates | WriteStates,
ReadOnly = ReadStates | AllowCall,
All = States | AllowCall | AllowNotify
}
}
9 changes: 3 additions & 6 deletions src/Neo.SmartContract.Framework/Services/Neo/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ public class Contract
public readonly UInt160 Hash;

/// <summary>
/// Script
/// Nef
/// </summary>
public readonly byte[] Script;
public readonly ByteString Nef;

/// <summary>
/// Manifest
/// </summary>
public readonly string Manifest;

[Syscall("System.Contract.Call")]
public static extern object Call(UInt160 scriptHash, string method, object[] arguments);

[Syscall("System.Contract.CallEx")]
public static extern object CallEx(UInt160 scriptHash, string method, object[] arguments, CallFlags flag);
public static extern object Call(UInt160 scriptHash, string method, CallFlags flags, params object[] args);

[Syscall("System.Contract.GetCallFlags")]
public static extern byte GetCallFlags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x081514120c7894779309255b7fb18b376cec731a")]
[Contract("0xbee421fdbb3e791265d2104cb34934f53fcc0e45")]
public class ContractManagement
{
public static extern UInt160 Hash { [ContractHash] get; }
public static extern string Name { get; }
public static extern Contract GetContract(UInt160 hash);
public static extern Contract Deploy(byte[] nefFile, string manifest);
public static extern void Update(byte[] nefFile, string manifest);
public static extern Contract Deploy(ByteString nefFile, string manifest);
public static extern void Update(ByteString nefFile, string manifest);
public static extern void Destroy();
}
}
16 changes: 8 additions & 8 deletions src/Neo.SmartContract.Framework/Services/Neo/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ namespace Neo.SmartContract.Framework.Services.Neo
public static class Crypto
{
[Syscall("Neo.Crypto.SHA256")]
public extern static byte[] SHA256(byte[] value);
public extern static ByteString SHA256(ByteString value);

[Syscall("Neo.Crypto.RIPEMD160")]
public extern static byte[] RIPEMD160(byte[] value);
public extern static ByteString RIPEMD160(ByteString value);

[Syscall("Neo.Crypto.SHA256")]
[Syscall("Neo.Crypto.RIPEMD160")]
public extern static byte[] Hash160(byte[] value);
public extern static ByteString Hash160(ByteString value);

[Syscall("Neo.Crypto.SHA256")]
[Syscall("Neo.Crypto.SHA256")]
public extern static byte[] Hash256(byte[] value);
public extern static ByteString Hash256(ByteString value);

public static class ECDsa
{
public static class Secp256r1
{
[Syscall("Neo.Crypto.VerifyWithECDsaSecp256r1")]
public extern static bool Verify(byte[] message, Cryptography.ECC.ECPoint pubkey, byte[] signature);
public extern static bool Verify(ByteString message, Cryptography.ECC.ECPoint pubkey, ByteString signature);

[Syscall("Neo.Crypto.CheckMultisigWithECDsaSecp256r1")]
public extern static bool CheckMultiSig(byte[] message, Cryptography.ECC.ECPoint[] pubkey, byte[][] signature);
public extern static bool CheckMultiSig(ByteString message, Cryptography.ECC.ECPoint[] pubkey, ByteString[] signature);
}

public static class Secp256k1
{
[Syscall("Neo.Crypto.VerifyWithECDsaSecp256k1")]
public extern static bool Verify(byte[] message, Cryptography.ECC.ECPoint pubkey, byte[] signature);
public extern static bool Verify(ByteString message, Cryptography.ECC.ECPoint pubkey, ByteString signature);

[Syscall("Neo.Crypto.CheckMultisigWithECDsaSecp256k1")]
public extern static bool CheckMultiSig(byte[] message, Cryptography.ECC.ECPoint[] pubkey, byte[][] signature);
public extern static bool CheckMultiSig(ByteString message, Cryptography.ECC.ECPoint[] pubkey, ByteString[] signature);
}
}
}
Expand Down
22 changes: 0 additions & 22 deletions src/Neo.SmartContract.Framework/Services/Neo/Enumerator.cs

This file was deleted.

17 changes: 17 additions & 0 deletions src/Neo.SmartContract.Framework/Services/Neo/FindOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace Neo.SmartContract.Framework.Services.Neo
{
[Flags]
public enum FindOptions : byte
{
None = 0,

KeysOnly = 1 << 0,
RemovePrefix = 1 << 1,
ValuesOnly = 1 << 2,
DeserializeValues = 1 << 3,
PickField0 = 1 << 4,
PickField1 = 1 << 5
}
}
Loading