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

Support Koblitz-based and Keccak256-based custom witness verification #3209

Merged
merged 29 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b77b5ed
Native: extend CryptoLib's verifyWithECDsa with hasher parameter
AnnaShaleva May 3, 2024
7b730b3
SmartContract: add extension to ScriptBuilder for System.Contract.Call
AnnaShaleva May 3, 2024
46d6c51
Native: add an example of custom Koblitz signature verification
AnnaShaleva May 3, 2024
96e3af0
SmartContract: make multisig koblitz easier to parse
AnnaShaleva May 4, 2024
52d8a83
SmartContract: use ABORT in Koblitz multisig
AnnaShaleva May 6, 2024
48d3177
SmartContract: reduce callflag scope for Koblitz verification scripts
AnnaShaleva May 6, 2024
018968f
Native: add tests for CryptoLib's verifyWithECDsa
AnnaShaleva May 6, 2024
e7d9122
Native: update NamedCurveHash values for Keccak256 hasher
AnnaShaleva May 6, 2024
225f7f5
SmartContract: move EmitAppCallNoArgs to the testing code
AnnaShaleva May 6, 2024
79b5626
Merge branch 'master' into custom-witness
shargon May 7, 2024
cec836e
Apply suggestions from code review
shargon May 7, 2024
ebe2588
fix names
shargon May 7, 2024
b7f86e9
Merge branch 'master' into custom-witness
Jim8y May 7, 2024
02cbc50
Cryptography: cache ECDomainParameters for Secp256r1 and Secp256k1
AnnaShaleva May 8, 2024
c8bb5f5
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
a70b85c
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
47fe071
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
a7eaf7a
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
f565ea4
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
c2d9801
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
ff482ec
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
8d970eb
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
fc5f540
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
d108a03
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
a349af8
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
fe1b449
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
e2c88f6
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
bab3b21
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
64959f7
Update tests/Neo.UnitTests/SmartContract/Native/UT_CryptoLib.cs
Jim8y May 9, 2024
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
71 changes: 55 additions & 16 deletions src/Neo/Cryptography/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public static class Crypto
private static readonly bool IsOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
private static readonly ECCurve secP256k1 = ECCurve.CreateFromFriendlyName("secP256k1");
private static readonly X9ECParameters bouncySecp256k1 = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256k1");
private static readonly X9ECParameters bouncySecp256r1 = Org.BouncyCastle.Asn1.Sec.SecNamedCurves.GetByName("secp256r1");
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Holds domain parameters for Secp256r1 elliptic curve.
/// </summary>
private static readonly ECDomainParameters secp256r1DomainParams = new ECDomainParameters(bouncySecp256r1.Curve, bouncySecp256r1.G, bouncySecp256r1.N, bouncySecp256r1.H);

/// <summary>
/// Holds domain parameters for Secp256k1 elliptic curve.
/// </summary>
private static readonly ECDomainParameters secp256k1DomainParams = new ECDomainParameters(bouncySecp256k1.Curve, bouncySecp256k1.G, bouncySecp256k1.N, bouncySecp256k1.H);

/// <summary>
/// Calculates the 160-bit hash value of the specified message.
Expand All @@ -50,22 +61,30 @@ public static byte[] Hash256(ReadOnlySpan<byte> message)
}

