Avoid zero-length array allocations
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemHelpers.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemHelpers.cs
@@ -13,12 +13,12 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
{
public static bool Verify(Statement statement, Proof proof)
{
- return ProofSystem.Verify(new Transcript(new byte[0]), new[] { statement }, new[] { proof });
+ return ProofSystem.Verify(new Transcript(Array.Empty<byte>()), new[] { statement }, new[] { proof });
}
public static Proof Prove(Knowledge knowledge, WasabiRandom random)
{
- return ProofSystem.Prove(new Transcript(new byte[0]), new[] { knowledge }, random).First();
+ return ProofSystem.Prove(new Transcript(Array.Empty<byte>()), new[] { knowledge }, random).First();
}
public static Proof Prove(Statement statement, Scalar witness, WasabiRandom random)

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
@@ -235,7 +235,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
ProofSystem.ZeroProofKnowledge(Ma1, r1)
};
- var proofs = ProofSystem.Prove(new Transcript(new byte[0]), knowledge, rnd);
+ var proofs = ProofSystem.Prove(new Transcript(Array.Empty<byte>()), knowledge, rnd);
var statements = new[]
{
@@ -243,7 +243,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
ProofSystem.ZeroProofStatement(Ma1)
};
- Assert.True(ProofSystem.Verify(new Transcript(new byte[0]), statements, proofs));
+ Assert.True(ProofSystem.Verify(new Transcript(Array.Empty<byte>()), statements, proofs));
}
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
WalletWasabi.Tests/UnitTests/Crypto/TranscriptTests.cs
@@ -172,7 +172,7 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
var transcript = new Transcript(protocol);
- Assert.ThrowsAny<ArgumentException>(() => transcript.CreateSyntheticSecretNonceProvider(new Scalar[0], rnd));
+ Assert.ThrowsAny<ArgumentException>(() => transcript.CreateSyntheticSecretNonceProvider(Array.Empty<Scalar>(), rnd));
}
}
}

MODIFY
WalletWasabi.Tests/UnitTests/Wabisabi/CredentialTests.cs
WalletWasabi.Tests/UnitTests/Wabisabi/CredentialTests.cs
+using System;
using System.Linq;
using NBitcoin;
using NBitcoin.Secp256k1;
@@ -106,7 +107,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
credentialResponse = issuer.HandleRequest(credentialRequest);
client0.HandleResponse(credentialResponse, validationData);
- (credentialRequest, validationData) = client0.CreateRequest(new Money[0], client0.Credentials.Valuable);
+ (credentialRequest, validationData) = client0.CreateRequest(Array.Empty<Money>(), client0.Credentials.Valuable);
credentialResponse = issuer.HandleRequest(credentialRequest);
client0.HandleResponse(credentialResponse, validationData);
@@ -133,7 +134,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
var credentialResponse = issuer.HandleRequest(credentialRequest);
client.HandleResponse(credentialResponse, validationData);
- var (validCredentialRequest, _) = client.CreateRequest(new Money[0], client.Credentials.ZeroValue.Take(1));
+ var (validCredentialRequest, _) = client.CreateRequest(Array.Empty<Money>(), client.Credentials.ZeroValue.Take(1));
// Test incorrect number of presentations (one instead of 3)
var presented = validCredentialRequest.Presented.ToArray();
@@ -151,7 +152,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
presented = credentialRequest.Presented.ToArray();
invalidCredentialRequest = new RegistrationRequestMessage(
Money.Coins(2),
- new CredentialPresentation[0], // Should present 3 credentials
+ Array.Empty<CredentialPresentation>(), // Should present 3 credentials
validCredentialRequest.Requested,
validCredentialRequest.Proofs);
@@ -159,7 +160,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
Assert.Equal(WabiSabiErrorCode.InvalidNumberOfPresentedCredentials, ex.ErrorCode);
Assert.Equal("3 credential presentations were expected but 0 were received.", ex.Message);
- (validCredentialRequest, _) = client.CreateRequest(new Money[0], client.Credentials.All);
+ (validCredentialRequest, _) = client.CreateRequest(Array.Empty<Money>(), client.Credentials.All);
// Test incorrect number of credential requests
invalidCredentialRequest = new RegistrationRequestMessage(
@@ -175,7 +176,7 @@ namespace WalletWasabi.Tests.UnitTests.Wabisabi
// Test incorrect number of credential requests
invalidCredentialRequest = new RegistrationRequestMessage(
Money.Coins(2),
- new CredentialPresentation[0],
+ Array.Empty<CredentialPresentation>(),
validCredentialRequest.Requested.Take(1),
validCredentialRequest.Proofs);

MODIFY
WalletWasabi/Gma/QrCodeNet/Encoding/Positioning/Stencils/AlignmentPattern.cs
WalletWasabi/Gma/QrCodeNet/Encoding/Positioning/Stencils/AlignmentPattern.cs
+using System;
using System.Collections.Generic;
using System.Linq;
@@ -27,7 +28,7 @@ namespace Gma.QrCodeNet.Encoding.Positioning.Stencils
new[]
{
null,
- System.Array.Empty<byte>(),
+ Array.Empty<byte>(),
new byte[] { 6, 18 },
new byte[] { 6, 22 },
new byte[] { 6, 26 },

Avoid zero-length array allocations