Skip to content

Update libtropic and speed up tropic communication#6956

Open
onvej-sl wants to merge 8 commits into
mainfrom
onvej-sl/tropic-speedup
Open

Update libtropic and speed up tropic communication#6956
onvej-sl wants to merge 8 commits into
mainfrom
onvej-sl/tropic-speedup

Conversation

@onvej-sl
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8fab550-7fbd-4064-8687-7d4e63aa99c3

📥 Commits

Reviewing files that changed from the base of the PR and between e16922a and ebaff61.

📒 Files selected for processing (1)
  • core/embed/projects/prodtest/cmd/prodtest_tropic.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/embed/projects/prodtest/cmd/prodtest_tropic.c

Walkthrough

This PR updates Tropic firmware compilation configuration across all T3W1 build targets to use versioned silicon revision macros and L1 read retry parameters. It adjusts core Tropic operation time estimation helpers and retry classification logic, refactors firmware update and pairing key discovery into reusable components, and introduces a new tropic-benchmark CLI command to measure actual Tropic operation performance across multiple iterations. A vendor submodule reference is updated and documentation is added for the new benchmark command.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, though the repository template includes guidelines for internal developers. Add a detailed pull request description explaining the changes, their motivation, and any testing or QA requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: updating libtropic dependency and performance improvements for tropic communication.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch onvej-sl/tropic-speedup

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@trezor-bot trezor-bot Bot added this to Firmware May 20, 2026
@github-project-automation github-project-automation Bot moved this to 🔎 Needs review in Firmware May 20, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

en main(all)

model device_test click_test persistence_test
T2T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3B1 test(all) main(all) test(all) main(all) test(all) main(all)
T3T1 test(all) main(all) test(all) main(all) test(all) main(all)
T3W1 test(all) main(all) test(all) main(all) test(all) main(all)

Latest CI run: 26748061888

@onvej-sl onvej-sl force-pushed the onvej-sl/tropic-speedup branch from ede851a to 26e56c6 Compare May 20, 2026 15:09
@onvej-sl onvej-sl mentioned this pull request May 21, 2026
@onvej-sl onvej-sl force-pushed the onvej-sl/tropic-speedup branch from 26e56c6 to 7e7e478 Compare May 22, 2026 13:10
@onvej-sl onvej-sl force-pushed the onvej-sl/tropic-speedup branch from 7e7e478 to e16922a Compare May 22, 2026 14:39
@onvej-sl onvej-sl marked this pull request as ready for review May 25, 2026 12:56
@onvej-sl onvej-sl requested review from M-pasta and removed request for TychoVrahe and obrusvit May 25, 2026 12:56
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/embed/projects/prodtest/cmd/prodtest_tropic.c`:
- Around line 1634-1638: The cli_trace call is incorrectly passing CLI_ERROR as
the format string which corrupts variadic args; update the call site to use
cli_trace(cli, " `tropic_custom_session_start()` for key %d failed with error
'%s'", i, lt_ret_verbose(res)) (i.e., remove the CLI_ERROR argument), or if you
intend to log an error use cli_error(cli, ...) instead; locate and fix the call
to cli_trace in the loop where tropic_custom_session_start() is checked and
ensure the format string is the second argument and the subsequent i and
lt_ret_verbose(res) are the variadic parameters.

In `@core/embed/projects/prodtest/README.md`:
- Around line 1474-1486: The fenced code block showing the tropic-benchmark
output in README.md violates markdownlint MD040 because it lacks a language;
update the opening fence from ``` to ```text (or another appropriate language
such as `console`) so the block explicitly declares a language and resolves the
lint error; locate the block containing the "tropic-benchmark" output in
core/embed/projects/prodtest/README.md and change its fence accordingly.

In `@core/site_scons/models/T3W1/emulator.py`:
- Around line 124-126: The build macros LT_L1_READ_MAX_TRIES and
LT_L1_READ_RETRY_DELAY_MS added in emulator.py are not referenced anywhere in
the C/C++ code so they may have no effect; search for LT_L1_READ_MAX_TRIES and
LT_L1_READ_RETRY_DELAY_MS across libtropic/tropic and the firmware sources and
if no consumer exists either (A) wire them into the compiled code path that
implements the L1 read retry loop (add/consume them in the C source or header
that implements the L1 read retry) or (B) export them into a shared generated
header via the SCons rules so the C build sees the defines, or (C) remove the
misleading defines from core/site_scons/models/T3W1/emulator.py; update the
emulator.py change accordingly and document where the L1 retry behavior is
actually implemented (reference LT_L1_READ_MAX_TRIES, LT_L1_READ_RETRY_DELAY_MS,
and the L1 read retry implementation function/module you find).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 60ed4ac7-4b3a-492c-89d3-6f90cad344a9

📥 Commits

Reviewing files that changed from the base of the PR and between decbc4e and e16922a.

📒 Files selected for processing (8)
  • core/embed/projects/prodtest/README.md
  • core/embed/projects/prodtest/cmd/prodtest_tropic.c
  • core/embed/sec/tropic/tropic.c
  • core/site_scons/models/T3W1/emulator.py
  • core/site_scons/models/T3W1/trezor_t3w1_revA.py
  • core/site_scons/models/T3W1/trezor_t3w1_revB.py
  • core/site_scons/models/T3W1/trezor_t3w1_revC.py
  • vendor/libtropic

Comment thread core/embed/projects/prodtest/cmd/prodtest_tropic.c
Comment on lines +1474 to +1486
```
tropic-benchmark
# session_start() 204 ms
# mac_and_destroy() 28 ms
# r_mem_data_write() 37 ms
# r_mem_data_read() 33 ms
# r_mem_data_erase() 4 ms
# mcounter_init() 9 ms
# mcounter_get() 4 ms
# mcounter_update() 4 ms
# random_value_get() 10 ms
OK
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a language to the new fenced example block.

