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

Add hardfork HF_Echidna #3454

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bcc5fd0
add hardofork HF_Echidna
Jim8y Aug 7, 2024
e63f10b
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
9d16c53
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
f746f8d
add hardofork HF_Echidna
Jim8y Aug 7, 2024
8d7f9e8
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
3fc8077
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
620d938
Merge branch 'HF_Echidna' of github.com:neo-project/neo into HF_Echidna
Jim8y Oct 2, 2024
7e31d0c
add hardofork HF_Echidna
Jim8y Aug 7, 2024
993e3fe
Add entries to `Designation` event (#3397)
shargon Aug 8, 2024
37bf0cb
[Neo Core StdLib] Add Base64url (#3453)
Jim8y Aug 8, 2024
7dba130
format
Jim8y Nov 6, 2024
0457ccd
Merge branch 'HF_Echidna' of github.com:neo-project/neo into HF_Echidna
Jim8y Nov 6, 2024
d7a291e
Merge Master
cschuchardt88 Nov 17, 2024
6e780c0
Fixed typo
cschuchardt88 Nov 17, 2024
02d6ab9
Added back #3397
cschuchardt88 Nov 17, 2024
8fb30df
Fixed tests
cschuchardt88 Nov 17, 2024
f9244eb
fixed global.json
cschuchardt88 Nov 17, 2024
650c9e9
Merge branch 'master' into HF_Echidna
Jim8y Nov 18, 2024
331541a
Merge branch 'master' into HF_Echidna
Jim8y Nov 20, 2024
eb96d14
Merge branch 'master' into HF_Echidna
shargon Nov 20, 2024
74498e5
Merge branch 'master' into HF_Echidna
Jim8y Nov 23, 2024
577c431
Merge branch 'master' into HF_Echidna
cschuchardt88 Dec 4, 2024
1c82ed9
Update src/Neo/Neo.csproj
cschuchardt88 Dec 4, 2024
b81b127
Update src/Neo/Neo.csproj
cschuchardt88 Dec 4, 2024
a3a6fd5
Merge branch 'master' into HF_Echidna
Jim8y Dec 11, 2024
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
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.fs.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"HF_Aspidochelone": 3000000,
"HF_Basilisk": 4500000,
"HF_Cockatrice": 5800000,
"HF_Domovoi": 5800000
"HF_Domovoi": 5800000,
"HF_Echidna": 5800001
},
"StandbyCommittee": [
"026fa34ec057d74c2fdf1a18e336d0bd597ea401a0b2ad57340d5c220d09f44086",
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"HF_Aspidochelone": 1730000,
"HF_Basilisk": 4120000,
"HF_Cockatrice": 5450000,
"HF_Domovoi": 5570000
"HF_Domovoi": 5570000,
"HF_Echidna": 5570001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"HF_Aspidochelone": 1730000,
"HF_Basilisk": 4120000,
"HF_Cockatrice": 5450000,
"HF_Domovoi": 5570000
"HF_Domovoi": 5570000,
"HF_Echidna": 5570001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.CLI/config.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"HF_Aspidochelone": 210000,
"HF_Basilisk": 2680000,
"HF_Cockatrice": 3967000,
"HF_Domovoi": 4144000
"HF_Domovoi": 4144000,
"HF_Echidna": 4144001
},
"InitialGasDistribution": 5200000000000000,
"ValidatorsCount": 7,
Expand Down
3 changes: 2 additions & 1 deletion src/Neo/Hardfork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum Hardfork : byte
HF_Aspidochelone,
HF_Basilisk,
HF_Cockatrice,
HF_Domovoi
HF_Domovoi,
HF_Echidna
}
}
2 changes: 2 additions & 0 deletions src/Neo/Neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.2.1" />
<PackageReference Include="System.IO.Hashing" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 22 additions & 2 deletions src/Neo/SmartContract/Native/RoleManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ public sealed class RoleManagement : NativeContract
{
[ContractEvent(0, name: "Designation",
"Role", ContractParameterType.Integer,
"BlockIndex", ContractParameterType.Integer)]
"BlockIndex", ContractParameterType.Integer,
Hardfork.HF_Echidna)]

[ContractEvent(Hardfork.HF_Echidna, 0, name: "Designation",
"Role", ContractParameterType.Integer,
"BlockIndex", ContractParameterType.Integer,
"Old", ContractParameterType.Array,
"New", ContractParameterType.Array
)]

