chore(core): move `keccak_32` to unittests
What changed, and why it matters
This commit is a routine code cleanup. It removes a small helper function called keccak_32 from a shared crypto utility file and places an equivalent helper directly inside the only test file that still uses it. There is no change to how the device handles user data, no bug fix, and no security-related behavior change.
No security action needed. Treat as normal maintenance/refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch deletes keccak_32 from core/src/trezor/crypto/base58.py and adds a local replacement in core/tests/test_apps.ethereum.yielding.py that uses apps.ethereum.helpers.keccak256().get_digest()[:4]. The replacement produces the same 4-byte Keccak digest as the old implementation. The function was only used by this test, so the change is purely a refactor to avoid keeping dead code in a generic module.
Changed components
core/src/trezor/crypto/base58.pycore/tests/test_apps.ethereum.yielding.pyInspect captured patch +8 / −12
### core/src/trezor/crypto/base58.py
@@ -78,12 +78,6 @@ def blake256d_32(data: AnyBytes) -> bytes:
return blake256(blake256(data).digest()).digest()[:4]
-def keccak_32(data: AnyBytes) -> bytes:
- from .hashlib import sha3_256
-
- return sha3_256(data, keccak=True).digest()[:4]
-
-
def ripemd160_32(data: AnyBytes) -> bytes:
from .hashlib import ripemd160
### core/tests/test_apps.ethereum.yielding.py
@@ -2,9 +2,11 @@
from common import * # isort:skip
if not utils.BITCOIN_ONLY:
- from trezor.crypto import base58
-
from apps.ethereum import yielding
+ from apps.ethereum.helpers import keccak256
+
+ def keccak_32(data: bytes) -> bytes:
+ return keccak256(data).get_digest()[:4]
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
@@ -15,19 +17,19 @@ def test_known_func_sigs(self):
# the wrong contract method.
self.assertEqual(
yielding.FUNC_SIG_DEPOSIT,
- base58.keccak_32(b"deposit(uint256,address)"),
+ keccak_32(b"deposit(uint256,address)"),
)
self.assertEqual(
yielding.FUNC_SIG_WITHDRAW,
- base58.keccak_32(b"withdraw(uint256,address,address)"),
+ keccak_32(b"withdraw(uint256,address,address)"),
)
self.assertEqual(
yielding.FUNC_SIG_REDEEM,
- base58.keccak_32(b"redeem(uint256,address,address)"),
+ keccak_32(b"redeem(uint256,address,address)"),
)
self.assertEqual(
yielding.FUNC_SIG_CLAIM,
- base58.keccak_32(b"claim(address[],address[],uint256[],bytes32[][])"),
+ keccak_32(b"claim(address[],address[],uint256[],bytes32[][])"),
)
def test_known_address(self):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.