/// <summary>
/// Signs the specified message using the ECDSA algorithm.
/// Signs the specified message using the ECDSA algorithm and specified hash algorithm.
/// </summary>
/// <param name="message">The message to be signed.</param>
/// <param name="priKey">The private key to be used.</param>
/// <param name="ecCurve">The <see cref="ECC.ECCurve"/> curve of the signature, default is <see cref="ECC.ECCurve.Secp256r1"/>.</param>
/// <param name="hasher">The hash algorithm to hash the message, default is SHA256.</param>
/// <returns>The ECDSA signature for the specified message.</returns>
public static byte[] Sign(byte[] message, byte[] priKey, ECC.ECCurve ecCurve = null)
public static byte[] Sign(byte[] message, byte[] priKey, ECC.ECCurve ecCurve = null, Hasher hasher = Hasher.SHA256)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
if (IsOSX && ecCurve == ECC.ECCurve.Secp256k1)
if (hasher == Hasher.Keccak256 || (IsOSX && ecCurve == ECC.ECCurve.Secp256k1))
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
var domain = new ECDomainParameters(bouncySecp256k1.Curve, bouncySecp256k1.G, bouncySecp256k1.N, bouncySecp256k1.H);
var domain =
ecCurve == null || ecCurve == ECC.ECCurve.Secp256r1 ? secp256r1DomainParams :
ecCurve == ECC.ECCurve.Secp256k1 ? secp256k1DomainParams :
throw new NotSupportedException(nameof(ecCurve));
var signer = new Org.BouncyCastle.Crypto.Signers.ECDsaSigner();
var privateKey = new BigInteger(1, priKey);
var priKeyParameters = new ECPrivateKeyParameters(privateKey, domain);
signer.Init(true, priKeyParameters);
var signature = signer.GenerateSignature(message.Sha256());
var messageHash =
hasher == Hasher.SHA256 ? message.Sha256() :
hasher == Hasher.Keccak256 ? message.Keccak256() :
throw new NotSupportedException(nameof(hasher));
var signature = signer.GenerateSignature(messageHash);

var signatureBytes = new byte[64];
var rBytes = signature[0].ToByteArrayUnsigned();
Expand All @@ -87,24 +106,35 @@ public static byte[] Sign(byte[] message, byte[] priKey, ECC.ECCurve ecCurve = n
Curve = curve,
D = priKey,
});
return ecdsa.SignData(message, HashAlgorithmName.SHA256);
var hashAlg =
hasher == Hasher.SHA256 ? HashAlgorithmName.SHA256 :
throw new NotSupportedException(nameof(hasher));
return ecdsa.SignData(message, hashAlg);
}

