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 changes #391

Merged
merged 55 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
4c2e79d
Initial commit
shargon Nov 12, 2020
f5f161b
Remove hash from ABI
shargon Nov 12, 2020
38e0590
Clean lines
shargon Nov 12, 2020
9c8e7db
Fixes
shargon Nov 13, 2020
5379d41
Merge remote-tracking branch 'neo-project/master' into sync-nep17
shargon Nov 13, 2020
7ad9b72
Fix some UT
shargon Nov 13, 2020
4448877
Change name to manifest
shargon Nov 16, 2020
cc4cced
Merge branch 'master' into sync-nep17
shargon Nov 19, 2020
88fa514
Update nuget
shargon Nov 19, 2020
6947047
Update NEP17.cs
shargon Nov 20, 2020
c0db531
Merge branch 'master' into sync-nep17
shargon Nov 20, 2020
f4df31a
Fix more UT
shargon Nov 20, 2020
2ec0748
Some fixes
shargon Nov 20, 2020
9894e83
Fix Contract
shargon Nov 20, 2020
821f834
Update NEP17.Owner.cs
shargon Nov 21, 2020
057d5ba
Update NEP17.Methods.cs
shargon Nov 26, 2020
9e79f27
Merge branch 'master' into sync-nep17
shargon Nov 26, 2020
af62c81
Add data to Transfer
shargon Nov 26, 2020
32905b6
add data to onPayment
shargon Nov 26, 2020
1650325
Remove name
shargon Nov 27, 2020
afad1b1
Merge branch 'master' into sync-nep17
shargon Dec 1, 2020
425718f
Update src/Neo.Compiler.MSIL/Neo.Compiler.MSIL.csproj
shargon Dec 1, 2020
ecdb308
Fix NEF Version
shargon Dec 1, 2020
0fafec4
Fix UT
shargon Dec 1, 2020
0633281
Fix test
shargon Dec 1, 2020
3de92ed
Add OnPayment() for Mint()
superboyiii Dec 4, 2020
9110b42
Fix
superboyiii Dec 4, 2020
ba8a716
Fix
superboyiii Dec 4, 2020
c496fe8
Format
superboyiii Dec 4, 2020
da701ad
Format
superboyiii Dec 4, 2020
2e4fc2c
Format
superboyiii Dec 4, 2020
1cfec66
Update NEP17.Owner.cs
shargon Dec 4, 2020
e1eff81
Update templates/Template.NEP17.CSharp/NEP17.cs
shargon Dec 4, 2020
560e161
Update templates/Template.NEP17.CSharp/NEP17.Methods.cs
shargon Dec 4, 2020
0ef68d9
Update AssetStorage.cs
shargon Dec 4, 2020
b7d657a
Update AssetStorage.cs
shargon Dec 4, 2020
c75bb6b
Update AssetStorage.cs
shargon Dec 4, 2020
a33b14b
Merge pull request #9 from superboyiii/sync-nep17
shargon Dec 4, 2020
d1d2300
Update templates/Template.NEP17.CSharp/NEP17.cs
shargon Dec 4, 2020
0b9fd67
Update templates/Template.NEP17.CSharp/NEP17.Methods.cs
shargon Dec 4, 2020
0c27e44
Rename to ContractNameAttribute & fix invocation counter
shargon Dec 7, 2020
e3d02dc
Change mint
shargon Dec 8, 2020
5db20de
Rename to IsDeployed
shargon Dec 8, 2020
ad2d89e
Use DisplayName
shargon Dec 8, 2020
c903184
Fix mint
shargon Dec 8, 2020
882a721
Fix
shargon Dec 8, 2020
bd4c246
Optimize Mint
erikzhang Dec 9, 2020
8d0d298
Remove GetTransactionAmount
erikzhang Dec 9, 2020
493b278
Fix claim gas
erikzhang Dec 9, 2020
15f9de1
Add IsValid
shargon Dec 9, 2020
8d1e266
Update NEP17.Crowdsale.cs
erikzhang Dec 10, 2020
0823a31
Update src/Neo.SmartContract.Framework/UInt160.cs
shargon Dec 10, 2020
7992c3a
Remove Size from UInt160 and UInt256
erikzhang Dec 10, 2020
befe380
Update UInt256.cs
erikzhang Dec 10, 2020
a572293
Fix UT
erikzhang Dec 10, 2020
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
4 changes: 2 additions & 2 deletions neo-devpack-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D5266066-0AFD-44D5-A83E-2F73668A63C8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Template.NEP5.CSharp", "templates\Template.NEP5.CSharp\Template.NEP5.CSharp.csproj", "{ADD05222-DC45-4FDC-A41A-30A97BACC95F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Template.NEP17.CSharp", "templates\Template.NEP17.CSharp\Template.NEP17.CSharp.csproj", "{ADD05222-DC45-4FDC-A41A-30A97BACC95F}"
ProjectSection(ProjectDependencies) = postProject
{42C0FF0F-0A7C-4166-A773-1F944642C209} = {42C0FF0F-0A7C-4166-A773-1F944642C209}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Template.NEP5.UnitTests", "tests\Template.NEP5.UnitTests\Template.NEP5.UnitTests.csproj", "{780141EE-D6E9-4591-8470-8F91B12027CA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Template.NEP17.UnitTests", "tests\Template.NEP17.UnitTests\Template.NEP17.UnitTests.csproj", "{780141EE-D6E9-4591-8470-8F91B12027CA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
3 changes: 1 addition & 2 deletions src/Neo.Compiler.MSIL/DebugExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ private static JArray GetDocuments(IReadOnlyDictionary<string, int> docMap)
return outjson;
}

public static JObject Export(NeoModule module, byte[] script, IReadOnlyDictionary<int, int> addrConvTable)
public static JObject Export(NeoModule module, IReadOnlyDictionary<int, int> addrConvTable)
{
var docMap = GetDocumentMap(module);
addrConvTable ??= ImmutableDictionary<int, int>.Empty;

var outjson = new JObject();
outjson["hash"] = FuncExport.ComputeHash(script);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devhawk do you need the name in debugExport?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need whatever unique identifier is used to identify the contract.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a design document describing how contract deploy and invoke is supposed to work now? I am all for having a stable contract identifier other than the script hash, though it's not clear what the new design is?

One question - Have we considered the impact on dynamic contract invocations scenarios. Using script hash to invoke a contract means that any calling contracts break when a dependent contract is updated. That is, I was calling a specific contract by script hash it will be obvious something has changed if that script hash is no longer valid. With a stable identifier, will it still be obvious if a dependent contract has made a backwards incompatible change?

Copy link
Member

@vncoelho vncoelho Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @devhawk, thinking in this perspective you mentioned, it may be important to create a flag that says that the contract trust any update on the dynamic invoked contract.
For instance, most of the DeFi projects are relying on external dynamic invoked contracts. In this sense, consider the need of mutual update is something plausible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect that dynamic invoke scenarios always require "mutual update" as you called it @vncoelho. I'm not sure it's a good idea to make the change less obvious. Right now, if you update your contract it breaks anyone who calls it since the hash changes. If we keep the hash, will that allow a developer to publish a malicious contract update w/o their users noticing?

// outjson["entrypoint"]= module.mainMethod;
outjson["documents"] = GetDocuments(docMap);
outjson["methods"] = GetMethods(module, docMap, addrConvTable);
Expand Down
23 changes: 5 additions & 18 deletions src/Neo.Compiler.MSIL/FuncExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,15 @@ internal static string ConvType(TypeReference t)
return "Unknown:" + type;
}

public static string ComputeHash(byte[] script)
{
var sha256 = System.Security.Cryptography.SHA256.Create();
byte[] hash256 = sha256.ComputeHash(script);
var ripemd160 = new Neo.Cryptography.RIPEMD160Managed();
var hash = ripemd160.ComputeHash(hash256);

StringBuilder sb = new StringBuilder();
sb.Append("0x");
for (int i = hash.Length - 1; i >= 0; i--)
{
sb.Append(hash[i].ToString("x02"));
}
return sb.ToString();
}

public static JObject Export(NeoModule module, byte[] script, Dictionary<int, int> addrConvTable)
{
var outjson = new JObject();

//hash
outjson["hash"] = ComputeHash(script);
//name
outjson["name"] = module.attributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the https://github.com/neo-project/neo/pull/2024/files#diff-6a8fe6159fb062d52f619635b6c0e2123632e3a61acdc5f86b867da878af2e02R166, name is on first level in manifest, but here the name is inside the abi.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I am not sure, maybe it's more appropriate to put the Name in the abi 🤔. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think name and supportedstandards should be on the same level, maybe it shouldn't be added here?

.Where(u => u.AttributeType.FullName == "Neo.SmartContract.Framework.ManifestNameAttribute")
.Select(u => (string)u.ConstructorArguments.FirstOrDefault().Value)
.FirstOrDefault() ?? "";

shargon marked this conversation as resolved.
Show resolved Hide resolved
//functions
var methods = new JArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.Compiler.MSIL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static int Compile(Options options, ILogger log = null)

try
{
var outjson = DebugExport.Export(module, bytes, addrConvTable);
var outjson = DebugExport.Export(module, addrConvTable);
debugstr = outjson.ToString(false);
log.Log("gen debug succ");
}
Expand Down
15 changes: 15 additions & 0 deletions src/Neo.SmartContract.Framework/ManifestNameAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace Neo.SmartContract.Framework
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class ManifestNameAttribute : Attribute
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
{
public string Value { get; set; }

public ManifestNameAttribute(string value)
{
Value = value;
}
}
}
16 changes: 8 additions & 8 deletions src/Neo.SmartContract.Framework/Services/Neo/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ namespace Neo.SmartContract.Framework.Services.Neo
public class Contract
{
/// <summary>
/// Script
/// Id
/// </summary>
public readonly byte[] Script;
public readonly int Id;

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

/// <summary>
/// Has storage
/// Script
/// </summary>
public readonly bool HasStorage;
public readonly byte[] Script;

/// <summary>
/// Is payable
/// Manifest
/// </summary>
public readonly bool IsPayable;
public readonly string Manifest;

[Syscall("System.Contract.Call")]
public static extern object Call(UInt160 scriptHash, string method, object[] arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System;
using System.Numerics;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public partial class NEP5 : SmartContract
public partial class NEP17 : SmartContract
{
private static BigInteger GetTransactionAmount(Notification notification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public partial class NEP5 : SmartContract
public partial class NEP17 : SmartContract
{
private static bool ValidateAddress(UInt160 address) => !address.IsZero;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
private static bool IsPayable(UInt160 address) => Blockchain.GetContract(address)?.IsPayable ?? true;
private static bool IsContract(UInt160 address) => Blockchain.GetContract(address) != null;
erikzhang marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using System;
using System.Numerics;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public partial class NEP5 : SmartContract
public partial class NEP17 : SmartContract
{
public static BigInteger TotalSupply() => TotalSupplyStorage.Get();

Expand All @@ -21,7 +21,6 @@ public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount)
{
if (!ValidateAddress(from) || !ValidateAddress(to)) throw new Exception("The parameters from and to SHOULD be 20-byte non-zero addresses.");
if (amount <= 0) throw new Exception("The parameter amount MUST be greater than 0.");
if (!IsPayable(to)) throw new Exception("Receiver cannot receive.");
if (!Runtime.CheckWitness(from) && !from.Equals(ExecutionEngine.CallingScriptHash)) throw new Exception("No authorization.");
if (AssetStorage.Get(from) < amount) throw new Exception("Insufficient balance.");
if (from == to) return true;
Expand All @@ -30,6 +29,9 @@ public static bool Transfer(UInt160 from, UInt160 to, BigInteger amount)
AssetStorage.Increase(to, amount);

OnTransfer(from, to, amount);

// Validate payable
if (IsContract(to)) Contract.Call(to, "onPayment", new object[] { amount });
shargon marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using Neo.SmartContract.Framework.Services.System;
using System;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public partial class NEP5 : SmartContract
public partial class NEP17 : SmartContract
{
public static bool Deploy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using System.ComponentModel;
using System.Numerics;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
[ManifestName("Token Name")]
[ManifestExtra("Author", "Neo")]
[ManifestExtra("Email", "dev@neo.org")]
[ManifestExtra("Description", "This is a NEP5 example")]
shargon marked this conversation as resolved.
Show resolved Hide resolved
[SupportedStandards("NEP5", "NEP10")]
public partial class NEP5 : SmartContract
[SupportedStandards("NEP17", "NEP10")]
public partial class NEP17 : SmartContract
{
#region Token Settings
static readonly ulong MaxSupply = 10_000_000_000_000_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Neo.SmartContract.Framework.Services.Neo;
using System.Numerics;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public static class AssetStorage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Neo.SmartContract.Framework.Services.Neo;
using System.Numerics;

namespace Template.NEP5.CSharp
namespace Template.NEP17.CSharp
{
public static class TotalSupplyStorage
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/Utils/BuildScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void Build(Stream fs, Stream fspdb, bool optimizer)

try
{
debugInfo = DebugExport.Export(converterIL.outModule, finalNEF, addrConvTable);
debugInfo = DebugExport.Export(converterIL.outModule, addrConvTable);
}
catch (Exception err)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Numerics;
using System.Text;

namespace Template.NEP5.UnitTests
namespace Template.NEP17.UnitTests
{
[TestClass]
public class UnitTest_NEP5
Expand All @@ -26,13 +26,13 @@ TestEngine CreateEngine()
var engine = new TestEngine();
engine.AddEntryScript(new string[]
{
"../../../../../templates/Template.NEP5.CSharp/NEP5.cs",
"../../../../../templates/Template.NEP5.CSharp/Storage/TotalSupplyStorage.cs",
"../../../../../templates/Template.NEP5.CSharp/Storage/AssetStorage.cs",
"../../../../../templates/Template.NEP5.CSharp/NEP5.Owner.cs",
"../../../../../templates/Template.NEP5.CSharp/NEP5.Crowdsale.cs",
"../../../../../templates/Template.NEP5.CSharp/NEP5.Helpers.cs",
"../../../../../templates/Template.NEP5.CSharp/NEP5.Methods.cs"
"../../../../../templates/Template.NEP17.CSharp/NEP17.cs",
"../../../../../templates/Template.NEP17.CSharp/Storage/TotalSupplyStorage.cs",
"../../../../../templates/Template.NEP17.CSharp/Storage/AssetStorage.cs",
"../../../../../templates/Template.NEP17.CSharp/NEP17.Owner.cs",
"../../../../../templates/Template.NEP17.CSharp/NEP17.Crowdsale.cs",
"../../../../../templates/Template.NEP17.CSharp/NEP17.Helpers.cs",
"../../../../../templates/Template.NEP17.CSharp/NEP17.Methods.cs"
});

return engine;
Expand All @@ -47,6 +47,7 @@ public void Test_name()
var item = result.Pop();
Assert.IsInstanceOfType(item, typeof(ByteString));
Assert.AreEqual("Token Name", item.GetString());
Assert.AreEqual("Token Name", _engine.ScriptEntry.finalABI["name"].AsString());
}

[TestMethod]
Expand Down