This block currently violates markdownlint MD040 and can fail docs linting.

Suggested fix
-```
+```text
 tropic-benchmark
 # session_start()    204 ms
 # mac_and_destroy()  28 ms
 # r_mem_data_write() 37 ms
 # r_mem_data_read()  33 ms
 # r_mem_data_erase() 4 ms
 # mcounter_init()    9 ms
 # mcounter_get()     4 ms
 # mcounter_update()  4 ms
 # random_value_get() 10 ms
 OK
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 1474-1474: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/embed/projects/prodtest/README.md` around lines 1474 - 1486, The fenced
code block showing the tropic-benchmark output in README.md violates
markdownlint MD040 because it lacks a language; update the opening fence from
``` to ```text (or another appropriate language such as `console`) so the block
explicitly declares a language and resolves the lint error; locate the block
containing the "tropic-benchmark" output in
core/embed/projects/prodtest/README.md and change its fence accordingly.

Comment on lines +124 to +126
defines += [("LT_SILICON_REV_ABAB", "1")]
defines += [("LT_L1_READ_RETRY_DELAY_MS", "1")]
defines += [("LT_L1_READ_MAX_TRIES", "1250")]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the new LT_ defines are used in libtropic or tropic code

echo "=== Searching for LT_SILICON_REV_ABAB usage ==="
rg -n 'LT_SILICON_REV_ABAB' --type=c --type=h -C2

echo -e "\n=== Searching for LT_L1_READ_MAX_TRIES usage ==="
rg -n 'LT_L1_READ_MAX_TRIES' --type=c --type=h -C2

echo -e "\n=== Searching for LT_L1_READ_RETRY_DELAY_MS usage ==="
rg -n 'LT_L1_READ_RETRY_DELAY_MS' --type=c --type=h -C2

echo -e "\n=== Checking for retry/delay related comments or documentation ==="
rg -n -i 'retry.*delay|L1.*read.*retry' vendor/libtropic/ -C2

Repository: trezor/trezor-firmware

Length of output: 1973


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for p in LT_SILICON_REV_ABAB LT_L1_READ_MAX_TRIES LT_L1_READ_RETRY_DELAY_MS; do
  echo "=== Matches for $p ==="
  rg -n --hidden --no-ignore-vcs --max-count 200 "$p" . -S || true
done

echo "=== Likely L1 retry/delay logic ==="
rg -n --hidden --no-ignore-vcs --max-count 200 -i 'l1.*read.*retry|retry.*delay' . -S --glob='*.c' --glob='*.h' || true

Repository: trezor/trezor-firmware

Length of output: 1474


Ensure LT_L1_READ_MAX_TRIES / LT_L1_READ_RETRY_DELAY_MS actually drive L1 read retry behavior

LT_L1_READ_MAX_TRIES=1250 and LT_L1_READ_RETRY_DELAY_MS=1 implies up to ~1.25s of retry delay per L1 read; however, repo-wide search only finds LT_L1_READ_MAX_TRIES / LT_L1_READ_RETRY_DELAY_MS being defined in core/site_scons/models/T3W1/* (including emulator.py, revA/revB/revC) and shows no corresponding usage in any C/C++/header code. Confirm that libtropic/tropic’s L1 read retry loop consumes these macros (otherwise the emulator change may be ineffective or misleading).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/site_scons/models/T3W1/emulator.py` around lines 124 - 126, The build
macros LT_L1_READ_MAX_TRIES and LT_L1_READ_RETRY_DELAY_MS added in emulator.py
are not referenced anywhere in the C/C++ code so they may have no effect; search
for LT_L1_READ_MAX_TRIES and LT_L1_READ_RETRY_DELAY_MS across libtropic/tropic
and the firmware sources and if no consumer exists either (A) wire them into the
compiled code path that implements the L1 read retry loop (add/consume them in
the C source or header that implements the L1 read retry) or (B) export them
into a shared generated header via the SCons rules so the C build sees the
defines, or (C) remove the misleading defines from
core/site_scons/models/T3W1/emulator.py; update the emulator.py change
accordingly and document where the L1 retry behavior is actually implemented
(reference LT_L1_READ_MAX_TRIES, LT_L1_READ_RETRY_DELAY_MS, and the L1 read
retry implementation function/module you find).

Comment on lines +125 to +126
defines += [("LT_L1_READ_RETRY_DELAY_MS", "1")]
defines += [("LT_L1_READ_MAX_TRIES", "1250")]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check I understand what is happening here. My interpretation is as follows: In version 4.0.0 libtropic added

Possibility to configure LT_L1_READ_MAX_TRIES and LT_L1_READ_RETRY_DELAY_MS.

And this is our setting of these variables in our environment. Am I correct?

If so, I wanted to ask: In Tropic documentation I found a note saying

It is better to use the interrupt pin functionality of TROPIC01 if you need to shorten reaction time. See LT_USE_INT_PIN parameter.

My interpretation is that they claim it is better to use some interrupt pin functionality than these variables. the question is: Do you know what the functionality is and if it is better for us?

Comment thread core/embed/projects/prodtest/cmd/prodtest_tropic.c Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Needs review

Development

Successfully merging this pull request may close these issues.

2 participants