fix: zcash address for exchange (#3491)
What changed, and why it matters
This commit fixes two user-facing bugs in Cake Wallet's Zcash handling. First, it ensures the correct transparent Zcash address is used when sending funds to an exchange, which could previously lead to deposits going to the wrong address type. Second, it makes wallet restore respect the block height the user typed in, and allows that height to contain grouping separators like commas. The changes are bug fixes rather than a disclosed security vulnerability, but the wrong-address issue has clear financial-impact potential.
Treat as a routine but important bug-fix release. Verify that exchange flows with Zcash now produce a transparent receive address and that key-based restores use the user-supplied height. No emergency response is warranted absent additional disclosure.
Security signals we found
Financial-impact bug fix: exchange deposits could be directed to an incorrect Zcash address type before this patch
New address selection path in exchange_view_model.dart relying on walletInfo address labels
Restore-height now honored for key-based restores and tolerant of formatting separators
Rescan logic now validates on-disk birth height before proceeding
No explicit security disclosure, CVE, or researcher attribution in commit or supplied references
Evidence from the diff
The patch modifies Zcash address persistence and selection for exchange flows, and improves restore-height handling. In zcash_wallet_addresses.dart, _persistAddressForExchange now stores the exchange address (if not a placeholder) labelled as ‘transparent’. exchange_view_model.dart then looks up that stored transparent address when the receiving currency is ZEC and the selected address-book wallet is Zcash. The rescan logic in zcash_wallet.dart is rewritten to cancel sync, update the account birth height, verify it persisted, reset sync, save the wallet, and restart sync. wallet_restore_page.dart now passes the user-entered height into credentials when restoring from keys, and blockchain_height_widget.dart strips non-digit characters before parsing the height.
Changed components
cw_zcash/lib/src/zcash_wallet.dartcw_zcash/lib/src/zcash_wallet_addresses.dartlib/src/screens/restore/wallet_restore_page.dartlib/src/widgets/blockchain_height_widget.dartlib/view_model/exchange/exchange_view_model.dartInspect captured patch +71 / −2
diff --git a/cw_zcash/lib/src/zcash_wallet.dart b/cw_zcash/lib/src/zcash_wallet.dart
index 6266c670..34ae0f1e 100644
--- a/cw_zcash/lib/src/zcash_wallet.dart
+++ b/cw_zcash/lib/src/zcash_wallet.dart
@@ -1021,7 +1021,50 @@ abstract class ZcashWalletBase
@override
@action
Future<void> rescan({required final int height}) async {
- await zkool_sync.rewindSync(height: height, account: accountId, c: c);
+ syncStatus = StartingScanSyncStatus(height);
+ try {
+ await zkool_sync.cancelSync();
+ isSyncing = false;
+
+ await runWithCoin(
+ accountId: accountId,
+ func: (final coin) async {
+ await zkool_account.updateAccount(
+ update: zkool_account.AccountUpdate(
+ coin: coin.coin,
+ id: accountId,
+ birth: height,
+ folder: 0,
+ ),
+ c: coin,
+ );
+
+ final accounts = await zkool_account.listAccounts(c: coin);
+ final updated =
+ accounts.where((final a) => a.id == accountId).firstOrNull;
+ if (updated == null) {
+ throw Exception('account $accountId not found after update');
+ }
+ if (updated.birth != height) {
+ throw Exception(
+ 'birth height did not persist: wanted $height, '
+ 'database still has ${updated.birth}',
+ );
+ }
+
+ await zkool_account.resetSync(id: accountId, c: coin);
+ },
+ );
+
+ lastKnownRestoreHeight = height;
+ await save();
+
+ syncStatus = ConnectedSyncStatus();
+ unawaited(startSync());
+ } catch (e) {
+ printV('Zcash rescan failed: $e');
+ syncStatus = FailedSyncStatus(error: e.toString());
+ }
// try {
// syncStatus = StartingScanSyncStatus(height);
// printV("rescanning from: $height");
diff --git a/cw_zcash/lib/src/zcash_wallet_addresses.dart b/cw_zcash/lib/src/zcash_wallet_addresses.dart
index 295f2b09..d2b83130 100644
--- a/cw_zcash/lib/src/zcash_wallet_addresses.dart
+++ b/cw_zcash/lib/src/zcash_wallet_addresses.dart
@@ -220,6 +220,13 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
};
await _syncRotationHiddenAddresses();
await _applyAddressForCurrentType();
+ await _persistAddressForExchange();
+ }
+
+ Future<void> _persistAddressForExchange() async {
+ final addr = addressForExchange;
+ if (isPlaceholderAddress(addr)) return;
+ await walletInfo.setAddresses({addr: 'transparent'});
}
Future<void> _applyAddressForCurrentType() async {
@@ -253,6 +260,7 @@ abstract class ZcashWalletAddressesBase extends WalletAddresses with Store {
walletInfo.address = address;
}
await walletInfo.setAddresses({});
+ await _persistAddressForExchange();
await walletInfo.setAddressInfos(addressInfos);
await walletInfo.setUsedAddresses(usedAddresses.toList());
await walletInfo.setHiddenAddresses(hiddenAddresses.toList());
diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart
index de2157be..3e5ed20a 100644
--- a/lib/src/screens/restore/wallet_restore_page.dart
+++ b/lib/src/screens/restore/wallet_restore_page.dart
@@ -215,6 +215,10 @@ class WalletRestorePage extends BasePage {
walletRestoreFromKeysFormKey.currentState!.privateKeyController.text;
credentials['name'] =
walletRestoreFromKeysFormKey.currentState!.nameTextEditingController.text;
+ if (walletRestoreViewModel.hasBlockchainHeightSelector) {
+ credentials['height'] =
+ walletRestoreFromKeysFormKey.currentState!.blockchainHeightKey.currentState?.height;
+ }
} else {
credentials['name'] =
walletRestoreFromKeysFormKey.currentState!.nameTextEditingController.text;
diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart
index c4cafb5a..273db827 100644
--- a/lib/src/widgets/blockchain_height_widget.dart
+++ b/lib/src/widgets/blockchain_height_widget.dart
@@ -65,7 +65,8 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
try {
final int _height;
if (restoreHeightController.text.isNotEmpty) {
- _height = int.tryParse(restoreHeightController.text) ?? 0;
+ final digits = restoreHeightController.text.replaceAll(RegExp(r'[^0-9]'), '');
+ _height = int.tryParse(digits) ?? 0;
} else {
_height = 0;
}
diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart
index 84770a3a..595d70d4 100644
--- a/lib/view_model/exchange/exchange_view_model.dart
+++ b/lib/view_model/exchange/exchange_view_model.dart
@@ -1185,6 +1185,19 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
}
}
+ if (receiveCurrency == CryptoCurrency.zec &&
+ selectedAddressBookWallet?.type == WalletType.zcash) {
+ if (wallet.type == WalletType.zcash && wallet.name == selectedAddressBookWallet!.name) {
+ receiveAddress = wallet.walletAddresses.addressForExchange;
+ } else {
+ receiveAddress = (await selectedAddressBookWallet!.getAddresses())
+ .entries
+ .firstWhereOrNull((e) => e.value == 'transparent')
+ ?.key ??
+ receiveAddress;
+ }
+ }
+
// parse Lightning address to bolt11 invoice
if (receiveAddress.contains("@")) {
receiveAddress = await getBolt11FromLightingAddress(receiveAddress) ?? receiveAddress;
Why this scored 42/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.