Merge pull request #3891 from cake-tech/zec-hide-tx-stacktrace
What changed, and why it matters
This change stops the Cake Wallet Zcash code from showing users a full Rust programming stack trace when sending or creating a Zcash transaction fails. Instead, it logs the detailed error internally and shows the user a shorter, friendlier error message. This is a user-experience and minor privacy improvement, not a fix for a code-execution vulnerability.
No urgent action required. Treat as routine UX hardening. If desired, verify that `printV` logs are not written to user-accessible storage and that the new exception messages do not leak sensitive values such as amounts, addresses, or memo contents.
Security signals we found
Error-message sanitization: verbose Rust stack traces are no longer propagated to the UI
Internal logging retained via printV, preserving debuggability
New exception types (TransactionSendingException, TransactionGenerationException) provide less implementation detail to users
Evidence from the diff
The commit wraps Zcash transaction creation, sending, shielding, and airgap-commit callbacks in a new helper withCompactRustErrors. When a caught error contains the literal string “Stack backtrace:”, the helper prints the full error via printV and rethrows a new TransactionSendingException or TransactionGenerationException containing only the portion before the backtrace. This prevents verbose Rust stack traces from being surfaced to end users while preserving internal logging.
Changed components
cw_zcash/lib/src/pending_zcash_transaction.dartcw_zcash/lib/src/util/exceptions.dartcw_zcash/lib/src/zcash_wallet.dartInspect captured patch +32 / −5
### cw_zcash/lib/src/pending_zcash_transaction.dart
@@ -2,9 +2,11 @@ import 'dart:async';
import 'package:cw_core/amount/money.dart';
import 'package:cw_core/exceptions.dart';
+import 'package:cw_core/exceptions/cake_exception.dart';
import 'package:cw_core/pending_transaction.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:cw_zcash/cw_zcash.dart';
+import 'package:cw_zcash/src/util/exceptions.dart';
import 'package:zkool/src/rust/api/pay.dart' as zkool_pay;
class PendingZcashTransaction with PendingTransaction {
@@ -41,7 +43,9 @@ class PendingZcashTransaction with PendingTransaction {
final Money fee;
@override
- Future<void> commit() async {
+ Future<void> commit() => withCompactRustErrors(_commit, TransactionSendingException.new);
+
+ Future<void> _commit() async {
await ZcashWalletBase.runWithCoin(
accountId: zcashWallet.accountId,
func: (coin) async {
@@ -81,7 +85,8 @@ class PendingZcashTransaction with PendingTransaction {
@override
Future<Map<String, String>> commitUR() async {
- zcashWallet.onCommitAirgapUr = _commitScannedUr;
+ zcashWallet.onCommitAirgapUr = (raw) =>
+ withCompactRustErrors(() => _commitScannedUr(raw), TransactionSendingException.new);
return {'Cupcake': encodeZcashPcztUr(txPlan.pczt).join('\n')};
}
### cw_zcash/lib/src/util/exceptions.dart
@@ -1,6 +1,7 @@
import "package:cw_core/exceptions/cake_exception.dart";
+import "package:cw_core/utils/print_verbose.dart";
class WalletLockedException extends CakeException {
const WalletLockedException() : super("Zcash wallet locked! Please contact support");
@@ -20,4 +21,19 @@ class AddressRotationException extends CakeException {
class MigrationException extends CakeException {
const MigrationException(super.message);
-}
\ No newline at end of file
+}
+
+Future<T> withCompactRustErrors<T>(
+ final Future<T> Function() body,
+ final CakeException Function(String message) wrap,
+) async {
+ try {
+ return await body();
+ } catch (e, s) {
+ if (!e.toString().contains("Stack backtrace:")) {
+ rethrow;
+ }
+ printV(e);
+ Error.throwWithStackTrace(wrap(e.toString().split("Stack backtrace:").first.trim()), s);
+ }
+}
### cw_zcash/lib/src/zcash_wallet.dart
@@ -450,7 +450,10 @@ abstract class ZcashWalletBase
@override
Future<PendingTransaction> createTransaction(final Object credentials) =>
- _createTransaction(credentials);
+ withCompactRustErrors(
+ () => _createTransaction(credentials),
+ TransactionGenerationException.new,
+ );
Future<PendingTransaction> _createTransaction(
final Object credentials, {
@@ -1302,7 +1305,10 @@ abstract class ZcashWalletBase
bool hasOrchardMigratableBalance() => _orchardMigratable;
- Future<PendingTransaction?> createShieldingTransaction() async {
+ Future<PendingTransaction?> createShieldingTransaction() =>
+ withCompactRustErrors(_createShieldingTransaction, TransactionGenerationException.new);
+
+ Future<PendingTransaction?> _createShieldingTransaction() async {
final txPlan = await runWithCoin(
accountId: accountId,
func: (coin) async {Why this scored 25/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.