Add self spend reuse test
MODIFY
WalletWasabi.Tests/UnitTests/BlockchainAnalysis/PubKeyReuseAnonScoreTests.cs
WalletWasabi.Tests/UnitTests/BlockchainAnalysis/PubKeyReuseAnonScoreTests.cs
@@ -35,6 +35,28 @@ namespace WalletWasabi.Tests.UnitTests.BlockchainAnalysis
Assert.True(tx.WalletOutputs.First().HdPubKey.AnonymitySet < 30);
}
+ [Fact]
+ public void SelfSpendReuse()
+ {
+ var analyser = ServiceFactory.CreateBlockchainAnalyzer();
+ var km = ServiceFactory.CreateKeyManager();
+ var reuse = BitcoinFactory.CreateHdPubKey(km);
+ var tx = BitcoinFactory.CreateSmartTransaction(
+ 0,
+ Enumerable.Empty<Money>(),
+ new[] { (Money.Coins(1.1m), 100, BitcoinFactory.CreateHdPubKey(km)) },
+ new[] { (Money.Coins(1m), HdPubKey.DefaultHighAnonymitySet, reuse) });
+
+ reuse.AnonymitySet = 30;
+
+ analyser.Analyze(tx);
+
+ Assert.All(tx.WalletInputs, x => Assert.True(x.HdPubKey.AnonymitySet < 30));
+
+ // It should be smaller than 30, because reuse also gets punishment.
+ Assert.True(tx.WalletOutputs.First().HdPubKey.AnonymitySet < 30);
+ }
+
[Fact]
public void AddressReuseIrrelevantInNormalSpend()
{

MODIFY
WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs
WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs
@@ -171,9 +171,16 @@ namespace WalletWasabi.Blockchain.Analysis
private void AnalyzeSelfSpend(SmartTransaction tx, int newInputAnonset)
{
foreach (var key in tx.WalletOutputs.Select(x => x.HdPubKey))
+ {
+ if (key.AnonymitySet == HdPubKey.DefaultHighAnonymitySet)
{
key.AnonymitySet = newInputAnonset;
}
+ else
+ {
+ key.AnonymitySet = Intersect(new[] { newInputAnonset, key.AnonymitySet }, 1);
+ }
+ }
}
private static void AnalyzeReceive(SmartTransaction tx)

Add self spend reuse test