SFT-7086: fix hex import and test settings for the simulator
What changed, and why it matters
This commit fixes two small bugs that only affect the Passport hardware wallet's software simulator and its unit tests. It swaps one way of converting bytes to hex for another already-provided alias, and it gives the test harness default settings so a warning test can run. There is no indication this changes real-device behavior or fixes a security vulnerability.
No security action required. Treat as a normal test/simulator compatibility fix. If reviewing the broader OP_RETURN warning feature, verify that valued OP_RETURN outputs still produce the expected 'can never be spent' warning on real firmware.
Security signals we found
No security-relevant behavior change on real hardware: the same b2a_hex alias is used, only the import source changes.
No bounds-checking, parsing, cryptographic, or privilege changes.
Test-only settings mutation is wrapped in try/finally to avoid leaking state between tests.
No vendor disclosure of security relevance, no CVE, no advisory, no researcher attribution in the commit.
Evidence from the diff
The diff makes two changes: (1) In sign_psbt_common_flow.py it replaces a local import of ubinascii.b2a_hex with an import of utils.b2a_hex, because the simulator’s ubinascii lacks b2a_hex. The function render_op_return_message still hex-encodes non-printable OP_RETURN messages the same way. (2) In the unit test op_return_burn_warning.py it saves common.settings, supplies an empty dict as defaults for chains.current_chain()/render_value(), runs the existing assertions, and restores the original settings in a finally block. The commit message frames this as ‘fix hex import and test settings for the simulator.’
Changed components
ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.pyports/stm32/boards/Passport/modules/tests/unit/op_return_burn_warning.pyInspect captured patch +34 / −27
### ports/stm32/boards/Passport/modules/flows/sign_psbt_common_flow.py
@@ -14,7 +14,7 @@
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):
@@ -24,7 +24,6 @@ def render_op_return_message(message):
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)
### ports/stm32/boards/Passport/modules/tests/unit/op_return_burn_warning.py
@@ -4,6 +4,7 @@
# 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
@@ -68,31 +69,38 @@ 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)])
+# 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 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]]
+ 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')Why this scored 19/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.