SFT-7086: label OP_RETURN outputs and warn when they carry value
What changed, and why it matters
This commit improves the user interface shown when reviewing Bitcoin transactions that include OP_RETURN outputs. OP_RETURN outputs permanently destroy any bitcoins sent to them. Previously, the wallet displayed these outputs like a normal payment with a note, which could mislead a user into thinking the funds were spendable. The change now clearly labels the output as OP_RETURN, never leaves the message field blank, falls back to hex for unprintable characters, and shows a warning when any value is being burned. It is a defensive UX fix rather than a cryptographic vulnerability patch.
Treat as a security-relevant hardening improvement. Users should install the firmware update containing this commit, and developers should verify that the new warning page is shown during all OP_RETURN spend reviews. No immediate incident response is indicated by the commit itself.
Security signals we found
UI spoofing / social-engineering risk mitigated: OP_RETURN outputs previously resembled spendable payments with a memo
Non-printable OP_RETURN payloads now rendered as hex, preventing invisible or misleading message content
Empty OP_RETURN payloads explicitly labeled '(empty)' so the message field is never blank
Burned-value warning added for any satoshis sent to OP_RETURN outputs
Forged label injection in the message is escaped, preserving single real headings
Evidence from the diff
The patch modifies the transaction review flow for PSBT signing in the Foundation Passport firmware. It adds a render_op_return_message helper that ensures an OP_RETURN payload is always visible: empty payloads show ‘(empty)’, and payloads containing no printable ASCII are rendered as hex. The output review screen now explicitly shows ‘Destination: OP_RETURN’ before the message. In psbt.py, consider_outputs sums nValue for any output whose scriptPubKey starts with 0x6a (OP_RETURN) and appends a ‘Burned Amount’ warning if the total is non-zero. Tests verify the warning, review page ordering, and that forged headings inside the message are escaped so they cannot spoof real UI labels.
Changed components
ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.pyports/stm32/boards/Passport/modules/psbt.pyports/stm32/boards/Passport/modules/tests/test_unit.pyports/stm32/boards/Passport/modules/tests/unit/op_return_burn_warning.pyports/stm32/boards/Passport/modules/tests/unit/sign_psbt.pyInspect captured patch +151 / −7
### ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.py
@@ -17,6 +17,18 @@
from utils import escape_text, spinner_task, recolor, stylize_address
+def render_op_return_message(message):
+ # The review fonts only carry printable ASCII, and anything else is drawn as
+ # nothing at zero width. A message the user can't see must never look like no
+ # message, so fall back to its bytes in hex.
+ if not message:
+ return '(empty)'
+ if not any('!' <= char <= '~' for char in message):
+ from ubinascii import b2a_hex
+ return b2a_hex(message.encode()).decode()
+ return escape_text(message)
+
+
class SignPsbtCommonFlow(Flow):
def __init__(self, psbt_len):
import chains
@@ -239,11 +251,14 @@ def render_output(self, o):
dest = self.chain.render_address(o.scriptPubKey)
if dest.startswith("OP_RETURN"):
- return '\n{}\n{}\n\n{}\n{}'.format(
+ # user-defined message starts after "OP_RETURN:\n"
+ message = dest.split('\n', 1)[1]
+ return '\n{}\n{}\n\n{}\nOP_RETURN\n\n{}\n{}'.format(
recolor(HIGHLIGHT_TEXT_HEX, 'Amount'),
val,
+ recolor(HIGHLIGHT_TEXT_HEX, 'Destination'),
recolor(HIGHLIGHT_TEXT_HEX, 'Message'),
- escape_text(dest.split('\n', 1)[1])) # user-defined message starts after "OP_RETURN:\n"
+ render_op_return_message(message))
dest = stylize_address(dest)
### ports/stm32/boards/Passport/modules/psbt.py
@@ -1401,6 +1401,7 @@ def consider_outputs(self):
# - mark change outputs, so perhaps we don't show them to users
total_change = 0
+ total_burned = 0
# print('len(self.outputs)={}'.format(len(self.outputs)))
for idx, txo in self.output_iter():
self.outputs[idx].validate(idx, txo, self.my_xfp, self.active_multisig,
@@ -1409,11 +1410,23 @@ def consider_outputs(self):
if self.outputs[idx].is_change:
total_change += txo.nValue
+ if txo.scriptPubKey[:1] == b'\x6a':
+ total_burned += txo.nValue
+
if self.total_value_out is None:
# this happens, but would expect this to have done already?
for out_idx, txo in self.output_iter():
pass
+ # An OP_RETURN output can never be spent, so any value it carries is lost.
+ # Review shows the amount on the output itself, but nothing there says it's gone.
+ if total_burned:
+ import chains
+ amount = ' '.join(chains.current_chain().render_value(total_burned))
+ self.warnings.append(
+ ('Burned Amount',
+ '{} is sent to OP_RETURN and can never be spent.'.format(amount)))
+
# A change script containing our key does not give us exclusive control
# when any one of several cosigners can spend it. Keep existing wallets
# usable, but disclose this on every spend, including self-sends and
### ports/stm32/boards/Passport/modules/tests/test_unit.py
@@ -104,6 +104,10 @@ def test_op_return_rendering(test):
assert test('op_return_rendering.py') == b'OK'
+def test_op_return_burn_warning(test):
+ assert test('op_return_burn_warning.py') == b'OK'
+
+
def test_message_display(test):
assert test('message_display.py') == b'OK'
### ports/stm32/boards/Passport/modules/tests/unit/op_return_burn_warning.py
@@ -0,0 +1,98 @@
+# SPDX-FileCopyrightText: © 2026 Foundation Devices, Inc. <hello@foundation.xyz>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# Value sent to OP_RETURN outputs is reported as a warning during review.
+
+import chains
+from flows.sign_psbt_common_flow import SignPsbtCommonFlow
+from psbt import psbtObject
+from serializations import CTxOut
+
+P2WPKH = b'\x00\x14' + (b'\x11' * 20)
+OP_RETURN = b'\x6a\x04memo'
+BARE_OP_RETURN = b'\x6a'
+
+
+class MockOutput:
+ is_change = False
+
+ def validate(self, *args):
+ pass
+
+
+class MockPSBT:
+ active_policy = None
+ active_multisig = None
+ my_xfp = 123
+ fee_is_verified = True
+
+ def __init__(self, outputs):
+ self.txouts = [CTxOut(value, script) for value, script in outputs]
+ self.outputs = [MockOutput() for _ in outputs]
+ self.total_value_out = sum(value for value, _ in outputs)
+ self.warnings = []
+ self.self_send = False
+
+ def output_iter(self):
+ for index, txout in enumerate(self.txouts):
+ yield index, txout
+
+ def calculate_fee(self):
+ return 1
+
+ def consider_dangerous_change(self, xfp):
+ pass
+
+
+class MockChain:
+ def render_value(self, value):
+ return str(value), 'sats'
+
+ def render_address(self, script):
+ return 'OP_RETURN:\nmemo' if script[:1] == b'\x6a' else 'bc1qtest'
+
+
+class MockFlow(SignPsbtCommonFlow):
+ def __init__(self, psbt):
+ self.psbt = psbt
+ self.chain = MockChain()
+
+
+def burn_warnings(outputs):
+ psbt = MockPSBT(outputs)
+ psbtObject.consider_outputs(psbt)
+ return psbt, [warning for warning in psbt.warnings if warning[0] == 'Burned Amount']
+
+
+def rendered(value):
+ return ' '.join(chains.current_chain().render_value(value))
+
+
+# Nothing is burned when OP_RETURN outputs carry no value, or there are none.
+for outputs in ([(1000, P2WPKH), (0, OP_RETURN)],
+ [(1000, P2WPKH), (0, BARE_OP_RETURN)],
+ [(1000, P2WPKH)]):
+ assert burn_warnings(outputs)[1] == []
+
+# A valued OP_RETURN is reported with its amount, bare or carrying data.
+for script in (OP_RETURN, BARE_OP_RETURN):
+ _, warnings = burn_warnings([(1000, P2WPKH), (100, script)])
+ assert len(warnings) == 1
+ assert warnings[0][1] == '{} is sent to OP_RETURN and can never be spent.'.format(rendered(100))
+
+# Several valued OP_RETURN outputs produce one warning for the total.
+_, warnings = burn_warnings([(100, OP_RETURN), (1000, P2WPKH), (50, BARE_OP_RETURN)])
+assert len(warnings) == 1
+assert rendered(150) in warnings[0][1]
+
+# Review gives the warning a page of its own, after the network fee page.
+psbt, _ = burn_warnings([(1000, P2WPKH), (100, OP_RETURN)])
+pages = list(MockFlow(psbt).review_pages())
+fee_page = [index for index, page in enumerate(pages) if 'Network Fee' in page]
+burn_page = [index for index, page in enumerate(pages) if 'Burned Amount' in page]
+assert len(fee_page) == 1 and len(burn_page) == 1
+assert fee_page[0] < burn_page[0]
+assert 'Warning 1/1' in pages[burn_page[0]]
+assert 'can never be spent' in pages[burn_page[0]]
+
+return_value.write(b'OK')
### ports/stm32/boards/Passport/modules/tests/unit/sign_psbt.py
@@ -35,31 +35,45 @@ def __init__(self, value, message):
self.scriptPubKey = message
-def assert_op_return_output(value, message):
+def assert_op_return_output(value, message, shown=None):
rendered = SignPsbtCommonFlow.render_output(MockFlow(), MockOutput(value, message))
amount_label = rendered.find('Amount')
amount = rendered.find('{} sats'.format(value))
+ destination_label = rendered.find('Destination')
+ destination = rendered.find('\nOP_RETURN\n')
message_label = rendered.find('Message')
- payload = rendered.find(message)
+ payload = rendered.rfind(message if shown is None else shown)
- assert -1 not in (amount_label, amount, message_label, payload)
- assert amount_label < amount < message_label < payload
+ assert -1 not in (amount_label, amount, destination_label, destination, message_label, payload)
+ assert amount_label < amount < destination_label < destination < message_label < payload
+ return rendered
assert_op_return_output(0, 'zero-value-message')
assert_op_return_output(50000000, 'payment-id-12345')
+# The message is never blank: no payload says so, and a payload with nothing the
+# review font can draw (it only carries printable ASCII) falls back to hex.
+assert assert_op_return_output(0, '', '(empty)').endswith('\n(empty)')
+assert assert_op_return_output(1, '‘', 'e28098').endswith('\ne28098')
+assert assert_op_return_output(1, '한글', 'ed959ceab880').endswith('\ned959ceab880')
+assert assert_op_return_output(1, ' \n ', '200a20').endswith('\n200a20')
+# One drawable character is enough to show the text itself.
+assert assert_op_return_output(1, 'a‘b').endswith('\na‘b')
+
amount_heading = recolor(HIGHLIGHT_TEXT_HEX, 'Amount')
message_heading = recolor(HIGHLIGHT_TEXT_HEX, 'Message')
destination_heading = recolor(HIGHLIGHT_TEXT_HEX, 'Destination')
malicious_message = '{}\n0.00000001 BTC\n\n{}\nbc1qattacker'.format(
amount_heading, destination_heading)
rendered = SignPsbtCommonFlow.render_output(MockFlow(), MockOutput(1, malicious_message))
assert escape_text(malicious_message) in rendered
+# Forged headings in the message are escaped, so only the real ones remain.
assert rendered.count('\n{}\n'.format(amount_heading)) == 1
assert rendered.count('\n{}\n'.format(message_heading)) == 1
-assert rendered.count('\n{}\n'.format(destination_heading)) == 0
+assert rendered.count('\n{}\n'.format(destination_heading)) == 1
+assert rendered.index('\n{}\nOP_RETURN\n'.format(destination_heading)) < rendered.index(message_heading)
assert malicious_message not in rendered
address = 'bc1qvaliddestination'Why this scored 52/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.