Skip to content
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

Cardano shelley update 1/3 #1096

Merged

Conversation

gabrielKerekes
Copy link
Contributor

@gabrielKerekes gabrielKerekes commented Jul 6, 2020

Cardano Shelley update issue: #948

As promised (#1048) we are splitting the Cardano Shelley update into (at least) 3 PRs. This is the first of them.

This PR contains minimal changes with which Trezor can work on the new Shelley fork. It enables sending funds from one Byron address to another. New addresses are not yet added. Neither are certificates and withdrawals.

What's changed:

  • Previous transactions (input sources) no longer need to be requested/received since Fee is included directly in the transaction.
  • TTL parameter has been added to transaction - this is the slot number until which the transaction can be submited.
  • Transaction format has changed a bit.
  • The biggest changes are in the sign_tx.py file. The logic around fee calculation has been removed and it has also been refactored quite a lot - e.g. Transaction class has been removed since it now mostly contained only functions anyways.
  • Support for CBOR NULL had to be added to support empty transaction metadata.
  • Protocol magic is included in Byron addresses on testnets - this has always been a part of the spec, but it hasn't been needed so far. We now also verify that outputs are from the network which the protocol magic represents.

What can still change in the following days (regarding this PR):

  • We still don't have specs/information about witnesses for Byron inputs from IOHK. This will probably require changes to the way the witnesses are built for Byron inputs. There's also a todo there. This has already been added.
  • Protocol magic in Byron addresses on Testnets - this functionality is drafted, but also needs to be confirmed by IOHK. This has already been added.
  • Maybe some other minor changes.

Here's a gist with a sample transaction input file for trezorctl (although tests also provide some samples).
Here's a gist with a description of the Shelley transaction format (including certificates and withdrawals).
Here's the official CDDL spec for Shelley.

This hasn't been tested on the latest testnet yet, since Byron addresses are not yet fully supported. Support should be added in the following days. When this happens, we will test it and let you know of the status (Some changes may still need to be made regarding this).

@prusnak
Copy link
Member

prusnak commented Jul 13, 2020

For the record: IOHK wants to do a hard-fork on the 29th of July.

@MichalPetro
Copy link

@matejcik @tsusanka guys are you going to review this? 2 more PRs will be coming in the following week as we divided the functionalities in 3 PRs.

@prusnak prusnak added this to the 2020-08 milestone Jul 13, 2020
@tsusanka
Copy link
Contributor

tsusanka commented Jul 13, 2020

@MichalPetro we will look into this ASAP, tomorrow most likely.


Regarding the PR schedule: we would like to "freeze" (branch of code into a separate branch and forward firmwares to QA) the upcoming release on July 24th. That gives us 10 working days to include the necessary changes.

Although I believe this was mentioned somewhere please confirm that to support sending funds we need to include this PR and one more you are about to open. Please open this PR asap so we can review it and include it till July 24th. Apologies for the sudden rush, I haven't realized the hard-fork date is so close.

As to the third PR (which will introduce staking support, correct?) we need to discuss this internally in the Product team whether we want such change in firmware. In another words, it depends on the number of needed changes. We usually support only a subset of functionalities because it is not sustainable to have advanced functionalities for each and every altcoin. I am basically trying to manage expectations here - while we definitely want to include PR 1 and 2 I can not guarantee the same for PR number 3. Feel free to file a draft PR again to decide this before you fine-tune it.

@MichalPetro
Copy link

@tsusanka we will add the 2nd PR today or tomorrow. Also, we probably need to do the small fix in the 1st (this) PR because some specs changed, we are currently assessing the impact.

The 3rd PR will be smaller than the others. We will be not introducing staking for stake pools, just staking delegation to the stake pools.

@tsusanka
Copy link
Contributor

Great, thank you.

The 3rd PR will be smaller than the others. We will be not introducing staking for stake pools, just staking delegation to the stake pools.

Ok ok. But it is something we might include in the next release if things go south, correct? It is not that essential as the other two.

@MichalPetro
Copy link

Yes definitely the first 2 PRs are critical. Lets make sure those are included. Lets see what we can do about the 3rd.

@gabrielKerekes
Copy link
Contributor Author

I've updated the code with:

  • correct mainnet protocol magic
  • correct transaction witnesses
  • correct way of including protocol magic in Byron on addresses on Testnet
  • some type hinting

Hopefully nothing else will change. I've kept the fixup commits (which is failing the checks), so it's easy to see what changed. I can rebase them or squash them or whatever if you wish.

Copy link
Contributor

@matejcik matejcik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does your core code typecheck? if yes, please add src/apps/cardano to core/Makefile mypy target

core/src/apps/cardano/protocol_magics.py Outdated Show resolved Hide resolved
@matejcik
Copy link
Contributor

I've kept the fixup commits (which is failing the checks), so it's easy to see what changed. I can rebase them or squash them or whatever if you wish.

Thanks.
Our review flow is as follows:

  • once you request reviews, only add fixup commits (you are doing that already, so 👍)
  • respond to individual review comments that this is done, ideally with a link to commit
  • the reviewer marks comments resolved
  • when you get all approvals, autosquash the fixup commits and force-push

@matejcik
Copy link
Contributor

please regenerate UI test fixtures, by running the test suite with --ui=record

common/protob/messages-cardano.proto Show resolved Hide resolved
core/src/apps/cardano/address.py Outdated Show resolved Hide resolved
core/src/apps/cardano/address.py Outdated Show resolved Hide resolved
core/src/apps/cardano/address.py Show resolved Hide resolved
core/src/apps/cardano/sign_tx.py Outdated Show resolved Hide resolved
core/src/apps/cardano/sign_tx.py Outdated Show resolved Hide resolved
core/src/apps/cardano/sign_tx.py Outdated Show resolved Hide resolved
@tsusanka
Copy link
Contributor

please regenerate UI test fixtures, by running the test suite with --ui=record

Or simply use pipenv run make -C core test_emu_ui_record, see https://docs.trezor.io/trezor-firmware/tests/ui-tests.html#updating-fixtures-recording.

@gabrielKerekes
Copy link
Contributor Author

I've updated the code with the suggestions. I've also updated the fixtures json here.

@gabrielKerekes
Copy link
Contributor Author

I had to update transaction signing due to Byron witnesses spec update. My commit. I am however unable to test this at the moment since they also have to release their version of cardano-node.

I suggest we get the code in order and I will test everything once more when it's ready. I expect this to be on monday.

@tsusanka tsusanka linked an issue Jul 16, 2020 that may be closed by this pull request
@matejcik
Copy link
Contributor

ah, I think I said this wrong

  • once you request reviews, only add fixup commits (you are doing that already, so +1)

You can add new commits. The "only fixup" thing is intended as "no rebasing", so modifications to existing commits should be fixups. But if the changes don't cleanly match some existing commits, a new commit is a better variant.
(you can also fully revert commits via git revert, but then you need to make sure during autosquash that the commit/revert pairs are removed)

@gabrielKerekes
Copy link
Contributor Author

Yes, that makes sense. I wasn't sure how to go about that so I kept on "fixing-up". I'll know better next time.

@matejcik
Copy link
Contributor

yeah, sorry about that 🙄

Copy link
Contributor

@matejcik matejcik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now.

what is the status of the second PR?
it should be based on top of this one, obviously. We will do something like merge this into a separate branch, and you'll be able to send a PR against that branch.

@gabrielKerekes
Copy link
Contributor Author

The second PR needs to be rebased onto this one - I've partially done this already, but I'll probably have to do it again. Then I'll clean it up, test it (also against the testnet) and it should be ready for review - hopefully until tomorrow afternoon.

And yes, we can probably do something like that. Should I squash and force push the fixups?

@matejcik
Copy link
Contributor

And yes, we can probably do something like that. Should I squash and force push the fixups?

not yet, please wait for approval from @tsusanka

Copy link
Contributor

@tsusanka tsusanka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one nit-pick!

* @next Failure
*/
message CardanoSignTx {
repeated CardanoTxInputType inputs = 1; // inputs to be used in transaction
repeated CardanoTxOutputType outputs = 2; // outputs to be used in transaction
optional uint32 transactions_count = 3; // transactions count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this commented out, so we know we should not use 3 anymore.

@tsusanka
Copy link
Contributor

tsusanka commented Jul 17, 2020

Thanks, great job! Please squash the commits now and force push. Then change this PR to be against the cardano-shelley branch I've just created.

@gabrielKerekes
Copy link
Contributor Author

Awesome! Should I squash all the comits into one, or just the fixups?

@matejcik
Copy link
Contributor

up to you honestly. ISTM that via the fixup confusion the original commits don't make sense separately anyway, so feel free to squash everything together.
alternately you can rename some commits and keep some semblance of history

Update protobuf

- Previous transactions don't need to be sent anymore, because fee is
  included in the transaction now. Thus transactions_count can be
  removed from CardanoSignTx message and the CardanoTxAck and
  CardanoTxRequest messages can be removed altogether.
- CardanoTxInputType.type is unused so remove it

Add NULL (None type) serialisation to CBOR

- Transaction metada must either have a valid structure or CBOR NULL
  must be used (if metadata is empty) - it can't be simply left out.

Add protocol_magics file

- Just to have a nicer way of representing protocol magics

Update transaction signing

- Previous transactions no longer need to be requested
- Output building is simplified, since fee doesn't need to be calculated
- Remove transaction class since it is no longer needed (only functions
  remained)
- Reorder functions so it reads top to bottom

Add protocol magic to byron address on testnet

- This has always been a part of the spec, but it hasn't been
  implemented before, because it wasn't really needed.

Update trezorlib

Update tests

- Transaction messages are no longer required
- Expected values are different since tx format changed
- Common values in test cases have been extracted

Remove unused file

- Progress was used when receiving previous transactions

Add CRC check to output address validation
@gabrielKerekes gabrielKerekes force-pushed the cardano-shelley-update-pr1 branch from ea4a4b3 to 12ecbb5 Compare July 17, 2020 09:30
@gabrielKerekes gabrielKerekes changed the base branch from master to cardano-shelley July 17, 2020 09:30
@matejcik matejcik merged commit 49a017a into trezor:cardano-shelley Jul 17, 2020
@gabrielKerekes
Copy link
Contributor Author

I've opened the second PR -> #1112

@gabrielKerekes gabrielKerekes deleted the cardano-shelley-update-pr1 branch July 2, 2021 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Cardano Shelley support
5 participants