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

feat(cardano): conway staking certificates #86

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jaskp
Copy link
Collaborator

@jaskp jaskp commented Nov 6, 2023

Update with select Cardano Conway features:

  • Transactions with new stake registration and deregistration certificates and a DRep vote delegation certificate (does not include any new key derivations nor voting procedures)
  • Explicit tagging of CBOR arrays as sets with tag 258
  • Increase of URL length limit from 64 to 128 bytes

https://github.com/IntersectMBO/cardano-ledger/blob/master/eras/conway/impl/cddl-files/conway.cddl
https://github.com/cardano-foundation/CIPs/tree/master/CIP-0005
https://github.com/cardano-foundation/CIPs/tree/master/CIP-1694
https://sancho.network/tools-resources/faq/#4-certificate-and-transaction-field-witnesses-and-deposits

@jaskp jaskp added the WIP Work In Progress label Nov 6, 2023
@jaskp jaskp requested a review from davidmisiak November 6, 2023 14:59
@jaskp jaskp self-assigned this Nov 6, 2023
@jaskp jaskp changed the title feat(cardano): conway staking reg certificate feat(cardano): conway certificates Nov 6, 2023
@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch from 2f2adc9 to bfad4c7 Compare November 7, 2023 13:43
@jaskp jaskp changed the title feat(cardano): conway certificates feat(cardano): conway staking certificates Nov 8, 2023
@jaskp jaskp marked this pull request as ready for review November 8, 2023 21:05
Copy link
Collaborator

@davidmisiak davidmisiak left a comment

Choose a reason for hiding this comment

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

Apart from the comments, LGTM!

common/protob/messages-cardano.proto Show resolved Hide resolved
common/protob/messages-cardano.proto Outdated Show resolved Hide resolved
core/src/apps/cardano/certificates.py Outdated Show resolved Hide resolved
core/src/apps/cardano/layout.py Outdated Show resolved Hide resolved
core/src/apps/cardano/layout.py Outdated Show resolved Hide resolved
common/tests/fixtures/cardano/sign_tx.json Show resolved Hide resolved
python/src/trezorlib/cardano.py Show resolved Hide resolved
@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch 2 times, most recently from cfa8c24 to c20cefc Compare November 10, 2023 17:22
@jaskp jaskp removed the WIP Work In Progress label Nov 10, 2023
@jaskp
Copy link
Collaborator Author

jaskp commented Nov 10, 2023

Handled comments except for the naming which I believe hasn't been decided on yet

@jaskp jaskp requested a review from davidmisiak November 10, 2023 17:23
Copy link
Collaborator

@davidmisiak davidmisiak left a comment

Choose a reason for hiding this comment

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

For now LGTM! Let's add the third certificate.

@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch 2 times, most recently from 98ed741 to e6c17c4 Compare November 20, 2023 17:22
@jaskp jaskp requested a review from davidmisiak November 20, 2023 17:26
core/src/apps/cardano/certificates.py Outdated Show resolved Hide resolved
core/src/apps/cardano/certificates.py Outdated Show resolved Hide resolved
common/protob/messages-cardano.proto Outdated Show resolved Hide resolved
python/src/trezorlib/cardano.py Outdated Show resolved Hide resolved
core/src/apps/cardano/certificates.py Outdated Show resolved Hide resolved
core/src/apps/cardano/certificates.py Outdated Show resolved Hide resolved
core/src/apps/cardano/layout.py Outdated Show resolved Hide resolved
@jaskp jaskp requested a review from davidmisiak November 23, 2023 23:59
Comment on lines 742 to 801
def _format_drep(drep: messages.CardanoDRep) -> tuple[str, str]:
if drep.type == CardanoDRepType.KEY_HASH:
assert drep.key_hash is not None # validate_drep
return (
"Delegating to key hash:",
bech32.encode(bech32.HRP_KEY_HASH, drep.key_hash),
)
elif drep.type == CardanoDRepType.SCRIPT_HASH:
assert drep.script_hash is not None # validate_drep
return (
"Delegating to script:",
bech32.encode(bech32.HRP_SCRIPT_HASH, drep.script_hash),
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@janmazak just to make sure - the drep key hash / script hash should be displayed with the usual addr_vkh and script bech32 prefixes, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The source code of this demo app suggests the prefix should be drep

            const dRepIDBech32 = dRepID.to_bech32('drep');

But I wasn't able to find anything about it elsewhere

Copy link

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

https://github.com/cardano-foundation/CIPs/blob/master/CIP-0005/README.md?plain=1#L118

@Ryun1 thanks, that explains key-hash drep IDs, is it also specified somewhere whether a script-hash drep ID should also have this prefix, or should it just be "script"?

Copy link
Collaborator

@davidmisiak davidmisiak left a comment

Choose a reason for hiding this comment

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

LGTM, I will do one final pass when we finalize the remaining features :)

