refactor(core): fix renamed micropython modules
What changed, and why it matters
This commit is a routine code cleanup that updates Trezor firmware to match a newer MicroPython version where built-in module names dropped the 'u' prefix (for example, 'uos' became 'os' and 'ustruct' became 'struct'). It renames imports, configuration flags, and source file references, and removes old mock files. There is no security fix or vulnerability here.
No security action needed. Treat as a normal dependency-compatibility refactor. Verify the build passes with the updated MicroPython module names.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adapts the Trezor Core codebase to MicroPython renames of built-in modules from the legacy ‘u’ prefix (uos, uerrno, ustruct, utime, etc.) to their unprefixed equivalents (os, errno, struct, time). Changes include: updating MICROPY_PY_ config macros in mpconfigport.h files, changing source file paths (moduos.c -> modos.c, moduerrno.c -> moderrno.c), updating C symbol names (mp_utime_ -> mp_time_, mp_uos_ -> mp_os_*), switching Python imports from ustruct/uos/uio to struct/os/io, and removing stale mock .pyi files. A single typo fix in a Rust comment is also included. No functional behavior changes are introduced.
Changed components
core/SConscript.unixcore/embed/projects/firmware/mpconfigport.hcore/embed/projects/unix/main.ccore/embed/projects/unix/mpconfigport.hcore/embed/rust/src/ui/geometry.rscore/embed/upymod/build.rscore/embed/upymod/modutime.ccore/mocks/generated/uio.pyicore/mocks/generated/uos.pyicore/mocks/generated/ustruct.pyicore/mocks/uio.pyicore/mocks/uos.pyicore/mocks/ustruct.pyicore/src/apps/bitcoin/sign_tx/omni.pycore/src/apps/bitcoin/sign_tx/zcash_v4.pycore/src/apps/common/cbor.pycore/src/apps/misc/sign_identity.pycore/src/apps/stellar/helpers.pycore/src/apps/webauthn/credential.pycore/src/apps/webauthn/fido2.pycore/src/prof/__main__.pycore/src/trezor/crypto/base32.pycore/src/trezor/utils.pycore/src/trezor/wire/codec/codec_v1.pycore/src/trezor/wire/thp/memory_manager.pycore/tests/test_trezor.wire.codec.codec_v1.pypyproject.tomlInspect captured patch +86 / −117
diff --git a/core/SConscript.unix b/core/SConscript.unix
index 90e4ee8d..8800c8f4 100644
--- a/core/SConscript.unix
+++ b/core/SConscript.unix
@@ -307,7 +307,7 @@ SOURCE_MOD += [
SOURCE_MICROPYTHON = [
'vendor/micropython/extmod/moductypes.c',
- 'vendor/micropython/extmod/moduos.c',
+ 'vendor/micropython/extmod/modos.c',
'vendor/micropython/extmod/utime_mphal.c',
'vendor/micropython/shared/readline/readline.c',
'vendor/micropython/shared/timeutils/timeutils.c',
@@ -352,7 +352,7 @@ SOURCE_MICROPYTHON = [
'vendor/micropython/py/modstruct.c',
'vendor/micropython/py/modsys.c',
'vendor/micropython/py/modthread.c',
- 'vendor/micropython/py/moduerrno.c',
+ 'vendor/micropython/py/moderrno.c',
'vendor/micropython/py/mpprint.c',
'vendor/micropython/py/mpstate.c',
'vendor/micropython/py/mpz.c',
diff --git a/core/embed/projects/firmware/mpconfigport.h b/core/embed/projects/firmware/mpconfigport.h
index 97cbeff2..ad9be500 100644
--- a/core/embed/projects/firmware/mpconfigport.h
+++ b/core/embed/projects/firmware/mpconfigport.h
@@ -131,36 +131,36 @@
#define MICROPY_PY_SYS_STDFILES (0)
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
#define MICROPY_PY_SYS_PLATFORM "trezor"
-#define MICROPY_PY_UERRNO (0)
+#define MICROPY_PY_ERRNO (0)
#define MICROPY_PY_THREAD (0)
#define MICROPY_PY_FSTRINGS (1)
// extended modules
#define MICROPY_PY_UCTYPES (!BITCOIN_ONLY) // used in FIDO
-#define MICROPY_PY_UZLIB (0)
-#define MICROPY_PY_UJSON (0)
-#define MICROPY_PY_UOS (0)
-#define MICROPY_PY_URE (0)
-#define MICROPY_PY_URE_SUB (0)
-#define MICROPY_PY_UHEAPQ (0)
-#define MICROPY_PY_UHASHLIB (0)
-#define MICROPY_PY_UHASHLIB_MD5 (0)
-#define MICROPY_PY_UHASHLIB_SHA1 (0)
-#define MICROPY_PY_UCRYPTOLIB (0)
-#define MICROPY_PY_UBINASCII (0)
-#define MICROPY_PY_UBINASCII_CRC32 (0)
-#define MICROPY_PY_URANDOM (0)
-#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
-#define MICROPY_PY_USELECT (0)
-#define MICROPY_PY_UTIME (1)
+#define MICROPY_PY_DEFLATE (0)
+#define MICROPY_PY_JSON (0)
+#define MICROPY_PY_OS (0)
+#define MICROPY_PY_RE (0)
+#define MICROPY_PY_RE_SUB (0)
+#define MICROPY_PY_HEAPQ (0)
+#define MICROPY_PY_HASHLIB (0)
+#define MICROPY_PY_HASHLIB_MD5 (0)
+#define MICROPY_PY_HASHLIB_SHA1 (0)
+#define MICROPY_PY_CRYPTOLIB (0)
+#define MICROPY_PY_BINASCII (0)
+#define MICROPY_PY_BINASCII_CRC32 (0)
+#define MICROPY_PY_RANDOM (0)
+#define MICROPY_PY_RANDOM_EXTRA_FUNCS (0)
+#define MICROPY_PY_SELECT (0)
+#define MICROPY_PY_TIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_OS_DUPTERM (0)
#define MICROPY_PY_LWIP_SOCK_RAW (0)
#define MICROPY_PY_MACHINE (0)
-#define MICROPY_PY_UWEBSOCKET (0)
+#define MICROPY_PY_WEBSOCKET (0)
#define MICROPY_PY_WEBREPL (0)
#define MICROPY_PY_FRAMEBUF (0)
-#define MICROPY_PY_USOCKET (0)
+#define MICROPY_PY_SOCKET (0)
#define MICROPY_PY_NETWORK (0)
// allocate traceback data only on debug builds
diff --git a/core/embed/projects/unix/main.c b/core/embed/projects/unix/main.c
index fabd3ae8..43204861 100644
--- a/core/embed/projects/unix/main.c
+++ b/core/embed/projects/unix/main.c
@@ -71,7 +71,7 @@ STATIC void stderr_print_strn(void *env, const char *str, size_t len) {
#ifdef USE_DBG_CONSOLE
dbg_console_write(str, len);
#endif
- mp_uos_dupterm_tx_strn(str, len);
+ mp_os_dupterm_tx_strn(str, len);
}
const mp_print_t mp_stderr_print = {NULL, stderr_print_strn};
@@ -746,5 +746,3 @@ void nlr_jump_fail(void *val) {
printf("FATAL: uncaught NLR %p\n", val);
exit(1);
}
-
-MP_REGISTER_MODULE(MP_QSTR_uos, mp_module_uos);
diff --git a/core/embed/projects/unix/mpconfigport.h b/core/embed/projects/unix/mpconfigport.h
index d7916961..a4241d5e 100644
--- a/core/embed/projects/unix/mpconfigport.h
+++ b/core/embed/projects/unix/mpconfigport.h
@@ -140,42 +140,42 @@
#define MICROPY_PY_SYS_STDFILES (0)
#define MICROPY_PY_SYS_STDIO_BUFFER (0)
#define MICROPY_PY_SYS_PLATFORM "trezor-emulator"
-#define MICROPY_PY_UERRNO (0)
+#define MICROPY_PY_ERRNO (0)
#define MICROPY_PY_THREAD (0)
#define MICROPY_PY_FSTRINGS (1)
// extended modules
#define MICROPY_PY_UCTYPES (!BITCOIN_ONLY) // used in FIDO
-#define MICROPY_PY_UZLIB (0)
-#define MICROPY_PY_UJSON (0)
-#define MICROPY_PY_UOS (1)
-#define MICROPY_PY_UOS_INCLUDEFILE "ports/unix/moduos.c"
-#define MICROPY_PY_UOS_ERRNO (1)
-#define MICROPY_PY_UOS_GETENV_PUTENV_UNSETENV (1)
-#define MICROPY_PY_UOS_SEP (1)
-#define MICROPY_PY_UOS_SYSTEM (1)
-#define MICROPY_PY_UOS_URANDOM (1)
-#define MICROPY_PY_URE (0)
-#define MICROPY_PY_URE_SUB (0)
-#define MICROPY_PY_UHEAPQ (0)
-#define MICROPY_PY_UHASHLIB (0)
-#define MICROPY_PY_UHASHLIB_MD5 (0)
-#define MICROPY_PY_UHASHLIB_SHA1 (0)
-#define MICROPY_PY_UCRYPTOLIB (0)
-#define MICROPY_PY_UBINASCII (0)
-#define MICROPY_PY_UBINASCII_CRC32 (0)
-#define MICROPY_PY_URANDOM (0)
-#define MICROPY_PY_URANDOM_EXTRA_FUNCS (0)
-#define MICROPY_PY_USELECT (0)
-#define MICROPY_PY_UTIME (1)
+#define MICROPY_PY_DEFLATE (0)
+#define MICROPY_PY_JSON (0)
+#define MICROPY_PY_OS (1)
+#define MICROPY_PY_OS_INCLUDEFILE "ports/unix/modos.c"
+#define MICROPY_PY_OS_ERRNO (1)
+#define MICROPY_PY_OS_GETENV_PUTENV_UNSETENV (1)
+#define MICROPY_PY_OS_SEP (1)
+#define MICROPY_PY_OS_SYSTEM (1)
+#define MICROPY_PY_OS_URANDOM (1)
+#define MICROPY_PY_RE (0)
+#define MICROPY_PY_RE_SUB (0)
+#define MICROPY_PY_HEAPQ (0)
+#define MICROPY_PY_HASHLIB (0)
+#define MICROPY_PY_HASHLIB_MD5 (0)
+#define MICROPY_PY_HASHLIB_SHA1 (0)
+#define MICROPY_PY_CRYPTOLIB (0)
+#define MICROPY_PY_BINASCII (0)
+#define MICROPY_PY_BINASCII_CRC32 (0)
+#define MICROPY_PY_RANDOM (0)
+#define MICROPY_PY_RANDOM_EXTRA_FUNCS (0)
+#define MICROPY_PY_SELECT (0)
+#define MICROPY_PY_TIME (1)
#define MICROPY_PY_UTIME_MP_HAL (1)
#define MICROPY_PY_OS_DUPTERM (0)
#define MICROPY_PY_LWIP_SOCK_RAW (0)
#define MICROPY_PY_MACHINE (0)
-#define MICROPY_PY_UWEBSOCKET (0)
+#define MICROPY_PY_WEBSOCKET (0)
#define MICROPY_PY_WEBREPL (0)
#define MICROPY_PY_FRAMEBUF (0)
-#define MICROPY_PY_USOCKET (0)
+#define MICROPY_PY_SOCKET (0)
#define MICROPY_PY_NETWORK (0)
// allocate traceback data only on debug builds
diff --git a/core/embed/rust/src/ui/geometry.rs b/core/embed/rust/src/ui/geometry.rs
index 76489623..cc5eebb8 100644
--- a/core/embed/rust/src/ui/geometry.rs
+++ b/core/embed/rust/src/ui/geometry.rs
@@ -373,7 +373,7 @@ impl Rect {
/// Checks if the rectangle is empty.
///
- /// It is possible to custruct a rectangle with negative width or height.
+ /// It is possible to construct a rectangle with negative width or height.
/// All such rectangles are considered as empty.
pub const fn is_empty(&self) -> bool {
self.x0 >= self.x1 || self.y0 >= self.y1
diff --git a/core/embed/upymod/build.rs b/core/embed/upymod/build.rs
index 24af9788..fd1b466f 100644
--- a/core/embed/upymod/build.rs
+++ b/core/embed/upymod/build.rs
@@ -165,7 +165,7 @@ fn main() -> Result<()> {
"py/modstruct.c",
"py/modsys.c",
"py/modthread.c",
- "py/moduerrno.c",
+ "py/moderrno.c",
"py/mpprint.c",
"py/mpstate.c",
"py/mpz.c",
@@ -249,7 +249,7 @@ fn main() -> Result<()> {
mpy_dir,
[
"extmod/vfs_posix_file.c",
- "extmod/moduos.c",
+ "extmod/modos.c",
"py/emitnarm.c",
"py/emitnative.c",
"py/emitnthumb.c",
diff --git a/core/embed/upymod/modutime.c b/core/embed/upymod/modutime.c
index 956c8374..83fc5246 100644
--- a/core/embed/upymod/modutime.c
+++ b/core/embed/upymod/modutime.c
@@ -52,14 +52,14 @@ STATIC const mp_rom_map_elem_t time_module_globals_table[] = {
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_utime)},
{MP_ROM_QSTR(MP_QSTR_gmtime2000), MP_ROM_PTR(&time_gmtime2000_obj)},
- {MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_utime_sleep_obj)},
- {MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_utime_sleep_ms_obj)},
- {MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_utime_sleep_us_obj)},
- {MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_utime_ticks_ms_obj)},
- {MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_utime_ticks_us_obj)},
- {MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_utime_ticks_cpu_obj)},
- {MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_utime_ticks_add_obj)},
- {MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_utime_ticks_diff_obj)},
+ {MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mp_time_sleep_obj)},
+ {MP_ROM_QSTR(MP_QSTR_sleep_ms), MP_ROM_PTR(&mp_time_sleep_ms_obj)},
+ {MP_ROM_QSTR(MP_QSTR_sleep_us), MP_ROM_PTR(&mp_time_sleep_us_obj)},
+ {MP_ROM_QSTR(MP_QSTR_ticks_ms), MP_ROM_PTR(&mp_time_ticks_ms_obj)},
+ {MP_ROM_QSTR(MP_QSTR_ticks_us), MP_ROM_PTR(&mp_time_ticks_us_obj)},
+ {MP_ROM_QSTR(MP_QSTR_ticks_cpu), MP_ROM_PTR(&mp_time_ticks_cpu_obj)},
+ {MP_ROM_QSTR(MP_QSTR_ticks_add), MP_ROM_PTR(&mp_time_ticks_add_obj)},
+ {MP_ROM_QSTR(MP_QSTR_ticks_diff), MP_ROM_PTR(&mp_time_ticks_diff_obj)},
};
STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
diff --git a/core/mocks/generated/uio.pyi b/core/mocks/generated/uio.pyi
deleted file mode 120000
index ac036f48..00000000
--- a/core/mocks/generated/uio.pyi
+++ /dev/null
@@ -1 +0,0 @@
-../uio.pyi
\ No newline at end of file
diff --git a/core/mocks/generated/uos.pyi b/core/mocks/generated/uos.pyi
deleted file mode 120000
index c5cae7aa..00000000
--- a/core/mocks/generated/uos.pyi
+++ /dev/null
@@ -1 +0,0 @@
-../uos.pyi
\ No newline at end of file
diff --git a/core/mocks/generated/ustruct.pyi b/core/mocks/generated/ustruct.pyi
deleted file mode 120000
index a3dbad3e..00000000
--- a/core/mocks/generated/ustruct.pyi
+++ /dev/null
@@ -1 +0,0 @@
-../ustruct.pyi
\ No newline at end of file
diff --git a/core/mocks/uio.pyi b/core/mocks/uio.pyi
deleted file mode 100644
index 6cf1e651..00000000
--- a/core/mocks/uio.pyi
+++ /dev/null
@@ -1,16 +0,0 @@
-class FileIO:
- def __enter__(self) -> FileIO: ...
-
- def __exit__(*args) -> None: ...
-
- def write(self, data: bytes | str) -> int: ...
-
-class StringIO:
- def __init__(self, _: int | str) -> None: ...
-
-class BytesIO:
- def __init__(self, _: int | bytes) -> None: ...
- def getvalue(self) -> bytes: ...
-
-def open(name: str, mode: str = ...) -> FileIO:
- pass
diff --git a/core/mocks/uos.pyi b/core/mocks/uos.pyi
deleted file mode 100644
index 9fb4e3a8..00000000
--- a/core/mocks/uos.pyi
+++ /dev/null
@@ -1 +0,0 @@
-def getenv(env: str) -> str: ...
diff --git a/core/mocks/ustruct.pyi b/core/mocks/ustruct.pyi
deleted file mode 100644
index 99821c2c..00000000
--- a/core/mocks/ustruct.pyi
+++ /dev/null
@@ -1,8 +0,0 @@
-from typing import *
-from buffer_types import *
-
-def calcsize(fmt: str) -> int: ...
-def pack(fmt: str, *args: Any) -> bytes: ...
-def pack_into(fmt: str, buffer: AnyBuffer, offset: int, *args: Any) -> None: ...
-def unpack(fmt: str, data: AnyBytes) -> Tuple: ...
-def unpack_from(fmt: str, data: AnyBytes, offset: int = ...) -> Tuple: ...
diff --git a/core/src/apps/bitcoin/sign_tx/omni.py b/core/src/apps/bitcoin/sign_tx/omni.py
index 9e840b92..9aebe0d4 100644
--- a/core/src/apps/bitcoin/sign_tx/omni.py
+++ b/core/src/apps/bitcoin/sign_tx/omni.py
@@ -20,7 +20,7 @@ def is_valid(data: AnyBytes) -> bool:
def parse(data: AnyBytes) -> str:
- from ustruct import unpack
+ from struct import unpack
from trezor import TR
from trezor.strings import format_amount, format_amount_unit
diff --git a/core/src/apps/bitcoin/sign_tx/zcash_v4.py b/core/src/apps/bitcoin/sign_tx/zcash_v4.py
index 3b69bfe2..b036110b 100644
--- a/core/src/apps/bitcoin/sign_tx/zcash_v4.py
+++ b/core/src/apps/bitcoin/sign_tx/zcash_v4.py
@@ -51,7 +51,7 @@ class Zip243SigHasher:
coin: CoinInfo,
hash_type: int,
) -> bytes:
- import ustruct as struct
+ import struct
from ..scripts import write_bip143_script_code_prefixed
from ..writers import get_tx_hash, write_bytes_fixed
diff --git a/core/src/apps/common/cbor.py b/core/src/apps/common/cbor.py
index 0db1ab27..cd4ddcbc 100644
--- a/core/src/apps/common/cbor.py
+++ b/core/src/apps/common/cbor.py
@@ -51,7 +51,7 @@ _CBOR_SET_TAG = const(0x102) # Tag 258
def _header(typ: int, l: int) -> bytes:
- from ustruct import pack
+ from struct import pack
if l < 24:
return pack(">B", typ + l)
diff --git a/core/src/apps/misc/sign_identity.py b/core/src/apps/misc/sign_identity.py
index 54c90c94..edbb0f15 100644
--- a/core/src/apps/misc/sign_identity.py
+++ b/core/src/apps/misc/sign_identity.py
@@ -91,7 +91,7 @@ def serialize_identity_without_proto(identity: IdentityType) -> str:
def get_identity_path(identity: str, index: int, num: int) -> Bip32Path:
- from ustruct import pack, unpack
+ from struct import pack, unpack
from apps.common.paths import HARDENED
diff --git a/core/src/apps/stellar/helpers.py b/core/src/apps/stellar/helpers.py
index 1d877aaf..189b8cf2 100644
--- a/core/src/apps/stellar/helpers.py
+++ b/core/src/apps/stellar/helpers.py
@@ -88,7 +88,7 @@ def _crc16_checksum(data: AnyBytes) -> bytes:
Initial value changed to 0x0000 to match Stellar configuration.
"""
- import ustruct
+ import struct
crc = 0x0000
polynomial = 0x1021
@@ -101,4 +101,4 @@ def _crc16_checksum(data: AnyBytes) -> bytes:
if c15 ^ bit:
crc ^= polynomial
- return ustruct.pack("<H", crc & 0xFFFF)
+ return struct.pack("<H", crc & 0xFFFF)
diff --git a/core/src/apps/webauthn/credential.py b/core/src/apps/webauthn/credential.py
index 0193344d..3ae76eee 100644
--- a/core/src/apps/webauthn/credential.py
+++ b/core/src/apps/webauthn/credential.py
@@ -1,4 +1,4 @@
-import ustruct
+import struct
from micropython import const
from typing import TYPE_CHECKING
@@ -306,7 +306,7 @@ class Fido2Credential(Credential):
def _private_key(self) -> bytes:
path = [HARDENED | 10022, HARDENED | int.from_bytes(self.id[:4], "big")] + [
- HARDENED | i for i in ustruct.unpack(">4L", self.id[-16:])
+ HARDENED | i for i in struct.unpack(">4L", self.id[-16:])
]
node = seed.derive_node_without_passphrase(path, _CURVE_NAME[self.curve])
return node.private_key()
@@ -423,7 +423,7 @@ class U2fCredential(Credential):
self.node = seed.derive_node_without_passphrase(nodepath, "nist256p1")
# first half of keyhandle is keypath
- keypath = ustruct.pack("<8L", *path)
+ keypath = struct.pack("<8L", *path)
# second half of keyhandle is a hmac of rp_id_hash and keypath
mac = hmac(hmac.SHA256, self.node.private_key(), self.rp_id_hash)
@@ -472,7 +472,7 @@ class U2fCredential(Credential):
# unpack the keypath from the first half of keyhandle
keypath = keyhandle[:32]
- path = ustruct.unpack(pathformat, keypath)
+ path = struct.unpack(pathformat, keypath)
# check high bit for hardened keys
for i in path:
diff --git a/core/src/apps/webauthn/fido2.py b/core/src/apps/webauthn/fido2.py
index a579223e..fb2a82b4 100644
--- a/core/src/apps/webauthn/fido2.py
+++ b/core/src/apps/webauthn/fido2.py
@@ -1,5 +1,5 @@
+import struct
import uctypes
-import ustruct
import utime
from micropython import const
from typing import TYPE_CHECKING
@@ -1421,7 +1421,7 @@ def _msg_authenticate_sign(
# get next counter
ctr = cred.next_signature_counter()
- ctrbuf = ustruct.pack(">L", ctr)
+ ctrbuf = struct.pack(">L", ctr)
# sign the input data together with counter
sig = cred.sign((rp_id_hash, flags, ctrbuf, challenge))
@@ -1437,15 +1437,15 @@ def _msg_authenticate_sign(
def msg_error(cid: int, code: int) -> Cmd:
- return Cmd(cid, _CMD_MSG, ustruct.pack(">H", code))
+ return Cmd(cid, _CMD_MSG, struct.pack(">H", code))
def cmd_error(cid: int, code: int) -> Cmd:
- return Cmd(cid, _CMD_ERROR, ustruct.pack(">B", code))
+ return Cmd(cid, _CMD_ERROR, struct.pack(">B", code))
def cbor_error(cid: int, code: int) -> Cmd:
- return Cmd(cid, _CMD_CBOR, ustruct.pack(">B", code))
+ return Cmd(cid, _CMD_CBOR, struct.pack(">B", code))
def credentials_from_descriptor_list(
diff --git a/core/src/prof/__main__.py b/core/src/prof/__main__.py
index cc3240a3..4f64c570 100644
--- a/core/src/prof/__main__.py
+++ b/core/src/prof/__main__.py
@@ -1,10 +1,10 @@
import micropython
import sys
+from io import open
+from os import getenv
from typing import TYPE_CHECKING, Any, Callable, TypeAlias
import coveragedata
-from uio import open
-from uos import getenv
if TYPE_CHECKING:
from types import FrameType
diff --git a/core/src/trezor/crypto/base32.py b/core/src/trezor/crypto/base32.py
index 575a195b..ef4d5a36 100644
--- a/core/src/trezor/crypto/base32.py
+++ b/core/src/trezor/crypto/base32.py
@@ -14,7 +14,7 @@ _b32rev = {ord(v): k for k, v in enumerate(_b32alphabet)}
def encode(s: AnyBytes) -> str:
- from ustruct import unpack
+ from struct import unpack
s = bytes(s)
quanta, leftover = divmod(len(s), 5)
diff --git a/core/src/trezor/utils.py b/core/src/trezor/utils.py
index 3add64b3..f8810d02 100644
--- a/core/src/trezor/utils.py
+++ b/core/src/trezor/utils.py
@@ -89,10 +89,10 @@ if __debug__:
from trezorutils import estimate_unused_stack, zero_unused_stack # noqa: F401
if EMULATOR:
- import uos
+ import os
- DISABLE_ANIMATION = uos.getenv("TREZOR_DISABLE_ANIMATION") == "1"
- LOG_MEMORY = uos.getenv("TREZOR_LOG_MEMORY") == "1"
+ DISABLE_ANIMATION = os.getenv("TREZOR_DISABLE_ANIMATION") == "1"
+ LOG_MEMORY = os.getenv("TREZOR_LOG_MEMORY") == "1"
else:
from trezorutils import DISABLE_ANIMATION
diff --git a/core/src/trezor/wire/codec/codec_v1.py b/core/src/trezor/wire/codec/codec_v1.py
index 610b58ab..43e0fb67 100644
--- a/core/src/trezor/wire/codec/codec_v1.py
+++ b/core/src/trezor/wire/codec/codec_v1.py
@@ -1,4 +1,4 @@
-import ustruct
+import struct
from micropython import const
from typing import TYPE_CHECKING
@@ -33,7 +33,7 @@ async def read_message(
iface.read(report, 0)
if report[0] != _REP_MARKER:
raise CodecError("Invalid magic")
- _, magic1, magic2, mtype, msize = ustruct.unpack(_REP_INIT, report)
+ _, magic1, magic2, mtype, msize = struct.unpack(_REP_INIT, report)
if magic1 != _REP_MAGIC or magic2 != _REP_MAGIC:
raise CodecError("Invalid magic")
@@ -88,7 +88,7 @@ async def write_message(iface: WireInterface, mtype: int, mdata: AnyBytes) -> No
# prepare the report buffer with header data
report = bytearray(iface.TX_PACKET_LEN)
repofs = _REP_INIT_DATA
- ustruct.pack_into(
+ struct.pack_into(
_REP_INIT, report, 0, _REP_MARKER, _REP_MAGIC, _REP_MAGIC, mtype, msize
)
diff --git a/core/src/trezor/wire/thp/memory_manager.py b/core/src/trezor/wire/thp/memory_manager.py
index 6b5eba54..a8aa3d04 100644
--- a/core/src/trezor/wire/thp/memory_manager.py
+++ b/core/src/trezor/wire/thp/memory_manager.py
@@ -1,6 +1,6 @@
from micropython import const
+from struct import pack_into
from typing import TYPE_CHECKING
-from ustruct import pack_into
from trezor import protobuf, wire
from trezorthp import APP_HEADER_LEN, SEND_BUFFER_OVERHEAD
diff --git a/core/tests/test_trezor.wire.codec.codec_v1.py b/core/tests/test_trezor.wire.codec.codec_v1.py
index 08be3807..46c5e305 100644
--- a/core/tests/test_trezor.wire.codec.codec_v1.py
+++ b/core/tests/test_trezor.wire.codec.codec_v1.py
@@ -1,7 +1,7 @@
# flake8: noqa: F403,F405
from common import * # isort:skip
-import ustruct
+import struct
from mock_wire_interface import MockHID
from trezor import io
@@ -11,11 +11,11 @@ from trezor.wire.protocol_common import WireError
MESSAGE_TYPE = 0x4242
-HEADER_PAYLOAD_LENGTH = MockHID.RX_PACKET_LEN - 3 - ustruct.calcsize(">HL")
+HEADER_PAYLOAD_LENGTH = MockHID.RX_PACKET_LEN - 3 - struct.calcsize(">HL")
def make_header(mtype, length):
- return b"?##" + ustruct.pack(">HL", mtype, length)
+ return b"?##" + struct.pack(">HL", mtype, length)
class TestWireCodecV1(unittest.TestCase):
diff --git a/pyproject.toml b/pyproject.toml
index 702b9f0a..8886c9da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -91,7 +91,6 @@ profile = "black"
extra_standard_library = [
"buffer_types",
"micropython",
- "ustruct",
"uctypes",
"utime",
"timeq",
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.