Skip to content

Commit

Permalink
Attempt to use empty imported addresses as change
Browse files Browse the repository at this point in the history
Previously when spending coins on imported-key wallets, the change address
would always be an address from one of the inputs. This address reuse is
pretty bad for privacy because it leaks which output is change.

This commit attempts to find unused imported addresses, and if there are any
then use them as change addresses.

The practical use-case I considered was the situation when using the Electrum
android app to do a cash-in-person trade. Some people might want to bring only
one of their UTXOs to the meetup for safety. This commit allows them to import
that one UTXO plus an unused change address, allowing them to create a
transaction without address reuse.

In order to keep the same default behaviour, this feature is disabled by
default but can be enabled easily by users.
  • Loading branch information
chris-belcher committed Jun 9, 2021
1 parent cad4e77 commit f5a3b7c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,8 @@ class Imported_Wallet(Simple_Wallet):

def __init__(self, db, storage, *, config):
Abstract_Wallet.__init__(self, db, storage, config=config)
#Keep the old default behaviour of not using change address in imported wallets
self.use_change = db.get('use_change', False)

def is_watching_only(self):
return self.keystore is None
Expand Down Expand Up @@ -2681,7 +2683,7 @@ def get_receiving_addresses(self, **kwargs):
return self.get_addresses()

def get_change_addresses(self, **kwargs):
return []
return [addr for addr in self.get_addresses() if len(self.db.get_addr_history(addr)) == 0]

def import_addresses(self, addresses: List[str], *,
write_to_disk=True) -> Tuple[List[str], List[Tuple[str, str]]]:
Expand Down

0 comments on commit f5a3b7c

Please sign in to comment.