Merge pull request #726 from Foundation-Devices/sft-7086-add-screen-confirming-amount-being-sent-to-op_return
What changed, and why it matters
This commit adds safety warnings and clearer labels for a special kind of Bitcoin transaction output called OP_RETURN. Any bitcoins sent to an OP_RETURN output are permanently destroyed ('burned'). Previously, the wallet showed the amount and a user message but did not clearly tell the user the money was unspendable. The change also makes sure that if the OP_RETURN message contains unusual characters the device cannot display, it shows the raw bytes in hex instead of silently appearing blank, which could hide a hidden message or trick the user.
Treat as a security-hardening fix. Users should install the firmware update containing this commit, and developers should review whether any other user-controlled fields rendered during transaction signing can spoof labels or hide information.
Security signals we found
Adds explicit warning when value is sent to an unspendable OP_RETURN output
Prevents invisible or zero-width OP_RETURN messages by falling back to hex when no printable ASCII is present
Escapes user-controlled OP_RETURN payload to prevent it from spoofing UI labels such as amount or destination
Adds unit tests covering burn warning, multi-output aggregation, page ordering, and message rendering edge cases
Evidence from the diff
The patch modifies the Passport firmware’s PSBT signing flow. In psbt.py, consider_outputs() now detects outputs whose scriptPubKey starts with 0x6a (OP_RETURN), sums their nValue into total_burned, and appends a ‘Burned Amount’ warning. In sign_psbt_common_flow.py, render_output() now separates the OP_RETURN destination from the user-supplied message, adds a ‘Destination’ label, and uses a new render_op_return_message() helper that falls back to hex if the payload contains no printable ASCII characters. Tests are added/updated to verify the warning, the page ordering, and the escaping/fallback behavior.
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 +159 / −8
### ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.py
@@ -14,7 +14,18 @@
from styles.colors import HIGHLIGHT_TEXT_HEX, BLACK_HEX
from tasks import validate_psbt_task
import gc
-from utils import escape_text, spinner_task, recolor, stylize_address
+from utils import b2a_hex, 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):
+ return b2a_hex(message.encode()).decode()
+ return escape_text(message)
class SignPsbtCommonFlow(Flow):
@@ -239,11 +250,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,106 @@
+# 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
+import common
+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))
+
+
+# chains.current_chain() and render_value() read settings, which the harness
+# leaves unset. Supply defaults (BTC, BTC units) and restore them afterwards.
+original_settings = common.settings
+common.settings = {}
+try:
+ # 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]]
+finally:
+ common.settings = original_settings
+
+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 60/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.