java-topology/defects/wasabi-0002/patch/wasabi-0002.md

1 KiB

UNDF: UNDF-2026-000000921

wasabi-0002: TransactionFactory.BuildTransaction O(CA) + O(CS) List.Any inside Where

Location

WalletWasabi/Blockchain/Transactions/TransactionFactory.cs:87,95

Defect

Two O(N*M) membership checks using List.Any inside LINQ Where:

  1. Line 87: parameters.AllowedInputs.Any(y => y.Hash == x.TransactionId && y.N == x.Index) For each coin C, scans AllowedInputs A linearly. O(C*A).

  2. Line 95: !allowedSmartCoinInputs.Any(y => x.TransactionId == y.TransactionId && x.Index == y.Index) For each available coin, scans allowedSmartCoinInputs linearly. O(C*S).

Severity

MEDIUM. C = available UTXO count, A = allowed input count, S = selected input count. For a wallet with 500 UTXOs and 50 allowed inputs: 25,000 + 25,000 comparisons vs 550 + 500 with HashSet.

Fix

Convert AllowedInputs to HashSet for O(1) lookup. Convert allowedSmartCoinInputs outpoints to HashSet for exclusion check.

Estimated speedup

At C=500, A=50: ~50x reduction in comparison operations.