-
Notifications
You must be signed in to change notification settings - Fork 102
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
AllowOverflow option to avoid checking int range #1205
base: master
Are you sure you want to change the base?
Conversation
Changed the methodology. Skip range checks and throws with compilation option |
Need a way to compile neo-devpack-dotnet\tests\Neo.Compiler.CSharp.TestContracts\Contract_BigInteger.cs with SimulateOverflow=true |
Allowed CompilationOptions to be used in tests. |
…to unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Array.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_BigInteger.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Delegate.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Foreach.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Inline.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Lambda.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Linq.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_NullableType.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Out.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Params.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_PostfixUnary.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Record.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Returns.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_StaticVar.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Switch.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_TryCatch.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_shift.cs # tests/Neo.Compiler.CSharp.UnitTests/UnitTest_NullableType.cs # tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_List.cs # tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_Map.cs # tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_Regex.cs # tests/Neo.SmartContract.Framework.UnitTests/TestingArtifacts/Contract_Runtime.cs
This name is so scary.... |
this can save tons of gas, yes,,,,,, but,,,,,,, |
rather than allow overflow, i think biginteger only is better |
We should not save gas if the security is involved |
Sorry miss click |
No security problem is involved. This is just handling all int, long, short as BigInteger. |
Sometimes it's impossible to write BigInteger everywhere literally in codes. For example, shifting operations (>> and <<) in C# supports only int as the shifted count of bits. Also indexes of arrays have to be int. Then we have to write an explicit coversion (int) which wastes a range check. |
And our current default settings (with or without my PR) are --checked=false (--allow-overflow=false). This allows silent overflows (from int.MaxValue to int.MinValue, without or without my PR). I think this is even more dangerous. Maybe it's better to have default as --checked=false --allow-overflow=true, or --checked=true --allow-overflow=false |
we should detect |
…to unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Out.cs
…to unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Polymorphism.cs
…to unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_GoTo.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Initializer.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_TryCatch.cs # tests/Neo.Compiler.CSharp.UnitTests/UnitTest_GoTo.cs
# Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Inline.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Linq.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Record.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Switch.cs
@shargon please review |
This is an option that should be false by default, so after you @shargon reviewed, please dont merge it, i will update the test to remove the option and revert gas change. |
I still don't know why we need this option, which is the use case? |
where user can handle the integer range and no need to do automatic range check. currently, every numerous operation requires a range check, its expensive. |
expensive not because it's required for safety |
{ | ||
AllowOverflow = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should leave the test as before, only create one test for this specific case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
…to unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestCleanup.cs # tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Linq.cs # tests/Neo.Compiler.CSharp.UnitTests/UnitTest_Record.cs
…o unchecked # Conflicts: # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_GoTo.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Initializer.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Inline.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Instance.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Linq.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Polymorphism.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Record.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_StaticClass.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_Switch.cs # tests/Neo.Compiler.CSharp.UnitTests/TestingArtifacts/Contract_TryCatch.cs
Can we discuss this pe in the meeting? |
That's really great |
gas examples to demonstrate gas saving. /or use biginteger as much as possible |
Take a look to #1249 |
unchecked((int)bigInteger))
Will conflict. Draft for now.