Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FireProofing] Don't allow to burn more than 30% of coins effective value in CJs #10739

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions WalletWasabi/WabiSabi/Client/CoinJoinCoinSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class CoinJoinCoinSelector
{
private const int MaxInputsRegistrableByWallet = 10; // how many
private const int MaxWeightedAnonLoss = 3; // Maximum tolerable WeightedAnonLoss.

private const double MaxEffectiveValueLossTolerance = 0.3; // Maximum tolerable effective value loss.

/// <param name="consolidationMode">If true it attempts to select as many coins as it can.</param>
/// <param name="anonScoreTarget">Tries to select few coins over this threshold.</param>
/// <param name="semiPrivateThreshold">Minimum anonymity of coins that can be selected together.</param>
Expand All @@ -38,26 +39,26 @@ public CoinJoinCoinSelector(
public int AnonScoreTarget { get; }
public int SemiPrivateThreshold { get; }
private WasabiRandom Rnd { get; }

public static CoinJoinCoinSelector FromWallet(IWallet wallet) =>
new (
new(
wallet.ConsolidationMode,
wallet.AnonScoreTarget,
wallet.RedCoinIsolation ? Constants.SemiPrivateThreshold : 0,
SecureRandom.Instance);

/// <param name="liquidityClue">Weakly prefer not to select inputs over this.</param>
public ImmutableList<TCoin> SelectCoinsForRound<TCoin>(IEnumerable<TCoin> coins, UtxoSelectionParameters parameters, Money liquidityClue)
where TCoin : class, ISmartCoin, IEquatable<TCoin>
{
liquidityClue = liquidityClue > Money.Zero
? liquidityClue
: Constants.MaximumNumberOfBitcoinsMoney;

var filteredCoins = coins
.Where(x => parameters.AllowedInputAmounts.Contains(x.Amount))
.Where(x => parameters.AllowedInputScriptTypes.Contains(x.ScriptType))
.Where(x => x.EffectiveValue(parameters.MiningFeeRate) > Money.Zero)
.Where(x => x.EffectiveValue(parameters.MiningFeeRate).Satoshi > x.Amount.Satoshi * MaxEffectiveValueLossTolerance)
adamPetho marked this conversation as resolved.
Show resolved Hide resolved
.ToArray();

// Sanity check.
Expand Down