neo-devpack-dotnet icon indicating copy to clipboard operation
neo-devpack-dotnet copied to clipboard

Unnecessary argument when the smart contract class and its methods are non-static

Open Hecate2 opened this issue 1 year ago • 3 comments

When a user does not define the compiled smart contract class and its methods as static, the compiler builds an unnecessary argument, and input it as arg 0 (this of the class object) for all the non-static methods. An example is the compilation results of neo-devpack-dotnet/tests/Neo.Compiler.CSharp.TestContracts/Contract_Abort.cs (manifest and dumpnef affliated). Maybe we can avoid generating this unnecessary arg 0 in the compiler. If (in the future) we have a symbolic VM that analyzes reads and writes to storage evaluation stack, static fields, arguments and local varaiables, we may try to identify the unnecessary constructions and delete the codes in the optimizer.

Contract_Abort.nef.txt Contract_Abort.manifest.json

Hecate2 avatar Sep 27 '24 10:09 Hecate2

are you going to process it?

Jim8y avatar Sep 27 '24 13:09 Jim8y

are you going to process it?

I'm not sure. I have not found the best way to handle it.

Hecate2 avatar Sep 27 '24 13:09 Hecate2

This problem can be handled by https://github.com/neo-project/neo-devpack-dotnet/pull/1185 in most cases. But in polymorphism tests, I did not remove the constructors in a derived smart contract class, because base may be called at any time.

Hecate2 avatar Sep 30 '24 10:09 Hecate2