From a3319aa38429789f2bf96dcadfb3081bcbbf07d4 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 08:23:46 +0800 Subject: [PATCH 01/11] fix hardfork issues --- .../Native/ContractMethodAttribute.cs | 7 ++++++ .../Native/ContractMethodMetadata.cs | 2 ++ src/Neo/SmartContract/Native/CryptoLib.cs | 22 ++++++++++++++++++- .../SmartContract/Native/NativeContract.cs | 9 +++++++- src/Neo/SmartContract/Native/NeoToken.cs | 20 +++++++++++------ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/Neo/SmartContract/Native/ContractMethodAttribute.cs b/src/Neo/SmartContract/Native/ContractMethodAttribute.cs index cd8f7de59e..7caa27c8b0 100644 --- a/src/Neo/SmartContract/Native/ContractMethodAttribute.cs +++ b/src/Neo/SmartContract/Native/ContractMethodAttribute.cs @@ -23,6 +23,7 @@ internal class ContractMethodAttribute : Attribute public long CpuFee { get; init; } public long StorageFee { get; init; } public Hardfork? ActiveIn { get; init; } = null; + public Hardfork? DeprecatedIn { get; init; } = null; public ContractMethodAttribute() { } @@ -30,5 +31,11 @@ public ContractMethodAttribute(Hardfork activeIn) { ActiveIn = activeIn; } + + public ContractMethodAttribute(bool isDeprecated, Hardfork deprecatedIn) + { + if (!isDeprecated) throw new ArgumentException("isDeprecated must be true", nameof(isDeprecated)); + DeprecatedIn = deprecatedIn; + } } } diff --git a/src/Neo/SmartContract/Native/ContractMethodMetadata.cs b/src/Neo/SmartContract/Native/ContractMethodMetadata.cs index 0688a0dac2..30874efb47 100644 --- a/src/Neo/SmartContract/Native/ContractMethodMetadata.cs +++ b/src/Neo/SmartContract/Native/ContractMethodMetadata.cs @@ -36,6 +36,7 @@ internal class ContractMethodMetadata public CallFlags RequiredCallFlags { get; } public ContractMethodDescriptor Descriptor { get; } public Hardfork? ActiveIn { get; init; } = null; + public Hardfork? DeprecatedIn { get; init; } = null; public ContractMethodMetadata(MemberInfo member, ContractMethodAttribute attribute) { @@ -60,6 +61,7 @@ public ContractMethodMetadata(MemberInfo member, ContractMethodAttribute attribu StorageFee = attribute.StorageFee; RequiredCallFlags = attribute.RequiredCallFlags; ActiveIn = attribute.ActiveIn; + DeprecatedIn = attribute.DeprecatedIn; Descriptor = new ContractMethodDescriptor { Name = Name, diff --git a/src/Neo/SmartContract/Native/CryptoLib.cs b/src/Neo/SmartContract/Native/CryptoLib.cs index 6e2876a860..452dd31faa 100644 --- a/src/Neo/SmartContract/Native/CryptoLib.cs +++ b/src/Neo/SmartContract/Native/CryptoLib.cs @@ -21,6 +21,12 @@ namespace Neo.SmartContract.Native /// public sealed partial class CryptoLib : NativeContract { + private static readonly Dictionary curves = new() + { + [NamedCurve.secp256k1] = ECCurve.Secp256k1, + [NamedCurve.secp256r1] = ECCurve.Secp256r1, + }; + private static readonly Dictionary s_curves = new() { [NamedCurveHash.secp256k1SHA256] = (ECCurve.Secp256k1, Hasher.SHA256), @@ -85,7 +91,7 @@ public static byte[] Keccak256(byte[] data) /// The signature to be verified. /// A pair of the curve to be used by the ECDSA algorithm and the hasher function to be used to hash message. /// if the signature is valid; otherwise, . - [ContractMethod(CpuFee = 1 << 15)] + [ContractMethod(Hardfork.HF_Cockatrice, CpuFee = 1 << 15)] public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurveHash curveHash) { try @@ -98,5 +104,19 @@ public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signatu return false; } } + + // This is for solving the hardfork issue in https://github.com/neo-project/neo/pull/3209 + [ContractMethod(true, Hardfork.HF_Cockatrice, CpuFee = 1 << 15)] + public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurve curve) + { + try + { + return Crypto.VerifySignature(message, signature, pubkey, curves[curve]); + } + catch (ArgumentException) + { + return false; + } + } } } diff --git a/src/Neo/SmartContract/Native/NativeContract.cs b/src/Neo/SmartContract/Native/NativeContract.cs index 70f67de538..1f13b547fa 100644 --- a/src/Neo/SmartContract/Native/NativeContract.cs +++ b/src/Neo/SmartContract/Native/NativeContract.cs @@ -184,7 +184,12 @@ private NativeContractsCache.CacheEntry GetAllowedMethods(IsHardforkEnabledDeleg byte[] script; using (ScriptBuilder sb = new()) { - foreach (ContractMethodMetadata method in methodDescriptors.Where(u => u.ActiveIn is null || hfChecker(u.ActiveIn.Value, index))) + foreach (ContractMethodMetadata method in methodDescriptors.Where(u + => + u.ActiveIn is null && u.DeprecatedIn is null || + u.DeprecatedIn is not null && hfChecker(u.DeprecatedIn.Value, index) == false || + u.ActiveIn is not null && hfChecker(u.ActiveIn.Value, index)) + ) { method.Descriptor.Offset = sb.Length; sb.EmitPush(0); //version @@ -366,6 +371,8 @@ internal async void Invoke(ApplicationEngine engine, byte version) ContractMethodMetadata method = currentAllowedMethods.Methods[context.InstructionPointer]; if (method.ActiveIn is not null && !engine.IsHardforkEnabled(method.ActiveIn.Value)) throw new InvalidOperationException($"Cannot call this method before hardfork {method.ActiveIn}."); + if (method.DeprecatedIn is not null && engine.IsHardforkEnabled(method.DeprecatedIn.Value)) + throw new InvalidOperationException($"Cannot call this method after hardfork {method.DeprecatedIn}."); ExecutionContextState state = context.GetState(); if (!state.CallFlags.HasFlag(method.RequiredCallFlags)) throw new InvalidOperationException($"Cannot call this method with the flag {state.CallFlags}."); diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs index 1ff9aa2fdb..466a4f74b5 100644 --- a/src/Neo/SmartContract/Native/NeoToken.cs +++ b/src/Neo/SmartContract/Native/NeoToken.cs @@ -203,14 +203,20 @@ internal override ContractTask OnPersistAsync(ApplicationEngine engine) cachedCommittee.Clear(); cachedCommittee.AddRange(ComputeCommitteeMembers(engine.Snapshot, engine.ProtocolSettings)); - var newCommittee = cachedCommittee.Select(u => u.PublicKey).ToArray(); - - if (!newCommittee.SequenceEqual(prevCommittee)) + // Hardfork check for https://github.com/neo-project/neo/pull/3158 + // New notification will case 3.7.0 and 3.6.0 have different behavior + var index = engine.PersistingBlock?.Index ?? Ledger.CurrentIndex(engine.Snapshot); + if (engine.ProtocolSettings.IsHardforkEnabled(Hardfork.HF_Cockatrice, index)) { - engine.SendNotification(Hash, "CommitteeChanged", new VM.Types.Array(engine.ReferenceCounter) { - new VM.Types.Array(engine.ReferenceCounter, prevCommittee.Select(u => (ByteString)u.ToArray())) , - new VM.Types.Array(engine.ReferenceCounter, newCommittee.Select(u => (ByteString)u.ToArray())) - }); + var newCommittee = cachedCommittee.Select(u => u.PublicKey).ToArray(); + + if (!newCommittee.SequenceEqual(prevCommittee)) + { + engine.SendNotification(Hash, "CommitteeChanged", new VM.Types.Array(engine.ReferenceCounter) { + new VM.Types.Array(engine.ReferenceCounter, prevCommittee.Select(u => (ByteString)u.ToArray())) , + new VM.Types.Array(engine.ReferenceCounter, newCommittee.Select(u => (ByteString)u.ToArray())) + }); + } } } return ContractTask.CompletedTask; From a88ebe45afb79cee6d5f72fb265e943b3538427b Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 08:43:45 +0800 Subject: [PATCH 02/11] fix hardfork for 3172 --- src/Neo/SmartContract/Native/NativeContract.cs | 3 +++ src/Neo/SmartContract/Native/RoleManagement.cs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/Neo/SmartContract/Native/NativeContract.cs b/src/Neo/SmartContract/Native/NativeContract.cs index 1f13b547fa..55e88b2ec6 100644 --- a/src/Neo/SmartContract/Native/NativeContract.cs +++ b/src/Neo/SmartContract/Native/NativeContract.cs @@ -186,8 +186,11 @@ private NativeContractsCache.CacheEntry GetAllowedMethods(IsHardforkEnabledDeleg { foreach (ContractMethodMetadata method in methodDescriptors.Where(u => + // no hardfork is involved u.ActiveIn is null && u.DeprecatedIn is null || + // deprecated method hardfork is involved u.DeprecatedIn is not null && hfChecker(u.DeprecatedIn.Value, index) == false || + // active method hardfork is involved u.ActiveIn is not null && hfChecker(u.ActiveIn.Value, index)) ) { diff --git a/src/Neo/SmartContract/Native/RoleManagement.cs b/src/Neo/SmartContract/Native/RoleManagement.cs index 6e989b78cf..b9f95a5dfd 100644 --- a/src/Neo/SmartContract/Native/RoleManagement.cs +++ b/src/Neo/SmartContract/Native/RoleManagement.cs @@ -43,6 +43,9 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index) throw new ArgumentOutOfRangeException(nameof(role)); if (Ledger.CurrentIndex(snapshot) + 1 < index) throw new ArgumentOutOfRangeException(nameof(index)); + // Fix hardfork for https://github.com/neo-project/neo/pull/3172 + if (role == Role.P2PNotary && !ProtocolSettings.Default.IsHardforkEnabled(Hardfork.HF_Cockatrice, index)) + throw new ArgumentOutOfRangeException(nameof(role)); byte[] key = CreateStorageKey((byte)role).AddBigEndian(index).ToArray(); byte[] boundary = CreateStorageKey((byte)role).ToArray(); return snapshot.FindRange(key, boundary, SeekDirection.Backward) @@ -62,6 +65,9 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node if (engine.PersistingBlock is null) throw new InvalidOperationException(nameof(DesignateAsRole)); uint index = engine.PersistingBlock.Index + 1; + // Fix hardfork for https://github.com/neo-project/neo/pull/3172 + if (role == Role.P2PNotary && !ProtocolSettings.Default.IsHardforkEnabled(Hardfork.HF_Cockatrice, index)) + throw new ArgumentOutOfRangeException(nameof(role)); var key = CreateStorageKey((byte)role).AddBigEndian(index); if (engine.Snapshot.Contains(key)) throw new InvalidOperationException(); From c1af44340f664a2e14632b10788b8cb9aef3ea57 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 11:25:02 +0800 Subject: [PATCH 03/11] fix 3195 --- .../Native/ContractEventAttribute.cs | 2 +- .../SmartContract/Native/NativeContract.cs | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Neo/SmartContract/Native/ContractEventAttribute.cs b/src/Neo/SmartContract/Native/ContractEventAttribute.cs index 656ecef725..c8cd9d5cfd 100644 --- a/src/Neo/SmartContract/Native/ContractEventAttribute.cs +++ b/src/Neo/SmartContract/Native/ContractEventAttribute.cs @@ -21,7 +21,7 @@ internal class ContractEventAttribute : Attribute { public int Order { get; init; } public ContractEventDescriptor Descriptor { get; set; } - public Hardfork? ActiveIn { get; init; } = null; + public Hardfork? ActiveIn { get; internal set; } = null; public ContractEventAttribute(Hardfork activeIn, int order, string name, string arg1Name, ContractParameterType arg1Value) : this(order, name, arg1Name, arg1Value) diff --git a/src/Neo/SmartContract/Native/NativeContract.cs b/src/Neo/SmartContract/Native/NativeContract.cs index 55e88b2ec6..e4f0785d06 100644 --- a/src/Neo/SmartContract/Native/NativeContract.cs +++ b/src/Neo/SmartContract/Native/NativeContract.cs @@ -142,20 +142,36 @@ protected NativeContract() List listMethods = new(); foreach (MemberInfo member in GetType().GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) { - ContractMethodAttribute attribute = member.GetCustomAttribute(); + var attribute = member.GetCustomAttribute(); if (attribute is null) continue; listMethods.Add(new ContractMethodMetadata(member, attribute)); } methodDescriptors = listMethods.OrderBy(p => p.Name, StringComparer.Ordinal).ThenBy(p => p.Parameters.Length).ToList().AsReadOnly(); + // fix the hardfork issue in https://github.com/neo-project/neo/pull/3195 + var contractEventAttributes = GetType() + .BaseType? + .GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)? + .GetCustomAttributes() + .ToList(); + if (contractEventAttributes != null) + { + foreach (var attribute in contractEventAttributes) + { + attribute.ActiveIn = Hardfork.HF_Cockatrice; + } + } + // Reflection to get the events eventsDescriptors = - GetType().GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. - GetCustomAttributes(). - // Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling. - Concat(GetType().BaseType?.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. - GetCustomAttributes()). - OrderBy(p => p.Order).ToList().AsReadOnly(); + GetType(). + GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. + GetCustomAttributes(). + // Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling. + Concat(contractEventAttributes). + OrderBy(p => p.Order). + ToList(). + AsReadOnly(); // Calculate the initializations forks usedHardforks = From dfa2520ceab5ea402bd63bf37b47f4f1b36b4791 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 13:59:37 +0800 Subject: [PATCH 04/11] set custom setting if load from config. --- src/Neo/ProtocolSettings.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Neo/ProtocolSettings.cs b/src/Neo/ProtocolSettings.cs index c3d8232afd..f03e5ffaf9 100644 --- a/src/Neo/ProtocolSettings.cs +++ b/src/Neo/ProtocolSettings.cs @@ -144,7 +144,7 @@ public static ProtocolSettings Load(string path, bool optional = true) /// The loaded . public static ProtocolSettings Load(IConfigurationSection section) { - return new ProtocolSettings + Custom = new ProtocolSettings { Network = section.GetValue("Network", Default.Network), AddressVersion = section.GetValue("AddressVersion", Default.AddressVersion), @@ -164,6 +164,7 @@ public static ProtocolSettings Load(IConfigurationSection section) ? EnsureOmmitedHardforks(section.GetSection("Hardforks").GetChildren().ToDictionary(p => Enum.Parse(p.Key, true), p => uint.Parse(p.Value))).ToImmutableDictionary() : Default.Hardforks }; + return Custom; } /// From c02d6f036827d12e8f173a4b23df8dedb431cdb5 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 14:40:14 +0800 Subject: [PATCH 05/11] fix hf index --- src/Neo/SmartContract/Native/RoleManagement.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Neo/SmartContract/Native/RoleManagement.cs b/src/Neo/SmartContract/Native/RoleManagement.cs index b9f95a5dfd..d653588d5a 100644 --- a/src/Neo/SmartContract/Native/RoleManagement.cs +++ b/src/Neo/SmartContract/Native/RoleManagement.cs @@ -44,7 +44,7 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index) if (Ledger.CurrentIndex(snapshot) + 1 < index) throw new ArgumentOutOfRangeException(nameof(index)); // Fix hardfork for https://github.com/neo-project/neo/pull/3172 - if (role == Role.P2PNotary && !ProtocolSettings.Default.IsHardforkEnabled(Hardfork.HF_Cockatrice, index)) + if (role == Role.P2PNotary && !ProtocolSettings.Custom.IsHardforkEnabled(Hardfork.HF_Cockatrice, Ledger.CurrentIndex(snapshot))) throw new ArgumentOutOfRangeException(nameof(role)); byte[] key = CreateStorageKey((byte)role).AddBigEndian(index).ToArray(); byte[] boundary = CreateStorageKey((byte)role).ToArray(); @@ -64,10 +64,10 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node throw new InvalidOperationException(nameof(DesignateAsRole)); if (engine.PersistingBlock is null) throw new InvalidOperationException(nameof(DesignateAsRole)); - uint index = engine.PersistingBlock.Index + 1; // Fix hardfork for https://github.com/neo-project/neo/pull/3172 - if (role == Role.P2PNotary && !ProtocolSettings.Default.IsHardforkEnabled(Hardfork.HF_Cockatrice, index)) + if (role == Role.P2PNotary && !ProtocolSettings.Custom.IsHardforkEnabled(Hardfork.HF_Cockatrice, engine.PersistingBlock.Index)) throw new ArgumentOutOfRangeException(nameof(role)); + uint index = engine.PersistingBlock.Index + 1; var key = CreateStorageKey((byte)role).AddBigEndian(index); if (engine.Snapshot.Contains(key)) throw new InvalidOperationException(); From 43236e633d57dfc0463144c85e4a5422cf35b0a0 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 15:04:44 +0800 Subject: [PATCH 06/11] fix UT --- tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs index 25ca7ee0d6..33fc7e0b1b 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs @@ -58,8 +58,8 @@ public void TestSetAndGet() publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); - - List roles = new List() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode, Role.P2PNotary }; + // Notary effect after the fork. + List roles = new List() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode };//, Role.P2PNotary }; foreach (var role in roles) { var snapshot1 = _snapshot.CreateSnapshot(); From d0433d61a33b6f7c49a4100498f4fd26e64a2894 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 15:05:43 +0800 Subject: [PATCH 07/11] Revert "fix 3195" This reverts commit c1af44340f664a2e14632b10788b8cb9aef3ea57. --- .../Native/ContractEventAttribute.cs | 2 +- .../SmartContract/Native/NativeContract.cs | 30 +++++-------------- 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/Neo/SmartContract/Native/ContractEventAttribute.cs b/src/Neo/SmartContract/Native/ContractEventAttribute.cs index c8cd9d5cfd..656ecef725 100644 --- a/src/Neo/SmartContract/Native/ContractEventAttribute.cs +++ b/src/Neo/SmartContract/Native/ContractEventAttribute.cs @@ -21,7 +21,7 @@ internal class ContractEventAttribute : Attribute { public int Order { get; init; } public ContractEventDescriptor Descriptor { get; set; } - public Hardfork? ActiveIn { get; internal set; } = null; + public Hardfork? ActiveIn { get; init; } = null; public ContractEventAttribute(Hardfork activeIn, int order, string name, string arg1Name, ContractParameterType arg1Value) : this(order, name, arg1Name, arg1Value) diff --git a/src/Neo/SmartContract/Native/NativeContract.cs b/src/Neo/SmartContract/Native/NativeContract.cs index e4f0785d06..55e88b2ec6 100644 --- a/src/Neo/SmartContract/Native/NativeContract.cs +++ b/src/Neo/SmartContract/Native/NativeContract.cs @@ -142,36 +142,20 @@ protected NativeContract() List listMethods = new(); foreach (MemberInfo member in GetType().GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)) { - var attribute = member.GetCustomAttribute(); + ContractMethodAttribute attribute = member.GetCustomAttribute(); if (attribute is null) continue; listMethods.Add(new ContractMethodMetadata(member, attribute)); } methodDescriptors = listMethods.OrderBy(p => p.Name, StringComparer.Ordinal).ThenBy(p => p.Parameters.Length).ToList().AsReadOnly(); - // fix the hardfork issue in https://github.com/neo-project/neo/pull/3195 - var contractEventAttributes = GetType() - .BaseType? - .GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)? - .GetCustomAttributes() - .ToList(); - if (contractEventAttributes != null) - { - foreach (var attribute in contractEventAttributes) - { - attribute.ActiveIn = Hardfork.HF_Cockatrice; - } - } - // Reflection to get the events eventsDescriptors = - GetType(). - GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. - GetCustomAttributes(). - // Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling. - Concat(contractEventAttributes). - OrderBy(p => p.Order). - ToList(). - AsReadOnly(); + GetType().GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. + GetCustomAttributes(). + // Take into account not only the contract constructor, but also the base type constructor for proper FungibleToken events handling. + Concat(GetType().BaseType?.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Array.Empty(), null)?. + GetCustomAttributes()). + OrderBy(p => p.Order).ToList().AsReadOnly(); // Calculate the initializations forks usedHardforks = From 18d4f46b5d3cc93010d114a8ab544861ee636798 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 19:40:27 +0800 Subject: [PATCH 08/11] revert role fix --- src/Neo/SmartContract/Native/RoleManagement.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Neo/SmartContract/Native/RoleManagement.cs b/src/Neo/SmartContract/Native/RoleManagement.cs index d653588d5a..6e989b78cf 100644 --- a/src/Neo/SmartContract/Native/RoleManagement.cs +++ b/src/Neo/SmartContract/Native/RoleManagement.cs @@ -43,9 +43,6 @@ public ECPoint[] GetDesignatedByRole(DataCache snapshot, Role role, uint index) throw new ArgumentOutOfRangeException(nameof(role)); if (Ledger.CurrentIndex(snapshot) + 1 < index) throw new ArgumentOutOfRangeException(nameof(index)); - // Fix hardfork for https://github.com/neo-project/neo/pull/3172 - if (role == Role.P2PNotary && !ProtocolSettings.Custom.IsHardforkEnabled(Hardfork.HF_Cockatrice, Ledger.CurrentIndex(snapshot))) - throw new ArgumentOutOfRangeException(nameof(role)); byte[] key = CreateStorageKey((byte)role).AddBigEndian(index).ToArray(); byte[] boundary = CreateStorageKey((byte)role).ToArray(); return snapshot.FindRange(key, boundary, SeekDirection.Backward) @@ -64,9 +61,6 @@ private void DesignateAsRole(ApplicationEngine engine, Role role, ECPoint[] node throw new InvalidOperationException(nameof(DesignateAsRole)); if (engine.PersistingBlock is null) throw new InvalidOperationException(nameof(DesignateAsRole)); - // Fix hardfork for https://github.com/neo-project/neo/pull/3172 - if (role == Role.P2PNotary && !ProtocolSettings.Custom.IsHardforkEnabled(Hardfork.HF_Cockatrice, engine.PersistingBlock.Index)) - throw new ArgumentOutOfRangeException(nameof(role)); uint index = engine.PersistingBlock.Index + 1; var key = CreateStorageKey((byte)role).AddBigEndian(index); if (engine.Snapshot.Contains(key)) From 5926b21c63bf28a62bd0b7efe7e64b6fc82752eb Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 20:40:34 +0800 Subject: [PATCH 09/11] fix manifest --- src/Neo/SmartContract/Native/NeoToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs index 466a4f74b5..7d7c1e716b 100644 --- a/src/Neo/SmartContract/Native/NeoToken.cs +++ b/src/Neo/SmartContract/Native/NeoToken.cs @@ -63,7 +63,7 @@ public sealed class NeoToken : FungibleToken "from", ContractParameterType.PublicKey, "to", ContractParameterType.PublicKey, "amount", ContractParameterType.Integer)] - [ContractEvent(3, name: "CommitteeChanged", + [ContractEvent(Hardfork.HF_Cockatrice,3, name: "CommitteeChanged", "old", ContractParameterType.Array, "new", ContractParameterType.Array)] internal NeoToken() : base() From e5540ed750ff6376a005bb70b0151ea1ef92d6cf Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 15 May 2024 20:46:36 +0800 Subject: [PATCH 10/11] format --- src/Neo/SmartContract/Native/NeoToken.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Neo/SmartContract/Native/NeoToken.cs b/src/Neo/SmartContract/Native/NeoToken.cs index 7d7c1e716b..1fbf07204e 100644 --- a/src/Neo/SmartContract/Native/NeoToken.cs +++ b/src/Neo/SmartContract/Native/NeoToken.cs @@ -63,7 +63,7 @@ public sealed class NeoToken : FungibleToken "from", ContractParameterType.PublicKey, "to", ContractParameterType.PublicKey, "amount", ContractParameterType.Integer)] - [ContractEvent(Hardfork.HF_Cockatrice,3, name: "CommitteeChanged", + [ContractEvent(Hardfork.HF_Cockatrice, 3, name: "CommitteeChanged", "old", ContractParameterType.Array, "new", ContractParameterType.Array)] internal NeoToken() : base() From 372eb6e8ce52dc6f7ac91df85a7662a0011e7ee9 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 16 May 2024 15:59:59 +0800 Subject: [PATCH 11/11] revert role UT --- tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs index 33fc7e0b1b..25ca7ee0d6 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_RoleManagement.cs @@ -58,8 +58,8 @@ public void TestSetAndGet() publicKeys[0] = key1.PublicKey; publicKeys[1] = key2.PublicKey; publicKeys = publicKeys.OrderBy(p => p).ToArray(); - // Notary effect after the fork. - List roles = new List() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode };//, Role.P2PNotary }; + + List roles = new List() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode, Role.P2PNotary }; foreach (var role in roles) { var snapshot1 = _snapshot.CreateSnapshot();