fix: t addr rotation rescan (#3827)
What changed, and why it matters
This commit fixes a bug in Cake Wallet's Zcash wallet where rescanning the blockchain did not properly reset the wallet's rotated transparent (t-) addresses. Transparent addresses are public on the blockchain; when a wallet rotates to a new one, the old cache of transactions must be cleared during a rescan so the wallet doesn't show stale or incorrect balance/history. The fix adds a helper that updates the rotated account's birth height, resets its sync state, and clears cached transaction data so the rescan starts fresh for those addresses too.
Treat as a routine bug fix with possible financial-integrity implications. Review whether any other rotated-account caches (e.g., address lists, UTXO sets, note witnesses) also need invalidation during rescan. No immediate security response appears necessary unless users report incorrect balances after prior rescans.
Security signals we found
State/cache invalidation bug in cryptographic wallet rescan flow
Transparent address rotation state not rewound during rescan
Potential stale transaction cache leading to incorrect balance or history
Fix adds explicit sync reset and cache eviction for rotated accounts
Evidence from the diff
The patch adds ZcashTaddressRotation.rewindForRescan(), which updates the rotated account’s birth field to the requested rescan height, calls zkool_account.resetSync(), and removes entries from shieldedAccountsTx, _resyncedRotationAccounts, and _poolRescanAttempted for the rotated account. The wallet’s rescan() method now fetches the rotation account for the main account and, if present, invokes rewindForRescan() after resetting the main account’s sync. This ensures that a user-initiated rescan rewinds both the main shielded account and its associated rotated transparent account consistently.
Changed components
cw_zcash/lib/src/zcash_taddress_rotation.dartcw_zcash/lib/src/zcash_wallet.dartZcash transparent (t-) address rotation featureZcash wallet rescan functionalityInspect captured patch +32 / −0
### cw_zcash/lib/src/zcash_taddress_rotation.dart
@@ -210,6 +210,28 @@ class ZcashTaddressRotation {
);
}
+ static Future<void> rewindForRescan({
+ required final int mainAccountId,
+ required final int accountId,
+ required final int height,
+ required final zkool_coin.Coin coin,
+ }) async {
+ await zkool_account.updateAccount(
+ update: zkool_account.AccountUpdate(
+ coin: coin.coin,
+ id: accountId,
+ birth: height,
+ folder: 0,
+ ),
+ c: coin,
+ );
+ await zkool_account.resetSync(id: accountId, c: coin);
+ shieldedAccountsTx.remove(mainAccountId);
+ shieldedAccountsTx.remove(accountId);
+ _resyncedRotationAccounts.remove(accountId);
+ _poolRescanAttempted.removeWhere((final key) => key.startsWith('$accountId:'));
+ }
+
static Future<int?> getRotationAccountForMainAccount(final int mainAccountId) async {
final cached = _rotationAccountByMain[mainAccountId];
if (cached != null) {
### cw_zcash/lib/src/zcash_wallet.dart
@@ -1044,6 +1044,8 @@ abstract class ZcashWalletBase
@action
Future<void> rescan({required final int height}) async {
syncStatus = StartingScanSyncStatus(height);
+ final rotationAccountId =
+ await ZcashTaddressRotation.getRotationAccountForMainAccount(accountId);
try {
await zkool_sync.cancelSync(c: c);
isSyncing = false;
@@ -1075,6 +1077,14 @@ abstract class ZcashWalletBase
}
await zkool_account.resetSync(id: accountId, c: coin);
+ if (rotationAccountId != null) {
+ await ZcashTaddressRotation.rewindForRescan(
+ mainAccountId: accountId,
+ accountId: rotationAccountId,
+ height: height,
+ coin: coin,
+ );
+ }
},
);
Why this scored 24/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.