Show the psbt's warnings through one View
What changed, and why it matters
This commit is a code cleanup, not a security fix. It consolidates several warning screens shown before signing a Bitcoin transaction into a single reusable view. The warnings themselves—such as 'high fee' and 'no change'—still behave the same way and still require the user to press Continue. Nothing in the commit changes how transactions are validated or signed.
No security action required. Treat as a normal maintainability refactor.
Security signals we found
Refactor only: no change to validation, cryptography, or signing logic
User-facing warning text and flow remain equivalent
Adds unit tests covering high-fee, no-change, and combined warning sequences
Evidence from the diff
The patch refactors PSBT warning presentation in SeedSigner. It replaces separate view classes (PSBTHighFeeWarningView, PSBTNoChangeWarningView, PSBTUnsupportedScriptTypeWarningView) with one PSBTWarningView that iterates over a self.warnings list produced by PSBTParser. The parser now records non-fatal findings as constants in order of severity. Routing logic in PSBTOverviewView is simplified, and tests/screenshot generation are updated. The functional behavior—showing warnings before transaction details and allowing the user to continue or go back—is preserved.
Changed components
src/seedsigner/models/psbt_parser.pysrc/seedsigner/views/psbt_views.pytests/screenshot_generator/generator.pytests/test_flows_psbt.pyInspect captured patch +163 / −78
### src/seedsigner/models/psbt_parser.py
@@ -287,6 +287,10 @@ class PSBTParser():
# change). TODO: Possibly make this configurable via settings.
HIGH_FEES_WARNING_THRESHOLD = 25
+ # The non-fatal findings that can be recorded in self.warnings
+ WARNING__HIGH_FEE = "high_fee"
+ WARNING__NO_CHANGE = "no_change"
+
def __init__(self, p: PSBT, seed: Seed, network: str = SettingsConstants.MAINNET):
self.psbt: PSBT = p
@@ -309,6 +313,9 @@ def __init__(self, p: PSBT, seed: Seed, network: str = SettingsConstants.MAINNET
# re-walking the outputs.
self.is_high_fee: bool = False
+ # The psbt's non-fatal findings, as WARNING__* constants, most serious first
+ self.warnings: List[str] = []
+
# Contains one entry per input in psbt.inputs and per output in psbt.outputs. Each
# entry lists every derivation path the seed genuinely owns there, in the order
# the psbt lists them. On an input, the key at each listed path is also one the
@@ -468,6 +475,14 @@ def parse(self):
# Every total is known now, so settle this once rather than per view.
self.is_high_fee = self.has_high_fee()
+ # Record the non-fatal findings, most serious first
+ self.warnings = []
+ if self.is_high_fee:
+ self.warnings.append(PSBTParser.WARNING__HIGH_FEE)
+
+ if self.change_amount == 0:
+ self.warnings.append(PSBTParser.WARNING__NO_CHANGE)
+
return True
### src/seedsigner/views/psbt_views.py
@@ -115,6 +115,12 @@ def __init__(self):
# Note that in almost every exception case, we set clear_history to disable
# returning via BACK button in the Destination.
+ #
+ # TODO: Most of these except clauses route to a View of their own whose only
+ # job is to show a WarningScreen or DireWarningScreen and discard the psbt.
+ # Replace them with a dict that maps each error type to its warning level and
+ # user-facing message, shown by one generic View (as PSBTWarningView does for
+ # the non-fatal warnings).
except PSBTInputOwnershipClaimError:
self.set_redirect(Destination(PSBTInputOwnershipClaimFailedView, clear_history=True))
return
@@ -232,97 +238,66 @@ def run(self):
self.controller.psbt_seed = None
return Destination(BackStackView)
- # expecting p2sh (legacy multisig) and p2pkh to have no policy set
- # skip change warning and psbt math view
- if psbt_parser.policy == None:
- return Destination(PSBTUnsupportedScriptTypeWarningView)
-
- elif psbt_parser.is_high_fee:
- return Destination(PSBTHighFeeWarningView, view_args={"warning_threshold_percent": psbt_parser.HIGH_FEES_WARNING_THRESHOLD})
-
- elif psbt_parser.change_amount == 0:
- return Destination(PSBTNoChangeWarningView)
+ if len(psbt_parser.warnings) > 0:
+ return Destination(PSBTWarningView)
else:
return Destination(PSBTMathView)
-class PSBTUnsupportedScriptTypeWarningView(View):
- def run(self):
- selected_menu_num = self.run_screen(
- WarningScreen,
- status_headline=_("Unsupported Script Type!"),
- text=_("Transaction has unsupported input script type, please verify your change addresses."),
- button_data=[ButtonOption("Continue")],
- )
-
- if selected_menu_num == RET_CODE__BACK_BUTTON:
- return Destination(BackStackView)
-
- # Only one exit point
- # skip PSBTMathView
- return Destination(
- PSBTAddressDetailsView, view_args={"address_num": 0},
- skip_current_view=True, # Prevent going BACK to WarningViews
- )
+class PSBTWarningView(View):
+ """
+ Shows the psbt's warning at warning_index and then moves on to the next one. Once
+ every warning has been shown, redirects to PSBTMathView instead.
+ """
+ CONTINUE = ButtonOption("Continue")
+ def __init__(self, warning_index: int = 0):
+ super().__init__()
+ self.warning_index = warning_index
+
+ if warning_index >= len(self.controller.psbt_parser.warnings):
+ self.set_redirect(Destination(PSBTMathView))
+ return
-class PSBTNoChangeWarningView(View):
def run(self):
- selected_menu_num = self.run_screen(
- WarningScreen,
+ warning = self.controller.psbt_parser.warnings[self.warning_index]
+ if warning == PSBTParser.WARNING__HIGH_FEE:
+ Screen_cls = DireWarningScreen
+ status_headline = _("High Fee!")
+ # TRANSLATOR_NOTE: Variable is the percentage of the total output value (excluding change) that the fee exceeds. (e.g. "This transaction has a fee higher than 25% of the total output value (excluding change).")
+ text = _("This transaction has a fee higher than {}% of the total output value (excluding change).").format(PSBTParser.HIGH_FEES_WARNING_THRESHOLD)
+
+ elif warning == PSBTParser.WARNING__NO_CHANGE:
+ Screen_cls = WarningScreen
# TRANSLATOR_NOTE: User will receive no change back; the inputs to this transaction are fully spent
- status_headline=_("Full Spend!"),
- text=_("This transaction spends its entire input value. No change is coming back to your wallet."),
- button_data=[ButtonOption("Continue")],
+ status_headline = _("Full Spend!")
+ text = _("This transaction spends its entire input value. No change is coming back to your wallet.")
+
+ else:
+ raise Exception(f"Unhandled psbt warning: {warning}")
+
+ selected_menu_num = self.run_screen(
+ Screen_cls,
+ status_headline=status_headline,
+ text=text,
+ button_data=[self.CONTINUE],
)
if selected_menu_num == RET_CODE__BACK_BUTTON:
return Destination(BackStackView)
# Only one exit point
return Destination(
- PSBTMathView,
+ PSBTWarningView,
+ view_args=dict(warning_index=self.warning_index + 1),
skip_current_view=True, # Prevent going BACK to WarningViews
)
-class PSBTHighFeeWarningView(View):
- def __init__(self, warning_threshold_percent: int):
- super().__init__()
-
- self.warning_threshold_percent = warning_threshold_percent
-
- def run(self):
- selected_menu_num = self.run_screen(
- DireWarningScreen,
- status_headline=_("High Fee!"),
- # TRANSLATOR_NOTE: Variable is the percentage of the total output value (excluding change) that the fee exceeds. (e.g. "This transaction has a fee higher than 25% of the total output value (excluding change).")
- text=_("This transaction has a fee higher than {}% of the total output value (excluding change).").format(self.warning_threshold_percent),
- button_data=[ButtonOption("Continue")],
- )
-
- if selected_menu_num == RET_CODE__BACK_BUTTON:
- return Destination(BackStackView)
-
- # PSBT may have high fee + no change
- if self.controller.psbt_parser.change_amount == 0:
- return Destination(
- PSBTNoChangeWarningView,
- skip_current_view=True, # Prevent going BACK to WarningViews
- )
-
- else:
- return Destination(
- PSBTMathView,
- skip_current_view=True, # Prevent going BACK to WarningViews
- )
-
-
-
class PSBTMathView(View):
"""
Follows the Overview pictogram. Shows:
### tests/screenshot_generator/generator.py
@@ -281,6 +281,14 @@ def mock_single_sig_psbt_loaded():
yield
+ @contextmanager
+ def mock_single_sig_psbt_with_every_warning_loaded():
+ with mock_single_sig_psbt_loaded():
+ # List every warning so each one can be shown by its index
+ with patch.object(controller.psbt_parser, "warnings", [PSBTParser.WARNING__HIGH_FEE, PSBTParser.WARNING__NO_CHANGE]):
+ yield
+
+
@contextmanager
def mock_multisig_psbt_loaded():
with mock_load_psbt(BASE64_MULTISIG_PSBT):
@@ -438,9 +446,8 @@ def mock_version_to_most_recent_release():
"PSBT Views": [
ScreenshotConfig(psbt_views.PSBTSelectSeedView, mock_context_manager=mock_controller_psbt_seed_empty),
ScreenshotConfig(psbt_views.PSBTOverviewView, mock_context_manager=mock_multisig_psbt_loaded),
- ScreenshotConfig(psbt_views.PSBTUnsupportedScriptTypeWarningView),
- ScreenshotConfig(psbt_views.PSBTNoChangeWarningView),
- ScreenshotConfig(psbt_views.PSBTHighFeeWarningView, dict(warning_threshold_percent=25)),
+ ScreenshotConfig(psbt_views.PSBTWarningView, dict(warning_index=0), screenshot_name="PSBTWarningView_high_fee", mock_context_manager=mock_single_sig_psbt_with_every_warning_loaded),
+ ScreenshotConfig(psbt_views.PSBTWarningView, dict(warning_index=1), screenshot_name="PSBTWarningView_no_change", mock_context_manager=mock_single_sig_psbt_with_every_warning_loaded),
ScreenshotConfig(psbt_views.PSBTMathView, mock_context_manager=mock_multisig_psbt_loaded),
ScreenshotConfig(psbt_views.PSBTAddressDetailsView, dict(address_num=0), mock_context_manager=mock_multisig_psbt_loaded),
### tests/test_flows_psbt.py
@@ -11,7 +11,7 @@
from seedsigner.controller import Controller
from seedsigner.views.view import MainMenuView
from seedsigner.views import scan_views, seed_views, psbt_views
-from seedsigner.models.psbt_parser import OPCODES
+from seedsigner.models.psbt_parser import OPCODES, PSBTParser
from seedsigner.models.seed import Seed
from seedsigner.models.settings import SettingsConstants
@@ -208,14 +208,10 @@ def load_seed_into_decoder(view: scan_views.ScanView):
-class TestPSBTOwnershipClaimRouting(FlowTest):
+class PSBTSigningFlowTest(FlowTest):
"""
- A psbt whose own description of itself does not hold up, or whose arithmetic is
- impossible, is refused during parsing, before the user is shown anything about the
- transaction. These cover what the user meets when that happens: a warning screen that
- ends the flow, not a crash.
+ Shared helpers for flow tests that load a psbt and walk through the signing flow.
"""
-
def _load_psbt_for_signing(self, psbt: PSBT, seed: Seed = None):
"""
Stage the psbt in the Controller and load the signing seed into storage, as if
@@ -234,6 +230,15 @@ def _psbt_with_change(self):
return psbt
+
+class TestPSBTOwnershipClaimRouting(PSBTSigningFlowTest):
+ """
+ A psbt whose own description of itself does not hold up, or whose arithmetic is
+ impossible, is refused during parsing, before the user is shown anything about the
+ transaction. These cover what the user meets when that happens: a warning screen that
+ ends the flow, not a crash.
+ """
+
def test_forged_output_claim_terminates_signing_flow(self):
"""
A forged ownership claim on an output is framed as a potential attack, so it
@@ -584,3 +589,86 @@ def test_negative_fee_terminates_signing_flow(self):
FlowStep(psbt_views.PSBTNegativeFeeView, button_data_selection=psbt_views.PSBTNegativeFeeView.DISCARD),
FlowStep(MainMenuView),
])
+
+
+
+class TestPSBTWarningRouting(PSBTSigningFlowTest):
+ """
+ Some findings are worth a warning but leave the decision to the user. Each applicable
+ warning is shown in turn before the transaction details. The user can then continue
+ to sign. These cover each warning alone and in the sequences that can occur together.
+ """
+
+ def test_high_fee_warning_alone_continues_to_the_transaction_details(self):
+ """
+ The psbt pays a 50,000 sat recipient out of a 1 BTC input, with its change at an
+ ordinary address index, so nearly all of the input goes to the fee.
+
+ The user should see the high fee warning and then the transaction details.
+ """
+ psbt = self._psbt_with_change()
+ psbt.outputs.append(create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_RECEIVE, 50_000))
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView),
+ FlowStep(psbt_views.PSBTWarningView, button_data_selection=psbt_views.PSBTWarningView.CONTINUE),
+ FlowStep(psbt_views.PSBTWarningView, is_redirect=True),
+ FlowStep(psbt_views.PSBTMathView),
+ ])
+
+ assert self.controller.psbt_parser.warnings == [PSBTParser.WARNING__HIGH_FEE]
+
+
+ def test_no_change_warning_alone_continues_to_the_transaction_details(self):
+ """
+ The psbt spends its whole 1 BTC input on a single recipient, apart from a 10,000
+ sat fee, so no change comes back.
+
+ The user should see the no change warning and then the transaction details.
+ """
+ psbt = PSBT.parse(a2b_base64(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_1_INPUT))
+ input_amount = psbt.inputs[0].utxo.value
+ psbt.outputs.append(create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_RECEIVE, input_amount - 10_000))
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView),
+ FlowStep(psbt_views.PSBTWarningView, button_data_selection=psbt_views.PSBTWarningView.CONTINUE),
+ FlowStep(psbt_views.PSBTWarningView, is_redirect=True),
+ FlowStep(psbt_views.PSBTMathView),
+ ])
+
+ assert self.controller.psbt_parser.warnings == [PSBTParser.WARNING__NO_CHANGE]
+
+
+ def test_high_fee_warning_continues_to_the_no_change_warning(self):
+ """
+ The psbt pays a single 50,000 sat recipient out of a 1 BTC input and sends no
+ change back, so nearly all of the input goes to the fee.
+
+ The user should see the high fee warning, then the no change warning, and then the
+ transaction details.
+ """
+ psbt = PSBT.parse(a2b_base64(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_1_INPUT))
+ psbt.outputs.append(create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_RECEIVE, 50_000))
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView),
+ FlowStep(psbt_views.PSBTWarningView, button_data_selection=psbt_views.PSBTWarningView.CONTINUE),
+ FlowStep(psbt_views.PSBTWarningView, button_data_selection=psbt_views.PSBTWarningView.CONTINUE),
+ FlowStep(psbt_views.PSBTWarningView, is_redirect=True),
+ FlowStep(psbt_views.PSBTMathView),
+ ])
+
+ assert self.controller.psbt_parser.warnings == [
+ PSBTParser.WARNING__HIGH_FEE,
+ PSBTParser.WARNING__NO_CHANGE,
+ ]Why this scored 14/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.