sum the swept key once per input when sweeping to a silent payment address, and refuse silent payment sweeps from uncompressed keys
What changed, and why it matters
This commit fixes two bugs in Sparrow Wallet's feature that lets users sweep old private keys into a 'silent payment' address. First, when multiple transaction outputs were being swept, the wallet was incorrectly using the same private key once instead of mathematically combining it once per input, which would produce the wrong silent payment address and likely make the funds unspendable or send them to an address no one controls. Second, the wallet now blocks sweeping from uncompressed private keys into silent payments, because silent payments require compressed keys to work correctly. The commit is a bug fix rather than an exploit against users, but the underlying flaw could have caused loss of funds if a user tried a multi-input silent-payment sweep.
Users who attempted to sweep multiple outputs from a private key into a silent payment address before this fix should verify whether the resulting transaction was broadcast and, if so, whether the funds are recoverable. Upgrading to the fixed version is recommended. Developers should add tests covering multi-input silent-payment sweeps and compressed/uncompressed key validation.
Security signals we found
Funds-loss bug in silent-payment sweep with multiple inputs
Incorrect scalar handling for per-input key aggregation
Missing key-format validation for silent payment sender
Patch is narrowly scoped to a single dialog class
Evidence from the diff
In PrivateKeySweepDialog.java, computeSilentPaymentAddress() previously derived a single per-input private key and passed it to the silent-payment address computation. Because each swept output creates a separate input signed with the same key, the BIP352 shared-secret/address calculation must use the scalar sum (here implemented as multiplication by the number of inputs modulo the curve order) of the input keys. The patch changes the code to compute inputPrivateKey, then derive summedPrivateKey = inputPrivateKey * n mod CURVE_ORDER. It also adds a guard at the start of createTransaction() that refuses to sweep an uncompressed key to a silent payment address, since silent payments rely on compressed public-key encoding. The change is small and defensive; it does not by itself prove an active vulnerability was exploited, but it corrects a clear functional error in a funds-moving code path.
Changed components
src/main/java/com/sparrowwallet/sparrow/control/PrivateKeySweepDialog.javaSilent payment sweep featurePrivate key import/sweep workflowInspect captured patch +12 / −3
### src/main/java/com/sparrowwallet/sparrow/control/PrivateKeySweepDialog.java
@@ -52,6 +52,7 @@
import java.io.File;
import java.io.IOException;
+import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
@@ -385,6 +386,11 @@ private void unsealPrivateKey() {
private void createTransaction() {
try {
DumpedPrivateKey privateKey = getPrivateKey();
+ if(silentPaymentAddress != null && !privateKey.getKey().isCompressed()) {
+ AppServices.showErrorDialog("Cannot sweep to a silent payment address", "Silent payments cannot be sent from an uncompressed private key. Sweep to a regular address instead.");
+ return;
+ }
+
ScriptType scriptType = keyScriptType.getValue();
Address fromAddress = scriptType.getAddress(PolicyType.SINGLE_HD, privateKey.getKey());
Payment payment = silentPaymentAddress != null ? new SilentPayment(silentPaymentAddress, null, 0, true)
@@ -525,11 +531,14 @@ private void createTransaction(ECKey privKey, ScriptType scriptType, List<Transa
}
private Address computeSilentPaymentAddress(ECKey privKey, ScriptType scriptType, List<TransactionOutput> txOutputs, SilentPayment silentPayment) {
- ECKey summedPrivateKey = scriptType.getOutputKey(PolicyType.SINGLE_HD, privKey);
- if(scriptType == P2TR && summedPrivateKey.hasOddYCoord()) {
- summedPrivateKey = summedPrivateKey.negatePrivate();
+ ECKey inputPrivateKey = scriptType.getOutputKey(PolicyType.SINGLE_HD, privKey);
+ if(scriptType == P2TR && inputPrivateKey.hasOddYCoord()) {
+ inputPrivateKey = inputPrivateKey.negatePrivate();
}
+ //Each swept output is spent by an input signed with the same key, so the summed input key is the key multiplied by the number of inputs
+ ECKey summedPrivateKey = ECKey.fromPrivate(inputPrivateKey.getPrivKey().multiply(BigInteger.valueOf(txOutputs.size())).mod(ECKey.CURVE_ORDER));
+
Set<HashIndex> outpoints = new LinkedHashSet<>();
for(TransactionOutput txOutput : txOutputs) {
outpoints.add(new HashIndex(txOutput.getHash(), txOutput.getIndex()));Why this scored 59/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.