Bikeshed `Credential` class
Rename `Amount` property to `Value`, since `Amount` typically implies
a bitcoin value, but credentials can also represent vbytes
Also change its type from `Scalar` to `long`, slightly simplifying
interface
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
@@ -65,9 +65,9 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
// A blinded amount is known as an `attribute`. In this case the attribute Ma is the
// value 10000 blinded with a random `blindingFactor`. This attribute is sent to
// the coordinator.
- var amount = new Scalar(10_000);
+ var amount = 10_000L;
var r = rnd.GetScalar();
- var ma = amount * Generators.Gg + r * Generators.Gh;
+ var ma = new Scalar((ulong)amount) * Generators.Gg + r * Generators.Gh;
// The coordinator generates a MAC and a proof that the MAC was generated using the
// coordinator's secret key. The coordinator sends the pair (MAC, proofOfMac) back

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/Credential.cs
WalletWasabi/Crypto/ZeroKnowledge/Credential.cs
using NBitcoin.Secp256k1;
using WalletWasabi.Crypto.Groups;
+using WalletWasabi.Helpers;
namespace WalletWasabi.Crypto.ZeroKnowledge
{
@@ -11,12 +12,12 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
/// <summary>
/// Initializes a new Credential instance.
/// </summary>
- /// <param name="amount">The amount represented by the credential.</param>
+ /// <param name="value">The amount represented by the credential.</param>
/// <param name="randomness">The randomness used as blinding factor in the Pedersen committed amount.</param>
/// <param name="mac">The algebraic MAC representing the anonymous credential issued by the coordinator.</param>
- public Credential(Scalar amount, Scalar randomness, MAC mac)
+ public Credential(long value, Scalar randomness, MAC mac)
{
- Amount = amount;
+ Value = Guard.MinimumAndNotNull(nameof(value), value, 0);
Randomness = randomness;
Mac = mac;
}
@@ -24,7 +25,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
/// <summary>
/// Amount represented by the credential.
/// </summary>
- public Scalar Amount { get; }
+ public long Value { get; }
/// <summary>
/// Randomness used as blinding factor for the Pedersen committed Amount.
@@ -45,7 +46,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
{
GroupElement Randomize(GroupElement g, GroupElement m) => m + z * g;
return new CredentialPresentation(
- ca: Randomize(Generators.Ga, ProofSystem.PedersenCommitment(Amount, Randomness)),
+ ca: Randomize(Generators.Ga, ProofSystem.PedersenCommitment(new Scalar((ulong)Value), Randomness)),
cx0: Randomize(Generators.Gx0, Mac.U),
cx1: Randomize(Generators.Gx1, Mac.T * Mac.U),
cV: Randomize(Generators.GV, Mac.V),

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/ProofSystem.cs
WalletWasabi/Crypto/ZeroKnowledge/ProofSystem.cs
@@ -103,7 +103,7 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
public static Knowledge ShowCredentialKnowledge(CredentialPresentation presentation, Scalar z, Credential credential, CredentialIssuerParameters iparams)
=> new(
ShowCredentialStatement(presentation, z * iparams.I, iparams),
- new ScalarVector(z, (credential.Mac.T * z).Negate(), credential.Mac.T, credential.Amount, credential.Randomness));
+ new ScalarVector(z, (credential.Mac.T * z).Negate(), credential.Mac.T, new Scalar((ulong)credential.Value), credential.Randomness));
public static Statement ShowCredentialStatement(CredentialPresentation c, GroupElement z, CredentialIssuerParameters iparams)
=> new(new GroupElement[,]

MODIFY
WalletWasabi/WabiSabi/Client/ArenaClient.cs
WalletWasabi/WabiSabi/Client/ArenaClient.cs
@@ -74,13 +74,13 @@ namespace WalletWasabi.WabiSabi.Client
Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, AmountCredentialClient.NumberOfCredentials);
Guard.InRange(nameof(vsizeCredentialsToPresent), vsizeCredentialsToPresent, 0, VsizeCredentialClient.NumberOfCredentials);
- var presentedAmount = amountCredentialsToPresent.Sum(x => (long)x.Amount.ToUlong());
+ var presentedAmount = amountCredentialsToPresent.Sum(x => x.Value);
var (realAmountCredentialRequest, realAmountCredentialResponseValidation) = AmountCredentialClient.CreateRequest(
new[] { presentedAmount - amount },
amountCredentialsToPresent,
cancellationToken);
- var presentedVsize = vsizeCredentialsToPresent.Sum(x => (long)x.Amount.ToUlong());
+ var presentedVsize = vsizeCredentialsToPresent.Sum(x => x.Value);
var (realVsizeCredentialRequest, realVsizeCredentialResponseValidation) = VsizeCredentialClient.CreateRequest(
new[] { presentedVsize - scriptPubKey.EstimateOutputVsize() },
vsizeCredentialsToPresent,
@@ -110,13 +110,13 @@ namespace WalletWasabi.WabiSabi.Client
{
Guard.InRange(nameof(amountCredentialsToPresent), amountCredentialsToPresent, 0, AmountCredentialClient.NumberOfCredentials);
- var presentedAmount = amountCredentialsToPresent.Sum(x => (long)x.Amount.ToUlong());
+ var presentedAmount = amountCredentialsToPresent.Sum(x => x.Value);
if (amountsToRequest.Sum() != presentedAmount)
{
throw new InvalidOperationException($"Reissuence amounts must equal with the sum of the presented ones.");
}
- var presentedVsize = vsizeCredentialsToPresent.Sum(x => (long)x.Amount.ToUlong());
+ var presentedVsize = vsizeCredentialsToPresent.Sum(x => x.Value);
var (realVsizeCredentialRequest, realVsizeCredentialResponseValidation) = VsizeCredentialClient.CreateRequest(
vsizesToRequest,
vsizeCredentialsToPresent,

MODIFY
WalletWasabi/WabiSabi/Client/SmartRequestNode.cs
WalletWasabi/WabiSabi/Client/SmartRequestNode.cs
@@ -134,7 +134,7 @@ namespace WalletWasabi.WabiSabi.Client
return nonZeroValues;
}
- var missing = presentedCredentials.Sum(cr => (long)cr.Amount.ToUlong()) - valuesToRequest.Sum();
+ var missing = presentedCredentials.Sum(cr => cr.Value) - valuesToRequest.Sum();
if (missing > 0)
{

MODIFY
WalletWasabi/WabiSabi/Crypto/IssuanceValidationData.cs
WalletWasabi/WabiSabi/Crypto/IssuanceValidationData.cs
@@ -6,9 +6,9 @@ namespace WalletWasabi.WabiSabi.Crypto
{
public record IssuanceValidationData
{
- internal IssuanceValidationData(long amount, Scalar r, GroupElement ma)
+ internal IssuanceValidationData(long value, Scalar r, GroupElement ma)
{
- Amount = amount;
+ Value = value;
Randomness = r;
Ma = ma;
}
@@ -16,7 +16,7 @@ namespace WalletWasabi.WabiSabi.Crypto
/// <summary>
/// Amount committed in the pedersen commitment (<see cref="Ma">Ma</see>).
/// </summary>
- public long Amount { get; }
+ public long Value { get; }
/// <summary>
/// Randomness used as blinding factor in the pedersen commitment (<see cref="Ma">Ma</see>).

MODIFY
WalletWasabi/WabiSabi/Crypto/WabiSabiClient.cs
WalletWasabi/WabiSabi/Crypto/WabiSabiClient.cs
@@ -132,18 +132,18 @@ namespace WalletWasabi.WabiSabi.Crypto
var validationData = new IssuanceValidationData[NumberOfCredentials];
for (var i = 0; i < NumberOfCredentials; i++)
{
- var amount = credentialAmountsToRequest[i];
- var scalarAmount = new Scalar((ulong)amount);
+ var value = credentialAmountsToRequest[i];
+ var scalar = new Scalar((ulong)value);
var randomness = RandomNumberGenerator.GetScalar(allowZero: false);
- var ma = ProofSystem.PedersenCommitment(scalarAmount, randomness);
+ var ma = ProofSystem.PedersenCommitment(scalar, randomness);
- var (rangeKnowledge, bitCommitments) = ProofSystem.RangeProofKnowledge(scalarAmount, randomness, RangeProofWidth, RandomNumberGenerator);
+ var (rangeKnowledge, bitCommitments) = ProofSystem.RangeProofKnowledge(scalar, randomness, RangeProofWidth, RandomNumberGenerator);
knowledgeToProve.Add(rangeKnowledge);
var credentialRequest = new IssuanceRequest(ma, bitCommitments);
credentialsToRequest[i] = credentialRequest;
- validationData[i] = new IssuanceValidationData(amount, randomness, ma);
+ validationData[i] = new IssuanceValidationData(value, randomness, ma);
}
// Generate Balance Proof
@@ -158,7 +158,7 @@ namespace WalletWasabi.WabiSabi.Crypto
var transcript = BuildTransnscript(isNullRequest: false);
return new(
new RealCredentialsRequest(
- amountsToRequest.Sum() - credentialsToPresent.Sum(x => (long)x.Amount.ToUlong()),
+ amountsToRequest.Sum() - credentialsToPresent.Sum(x => x.Value),
presentations,
credentialsToRequest,
ProofSystem.Prove(transcript, knowledgeToProve, RandomNumberGenerator)),
@@ -208,7 +208,7 @@ namespace WalletWasabi.WabiSabi.Crypto
}
var credentialReceived = credentials.Select(x =>
- new Credential(new Scalar((ulong)x.Requested.Amount), x.Requested.Randomness, x.Issued));
+ new Credential(x.Requested.Value, x.Requested.Randomness, x.Issued));
return ZeroCredentialPool.ProcessAndGetValuableCredentials(credentialReceived).ToArray();
}

MODIFY
WalletWasabi/WabiSabi/Crypto/ZeroCredentialPool.cs
WalletWasabi/WabiSabi/Crypto/ZeroCredentialPool.cs
@@ -26,7 +26,7 @@ namespace WalletWasabi.WabiSabi.Crypto
{
foreach (var credential in credentials)
{
- if (credential.Amount.IsZero)
+ if (credential.Value == 0)
{
_zeroValueCredentials.Enqueue(credential);
}

Bikeshed `Credential` class

- Rename `Amount` property to `Value`, since `Amount` typically implies
  a bitcoin value, but credentials can also represent vbytes
- Also change its type from `Scalar` to `long`, slightly simplifying
  interface