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

Nullable ECPoint and ECFieldElement #3758

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Nullable ECPoint and ECFieldElement #3758

wants to merge 17 commits into from

Conversation

shargon
Copy link
Member

@shargon shargon commented Feb 13, 2025

Description

Check nullability in ECPoint and ECFieldElement

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Current

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

cschuchardt88
cschuchardt88 previously approved these changes Feb 14, 2025
@cschuchardt88
Copy link
Member

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed TestECFieldElementConstructor [4 ms]
  Error Message:
   Assert.ThrowsException failed. Expected exception type:<System.ArgumentNullException>. Actual exception type:<System.NullReferenceException>. 
  Stack Trace:
     at Neo.UnitTests.Cryptography.ECC.UT_ECFieldElement.TestECFieldElementConstructor() in /home/runner/work/neo/neo/tests/Neo.UnitTests/Cryptography/ECC/UT_ECFieldElement.cs:line 44
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

  Failed TestOpMultiply [< 1 ms]
  Error Message:
   Assert.ThrowsException failed. Expected exception type:<System.ArgumentNullException>. Actual exception type:<System.ArgumentException>. 
  Stack Trace:
     at Neo.UnitTests.Cryptography.ECC.UT_ECPoint.TestOpMultiply() in /home/runner/work/neo/neo/tests/Neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs:line 337
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

nan01ab
nan01ab previously approved these changes Feb 19, 2025
Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com>
@shargon
Copy link
Member Author

shargon commented Feb 19, 2025

@cschuchardt88 is not the first time that your "fixes" break the build, please fix it

@cschuchardt88
Copy link
Member

cschuchardt88 commented Feb 19, 2025

It was styling issue for variable name and yes we all make mistakes. But I put these rules in place to protect us... all of us, even me.

Should be fixed now.

@cschuchardt88 is not the first time that your "fixes" break the build, please fix it

I can count on one hand, even with missing fingers too.

Comment on lines +243 to +250
var hexPubKey = ((ByteString)resJArray[2])?.GetSpan().ToHexString();
if (string.IsNullOrEmpty(hexPubKey))
{
ConsoleHelper.Error("Error parsing the result");
return;
}

var publickey = ECPoint.Parse(hexPubKey, ECCurve.Secp256r1);
Copy link
Member

@cschuchardt88 cschuchardt88 Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ECPoint.TryParse? Index for resJArray[2] could be out of range as well.

Comment on lines 68 to 69
action = () => new ECPoint(null, Y, null);
Assert.ThrowsException<ArgumentException>(action);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still check if the output is correct. No test functionality should be removed. But should be adjusted for new logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not null now

Copy link
Member

@cschuchardt88 cschuchardt88 Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well whatever it should be, can we check that? What will new ECPoint(null, Y, null) be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but it has no logic to have tests with null, when the argument is not null, but it's ok, if this is your wish I will change it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test with a pragma for avoid the warning compilation seems weird, why are you asking for this test? Is not null argument, no coverage is increased

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure the ECPoint is returning the right thing. What if doesn't return null.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a constructor

Copy link
Member

@cschuchardt88 cschuchardt88 Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a constructor

What i meant is what does new ECPoint(null, Y, null) equal? for example new ECPoint(null, Y, null) == CCurve.G.

Can we test to make sure it equals the right thing?

Comment on lines 338 to 349
ECPoint p = null;
byte[] n = new byte[] { 1 };
Action action = () => p = p * n;
Assert.ThrowsException<ArgumentNullException>(action);
var p = ECCurve.Secp256k1.G;

p = ECCurve.Secp256k1.G;
n = null;
action = () => p = p * n;
Assert.ThrowsException<ArgumentNullException>(action);

n = new byte[] { 1 };
action = () => p = p * n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@Jim8y
Copy link
Contributor

Jim8y commented Feb 25, 2025

@shargon conflicts in this pr please.

n = new byte[] { 1 };
action = () => p = p * n;
byte[] n = [1];
var action = () => p = p * n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var action = () => p = p * n;
Action action = () => p = p * n;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants