Improve ZipForceEqualLength
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfRepresentationTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ZeroKnowledge/KnowledgeOfRepresentationTests.cs
@@ -25,7 +25,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto.ZeroKnowledge
var secrets = new[] { new Scalar(scalarSeed1), new Scalar(scalarSeed2) };
var generators = new[] { Generators.G, Generators.Ga };
var publicPoint = GroupElement.Infinity;
- var secretGeneratorPairs = secrets.TupleWith(generators);
+ var secretGeneratorPairs = secrets.ZipForceEqualLength(generators);
foreach (var (secret, generator) in secretGeneratorPairs)
{
publicPoint += secret * generator;

MODIFY
WalletWasabi.Tests/UnitTests/LinqExtensionsTests.cs
WalletWasabi.Tests/UnitTests/LinqExtensionsTests.cs
@@ -71,17 +71,17 @@ namespace WalletWasabi.Tests.UnitTests
}
[Fact]
- public void TuplingTests()
+ public void ZippingTests()
{
var collection1 = new int[] { 1, 3, 5, 14 };
var collection2 = new int[] { 7, 11, 13 };
- Assert.ThrowsAny<InvalidOperationException>(() => collection1.TupleWith(collection2));
+ Assert.ThrowsAny<InvalidOperationException>(() => collection1.ZipForceEqualLength(collection2));
collection1 = new int[] { 1, 3, 5, 14 };
collection2 = new int[] { 7, 11, 13, 1, 2 };
- Assert.ThrowsAny<InvalidOperationException>(() => collection1.TupleWith(collection2));
+ Assert.ThrowsAny<InvalidOperationException>(() => collection1.ZipForceEqualLength(collection2));
collection1 = new int[] { 1, 3, 5, 14, 3 };
collection2 = new int[] { 7, 11, 13, 1, 2 };
- var tuple = collection1.TupleWith(collection2).ToArray();
+ var tuple = collection1.ZipForceEqualLength(collection2).ToArray();
for (int i = 0; i < tuple.Length; i++)
{
Assert.Equal(collection1[i], tuple[i].Item1);

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Prover.cs
WalletWasabi/Crypto/ZeroKnowledge/Prover.cs
@@ -57,7 +57,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var responses = new List<Scalar>();
foreach (var (secret, randomScalar) in secretGeneratorPairs
.Select(x => x.secret)
- .TupleWith(randomScalars))
+ .ZipForceEqualLength(randomScalars))
{
var response = randomScalar + secret * challenge;
responses.Add(response);

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Verifier.cs
WalletWasabi/Crypto/ZeroKnowledge/Verifier.cs
@@ -30,7 +30,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
var a = challenge * publicPoint + nonce;
var b = GroupElement.Infinity;
- foreach (var (response, generator) in responses.TupleWith(generators))
+ foreach (var (response, generator) in responses.ZipForceEqualLength(generators))
{
b += response * generator;
}

MODIFY
WalletWasabi/Extensions/LinqExtensions.cs
WalletWasabi/Extensions/LinqExtensions.cs
@@ -232,13 +232,13 @@ namespace System.Linq
/// <summary>
/// Creates a tuple collection from two collections. If lengths differ, exception is thrown.
/// </summary>
- public static IEnumerable<(T1, T2)> TupleWith<T1, T2>(this IEnumerable<T1> source, IEnumerable<T2> otherCollection)
+ public static IEnumerable<(T1, T2)> ZipForceEqualLength<T1, T2>(this IEnumerable<T1> source, IEnumerable<T2> otherCollection)
{
if (source.Count() != otherCollection.Count())
{
throw new InvalidOperationException($"{nameof(source)} and {nameof(otherCollection)} collections must have the same number of elements. {nameof(source)}:{source.Count()}, {nameof(otherCollection)}:{otherCollection.Count()}.");
}
- return source.Zip(otherCollection, (x, y) => (x, y));
+ return source.Zip(otherCollection);
}
}
}

Improve ZipForceEqualLength