fix(core): remove MicroPython `math` and complex builtins
What changed, and why it matters
This commit simply turns off two unused MicroPython language features—the math module and complex numbers—to save about 11 kB of flash storage on the Trezor device. There is no indication this fixes a security bug or changes how user funds or secrets are handled.
No security action needed. Treat as a normal size-optimization change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch disables MICROPY_PY_BUILTINS_COMPLEX and MICROPY_PY_MATH in both the firmware and unix emulator MicroPython configuration headers. These macros remove support for Python complex number literals/types and the math built-in module. The stated motivation is a ~11 kB flash-size reduction. No runtime behavior, cryptographic code, or attack surface relevant to device security is altered.
Changed components
MicroPython runtime configuration (mpconfigport.h)firmware buildunix emulator buildInspect captured patch +4 / −0
diff --git a/core/embed/projects/firmware/mpconfigport.h b/core/embed/projects/firmware/mpconfigport.h
index 7d38157a..efa495e8 100644
--- a/core/embed/projects/firmware/mpconfigport.h
+++ b/core/embed/projects/firmware/mpconfigport.h
@@ -104,6 +104,7 @@
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#define MICROPY_PY_BUILTINS_COMPILE (MICROPY_ENABLE_COMPILER)
+#define MICROPY_PY_BUILTINS_COMPLEX (0)
#define MICROPY_PY_BUILTINS_EXECFILE (MICROPY_ENABLE_COMPILER)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_BUILTINS_INPUT (0)
@@ -116,6 +117,7 @@
#define MICROPY_PY_COLLECTIONS (0)
#define MICROPY_PY_COLLECTIONS_DEQUE (0)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
+#define MICROPY_PY_MATH (0)
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
#define MICROPY_PY_MATH_ISCLOSE (0)
#define MICROPY_PY_MATH_FACTORIAL (0)
diff --git a/core/embed/projects/unix/mpconfigport.h b/core/embed/projects/unix/mpconfigport.h
index 70a8beb0..03b26833 100644
--- a/core/embed/projects/unix/mpconfigport.h
+++ b/core/embed/projects/unix/mpconfigport.h
@@ -112,6 +112,7 @@
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
#define MICROPY_PY_ALL_SPECIAL_METHODS (0)
#define MICROPY_PY_BUILTINS_COMPILE (MICROPY_ENABLE_COMPILER)
+#define MICROPY_PY_BUILTINS_COMPLEX (0)
#define MICROPY_PY_BUILTINS_EXECFILE (MICROPY_ENABLE_COMPILER)
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (1)
#define MICROPY_PY_BUILTINS_INPUT (0)
@@ -124,6 +125,7 @@
#define MICROPY_PY_COLLECTIONS (0)
#define MICROPY_PY_COLLECTIONS_DEQUE (0)
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
+#define MICROPY_PY_MATH (0)
#define MICROPY_PY_MATH_SPECIAL_FUNCTIONS (0)
#define MICROPY_PY_MATH_ISCLOSE (0)
#define MICROPY_PY_MATH_FACTORIAL (0)
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.