Крипто-анализ

[neo-project/neo] Contract.Migrate not destroying the original contract (#153)

I’ve tested it and it seems to work as expected.
I depolyed the contract in tx: https://neoscan-testnet.io/transaction/6ecf61157ef76896698a62962ff4042ee41090f7b25a5cb1320643a59ead3ac3
The hash of the contract is:
«`
0x6b8ec3272f5797c2bc0f6ee0abc7ea0fbc33beb9
«`
And then I put a key-value `key: hello, value: world` into it: https://neoscan-testnet.io/transaction/ee3f452e85f19cf3f631b5eb2def3db8c62c6262fbf60505dbf7f5c7e815778b
And then I upgraded it: https://neoscan-testnet.io/transaction/7cd9238275ea0b442b1207f0f9108d56bb3244df0ea2374f605547656017f6d5
The hash of it has been changed to:
«`
0xcdd9e917c80d3e039e2e94ceb76e79a5d683e1ce
«`
Then you can see the key-value is in the new contract, and the old contract has disappeared.

The source code of this test is:
«`c#
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract.Framework.Services.System;

namespace NeoContract1
{
public class Contract1 : SmartContract
{
public static object Main(string operation, object[] args)
{
switch (operation)
{
case nameof(destroy):
return destroy();
case nameof(get):
return get((string)args[0]);
case nameof(put):
return put((string)args[0], (string)args[1]);
case nameof(upgrade):
return upgrade();
default:
return false;
}
}

public static bool destroy()
{
Contract.Destroy();
return true;
}

public static string get(string key)
{
return Storage.Get(Storage.CurrentContext, key).AsString();
}

public static bool put(string key, string value)
{
Storage.Put(Storage.CurrentContext, key, value);
return true;
}

public static bool upgrade()
{
byte[] newScript = Blockchain.GetContract(ExecutionEngine.ExecutingScriptHash).Script.Concat((byte[])(object)Runtime.Time);
Runtime.Notify(«Starting Upgrade»);
Contract.Migrate(newScript, new byte[] { 0x07, 0x10 }, 0x05, true, «new name», «new version», «new author», «new email», «new description»);
Runtime.Notify(«Upgrade Complete»);
return true;
}
}
}
«`

Добавить комментарий