feat(vendor): optimize MicroPython imports
What changed, and why it matters
This commit is a small internal cleanup in the Trezor firmware's embedded MicroPython environment. It replaces a helper function call with a direct way to check whether a loaded module is a package, matching a recent upstream MicroPython change. There is no indication this fixes or introduces a security problem.
No security action required. Treat as routine vendor maintenance / upstream synchronization.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch changes the Unix emulator’s module loading path. Instead of calling mp_obj_is_package(mod) to decide whether to attempt loading a subpackage, it directly calls mp_load_method_maybe(mod, MP_QSTR___path__, dest) and checks that dest[0] != MP_OBJ_NULL. This mirrors upstream MicroPython commit 525557738cccb73d7b00d2048b9fd47e4caeeec6, which re-implemented mp_obj_is_package using the same __path__ lookup. The change is functionally equivalent for the purpose of detecting packages and appears to be a code synchronization/optimization rather than a security fix.
Changed components
core/embed/projects/unix/main.cvendor/micropythonInspect captured patch +4 / −2
diff --git a/core/embed/projects/unix/main.c b/core/embed/projects/unix/main.c
index a658e5ed..5a3bd2ea 100644
--- a/core/embed/projects/unix/main.c
+++ b/core/embed/projects/unix/main.c
@@ -440,7 +440,9 @@ reimport:
exit(handle_uncaught_exception(nlr.ret_val) & 0xff);
}
- if (mp_obj_is_package(mod) && !subpkg_tried) {
+ mp_obj_t dest[2];
+ mp_load_method_maybe(mod, MP_QSTR___path__, dest);
+ if (dest[0] != MP_OBJ_NULL && !subpkg_tried) {
subpkg_tried = true;
vstr_t vstr;
int len = strlen(modname);
Why this scored 11/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.