@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch from a6ac340 to 8e84fc5 Compare December 8, 2023 15:53
@jaskp jaskp requested a review from davidmisiak December 11, 2023 11:54
Copy link
Collaborator

@davidmisiak davidmisiak left a comment

Choose a reason for hiding this comment

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

Apart from the comments, LGTM.

Please also run make pystyle.

common/protob/messages-cardano.proto Outdated Show resolved Hide resolved
tests/device_tests/cardano/test_sign_tx.py Outdated Show resolved Hide resolved
core/src/apps/common/cbor.py Outdated Show resolved Hide resolved
core/src/apps/common/cbor.py Outdated Show resolved Hide resolved
core/src/apps/cardano/sign_tx/signer.py Outdated Show resolved Hide resolved
core/src/apps/cardano/sign_tx/signer.py Outdated Show resolved Hide resolved
common/tests/fixtures/cardano/sign_tx.json Outdated Show resolved Hide resolved
certificate.key_hash,
ProcessError("Invalid certificate"),
)

account_path_checker.add_certificate(certificate)


def _validate_structure(certificate: messages.CardanoTxCertificate) -> None:
pool = certificate.pool # local_cache_attribute
pool_parameters = certificate.pool_parameters # local_cache_attribute
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand these comments --- should the newly added items get some comments too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand them either. I gather they're used for some metaprogramming to reduce code size but I'm not sure when to use them. But it's a trivial fix so I expect to find out in a review from trezor


# See https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml
_CBOR_RAW_TAG = const(0x18) # Tag 24
_CBOR_SET_TAG = const(0x102) # Tag 258
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about tag 30? It is used in pool registration for unit_interval, so I'd perhaps expect it to appear in this list too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For whatever reason, all the cbor constants are private in this file. But yeah tag 30 is used in pool registration. Tag 24 is also used somewhere but, again, hardcoded instead of using the constant that already exists here

@janmazak
Copy link
Collaborator

What about increased max URL / DNS name length? Not included in this PR yet?

@jaskp jaskp requested review from janmazak and davidmisiak January 13, 2024 22:58
@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch from fdbfa20 to 8cd00fd Compare January 14, 2024 22:00
Copy link

github-actions bot commented Jan 14, 2024

legacy UI changes device test(screens) main(screens)

Copy link

github-actions bot commented Jan 14, 2024

core UI changes device test click test persistence test
T2T1 Model T test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
T2B1 Safe 3 3280 test(screens) main(screens) 2724
T3T1 test(screens) main(screens) test(screens) main(screens) test(screens) main(screens)
All main(screens)

@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch from 8cd00fd to 6a8b99c Compare January 14, 2024 22:03
@jaskp
Copy link
Collaborator Author

jaskp commented Jan 14, 2024

What about increased max URL / DNS name length? Not included in this PR yet?

Right, length update added to this pr

@jaskp jaskp force-pushed the feat/cardano/conway/stake-certs branch 2 times, most recently from 9846b99 to d8922c3 Compare January 18, 2024 16:50
@davidmisiak davidmisiak force-pushed the feat/cardano/conway/stake-certs branch from d8922c3 to 7cd8dad Compare May 16, 2024 22:08
@davidmisiak davidmisiak force-pushed the feat/cardano/conway/stake-certs branch from 9ca2c8d to ad9b6e7 Compare May 22, 2024 14:58
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.

4 participants