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

Modify fee of System.Runtime.GetNotifications #2748

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 68 additions & 0 deletions benchmarks/Neo.Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.VM;
using System.Diagnostics;

namespace Neo;

static class Benchmarks
{
private static readonly ProtocolSettings protocol = ProtocolSettings.Default;
private static readonly NeoSystem system = new(protocol);

public static void NeoIssue2725()
{
// https://github.com/neo-project/neo/issues/2725
// L00: INITSSLOT 1
// L01: NEWARRAY0
// L02: PUSHDATA1 6161616161 //"aaaaa"
// L03: PUSHINT16 500
// L04: STSFLD0
// L05: OVER
// L06: OVER
// L07: SYSCALL 95016f61 //System.Runtime.Notify
// L08: LDSFLD0
// L09: DEC
// L10: DUP
// L11: STSFLD0
// L12: JMPIF L05
// L13: CLEAR
// L14: SYSCALL dbfea874 //System.Runtime.GetExecutingScriptHash
// L15: PUSHINT16 8000
// L16: STSFLD0
// L17: DUP
// L18: SYSCALL 274335f1 //System.Runtime.GetNotifications
// L19: DROP
// L20: LDSFLD0
// L21: DEC
// L22: DUP
// L23: STSFLD0
// L24: JMPIF L17
Run(nameof(NeoIssue2725), "VgHCDAVhYWFhYQH0AWBLS0GVAW9hWJ1KYCT1SUHb/qh0AUAfYEpBJ0M18UVYnUpgJPU=");
}

private static void Run(string name, string poc)
{
Random random = new();
Transaction tx = new()
{
Version = 0,
Nonce = (uint)random.Next(),
SystemFee = 20_00000000,
NetworkFee = 1_00000000,
ValidUntilBlock = ProtocolSettings.Default.MaxTraceableBlocks,
Signers = Array.Empty<Signer>(),
Attributes = Array.Empty<TransactionAttribute>(),
Script = Convert.FromBase64String(poc),
Witnesses = Array.Empty<Witness>()
};
using var snapshot = system.GetSnapshot();
using var engine = ApplicationEngine.Create(TriggerType.Application, tx, snapshot, system.GenesisBlock, protocol, tx.SystemFee);
engine.LoadScript(tx.Script);
Stopwatch stopwatch = Stopwatch.StartNew();
engine.Execute();
stopwatch.Stop();
Debug.Assert(engine.State == VMState.HALT);
Console.WriteLine($"Benchmark: {name},\tTime: {stopwatch.Elapsed}");
}
}
14 changes: 14 additions & 0 deletions benchmarks/Neo.Benchmarks/Neo.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>Neo</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\neo\neo.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions benchmarks/Neo.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Neo;
using System.Reflection;

foreach (var method in typeof(Benchmarks).GetMethods(BindingFlags.Public | BindingFlags.Static))
{
method.CreateDelegate<Action>().Invoke();
}
13 changes: 11 additions & 2 deletions neo.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29519.87
# Visual Studio Version 17
VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "neo", "src\neo\neo.csproj", "{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "neo.UnitTests", "tests\neo.UnitTests\neo.UnitTests.csproj", "{5B783B30-B422-4C2F-AC22-187A8D1993F4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Benchmarks", "benchmarks\Neo.Benchmarks\Neo.Benchmarks.csproj", "{BCD03521-5F8F-4775-9ADF-FA361480804F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B5339DF7-5D1D-43BA-B332-74B825E1770E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{EDE05FA8-8E73-4924-BC63-DD117127EEE1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,13 +28,18 @@ Global
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Release|Any CPU.Build.0 = Release|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{5B783B30-B422-4C2F-AC22-187A8D1993F4} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{BCD03521-5F8F-4775-9ADF-FA361480804F} = {C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/ApplicationEngine.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ partial class ApplicationEngine
/// The <see cref="InteropDescriptor"/> of System.Runtime.GetNotifications.
/// Gets the notifications sent by the specified contract during the execution.
/// </summary>
public static readonly InteropDescriptor System_Runtime_GetNotifications = Register("System.Runtime.GetNotifications", nameof(GetNotifications), 1 << 8, CallFlags.None);
public static readonly InteropDescriptor System_Runtime_GetNotifications = Register("System.Runtime.GetNotifications", nameof(GetNotifications), 1 << 12, CallFlags.None);
erikzhang marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The <see cref="InteropDescriptor"/> of System.Runtime.GasLeft.
Expand Down