Skip to content

Commit 38d91fc

Browse files
authored
Native: properly activate native methods/events (#4524)
#4520 fixes false-positive activation in case if DeprecatedIn hardfork is passed. However, it's not enough for proper ActiveIn work because there's a case of false-positive activation in case if both DeprecatedIn and ActiveIn hardforks are not yet passed. This commit rewrites ActiveIn condition: the method/event IS active if and only if ActiveIn hardfork IS active AND DeprecatedIn hardfork IS NOT active. ActiveIn hardfork IS active if it's null OR it's already passed. DeprecatedIn hardfork IS NOT active if it's null OR it's not yet passed. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
1 parent f7bc967 commit 38d91fc

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

src/Neo/SmartContract/Native/NativeContract.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,8 @@ private NativeContractsCache.CacheEntry GetAllowedMethods(IsHardforkEnabledDeleg
225225

226226
internal static bool IsActive(IHardforkActivable u, IsHardforkEnabledDelegate hfChecker, uint blockHeight)
227227
{
228-
return // no hardfork is involved
229-
u.ActiveIn is null && u.DeprecatedIn is null ||
230-
// deprecated method hardfork is involved
231-
u.DeprecatedIn is not null && hfChecker(u.DeprecatedIn.Value, blockHeight) == false ||
232-
// active method hardfork is involved
233-
(u.DeprecatedIn is null && u.ActiveIn is not null && hfChecker(u.ActiveIn.Value, blockHeight));
228+
// Method/event is active iff ActiveIn hardfork IS active AND DeprecatedIn hardfork IS NOT active.
229+
return (u.ActiveIn is null || hfChecker(u.ActiveIn.Value, blockHeight)) && (u.DeprecatedIn is null || !hfChecker(u.DeprecatedIn.Value, blockHeight));
234230
}
235231

236232
/// <summary>

tests/Neo.UnitTests/SmartContract/Native/UT_NativeContract.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public void TestActiveDeprecatedIn()
7676
Assert.IsTrue(NativeContract.IsActive(new active() { ActiveIn = null, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 1));
7777
Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = null, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 20));
7878

79+
Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Basilisk, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 9));
80+
Assert.IsTrue(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Basilisk, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 10));
7981
Assert.IsTrue(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Basilisk, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 19));
8082
Assert.IsFalse(NativeContract.IsActive(new active() { ActiveIn = Hardfork.HF_Basilisk, DeprecatedIn = Hardfork.HF_Cockatrice }, settings.IsHardforkEnabled, 20));
8183
}

0 commit comments

Comments
 (0)