/// <summary>
/// Verifies that a digital signature is appropriate for the provided key and message.
/// Verifies that a digital signature is appropriate for the provided key, message and hash algorithm.
/// </summary>
/// <param name="message">The signed message.</param>
/// <param name="signature">The signature to be verified.</param>
/// <param name="pubkey">The public key to be used.</param>
/// <param name="hasher">The hash algorithm to be used to hash the message, the default is SHA256.</param>
/// <returns><see langword="true"/> if the signature is valid; otherwise, <see langword="false"/>.</returns>
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ECC.ECPoint pubkey)
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ECC.ECPoint pubkey, Hasher hasher = Hasher.SHA256)
{
if (signature.Length != 64) return false;

if (IsOSX && pubkey.Curve == ECC.ECCurve.Secp256k1)
if (hasher == Hasher.Keccak256 || (IsOSX && pubkey.Curve == ECC.ECCurve.Secp256k1))
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

should the else branch be dropped?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because we still have to process SHA256 with Koblitz curve (if not on mac).

Copy link
Contributor

Choose a reason for hiding this comment

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

but i think BouncyCastle is able to handle this case, isn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe the IsOSX && pubkey.Curve == ECC.ECCurve.Secp256k1 is introduced here for performance optimization, @shargon do you have some comments here?

Copy link
Member

Choose a reason for hiding this comment

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

Secp256k1 isn't natively supported on MacOS; reason we need to use BouncyCastle.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cschuchardt88 why not just use BouncyCastle and drop the else branch

Copy link
Member Author

Choose a reason for hiding this comment

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

In general, to me it seems to be more preferable (and safe) to use native built-in implementation instead of some external libraries, and thus, we're stick to the native ECDsa's sign/verify implementation as much as possible. In future both k1 on macOS and Koblitz hasher may be added to the native library, then we may drop this if. But until then I think it's OK to keep BouncyCastle for these two cases.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% sure why. Maybe we want to avoid 3rd-party libraries or unsupported features for linux/windows support.

Maybe @shargon @Jim8y can help us.

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, to me it seems to be more preferable (and safe) to use native built-in implementation instead of some external libraries, and thus, we're stick to the native ECDsa's sign/verify implementation as much as possible. In future both k1 on macOS and Koblitz hasher may be added to the native library, then we may drop this if. But until then I think it's OK to keep BouncyCastle for these two cases.

I hold the opposite view

for blockchain, consistency is very important, and behavioral differences caused by architecture and platform cannot be tolerated.

the implementation of dotnet's Crypto library is to directly call the operating system API instead of implementing it by themselves. even their own developers are not clear enough about these behaviors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's then start a discussion issue, #3220.

AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
{
var domain = new ECDomainParameters(bouncySecp256k1.Curve, bouncySecp256k1.G, bouncySecp256k1.N, bouncySecp256k1.H);
var point = bouncySecp256k1.Curve.CreatePoint(
var domain =
pubkey.Curve == ECC.ECCurve.Secp256r1 ? secp256r1DomainParams :
pubkey.Curve == ECC.ECCurve.Secp256k1 ? secp256k1DomainParams :
throw new NotSupportedException(nameof(pubkey.Curve));
var curve =
pubkey.Curve == ECC.ECCurve.Secp256r1 ? bouncySecp256r1.Curve :
bouncySecp256k1.Curve;
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved

var point = curve.CreatePoint(
new BigInteger(pubkey.X.Value.ToString()),
new BigInteger(pubkey.Y.Value.ToString()));
var pubKey = new ECPublicKeyParameters("ECDSA", point, domain);
Expand All @@ -115,11 +145,19 @@ public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte
var r = new BigInteger(1, sig, 0, 32);
var s = new BigInteger(1, sig, 32, 32);

return signer.VerifySignature(message.Sha256(), r, s);
var messageHash =
hasher == Hasher.SHA256 ? message.Sha256() :
hasher == Hasher.Keccak256 ? message.Keccak256() :
throw new NotSupportedException(nameof(hasher));

return signer.VerifySignature(messageHash, r, s);
}

var ecdsa = CreateECDsa(pubkey);
return ecdsa.VerifyData(message, signature, HashAlgorithmName.SHA256);
var hashAlg =
hasher == Hasher.SHA256 ? HashAlgorithmName.SHA256 :
shargon marked this conversation as resolved.
Show resolved Hide resolved
throw new NotSupportedException(nameof(hasher));
return ecdsa.VerifyData(message, signature, hashAlg);
}

/// <summary>
Expand Down Expand Up @@ -153,16 +191,17 @@ public static ECDsa CreateECDsa(ECC.ECPoint pubkey)
}

/// <summary>
/// Verifies that a digital signature is appropriate for the provided key and message.
/// Verifies that a digital signature is appropriate for the provided key, curve, message and hasher.
/// </summary>
/// <param name="message">The signed message.</param>
/// <param name="signature">The signature to be verified.</param>
/// <param name="pubkey">The public key to be used.</param>
/// <param name="curve">The curve to be used by the ECDSA algorithm.</param>
/// <param name="hasher">The hash algorithm to be used hash the message, the default is SHA256.</param>
/// <returns><see langword="true"/> if the signature is valid; otherwise, <see langword="false"/>.</returns>
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ReadOnlySpan<byte> pubkey, ECC.ECCurve curve)
public static bool VerifySignature(ReadOnlySpan<byte> message, ReadOnlySpan<byte> signature, ReadOnlySpan<byte> pubkey, ECC.ECCurve curve, Hasher hasher = Hasher.SHA256)
Copy link
Member

@cschuchardt88 cschuchardt88 May 6, 2024

Choose a reason for hiding this comment

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

I still think this should be marked as [Obsolete] and add creating of new method. We dont want to break wallets, dapps, etc.

Copy link
Member Author

@AnnaShaleva AnnaShaleva May 6, 2024

Choose a reason for hiding this comment

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

The behaviour is compatible. It was SHA256 before this change, and it's now SHA256 by default. Users don't have to change anything in their code, and nothing is broken by this change.