internal RoleManagement() : base() { }

/// <summary>
Expand All @@ -51,6 +60,7 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index)
}

[ContractMethod(CpuFee = 1 << 15, RequiredCallFlags = CallFlags.States | CallFlags.AllowNotify)]
[Obsolete]
private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] nodes)
{
if (nodes.Length == 0 || nodes.Length > 32)
Expand All @@ -69,7 +79,17 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node
list.AddRange(nodes);
list.Sort();
engine.SnapshotCache.Add(key, new StorageItem(list));
engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, new StackItem[] { (int)role, engine.PersistingBlock.Index }));
if (engine.IsHardforkEnabled(Hardfork.HF_Echidna))
{
var oldNodes = new VM.Types.Array(engine.ReferenceCounter, GetDesignatedByRole(engine.Snapshot, role, index - 1).Select(u => (ByteString)u.EncodePoint(true)));
var newNodes = new VM.Types.Array(engine.ReferenceCounter, nodes.Select(u => (ByteString)u.EncodePoint(true)));

engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, [(int)role, engine.PersistingBlock.Index, oldNodes, newNodes]));
}
else
{
engine.SendNotification(Hash, "Designation", new VM.Types.Array(engine.ReferenceCounter, [(int)role, engine.PersistingBlock.Index]));
}
}

private class NodeList : InteroperableList<ECPoint>
Expand Down
23 changes: 23 additions & 0 deletions src/Neo/SmartContract/Native/StdLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#pragma warning disable IDE0051

using Microsoft.IdentityModel.Tokens;
using Neo.Cryptography;
using Neo.Json;
using Neo.VM.Types;
Expand Down Expand Up @@ -131,6 +132,28 @@ public static byte[] Base64Decode([MaxLength(MaxInputLength)] string s)
return Convert.FromBase64String(s);
}

/// <summary>
/// Encodes a byte array into a base64Url string.
/// </summary>
/// <param name="data">The base64Url to be encoded.</param>
/// <returns>The encoded base64Url string.</returns>
[ContractMethod(Hardfork.HF_Echidna, CpuFee = 1 << 5)]
public static string Base64UrlEncode([MaxLength(MaxInputLength)] string data)
{
return Base64UrlEncoder.Encode(data);
}

/// <summary>
/// Decodes a byte array from a base64Url string.
/// </summary>
/// <param name="s">The base64Url string.</param>
/// <returns>The decoded base64Url string.</returns>
[ContractMethod(Hardfork.HF_Echidna, CpuFee = 1 << 5)]
public static string Base64UrlDecode([MaxLength(MaxInputLength)] string s)
{
return Base64UrlEncoder.Decode(s);
}

/// <summary>
/// Encodes a byte array into a base58 <see cref="string"/>.
/// </summary>
Expand Down
22 changes: 20 additions & 2 deletions tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions tests/Neo.UnitTests/SmartContract/Native/UT_StdLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,5 +406,25 @@ public void TestRuntime_Deserialize()
Assert.AreEqual(engine.ResultStack.Pop<Integer>().GetInteger(), 100);
Assert.AreEqual(engine.ResultStack.Pop<ByteString>().GetString(), "test");
}

[TestMethod]
public void TestBase64Url()
{
var snapshotCache = TestBlockchain.GetTestSnapshotCache();
using (var script = new ScriptBuilder())
{
// Test encoding
script.EmitDynamicCall(NativeContract.StdLib.Hash, "base64UrlEncode", "[email protected]&Issuer=https://example.com");
script.EmitDynamicCall(NativeContract.StdLib.Hash, "base64UrlDecode", "U3ViamVjdD10ZXN0QGV4YW1wbGUuY29tJklzc3Vlcj1odHRwczovL2V4YW1wbGUuY29t");

using var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshotCache, settings: TestBlockchain.TheNeoSystem.Settings);
engine.LoadScript(script.ToArray());

Assert.AreEqual(engine.Execute(), VMState.HALT);
Assert.AreEqual(2, engine.ResultStack.Count);
Assert.AreEqual("[email protected]&Issuer=https://example.com", engine.ResultStack.Pop<ByteString>());
Assert.AreEqual("U3ViamVjdD10ZXN0QGV4YW1wbGUuY29tJklzc3Vlcj1odHRwczovL2V4YW1wbGUuY29t", engine.ResultStack.Pop<ByteString>().GetString());
}
}
}
}
Loading