-
-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(core/ethereum): improve API of the rlp module #1704
Conversation
fb126d5
to
c126cc0
Compare
core/src/trezor/crypto/rlp.py
Outdated
if x < 0: | ||
raise ValueError # only unsigned ints are supported | ||
for exp in range(64): | ||
if x < 0xFF ** exp: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird. Maybe you meant:
if x < 0xFF ** exp: | |
if x < 0x100 ** exp: |
Also this function returns 0 for x=0. Not sure if that is the intention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this function returns 0 for x=0. Not sure if that is the intention.
This is intentional, yes
But good point about the equality test. I'll need to add an edge value to the testcases first as it's apparently not covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question, otherwise looks better and more efficient than the original version.
core/src/trezor/crypto/rlp.py
Outdated
from typing import Union | ||
from trezor.utils import Writer | ||
|
||
RLPItem = Union["RLPItem", bytes, int] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the recursion do here?
Also, should there be bytearray since it's checked against in the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I meant to run this though mypy and forgot. Good catch, this is supposed to be something like Union[list["RLPItem"], bytes, int]
(also I suspect that mypy won't actually allow a recursive type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4a009c8
to
57e8f6c
Compare
the test vectors in
test_trezor.crypto.rlp.py
, and the Ethereum device tests, show that the new implementation produces results identical to the old one