{
return VerifySignature(message, signature, ECC.ECPoint.DecodePoint(pubkey, curve));
return VerifySignature(message, signature, ECC.ECPoint.DecodePoint(pubkey, curve), hasher);
}
}
}
29 changes: 29 additions & 0 deletions src/Neo/Cryptography/Hasher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// Hasher.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.Cryptography
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
/// <summary>
/// Represents hash function identifiers supported by ECDSA message signature and verification.
/// </summary>
public enum Hasher : byte
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Hasher is to generic leaves guessing; not being able to identify it as a Enum. Currently the name says to me that it does something.

Maybe HashingAlgorithmNames, SigningHashNames

{
/// <summary>
/// The SHA256 hash algorithm.
/// </summary>
SHA256 = 0x00,

/// <summary>
/// The Keccak256 hash algorithm.
/// </summary>
Keccak256 = 0x01,
}
}
35 changes: 35 additions & 0 deletions src/Neo/Cryptography/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Neo.IO;
using Neo.Network.P2P.Payloads;
using Neo.Wallets;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Parameters;
Expand Down Expand Up @@ -153,6 +154,40 @@ public static byte[] Sha256(this Span<byte> value)
return Sha256((ReadOnlySpan<byte>)value);
}

/// <summary>
/// Computes the hash value for the specified byte array using the keccak256 algorithm.
/// </summary>
/// <param name="value">The input to compute the hash code for.</param>
/// <returns>The computed hash code.</returns>
public static byte[] Keccak256(this byte[] value)
{
KeccakDigest keccak = new(256);
keccak.BlockUpdate(value, 0, value.Length);
byte[] result = new byte[keccak.GetDigestSize()];
keccak.DoFinal(result, 0);
return result;
}

/// <summary>
/// Computes the hash value for the specified byte array using the keccak256 algorithm.
/// </summary>
/// <param name="value">The input to compute the hash code for.</param>
/// <returns>The computed hash code.</returns>
public static byte[] Keccak256(this ReadOnlySpan<byte> value)
{
return Keccak256(value.ToArray());
}

/// <summary>
/// Computes the hash value for the specified byte array using the keccak256 algorithm.
/// </summary>
/// <param name="value">The input to compute the hash code for.</param>
/// <returns>The computed hash code.</returns>
public static byte[] Keccak256(this Span<byte> value)
{
return Keccak256(value.ToArray());
}

