test(core): test RLP self-encoding bytestrings
What changed, and why it matters
This commit only adds a new unit test to the Trezor firmware codebase. It verifies that very short Ethereum RLP-encoded byte strings and small positive integers encode to themselves, which is a known property of the RLP specification. No production code was changed, and there is no security fix or vulnerability present in the diff.
No security action needed. Treat as routine test coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds test_rlp_same_encoding to core/tests/test_trezor.crypto.rlp.py. The test loops over byte values 0-127, confirms that single-byte bytestrings are self-encoding under rlp.write(), and confirms that small positive integers (1-127) encode to the same byte representation. This is purely an exhaustive regression test for correct RLP behavior per the Ethereum RLP spec; it does not modify the RLP implementation or any firmware logic.
Changed components
core/tests/test_trezor.crypto.rlp.pyInspect captured patch +16 / −0
### core/tests/test_trezor.crypto.rlp.py
@@ -138,6 +138,22 @@ def test_rlp_length(self):
length = rlp.length(i)
self.assertEqual(length, len(o) // 2)
+ def test_rlp_same_encoding(self):
+ for i in range(0, 128):
+ o = bytes([i])
+
+ # some short bytestrings are their own encoding
+ w = bytearray()
+ rlp.write(w, o)
+ self.assertEqual(w, o)
+
+ # small positive integers are their own encoding
+ if i == 0:
+ continue # already tested (see above)
+ w = bytearray()
+ rlp.write(w, i)
+ self.assertEqual(w, o)
+
if __name__ == "__main__":
unittest.main()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.