Skip to content

Conversation

@quantumagi
Copy link
Contributor

No description provided.

@quantumagi quantumagi requested review from YakupIpek and rowandh April 13, 2021 03:25
public static class Operations
{
public static void Noop() { }
public static Address DeserializeAddress(byte[] address)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not copy the much more readable existing implementation?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also this would go in the Stratis.SCL.Serialization namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored.

/// <param name="message">The message that was signed.</param>
/// <param name="addresses">If not <c>null</c> the addresses returned are intersected with these addresses.</param>
/// <returns>The list of addresses that produced the signatures and constrained to the list provided in <paramref name="addresses"/> if not <c>null</c>.</returns>
public static Address[] VerifySignatures(byte[] signatures, byte[] message, Address[] addresses = null)
Copy link
Contributor

@rowandh rowandh Apr 13, 2021

Choose a reason for hiding this comment

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

What do you think of the following:

  • Split this into 2 methods instead of allowing a null param for addresses
  • Using the Try pattern instead of returning null ie. bool TryVerifySignatures(..., out Address[] verifiedAddresses)

Copy link
Contributor

Choose a reason for hiding this comment

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

We should also wrap everything in a try/catch (gross, I know, but NBitcoin especially likes to throw a lot) to prevent exceptions being propagated into the contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@rowandh
Copy link
Contributor

rowandh commented Apr 13, 2021

Would be nice to see tests similar to those in #414.

@quantumagi
Copy link
Contributor Author

quantumagi commented Apr 13, 2021

Tests added. Additional tests to accompany the dictionary contract PR.

@quantumagi quantumagi changed the title Add VerifySignatures method for use by SCs [Infra] Add VerifySignatures method for use by SCs Apr 13, 2021
/// <returns>An array of size N * <paramref name="subArrayLength"/></returns>
public static T[] FlattenArray<T>(T[][] array, int subArrayLength) where T : struct
{
if (array == null || array.Any(x => x == null || x.Length != subArrayLength))
Copy link
Contributor

@YakupIpek YakupIpek Apr 14, 2021

Choose a reason for hiding this comment

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

It is needed to validate parameters ? Because below logic will already fail if array is null or contains null items.

These are going to cost gas so code should to be efficient. You can try catch whole logic and return null. Secondly below code already iterate values so you may validate items there. Imo if it will fail already so no need to check there even.

@rowandh wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we perhaps make this private for now? Otherwise there's 3 decisions about the SCL API in this PR.

I'm fine with the implementation. I think we could do a full review of additional optimizations before SCL is published.

Copy link
Contributor Author

@quantumagi quantumagi Apr 14, 2021

Choose a reason for hiding this comment

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

@rowandh , I've removed flatten / unflatten in favour of using the ContractPrimitiveSerializer.ToArray from within the contract itself. That means we're now passing string[] signatures to VerifySignatures.

@rowandh rowandh merged commit 11ffdc6 into stratisproject:infracontracts Apr 15, 2021
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 this pull request may close these issues.

3 participants