public static byte[] AES256Encrypt(this byte[] plainData, byte[] key, byte[] nonce, byte[] associatedData = null)
{
if (nonce.Length != 12) throw new ArgumentOutOfRangeException(nameof(nonce));
Expand Down
22 changes: 10 additions & 12 deletions src/Neo/SmartContract/Native/CryptoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

using Neo.Cryptography;
using Neo.Cryptography.ECC;
using Org.BouncyCastle.Crypto.Digests;
using System;
using System.Collections.Generic;

Expand All @@ -22,10 +21,12 @@ namespace Neo.SmartContract.Native
/// </summary>
public sealed partial class CryptoLib : NativeContract
{
private static readonly Dictionary<NamedCurve, ECCurve> curves = new()
private static readonly Dictionary<NamedCurveHash, (ECCurve Curve, Hasher Hasher)> s_curves = new()
{
[NamedCurve.secp256k1] = ECCurve.Secp256k1,
[NamedCurve.secp256r1] = ECCurve.Secp256r1
[NamedCurveHash.secp256k1SHA256] = (ECCurve.Secp256k1, Hasher.SHA256),
[NamedCurveHash.secp256r1SHA256] = (ECCurve.Secp256r1, Hasher.SHA256),
[NamedCurveHash.secp256k1Keccak256] = (ECCurve.Secp256k1, Hasher.Keccak256),
[NamedCurveHash.secp256r1Keccak256] = (ECCurve.Secp256r1, Hasher.Keccak256),
};

internal CryptoLib() : base() { }
Expand Down Expand Up @@ -73,11 +74,7 @@ public static byte[] Murmur32(byte[] data, uint seed)
[ContractMethod(Hardfork.HF_Cockatrice, CpuFee = 1 << 15)]
public static byte[] Keccak256(byte[] data)
{
KeccakDigest keccak = new(256);
keccak.BlockUpdate(data, 0, data.Length);
byte[] result = new byte[keccak.GetDigestSize()];
keccak.DoFinal(result, 0);
return result;
return data.Keccak256();
}

/// <summary>
Expand All @@ -86,14 +83,15 @@ public static byte[] Keccak256(byte[] data)
/// <param name="message">The signed message.</param>
/// <param name="pubkey">The public key to be used.</param>
/// <param name="signature">The signature to be verified.</param>
/// <param name="curve">The curve to be used by the ECDSA algorithm.</param>
/// <param name="curveHash">A pair of the curve to be used by the ECDSA algorithm and the hasher function to be used to hash message.</param>
/// <returns><see langword="true"/> if the signature is valid; otherwise, <see langword="false"/>.</returns>
[ContractMethod(CpuFee = 1 << 15)]
public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurve curve)
public static bool VerifyWithECDsa(byte[] message, byte[] pubkey, byte[] signature, NamedCurveHash curveHash)
{
try
{
return Crypto.VerifySignature(message, signature, pubkey, curves[curve]);
var ch = s_curves[curveHash];
return Crypto.VerifySignature(message, signature, pubkey, ch.Curve, ch.Hasher);
}
catch (ArgumentException)
{
Expand Down
8 changes: 7 additions & 1 deletion src/Neo/SmartContract/Native/NamedCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

using System;

namespace Neo.SmartContract.Native
{
/// <summary>
/// Represents the named curve used in ECDSA.
/// Represents the named curve used in ECDSA. This enum is obsolete
/// and will be removed in future versions. Please, use an extended <see cref="NamedCurveHash"/> instead.
/// </summary>
/// <remarks>
/// https://tools.ietf.org/html/rfc4492#section-5.1.1
/// </remarks>
[Obsolete("NamedCurve enum is obsolete and will be removed in future versions. Please, use an extended NamedCurveHash instead.")]
public enum NamedCurve : byte
{
/// <summary>
/// The secp256k1 curve.
/// </summary>
[Obsolete("secp256k1 value is obsolete and will be removed in future versions. Please, use NamedCurveHash.secp256k1SHA256 for compatible behaviour.")]
secp256k1 = 22,

/// <summary>
/// The secp256r1 curve, which known as prime256v1 or nistP-256.
/// </summary>
[Obsolete("secp256r1 value is obsolete and will be removed in future versions. Please, use NamedCurveHash.secp256r1SHA256 for compatible behaviour.")]
secp256r1 = 23
}
}
40 changes: 40 additions & 0 deletions src/Neo/SmartContract/Native/NamedCurveHash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2015-2024 The Neo Project.
//
// NamedCurveHash.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.SmartContract.Native
{
/// <summary>
/// Represents a pair of the named curve used in ECDSA and a hash algorithm used to hash message.
/// This is a compatible extension of an obsolete <see cref="NamedCurve"/> enum.
/// </summary>
public enum NamedCurveHash : byte
Copy link
Member

Choose a reason for hiding this comment

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

Maybe two different enums is better than this pair, no?

Copy link
Member Author

@AnnaShaleva AnnaShaleva May 6, 2024

Choose a reason for hiding this comment

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

We need native CryptoLib’s werifyWithECDsa method (its API, in fact) to be compatible with the old one, since there are transactions that call this method. And thus, we use a pair here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Theoretically, VerifyWithECDsa could be changed to have two parameters in some HF. But practically, #3210.

{
/// <summary>
/// The secp256k1 curve and SHA256 hash algorithm.
/// </summary>
secp256k1SHA256 = 22,
shargon marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The secp256r1 curve, which known as prime256v1 or nistP-256, and SHA256 hash algorithm.
/// </summary>
secp256r1SHA256 = 23,

/// <summary>
/// The secp256k1 curve and Keccak256 hash algorithm.
/// </summary>
secp256k1Keccak256 = 122,

/// <summary>
/// The secp256r1 curve, which known as prime256v1 or nistP-256, and Keccak256 hash algorithm.
/// </summary>
secp256r1Keccak256 = 123
}
}
Loading