refactor(core/ethereum): simplify `confirm_data_and_summary()`
What changed, and why it matters
This is a small internal code cleanup in Trezor's Ethereum transaction signing. It replaces two separate return values with a single tuple, because they are always either both present or both absent. There is no user-visible behavior change and no indication of a security fix.
No action required; treat as routine refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors confirm_tx_data() and confirm_data_and_summary() in core/src/apps/ethereum/sign_tx.py and core/src/apps/ethereum/sign_tx_eip1559.py. Previously confirm_tx_data() returned tuple[ConfirmDataFn | None, Coroutine | None]; now it returns tuple[ConfirmDataFn, Coroutine] | None, encoding the invariant that the two values are either both set or both None. Callers were updated accordingly. The logic flow is unchanged: when None is returned, clear-signing succeeded and no further confirmation is needed; otherwise both the data-chunk callback and the blind-signing summary coroutine are awaited.
Changed components
core/src/apps/ethereum/sign_tx.pycore/src/apps/ethereum/sign_tx_eip1559.pyInspect captured patch +23 / −29
diff --git a/core/src/apps/ethereum/sign_tx.py b/core/src/apps/ethereum/sign_tx.py
index e2b3849f..22016159 100644
--- a/core/src/apps/ethereum/sign_tx.py
+++ b/core/src/apps/ethereum/sign_tx.py
@@ -100,7 +100,7 @@ async def sign_tx(
initial_data = await request_initial_data(msg, sha)
- confirm_data_chunk, confirm_summary = await confirm_tx_data(
+ confirmation = await confirm_tx_data(
initial_data,
msg,
defs,
@@ -111,9 +111,7 @@ async def sign_tx(
sender_bytes,
)
- await confirm_data_and_summary(
- confirm_data_chunk, confirm_summary, initial_data, data_length, sha
- )
+ await confirm_data_and_summary(confirmation, initial_data, data_length, sha)
# eip 155 replay protection
rlp.write(sha, msg.chain_id)
@@ -130,29 +128,27 @@ async def sign_tx(
async def confirm_data_and_summary(
- confirm_data_chunk: ConfirmDataFn | None,
- confirm_summary: Coroutine[Any, Any, None] | None,
+ confirmation: tuple[ConfirmDataFn, Coroutine[Any, Any, None]] | None,
initial_data: AnyBytes,
data_length: int,
sha: HashWriter,
) -> None:
- # `confirm_data_chunk` and `confirm_summary` can be `None`
- # if we clear signed so there is nothing more to confirm
-
- if confirm_data_chunk is not None:
- await confirm_data_chunk(initial_data)
-
- data_left = data_length - len(initial_data)
- while data_left > 0:
- resp = await _send_request_chunk(data_left)
- chunk = resp.data_chunk
- await confirm_data_chunk(chunk)
- data_left -= len(chunk)
- sha.extend(chunk)
+ if confirmation is None:
+ return # clear-signing took place - nothing more to confirm
+
+ confirm_data_chunk, confirm_summary = confirmation
+ await confirm_data_chunk(initial_data)
+
+ data_left = data_length - len(initial_data)
+ while data_left > 0:
+ resp = await _send_request_chunk(data_left)
+ chunk = resp.data_chunk
+ await confirm_data_chunk(chunk)
+ data_left -= len(chunk)
+ sha.extend(chunk)
- if confirm_summary is not None:
- # blind signer's summary
- await confirm_summary
+ # blind signer's summary
+ await confirm_summary
_MAX_DATA_STORED = const(6144)
@@ -202,9 +198,9 @@ async def confirm_tx_data(
fee_items: Sequence[StrPropertyType],
payment_request_verifier: PaymentRequestVerifier | None,
sender_bytes: AnyBytes,
-) -> tuple[ConfirmDataFn | None, Coroutine[Any, Any, None] | None]:
+) -> tuple[ConfirmDataFn, Coroutine[Any, Any, None]] | None:
"""Returns data chunk callback and transaction summary layout to be awaited.
- [None, None] implies clear signing attempted and succeeded."""
+ `None` implies clear signing attempted and succeeded."""
from . import clear_signing, staking, yielding
from .helpers import format_ethereum_amount
@@ -302,7 +298,7 @@ async def confirm_tx_data(
chunkify=bool(msg.chunkify),
)
else:
- return None, None
+ return None
def _get_digest_length(msg: EthereumSignTx, data_total: int) -> int:
diff --git a/core/src/apps/ethereum/sign_tx_eip1559.py b/core/src/apps/ethereum/sign_tx_eip1559.py
index 5e4ae3bc..abd259dd 100644
--- a/core/src/apps/ethereum/sign_tx_eip1559.py
+++ b/core/src/apps/ethereum/sign_tx_eip1559.py
@@ -105,7 +105,7 @@ async def sign_tx_eip1559(
initial_data = await request_initial_data(msg, sha)
- confirm_data_chunk, confirm_summary = await confirm_tx_data(
+ confirmation = await confirm_tx_data(
initial_data,
msg,
defs,
@@ -116,9 +116,7 @@ async def sign_tx_eip1559(
sender_bytes,
)
- await confirm_data_and_summary(
- confirm_data_chunk, confirm_summary, initial_data, data_length, sha
- )
+ await confirm_data_and_summary(confirmation, initial_data, data_length, sha)
# write_access_list
payload_length = sum(access_list_item_length(i) for i in msg.access_list)
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.