Skip to content

Commit 62c8cf0

Browse files
authored
Allow HF in syscalls (#4119)
1 parent 1baf431 commit 62c8cf0

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/Neo/SmartContract/ApplicationEngine.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,16 @@ protected static void OnSysCall(ExecutionEngine engine, Instruction instruction)
274274
{
275275
if (engine is ApplicationEngine app)
276276
{
277-
app.OnSysCall(GetInteropDescriptor(instruction.TokenU32));
277+
var interop = GetInteropDescriptor(instruction.TokenU32);
278+
279+
if (interop?.Hardfork != null && !app.IsHardforkEnabled(interop.Hardfork.Value))
280+
{
281+
// The syscall is not active
282+
283+
throw new KeyNotFoundException();
284+
}
285+
286+
app.OnSysCall(interop);
278287
}
279288
else
280289
{
@@ -691,19 +700,20 @@ private static Block CreateDummyBlock(IReadOnlyStore snapshot, ProtocolSettings
691700
};
692701
}
693702

694-
private static InteropDescriptor Register(string name, string handler, long fixedPrice, CallFlags requiredCallFlags)
703+
private static InteropDescriptor Register(string name, string handler, long fixedPrice, CallFlags requiredCallFlags, Hardfork? hardfork = null)
695704
{
696705
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
697-
MethodInfo method = typeof(ApplicationEngine).GetMethod(handler, flags)
706+
var method = typeof(ApplicationEngine).GetMethod(handler, flags)
698707
?? typeof(ApplicationEngine).GetProperty(handler, flags).GetMethod;
699-
InteropDescriptor descriptor = new()
708+
var descriptor = new InteropDescriptor()
700709
{
701710
Name = name,
702711
Handler = method,
712+
Hardfork = hardfork,
703713
FixedPrice = fixedPrice,
704714
RequiredCallFlags = requiredCallFlags
705715
};
706-
services ??= new Dictionary<uint, InteropDescriptor>();
716+
services ??= [];
707717
services.Add(descriptor.Hash, descriptor);
708718
return descriptor;
709719
}

src/Neo/SmartContract/InteropDescriptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public uint Hash
5858
/// </summary>
5959
public long FixedPrice { get; init; }
6060

61+
/// <summary>
62+
/// Required Hardfork to be active.
63+
/// </summary>
64+
public Hardfork? Hardfork { get; init; }
65+
6166
/// <summary>
6267
/// The required <see cref="CallFlags"/> for the interoperable service.
6368
/// </summary>

0 commit comments

Comments
 (0)