fix: request new Lightning deposit address per receive (#3818)
What changed, and why it matters
This commit changes how Cake Wallet requests a Bitcoin deposit address when receiving funds through its Lightning integration. Previously, the app may have reused the same on-chain Bitcoin deposit address across multiple receives. Now it explicitly asks the Breez SDK for a fresh address each time. Reusing addresses can reduce privacy (making it easier to trace a user's transactions) and, in some edge cases, can lead to accounting or user-confusion issues if a prior payment is re-associated incorrectly. The change is a defensive privacy and correctness improvement rather than a critical exploit fix.
Treat as a routine privacy and correctness improvement. No urgent action required. Users and auditors may verify that ReceivePaymentMethod.bitcoinAddress(newAddress: true) is consistently used wherever a fresh deposit address is expected, and that address reuse is not reintroduced elsewhere in the Lightning receive flow.
Security signals we found
Address reuse mitigation for Lightning on-chain deposit addresses
Privacy improvement: fresh Bitcoin deposit address per receive
No explicit vulnerability disclosure or CVE referenced in commit
Change is defensive/hardening rather than a patch for an active exploit
Evidence from the diff
In cw_bitcoin/lib/lightning/lightning_wallet.dart, the getDepositAddress() method now passes ReceivePaymentMethod.bitcoinAddress(newAddress: true) to sdk.receivePayment(), whereas before it used bitcoinAddress() without the newAddress flag. The rest of the diff is cosmetic: quote style changes, renaming MAX_RETRIES to maxRetries, adding unawaited() around cancel() calls, and minor Dart style updates. The functional change is small and localized to address reuse behavior for Lightning-to-Bitcoin deposit addresses.
Changed components
cw_bitcoin/lib/lightning/lightning_wallet.dartcw_bitcoin/lib/lightning/utils.dartLightning receive/deposit address flowInspect captured patch +28 / −25
### cw_bitcoin/lib/lightning/lightning_wallet.dart
@@ -1,18 +1,18 @@
-import 'dart:async';
-import 'dart:io';
-import 'dart:typed_data';
-
-import 'package:breez_sdk_spark_flutter/breez_sdk_spark.dart';
-import 'package:cw_bitcoin/bitcoin_transaction_priority.dart';
-import 'package:cw_bitcoin/electrum_transaction_info.dart';
-import 'package:cw_bitcoin/lightning/pending_lightning_transaction.dart';
-import 'package:cw_core/amount/money.dart';
-import 'package:cw_core/crypto_currency.dart';
-import 'package:cw_core/currency.dart';
+import "dart:async";
+import "dart:io";
+import "dart:typed_data";
+
+import "package:breez_sdk_spark_flutter/breez_sdk_spark.dart";
+import "package:cw_bitcoin/bitcoin_transaction_priority.dart";
+import "package:cw_bitcoin/electrum_transaction_info.dart";
+import "package:cw_bitcoin/lightning/pending_lightning_transaction.dart";
+import "package:cw_core/amount/money.dart";
+import "package:cw_core/crypto_currency.dart";
+import "package:cw_core/currency.dart";
import "package:cw_core/exceptions/cake_exception.dart";
-import 'package:cw_core/transaction_direction.dart';
-import 'package:cw_core/utils/print_verbose.dart';
-import 'package:cw_core/wallet_type.dart';
+import "package:cw_core/transaction_direction.dart";
+import "package:cw_core/utils/print_verbose.dart";
+import "package:cw_core/wallet_type.dart";
bool _breezSdkSparkLibUninitialized = true;
Stream<LogEntry>? _logStream;
@@ -38,7 +38,7 @@ class LightningWallet {
String? cachedAddress;
- static int MAX_RETRIES = 10;
+ static int maxRetries = 10;
static bool get isAvailable => Platform.isIOS || Platform.isAndroid || Platform.isMacOS;
@@ -128,16 +128,16 @@ class LightningWallet {
}
Future<void> close() async {
- _eventSubscription?.cancel();
+ unawaited(_eventSubscription?.cancel());
try {
await _sdk?.disconnect();
} catch (_) {}
- _logSubscription?.cancel();
+ unawaited(_logSubscription?.cancel());
}
Future<String?> getAddress() async {
var retries = 0;
- while (retries < MAX_RETRIES) {
+ while (retries < maxRetries) {
try {
final address = (await sdk.getLightningAddress())?.lightningAddress;
@@ -154,7 +154,9 @@ class LightningWallet {
}
Future<String> getDepositAddress() async => (await sdk.receivePayment(
- request: const ReceivePaymentRequest(paymentMethod: ReceivePaymentMethod.bitcoinAddress()),
+ request: const ReceivePaymentRequest(
+ paymentMethod: ReceivePaymentMethod.bitcoinAddress(newAddress: true),
+ ),
))
.paymentRequest;
@@ -250,7 +252,7 @@ class LightningWallet {
return res.payment.id;
} on SdkError_SparkError catch (e) {
if (e.field0.contains("AlreadyExists")) {
- throw TransactionSendingException("Invoice already paid");
+ throw const TransactionSendingException("Invoice already paid");
}
rethrow;
}
@@ -320,7 +322,7 @@ class LightningWallet {
}
return PendingLightningTransaction(
- id: "", // ToDo: Find out where to get it
+ id: "",
amount: Money(prepareResponse.amount, currency),
fee: Money(fee, currency),
commitOverride: () async {
@@ -446,7 +448,8 @@ class LightningWallet {
} else if (sdkEvent is SdkEvent_ClaimedDeposits) {
onBalanceChangedEvent();
onUpdateDepositTransactionEvent(
- sdkEvent.claimedDeposits.map(_getElectrumTransactionInfoFromDepositInfo).toList());
+ sdkEvent.claimedDeposits.map(_getElectrumTransactionInfoFromDepositInfo).toList(),
+ );
} else if (sdkEvent is SdkEvent_UnclaimedDeposits) {
final unclaimedDeposits = <String, ElectrumTransactionInfo>{};
@@ -470,8 +473,8 @@ class LightningWallet {
}
String? preimage;
- if (payment.details != null && payment.details is PaymentDetails_Lightning) {
- preimage = (payment.details as PaymentDetails_Lightning).htlcDetails.preimage;
+ if (payment.details case final PaymentDetails_Lightning details) {
+ preimage = details.htlcDetails.preimage;
}
return ElectrumTransactionInfo(
### cw_bitcoin/lib/lightning/utils.dart
@@ -1,4 +1,4 @@
-import 'package:cw_core/lnurl.dart';
+import "package:cw_core/lnurl.dart";
String getLnurlOfLightningAddress(String lightningAddress) {
final parts = lightningAddress.split("@");Why this scored 35/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.