From d08549cb4503c477b886376f27ad08d78adc80b3 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Sat, 17 Apr 2021 13:37:03 +1000 Subject: [PATCH 1/3] Modify signaturure verification method --- .../SCL/ECRecover.cs | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs index 5180789d8c..2b8e1aef55 100644 --- a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs +++ b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs @@ -9,7 +9,14 @@ namespace Stratis.SCL.Crypto { public static class ECRecover { - private static Address[] VerifySignatures(string[] signatures, byte[] message, Address[] addresses) + /// + /// Takes a message and signatures and recovers the list of addresses that produced the signatures. + /// + /// The list of signatures of the message. + /// The message that was signed. + /// The addresses returned are intersected with these addresses (if not null). + /// The list of addresses that produced the signatures and constrained to the list provided in . + public static Address[] GetVerifiedSignatures(string[] signatures, byte[] message, Address[] addresses) { try { @@ -34,20 +41,11 @@ private static Address[] VerifySignatures(string[] signatures, byte[] message, A /// /// The list of signatures of the message. /// The message that was signed. - /// The addresses returned are intersected with these addresses. - /// The list of addresses that produced the signatures and constrained to the list provided in . - /// The boolean value returned only indicates whether the operation could be performed. The number of verified addresses should still be checked. - public static bool TryVerifySignatures(string[] signatures, byte[] message, Address[] addresses, out Address[] verifiedAddresses) + /// The addresses returned are intersected with these addresses (if not null). + /// The list of addresses that produced the signatures and constrained to the list provided in . + public static Address[] GetVerifiedSignatures(string[] signatures, string message, Address[] addresses) { - if (addresses == null) - { - verifiedAddresses = null; - return false; - } - - verifiedAddresses = VerifySignatures(signatures, message, addresses); - - return verifiedAddresses != null; + return GetVerifiedSignatures(signatures, System.Text.Encoding.ASCII.GetBytes(message), addresses); } } } From 6b8e48d02bb152f080de5f93248681a5785c14b7 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Sun, 18 Apr 2021 12:11:29 +1000 Subject: [PATCH 2/3] Changes based on feedback --- .../SCL/ECRecover.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs index 2b8e1aef55..6c804706c1 100644 --- a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs +++ b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs @@ -16,7 +16,7 @@ public static class ECRecover /// The message that was signed. /// The addresses returned are intersected with these addresses (if not null). /// The list of addresses that produced the signatures and constrained to the list provided in . - public static Address[] GetVerifiedSignatures(string[] signatures, byte[] message, Address[] addresses) + private static Address[] VerifySignatures(string[] signatures, byte[] message, Address[] addresses) { try { @@ -41,11 +41,20 @@ public static Address[] GetVerifiedSignatures(string[] signatures, byte[] messag /// /// The list of signatures of the message. /// The message that was signed. - /// The addresses returned are intersected with these addresses (if not null). - /// The list of addresses that produced the signatures and constrained to the list provided in . - public static Address[] GetVerifiedSignatures(string[] signatures, string message, Address[] addresses) + /// The addresses returned are intersected with these addresses. + /// The list of addresses that produced the signatures and constrained to the list provided in . + /// The boolean value returned only indicates whether the operation could be performed. The number of verified addresses should still be checked. + public static bool TryGetVerifiedSignatures(string[] signatures, string message, Address[] addresses, out Address[] verifiedAddresses) { - return GetVerifiedSignatures(signatures, System.Text.Encoding.ASCII.GetBytes(message), addresses); + if (addresses == null) + { + verifiedAddresses = null; + return false; + } + + verifiedAddresses = VerifySignatures(signatures, System.Text.Encoding.ASCII.GetBytes(message), addresses); + + return verifiedAddresses != null; } } } From 6e5e1f77a35960009f0dcdec2dd852ce0617e251 Mon Sep 17 00:00:00 2001 From: quantumagi Date: Sun, 18 Apr 2021 12:16:33 +1000 Subject: [PATCH 3/3] Refactor --- src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs index 6c804706c1..4234c45e9e 100644 --- a/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs +++ b/src/Stratis.SmartContracts.CLR/SCL/ECRecover.cs @@ -44,7 +44,7 @@ private static Address[] VerifySignatures(string[] signatures, byte[] message, A /// The addresses returned are intersected with these addresses. /// The list of addresses that produced the signatures and constrained to the list provided in . /// The boolean value returned only indicates whether the operation could be performed. The number of verified addresses should still be checked. - public static bool TryGetVerifiedSignatures(string[] signatures, string message, Address[] addresses, out Address[] verifiedAddresses) + public static bool TryGetVerifiedSignatures(string[] signatures, byte[] message, Address[] addresses, out Address[] verifiedAddresses) { if (addresses == null) { @@ -52,9 +52,22 @@ public static bool TryGetVerifiedSignatures(string[] signatures, string message, return false; } - verifiedAddresses = VerifySignatures(signatures, System.Text.Encoding.ASCII.GetBytes(message), addresses); + verifiedAddresses = VerifySignatures(signatures, message, addresses); return verifiedAddresses != null; } + + /// + /// Takes a message and signatures and recovers the list of addresses that produced the signatures. + /// + /// The list of signatures of the message. + /// The message that was signed. + /// The addresses returned are intersected with these addresses. + /// The list of addresses that produced the signatures and constrained to the list provided in . + /// The boolean value returned only indicates whether the operation could be performed. The number of verified addresses should still be checked. + public static bool TryGetVerifiedSignatures(string[] signatures, string message, Address[] addresses, out Address[] verifiedAddresses) + { + return TryGetVerifiedSignatures(signatures, System.Text.Encoding.ASCII.GetBytes(message), addresses, out verifiedAddresses); + } } }