-
-
Notifications
You must be signed in to change notification settings - Fork 206
Conversation
Please fix the failure in https://travis-ci.org/trezor/trezor-core/jobs/408917280#L852-L854 |
@prusnak fixed |
@Adman could you add python-trezor support and some device tests along the way please? We have two types of tests:
Have a look on the Cardano's or Ripple's PR for example for some inspiration. |
@tsusanka ok, I'll add python-trezor support and make a PR. |
@tsusanka Can you give me a hint how to run device_tests in python-trezor? unit_tests work properly. |
Run emulator first via PYOPT=0 ./emu.sh
Then in another window run "pytest" in device_tests directory.
|
@tsusanka @prusnak Here's the python-trezor implementation: trezor/python-trezor#302 |
Awesome! We are currently in the process of finalizing our next release. When that's done we'll review your PR completely. Thanks |
@Adman What do you think about supporting just one curve instead of all three? Supporting all three brings unnecessary complexity. We can add the other later but I believe in the first version of Tezos support we should use just one. You can choose (maybe do a bit of research what is used the most?) but I suggest secp256k or ed25519. What do you think? |
As per agreement on Gitter, we'll support only Ed25519 curve = tz1. Relevant commit to trezor-common: trezor/trezor-common@b6f59d3 Please update this PR (and PR to python-trezor) to use only tz1/Ed25519 curve. Thank you! |
@Adman please do a rebase (let me know if you need help), the tests should be passing then |
@tsusanka rebased, but master is failing because of cardano's get_public_key and address tests https://travis-ci.org/trezor/trezor-core/jobs/425716279#L1550 |
You did not rebase the commits - you did merge. Rebase is being done with Be careful, this can be quite dangerous, but if there are no conflicts, it should be pretty straightforward. |
@prusnak There were some conflicts, but I hope everything's fine now. |
Now that python-trezor is merged, please do a rebase and set |
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
@tsusanka Ok, I rebased and set |
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.
Thanks for you PR, consider this as a preliminary review, it's mostly nit-picks. I've requested some changes and have a general question:
Do you plan to use the GetPublicKey functions in particular on your front-end side? Or did you implement them just to fit the others? Since ed25519 does not support non-hardened derivation, therefore no xpub functionality, I am not sure what the use case is. If we don't have any in mind, let's remove it.
src/apps/tezos/get_address.py
Outdated
node = await seed.derive_node(ctx, address_n, TEZOS_CURVE) | ||
|
||
sk = node.private_key() | ||
pk = ed25519.publickey(sk) |
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.
Let's replace these two lines with:
pk = seed.remove_ed25519_prefix(node.public_key())
so it's consistent with stellar and others.
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.
you mean seed.remove_ed25519_prefix(node.private_key())
, right?
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, no, you are right, sorry
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.
No, private_key
does not have a prefix. node.public_key()
is computed so you can use it.
src/apps/tezos/get_address.py
Outdated
sk = node.private_key() | ||
pk = ed25519.publickey(sk) | ||
pkh = hashlib.blake2b(pk, outlen=20).digest() | ||
address = b58cencode(pkh, prefix=tezos_get_address_prefix(0)) |
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.
The zero in tezos_get_address_prefix(0)
looks kind of magic. Maybe let's simplify this to b58cencode(pkh, prefix="tz1")
or maybe better b58cencode(pkh, prefix=TEZOS_ED25519_PREFIX)
?
Also why is the function called b58cencode
and not b58encode
?
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.
it's called b58cencode
because it is "check_encode" (not pure "encode")
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.
Will call the prefix TEZOS_ED25519_ADDRESS_PREFIX
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.
Let's not be afraid of long names and use base58_encode_check
src/apps/tezos/get_public_key.py
Outdated
node = await seed.derive_node(ctx, address_n, TEZOS_CURVE) | ||
|
||
sk = node.private_key() | ||
pk = ed25519.publickey(sk) |
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.
As above
|
||
|
||
def split_address(address): | ||
return chunks(address, 18) |
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.
Let's use common.layout.split_address. It has size=17, but that doesn't matter that much or will be refactored together later
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.
If I use 17, the address in transaction won't fit on display.
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.
Ok, keep it.
src/apps/tezos/sign_tx.py
Outdated
|
||
def _encode_common(operation, str_operation): | ||
operation_tags = {"reveal": 7, "transaction": 8, "origination": 9, "delegation": 10} | ||
result = ustruct.pack("<b", operation_tags[str_operation]) |
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.
All those ustruct.pack
are supposed to convert unsigned ints to bytes, aren't they? And the ints will be always from 0 to 255? I believe it should be <B
, but one way or another let's refactor this to use app.common.writers
. If you indeed want to serialize uint8 you can use write_uint8
.
src/apps/tezos/sign_tx.py
Outdated
|
||
|
||
def _encode_contract_id(contract_id): | ||
return ustruct.pack("<b", contract_id.tag) + contract_id.hash |
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.
For example this:
def _encode_contract_id(w: bytearray, contract_id):
write_uint8(w, contract_id.tag)
write_bytes(w, contract_id.hash)
src/apps/tezos/sign_tx.py
Outdated
|
||
opbytes = _get_operation_bytes(msg) | ||
|
||
watermark = bytes([3]) |
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.
Could you maybe put a small comment why '3'?
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.
https://groups.google.com/forum/#!msg/tezos-developer-community/bD7DFkLT8QE/X4dNDp0ABgAJ
I will add a small comment to code
src/apps/tezos/sign_tx.py
Outdated
else: | ||
raise wire.DataError("Invalid operation") | ||
|
||
opbytes = _get_operation_bytes(msg) |
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.
Have a look on Stellar, we usually declare a bytearray, which we then pass as an argument. I'm providing an example in one of the following comments.
@tsusanka Requested changes applied. It would be cool if the common GetPublicKey - @jurajselep will post a comment about it here. |
When we inject transaction, origination or delegation into Tezos node for first time, we need to "reveal" public_key. We are using GetPublicKey on front-end side for operation preapply and forge . http://tezos.gitlab.io/betanet/api/rpc.html?highlight=reveal#post-block-id-helpers-forge-operations
|
src/apps/tezos/get_address.py
Outdated
pkh = hashlib.blake2b(pk, outlen=20).digest() | ||
address = b58cencode(pkh, prefix=tezos_get_address_prefix(0)) | ||
address = b58cencode(pkh, prefix=TEZOS_ED25519_ADDRESS_PREFIX) |
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.
Nice. Now we can use this also in sign_tx._get_address_by_tag
and remove tezos_get_address_prefix completely.
@jurajselep thanks for the explanation, that's fine by me. @Adman please note, that the tests are failing currently becuase of style |
@tsusanka Tests should be passing, but travis build failed with message |
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
@tsusanka Ok, I restarted the build and it is passing. If you have further comments on this PR I will fix them. |
Great. Looks good to me. I'd like @jpochyla to have a final look later, but this is on a good way to be merged. Please be patient, he's busy with other things. @jpochyla the only thing where I'm not sure is whether tACK dc6e405 |
(grr, the closing was of course unintentional) |
Maybe one more thing. Could you add a brief README? Have a look on Ripple and feel free to omit the maintainer/reviewer fields. It doesn't have to be verbose, but some links to documentation/explorer etc. would be nice. |
@tsusanka Readme added. |
Signed-off-by: Adrian Matejov <adrian.matejov@simplestaking.com>
Thank you! |
Thanks all for the collaboration! |
Updated fields of messages trezor/trezor-common#170