Refactor ShowCredential
MODIFY
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
WalletWasabi.Tests/UnitTests/Crypto/ProofSystemTests.cs
@@ -5,7 +5,6 @@ using WalletWasabi.Crypto;
using WalletWasabi.Crypto.Groups;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Crypto.ZeroKnowledge;
-using WalletWasabi.Crypto.ZeroKnowledge.LinearRelation;
using WalletWasabi.Crypto.ZeroKnowledge.NonInteractive;
using Xunit;
@@ -80,15 +79,14 @@ namespace WalletWasabi.Tests.UnitTests.Crypto
// The client randomizes the commitments before presenting them to the coordinator proving to
// the coordinator that a credential is valid (prover knows a valid MAC on non-randomized attribute)
var z = rnd.GetScalar();
- var randomizedCommitments = RandomizedCommitments.RandomizeMAC(mac, z, amount, r);
- var knowledge = ProofSystem.ShowCredential(coordinatorParameters, randomizedCommitments, z, mac.T, amount, r);
+ var randomizedCommitments = RandomizedCommitments.RandomizeMAC(mac, z, amount, r, coordinatorParameters);
+ var knowledge = ProofSystem.ShowCredential(randomizedCommitments, z, mac.T, amount, r, coordinatorParameters);
var proofOfMacShow = ProofSystem.Prove(knowledge, rnd);
// The coordinator must verify the received randomized credential is valid.
- var Z = randomizedCommitments.ComputeZ(coordinatorKey);
- Assert.Equal(Z, z * coordinatorParameters.I);
+ Assert.Equal(randomizedCommitments.Z, z * coordinatorParameters.I);
- var statement = ProofSystem.ShowCredential(coordinatorParameters, Z, randomizedCommitments);
+ var statement = ProofSystem.ShowCredential(randomizedCommitments, coordinatorParameters);
var isValidProof = ProofSystem.Verify(statement, proofOfMacShow);
Assert.True(isValidProof);

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/ProofSystem.cs
WalletWasabi/Crypto/ZeroKnowledge/ProofSystem.cs
@@ -42,15 +42,15 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
{ iparams.Cw, Generators.Gw, Generators.Gwp, O, O, O },
});
- public static Knowledge ShowCredential(CoordinatorParameters iparams, RandomizedCommitments c, Scalar z, Scalar t, Scalar a, Scalar r)
- => new Knowledge(ShowCredential(iparams, z * iparams.I, c), new ScalarVector(z, (t * z).Negate(), t, a, r));
+ public static Knowledge ShowCredential(RandomizedCommitments c, Scalar z, Scalar t, Scalar a, Scalar r, CoordinatorParameters iparams)
+ => new Knowledge(ShowCredential(c, iparams), new ScalarVector(z, (t * z).Negate(), t, a, r));
- public static Statement ShowCredential(CoordinatorParameters iparams, GroupElement Z, RandomizedCommitments c)
+ public static Statement ShowCredential(RandomizedCommitments c, CoordinatorParameters iparams)
=> new Statement(new GroupElement[,]
{
// public Witness terms:
// point z z0 t a r
- { Z, iparams.I, O, O, O, O },
+ { c.Z, iparams.I, O, O, O, O },
{ c.Cx1, Generators.Gx1, Generators.Gx0, c.Cx0, O, O },
{ c.Ca, Generators.Ga, O, O, Generators.Gg, Generators.Gh },
{ c.S, O, O, O, O, Generators.Gs }

MODIFY
WalletWasabi/Crypto/ZeroKnowledge/RandomizedCommitments.cs
WalletWasabi/Crypto/ZeroKnowledge/RandomizedCommitments.cs
@@ -5,13 +5,14 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
{
public class RandomizedCommitments
{
- private RandomizedCommitments(GroupElement Ca, GroupElement Cx0, GroupElement Cx1, GroupElement CV, GroupElement S)
+ private RandomizedCommitments(GroupElement Ca, GroupElement Cx0, GroupElement Cx1, GroupElement CV, GroupElement S, GroupElement Z)
{
this.Ca = Ca;
this.Cx0 = Cx0;
this.Cx1 = Cx1;
this.CV = CV;
this.S = S;
+ this.Z = Z;
}
public GroupElement Ca { get; }
@@ -19,8 +20,9 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
public GroupElement Cx1 { get; }
public GroupElement CV { get; }
public GroupElement S { get; }
+ public GroupElement Z { get; }
- public static RandomizedCommitments RandomizeMAC(MAC mac, Scalar z, Scalar a, Scalar r)
+ public static RandomizedCommitments RandomizeMAC(MAC mac, Scalar z, Scalar a, Scalar r, CoordinatorParameters iparams)
{
GroupElement Randomize(GroupElement G, GroupElement M) => M + z * G;
return new RandomizedCommitments(
@@ -28,10 +30,11 @@ namespace WalletWasabi.Crypto.ZeroKnowledge
Cx0: Randomize(Generators.Gx0, mac.U),
Cx1: Randomize(Generators.Gx1, mac.T * mac.U),
CV: Randomize(Generators.GV, mac.V),
- S: r * Generators.Gs);
+ S: r * Generators.Gs,
+ Z: z * iparams.I);
}
- public GroupElement ComputeZ(CoordinatorSecretKey sk)
- => CV - (sk.W * Generators.Gw + sk.X0 * Cx0 + sk.X1 * Cx1 + sk.Ya * Ca);
+ public static RandomizedCommitments RandomizeMAC(GroupElement Ca, GroupElement Cx0, GroupElement Cx1, GroupElement CV, GroupElement S, CoordinatorSecretKey sk)
+ => new RandomizedCommitments(Ca, Cx0, Cx1, CV, S, Z: CV - (sk.W * Generators.Gw + sk.X0 * Cx0 + sk.X1 * Cx1 + sk.Ya * Ca));
}
}
\ No newline at end of file

Refactor ShowCredential