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

Change smart contract hash computation #438

Merged
merged 4 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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-CI01159" />
<PackageReference Include="Neo" Version="3.0.0-CI01165" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xbee421fdbb3e791265d2104cb34934f53fcc0e45")]
[Contract("0xa501d7d7d10983673b61b7a2d3a813b36f9f0e43")]
public class ContractManagement
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/GAS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x9ac04cf223f646de5f7faccafe34e30e5d4382a2")]
[Contract("0x75844530eb44f4715a42950bb59b4d7ace0b2f3d")]
public class GAS
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x4961bf0ab79370b23dc45cde29f568d0e0fa6e93")]
[Contract("0xf617baca689d1abddedda7c3b80675c4ac21e932")]
public class NEO
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xa92fbe5bf164170a624474841485b20b45a26047")]
[Contract("0x1bda60bf76671280ab2ab80d78f7ba95434751b5")]
public class NameService
{
// NonfungibleToken
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Oracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0x8cd3889136056b3304ec59f6d424b8767710ed79")]
[Contract("0xb82bbf650f963dbf71577d10ea4077e711a13e7b")]
public class Oracle
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Neo.SmartContract.Framework/Services/Neo/Policy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xc939a4af1c762e5edca36d4b61c06ba82c4c6ff5")]
[Contract("0xe21a28cfc1e662e152f668c86198141cc17b6c37")]
public class Policy
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Neo.SmartContract.Framework.Services.Neo
{
[Contract("0xf4bbd95569e8dda2cb84eb609a1488ddd0d9fa91")]
[Contract("0x69b1909aaa14143b0624ba0d61d5cd3b8b67529d")]
public class RoleManagement
{
public static extern UInt160 Hash { [ContractHash] get; }
Expand Down
3 changes: 2 additions & 1 deletion tests/Neo.Compiler.MSIL.UnitTests/UnitTest_Delegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Neo.IO;
using Neo.Ledger;
using Neo.Persistence;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.VM.Types;

Expand Down Expand Up @@ -35,7 +36,7 @@ public void TestFunc()
[TestMethod]
public void TestDelegateCall()
{
var token = UInt160.Parse("0x4961bf0ab79370b23dc45cde29f568d0e0fa6e93"); // NEO token
var token = NativeContract.NEO.Hash; // NEO token

testengine.Reset();
var result = testengine.ExecuteTestCaseStandard("testDynamicCall", token.ToArray(), "symbol");
Expand Down
16 changes: 8 additions & 8 deletions tests/Neo.Compiler.MSIL.UnitTests/UnitTest_NativeContracts.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Compiler.MSIL.Extensions;
using Neo.Compiler.MSIL.UnitTests.Utils;
Expand All @@ -22,14 +23,13 @@ public void Test_Init()
[TestMethod]
public void TestHashes()
{
// var attr = typeof(Oracle).GetCustomAttribute<ContractAttribute>();
Assert.AreEqual(NativeContract.ContractManagement.Hash.ToString(), "0xbee421fdbb3e791265d2104cb34934f53fcc0e45");
Assert.AreEqual(NativeContract.RoleManagement.Hash.ToString(), "0xf4bbd95569e8dda2cb84eb609a1488ddd0d9fa91");
Assert.AreEqual(NativeContract.NameService.Hash.ToString(), "0xa92fbe5bf164170a624474841485b20b45a26047");
Assert.AreEqual(NativeContract.Oracle.Hash.ToString(), "0x8cd3889136056b3304ec59f6d424b8767710ed79");
Assert.AreEqual(NativeContract.NEO.Hash.ToString(), "0x4961bf0ab79370b23dc45cde29f568d0e0fa6e93");
Assert.AreEqual(NativeContract.GAS.Hash.ToString(), "0x9ac04cf223f646de5f7faccafe34e30e5d4382a2");
Assert.AreEqual(NativeContract.Policy.Hash.ToString(), "0xc939a4af1c762e5edca36d4b61c06ba82c4c6ff5");
Assert.AreEqual(NativeContract.ContractManagement.Hash.ToString(), "0xa501d7d7d10983673b61b7a2d3a813b36f9f0e43");
Assert.AreEqual(NativeContract.RoleManagement.Hash.ToString(), "0x69b1909aaa14143b0624ba0d61d5cd3b8b67529d");
Assert.AreEqual(NativeContract.NameService.Hash.ToString(), "0x1bda60bf76671280ab2ab80d78f7ba95434751b5");
Assert.AreEqual(NativeContract.Oracle.Hash.ToString(), "0xb82bbf650f963dbf71577d10ea4077e711a13e7b");
Assert.AreEqual(NativeContract.NEO.Hash.ToString(), "0xf617baca689d1abddedda7c3b80675c4ac21e932");
Assert.AreEqual(NativeContract.GAS.Hash.ToString(), "0x75844530eb44f4715a42950bb59b4d7ace0b2f3d");
Assert.AreEqual(NativeContract.Policy.Hash.ToString(), "0xe21a28cfc1e662e152f668c86198141cc17b6c37");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ public void Test_CreateCallDestroy()
var script = _engine.Build("./TestClasses/Contract_Create.cs");
var manifest = ContractManifest.FromJson(JObject.Parse(script.finalManifest));
var nef = new NefFile() { Script = script.finalNEFScript, Compiler = "unit-test-1.0", Tokens = System.Array.Empty<MethodToken>() };
var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.Script);
nef.CheckSum = NefFile.ComputeChecksum(nef);

var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.CheckSum, manifest.Name);

// Create

_engine.Reset();
Expand Down Expand Up @@ -96,9 +97,10 @@ public void Test_Update()
Compiler = "unit-test-1.0",
Tokens = script.nefFile.Tokens
};
var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.Script);
nef.CheckSum = NefFile.ComputeChecksum(nef);

var hash = Helper.GetContractHash((_engine.ScriptContainer as Transaction).Sender, nef.CheckSum, manifest.Name);

var scriptUpdate = _engine.Build("./TestClasses/Contract_Update.cs");
var manifestUpdate = ContractManifest.FromJson(JObject.Parse(scriptUpdate.finalManifest));

Expand Down