From e7e1711d73b922d71f8418a0962e49ff91bd0ff0 Mon Sep 17 00:00:00 2001 From: nopara73 Date: Mon, 4 Jul 2022 16:14:20 +0200 Subject: [PATCH 1/3] Avoid always punishing WW2 denom outputs --- .../Blockchain/Analysis/BlockchainAnalyzer.cs | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs index 8431e00b130..b38136d8b58 100644 --- a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs +++ b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs @@ -8,6 +8,17 @@ namespace WalletWasabi.Blockchain.Analysis; public class BlockchainAnalyzer { + private static long[] StdDenoms = new[]{ + 5000L, 6561L, 8192L, 10000L, 13122L, 16384L, 19683L, 20000L, 32768L, 39366L, 50000L, 59049L, 65536L, 100000L, 118098L, + 131072L, 177147L, 200000L, 262144L, 354294L, 500000L, 524288L, 531441L, 1000000L, 1048576L, 1062882L, 1594323L, 2000000L, + 2097152L, 3188646L, 4194304L, 4782969L, 5000000L, 8388608L, 9565938L, 10000000L, 14348907L, 16777216L, 20000000L, + 28697814L, 33554432L, 43046721L, 50000000L, 67108864L, 86093442L, 100000000L, 129140163L, 134217728L, 200000000L, + 258280326L, 268435456L, 387420489L, 500000000L, 536870912L, 774840978L, 1000000000L, 1073741824L, 1162261467L, + 2000000000L, 2147483648L, 2324522934L, 3486784401L, 4294967296L, 5000000000L, 6973568802L, 8589934592L, 10000000000L, + 10460353203L, 17179869184L, 20000000000L, 20920706406L, 31381059609L, 34359738368L, 50000000000L, 62762119218L, + 68719476736L, 94143178827L, 100000000000L, 137438953472L + }; + public BlockchainAnalyzer(int privacyLevelThreshold) { PrivacyLevelThreshold = privacyLevelThreshold; @@ -114,6 +125,10 @@ private void AnalyzeCoinjoinWalletOutputs(SmartTransaction tx, int startingMixed .GroupBy(x => x.Value) .ToDictionary(x => x.Key, y => y.Count()); + var outputValues = tx.Transaction.Outputs.Select(x => x.Value).OrderByDescending(x => x).ToArray(); + var largestValues = outputValues.Distinct().OrderByDescending(x => x).Take(2).Last(); + bool? isWasabi2Cj = null; + var foreignInputCount = tx.ForeignInputs.Count; foreach (var newCoin in tx.WalletOutputs) @@ -129,7 +144,27 @@ private void AnalyzeCoinjoinWalletOutputs(SmartTransaction tx, int startingMixed anonset /= ownEqualOutputCount; // If not anonset gain achieved on the output, then it's best to assume it's change. - var startingOutputAnonset = anonset == 0 ? startingNonMixedOutputAnonset : startingMixedOutputAnonset; + int startingOutputAnonset; + if (anonset == 0) + { + isWasabi2Cj ??= + tx.Transaction.Inputs.Count >= 50 // 50 was the minimum input count at the beginning of Wasabi 2. + && outputValues.Count(x => StdDenoms.Contains(x.Satoshi)) > tx.Transaction.Outputs.Count * 0.8 // Most of the outputs contains the denomination. + && outputValues.SequenceEqual(outputValues); // Outputs are ordered descending. + + if (isWasabi2Cj is true && StdDenoms.Contains(newCoin.Amount.Satoshi) && newCoin.Amount < largestValues) + { + startingOutputAnonset = startingMixedOutputAnonset; + } + else + { + startingOutputAnonset = startingNonMixedOutputAnonset; + } + } + else + { + startingOutputAnonset = startingMixedOutputAnonset; + } // Account for the inherited anonymity set size from the inputs in the // anonymity set size estimate. From 3ffb2d4147add01079c60172b3aa9e4681f394d3 Mon Sep 17 00:00:00 2001 From: nopara73 Date: Mon, 4 Jul 2022 16:16:41 +0200 Subject: [PATCH 2/3] Fix CF --- WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs index b38136d8b58..86d1746f853 100644 --- a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs +++ b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs @@ -8,7 +8,8 @@ namespace WalletWasabi.Blockchain.Analysis; public class BlockchainAnalyzer { - private static long[] StdDenoms = new[]{ + private static long[] StdDenoms = new[] + { 5000L, 6561L, 8192L, 10000L, 13122L, 16384L, 19683L, 20000L, 32768L, 39366L, 50000L, 59049L, 65536L, 100000L, 118098L, 131072L, 177147L, 200000L, 262144L, 354294L, 500000L, 524288L, 531441L, 1000000L, 1048576L, 1062882L, 1594323L, 2000000L, 2097152L, 3188646L, 4194304L, 4782969L, 5000000L, 8388608L, 9565938L, 10000000L, 14348907L, 16777216L, 20000000L, From 1c093c237bfdf100d3edf93c99b57b21531eb84e Mon Sep 17 00:00:00 2001 From: nopara73 Date: Mon, 4 Jul 2022 16:22:10 +0200 Subject: [PATCH 3/3] Add comment, rename variable --- WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs index 86d1746f853..c15ef75359d 100644 --- a/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs +++ b/WalletWasabi/Blockchain/Analysis/BlockchainAnalyzer.cs @@ -127,7 +127,7 @@ private void AnalyzeCoinjoinWalletOutputs(SmartTransaction tx, int startingMixed .ToDictionary(x => x.Key, y => y.Count()); var outputValues = tx.Transaction.Outputs.Select(x => x.Value).OrderByDescending(x => x).ToArray(); - var largestValues = outputValues.Distinct().OrderByDescending(x => x).Take(2).Last(); + var secondLargestOutputAmount = outputValues.Distinct().OrderByDescending(x => x).Take(2).Last(); bool? isWasabi2Cj = null; var foreignInputCount = tx.ForeignInputs.Count; @@ -144,7 +144,7 @@ private void AnalyzeCoinjoinWalletOutputs(SmartTransaction tx, int startingMixed // Picking randomly an output would make our anonset: total/ours. anonset /= ownEqualOutputCount; - // If not anonset gain achieved on the output, then it's best to assume it's change. + // If no anonset gain achieved on the output, then it's best to assume it's change. int startingOutputAnonset; if (anonset == 0) { @@ -153,7 +153,8 @@ private void AnalyzeCoinjoinWalletOutputs(SmartTransaction tx, int startingMixed && outputValues.Count(x => StdDenoms.Contains(x.Satoshi)) > tx.Transaction.Outputs.Count * 0.8 // Most of the outputs contains the denomination. && outputValues.SequenceEqual(outputValues); // Outputs are ordered descending. - if (isWasabi2Cj is true && StdDenoms.Contains(newCoin.Amount.Satoshi) && newCoin.Amount < largestValues) + // When WW2 denom output isn't too large, then it's not change. + if (isWasabi2Cj is true && StdDenoms.Contains(newCoin.Amount.Satoshi) && newCoin.Amount < secondLargestOutputAmount) { startingOutputAnonset = startingMixedOutputAnonset; }