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

secP256k1 not supported on OSX #2499

Closed
ixje opened this issue Jun 8, 2021 · 2 comments · Fixed by #2511
Closed

secP256k1 not supported on OSX #2499

ixje opened this issue Jun 8, 2021 · 2 comments · Fixed by #2511

Comments

@ixje
Copy link
Contributor

ixje commented Jun 8, 2021

Describe the bug
The single transaction in testnet block 49672 fails with a FAULT state when running neo-cli RC3 on OSX. The same transaction exits with a HALT state on Windows and Linux. This is due to using the system ECDSA (which was changed to here #2340) which does not support koblitz curves according to Microsoft where I tried to report the issue.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Interop+AppleCrypto+AppleCommonCryptoCryptographicException: Unknown format in import.
   at Interop.AppleCrypto.ImportEphemeralKey(ReadOnlySpan`1 keyBlob, Boolean hasPrivateKey)
   at System.Security.Cryptography.EccSecurityTransforms.ImportKey(ECParameters parameters)
   at System.Security.Cryptography.EccSecurityTransforms.ImportParameters(ECParameters parameters)
   at System.Security.Cryptography.ECDsa.ECDsaImplementation.ECDsaSecurityTransforms.ImportParameters(ECParameters parameters)
   at System.Security.Cryptography.ECDsa.Create(ECParameters parameters)
   at Neo.Cryptography.Crypto.VerifySignature(ReadOnlySpan`1 message, ReadOnlySpan`1 signature, ECPoint pubkey) in /Users/erik/Documents/code/neo3-csharp-rc3/neo/src/neo/Cryptography/Crypto.cs:line 67
   at Neo.Cryptography.Crypto.VerifySignature(ReadOnlySpan`1 message, ReadOnlySpan`1 signature, ReadOnlySpan`1 pubkey, ECCurve curve) in /Users/erik/Documents/code/neo3-csharp-rc3/neo/src/neo/Cryptography/Crypto.cs:line 89
   at Neo.SmartContract.Native.CryptoLib.VerifyWithECDsa(Byte[] message, Byte[] pubkey, Byte[] signature, NamedCurve curve) in /Users/erik/Documents/code/neo3-csharp-rc3/neo/src/neo/SmartContract/Native/CryptoLib.cs:line 56
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Neo.SmartContract.Native.NativeContract.Invoke(ApplicationEngine engine, Byte version) in /Users/erik/Documents/code/neo3-csharp-rc3/neo/src/neo/SmartContract/Native/NativeContract.cs:line 196

To Reproduce
The following code creates the same data as the above mentioned transaction would at this failing piece of NEO code

using System;
using System.Security.Cryptography;

namespace whatevertesting
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] message =
            {
                170,145,162,23,52,214,229,130,21,187,48,134,182,18,13,242,142,11,155,115,254,228,105,60,202,226,75,161,198,208,52,236
            };
            byte[] signature =
            {
                39, 234, 133, 46, 9, 81, 126, 32, 215, 159, 63, 99, 22, 126, 81, 132, 148, 122, 75, 194, 112, 52, 99,
                14, 148, 79, 92, 137, 250, 214, 124, 73, 42, 145, 46, 100, 154, 178, 86, 73, 69, 162, 121, 61, 127, 89,
                224, 215, 205, 30, 54, 100, 116, 230, 180, 143, 239, 45, 99, 83, 220, 83, 141, 90
            };
            byte[]
                buffer =
                {
                    4,
                    239, 68, 190, 186, 132, 66, 43, 215, 106, 89, 149, 49, 201, 254, 80, 150, 154, 146, 154, 15, 238,
                    53, 223, 102, 105, 15, 55, 12, 225, 159, 168, 192, 14, 212, 182, 73, 105, 29, 17, 107, 125, 238,
                    183, 155, 113, 65, 86, 209, 137, 129, 145, 110, 88, 174, 64, 192, 235, 172, 191, 59, 208, 184, 120,
                    119
                };

            using var ecdsa = ECDsa.Create(new ECParameters
            {
                Curve = ECCurve.CreateFromFriendlyName("secP256k1"),
                Q = new ECPoint
                {
                    X = buffer[1..33],
                    Y = buffer[33..]
                }
            });
            bool valid = ecdsa.VerifyData(message, signature, HashAlgorithmName.SHA256);
            Console.WriteLine(valid);
        }
    }
}

Expected behavior
I expect neo-cli to produces identical results on OSX as it would on Linux and Windows.

Platform:

  • OS: OSX catalina
  • Version: neo-cli rc3
@shargon
Copy link
Member

shargon commented Jun 9, 2021

It could be solved with a compiler directive, but I have no OSX for testing it, I will try to do it in the next days

@ixje
Copy link
Contributor Author

ixje commented Jun 9, 2021

@shargon I can test your solution

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

Successfully merging a pull request may close this issue.

2 participants