refactor(core/thp): use an explicitly named flag for ACK handling
What changed, and why it matters
This is a minor code cleanup in Trezor firmware's THP (Trezor Host Protocol) channel handling. It replaces a repeated check (`expected_ctrl_byte is None`) with a clearly named boolean variable (`return_after_ack`). There is no functional change and no security impact.
No action required. This is a non-security refactor with no behavioral change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors Channel._receive_payload in core/src/trezor/wire/thp/channel.py. The expression expected_ctrl_byte is None is evaluated once into return_after_ack, and two subsequent uses are replaced with the new variable. The diff shows no logic change, no new branches, no altered comparisons, and no change to control flow beyond the variable substitution. It is a pure readability refactor.
Changed components
core/src/trezor/wire/thp/channel.pyInspect captured patch +3 / −2
diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py
index dbc2d0172..f74e78105 100644
--- a/core/src/trezor/wire/thp/channel.py
+++ b/core/src/trezor/wire/thp/channel.py
@@ -241,6 +241,7 @@ class Channel:
If `expected_ctrl_byte` is `None`, returns after the first received ACK.
"""
+ return_after_ack = expected_ctrl_byte is None
while True:
# Handle an existing message (if already reassembled).
# Otherwise, receive and reassemble a new one.
@@ -254,11 +255,11 @@ class Channel:
# 1: Handle ACKs
if control_byte.is_ack(ctrl_byte):
handle_ack(self, control_byte.get_ack_bit(ctrl_byte))
- if expected_ctrl_byte is None:
+ if return_after_ack:
return payload
continue
- if expected_ctrl_byte is None or not expected_ctrl_byte(ctrl_byte):
+ if return_after_ack or not expected_ctrl_byte(ctrl_byte):
if __debug__:
self._log(
"Unexpected control byte - ignoring ",
Why this scored 15/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.