Skip to content

fix(core): track the update of cardano#241

Merged
somebodyLi merged 1 commit intomainfrom
ada_fix
Feb 7, 2025
Merged

fix(core): track the update of cardano#241
somebodyLi merged 1 commit intomainfrom
ada_fix

Conversation

@somebodyLi
Copy link
Copy Markdown
Contributor

@somebodyLi somebodyLi commented Feb 7, 2025

Summary by CodeRabbit

• New Features
 - Enhanced Cardano protocol support with new certificate types for stake registration (Conway) and vote delegation, plus refined delegation representation.
 - Updated vote key registration aligned with current CIP standards and improved address validation.
 - Expanded CLI options for address retrieval, transaction signing, and public key display.

• Documentation
 - Clarified staking key derivation paths and auxiliary data guidance to better inform users.

@somebodyLi somebodyLi requested a review from a team as a code owner February 7, 2025 06:53
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 7, 2025

Walkthrough

This pull request makes comprehensive updates to the Cardano-related modules. Protocol definitions and message types have been extended with new enums and fields (for example, CardanoDRep and CVote registration values). The updates include renaming governance registration to CVote registration, adding certificate fields (deposit and drep), and refining address validation, signing, and helper utilities. Similar changes are applied to TRON and CLI modules with revised imports and parameter handling.

Changes

File(s) Change Summary
common/…/messages-cardano.proto, …/trezor/messages.py, python/…/trezorlib/messages.py Expanded Cardano protocol definitions: added enums (CardanoDRepType, CardanoDRep), updated CardanoCertificateType (new values: STAKE_REGISTRATION_CONWAY, STAKE_DEREGISTRATION_CONWAY, VOTE_DELEGATION), renamed governance registration to CVote, and added fields (deposit, drep).
…/trezor/enums/CardanoCertificateType.py, …/trezor/enums/CardanoDRepType.py, …/trezor/enums/CardanoTxAuxiliaryDataSupplementType.py, …/trezor/enums/init.py Extended and renamed enumerations with new certificate types and introduced CardanoDRepType; changed governance registration format to CVote registration.
core/src/all_modules.py Updated import statements: added CardanoCVoteRegistrationFormat and CardanoDRepType; removed obsolete governance enum.
…/apps/cardano/README.md, …/apps/cardano/addresses.py, …/apps/cardano/auxiliary_data.py, …/apps/cardano/byron_addresses.py, …/apps/cardano/certificates.py, …/apps/cardano/get_address.py, …/apps/cardano/get_native_script_hash.py, …/apps/cardano/get_public_key.py, …/apps/cardano/layout.py, …/apps/cardano/native_script.py, …/apps/cardano/seed.py Refactored core Cardano app modules: updated address validation, integrated CVote registration, revised key derivation paths and protocol magic handling, and updated message references.
…/apps/cardano/sign_tx/init.py, …/apps/cardano/sign_tx/multisig_signer.py, …/apps/cardano/sign_tx/ordinary_signer.py, …/apps/cardano/sign_tx/plutus_signer.py, …/apps/cardano/sign_tx/pool_owner_signer.py, …/apps/cardano/sign_tx/signer.py Overhauled sign transaction modules: consolidated error handling, updated message access, refactored processing routines, and switched from list- to set-based structures for inputs and required signers.
…/apps/cardano/helpers/account_path_check.py, …/apps/cardano/helpers/bech32.py, …/apps/cardano/helpers/credential.py, …/apps/cardano/helpers/hash_builder_collection.py, …/apps/cardano/helpers/paths.py, …/apps/cardano/helpers/protocol_magics.py, …/apps/cardano/helpers/utils.py Updated helper utilities: adjusted error imports, renamed HRP constants, removed/added functions for flexible path handling, and enhanced CBOR and credential management routines.
…/apps/common/cbor.py, …/apps/common/keychain.py, …/apps/common/paths.py Enhanced common utilities: refactored CBOR encoding (added create_tagged_set_header), adjusted keychain derivation with type ignores, and changed Bip32Path type to list[int] with new account path functions.
…/apps/tron/sign_message.py, …/apps/tron/sign_tx.py Simplified TRON modules: removed fallback for address_n and updated path validation to use the direct value.
python/src/trezorlib/cardano.py, python/src/trezorlib/cli/cardano.py Updated CLI and library functions: added options (chunkify, tag_cbor_sets, show_display), refined BIP-32 path format, and transitioned governance constants to CVote.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (17)
core/src/apps/cardano/seed.py (2)

87-87: Remove redundant comment.

The comment "this is true now" adds no value.


88-92: Simplify assert block.

Multiple equality checks can be combined.

-assert (
-    len(BYRON_ROOT) == len(SHELLEY_ROOT)
-    and len(MULTISIG_ROOT) == len(SHELLEY_ROOT)
-    and len(MINTING_ROOT) == len(SHELLEY_ROOT)
-)
+assert len(BYRON_ROOT) == len(SHELLEY_ROOT) == len(MULTISIG_ROOT) == len(MINTING_ROOT)
python/src/trezorlib/messages.py (4)

588-590: Inconsistent line spacing after enum values

Extra blank line after VOTE_DELEGATION = 9

    STAKE_REGISTRATION_CONWAY = 7
    STAKE_DEREGISTRATION_CONWAY = 8
    VOTE_DELEGATION = 9
-

3607-3608: Missing docstring for class CardanoTxAuxiliaryDataSupplement


3667-3667: Typo in field name cvote_registration_signature

Should be vote_registration_signature


3679-3679: Typo in field name cvote_registration_signature

Should be vote_registration_signature

core/src/apps/cardano/helpers/paths.py (1)

3-3: Remove unused import

Remove unharden or use it.

core/src/apps/cardano/sign_tx/multisig_signer.py (1)

19-20: Improve variable name clarity.

_assert_tx_init_cond is unclear. Rename to assert_transaction_condition.

core/src/apps/cardano/sign_tx/pool_owner_signer.py (2)

30-41: Add comments to validation conditions.

Each condition in the tuple needs explanation.


86-88: Split error message.

Message is too long. Split into two sentences.

-                "Stakepool registration transaction can only contain the pool owner witness request"
+                "Invalid witness request. Only pool owner witness is allowed in stakepool registration."
core/src/apps/common/cbor.py (1)

54-54: Rename ambiguous variable 'l'.

Variable name 'l' is hard to read.

-def _header(typ: int, l: int) -> bytes:
+def _header(typ: int, length: int) -> bytes:
🧰 Tools
🪛 Ruff (0.8.2)

54-54: Ambiguous variable name: l

(E741)

python/src/trezorlib/cli/cardano.py (1)

160-164: Simplify chain code handling.

Nested ternary is hard to read.

-            "chain_code": (
-                witness["chain_code"].hex()
-                if witness["chain_code"] is not None
-                else None
-            ),
+            "chain_code": witness["chain_code"].hex() if witness["chain_code"] else None,
core/src/apps/cardano/addresses.py (1)

264-279: Move comments to function level.

Inline comments about removed functions should be docstring comments.

-        # _validate_shelley_address
-
-        # _validate_size
         assert_cond(
             _MIN_ADDRESS_BYTES_LENGTH <= len(address_bytes) <= _MAX_ADDRESS_BYTES_LENGTH
         )
-
-        # _validate_bech32_hrp
         valid_hrp = _get_bech32_hrp(address_type, network_id)
-        # get_hrp
         bech32_hrp = address.rsplit(bech32.HRP_SEPARATOR, 1)[0]
         assert_cond(valid_hrp == bech32_hrp)
-
-        # _validate_network_id
core/src/apps/cardano/README.md (1)

94-97: Grammar. Inconsistent singular and plural forms.

core/src/apps/cardano/sign_tx/__init__.py (1)

20-20: Remove redundant import.

CardanoSignTxFinished already imported in TYPE_CHECKING block.

-    from trezor.messages import CardanoSignTxFinished
core/src/apps/cardano/helpers/utils.py (1)

57-57: Fix typo in comment.

"concatenable" is not a word. Use "concatenatable" instead.

core/src/apps/cardano/sign_tx/plutus_signer.py (1)

60-61: Move imports to top of file

Imports scattered across methods. Move them to the top.

Also applies to: 89-90, 98-100

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af762b1 and 3adcb2d.

📒 Files selected for processing (39)
  • common/protob/messages-cardano.proto (10 hunks)
  • core/src/all_modules.py (1 hunks)
  • core/src/apps/cardano/README.md (2 hunks)
  • core/src/apps/cardano/addresses.py (14 hunks)
  • core/src/apps/cardano/auxiliary_data.py (5 hunks)
  • core/src/apps/cardano/byron_addresses.py (3 hunks)
  • core/src/apps/cardano/certificates.py (9 hunks)
  • core/src/apps/cardano/get_address.py (1 hunks)
  • core/src/apps/cardano/get_native_script_hash.py (2 hunks)
  • core/src/apps/cardano/get_public_key.py (3 hunks)
  • core/src/apps/cardano/helpers/account_path_check.py (5 hunks)
  • core/src/apps/cardano/helpers/bech32.py (2 hunks)
  • core/src/apps/cardano/helpers/credential.py (7 hunks)
  • core/src/apps/cardano/helpers/hash_builder_collection.py (3 hunks)
  • core/src/apps/cardano/helpers/paths.py (2 hunks)
  • core/src/apps/cardano/helpers/protocol_magics.py (1 hunks)
  • core/src/apps/cardano/helpers/utils.py (5 hunks)
  • core/src/apps/cardano/layout.py (28 hunks)
  • core/src/apps/cardano/native_script.py (3 hunks)
  • core/src/apps/cardano/seed.py (5 hunks)
  • core/src/apps/cardano/sign_tx/__init__.py (2 hunks)
  • core/src/apps/cardano/sign_tx/multisig_signer.py (3 hunks)
  • core/src/apps/cardano/sign_tx/ordinary_signer.py (4 hunks)
  • core/src/apps/cardano/sign_tx/plutus_signer.py (4 hunks)
  • core/src/apps/cardano/sign_tx/pool_owner_signer.py (3 hunks)
  • core/src/apps/cardano/sign_tx/signer.py (49 hunks)
  • core/src/apps/common/cbor.py (6 hunks)
  • core/src/apps/common/keychain.py (1 hunks)
  • core/src/apps/common/paths.py (8 hunks)
  • core/src/apps/tron/sign_message.py (1 hunks)
  • core/src/apps/tron/sign_tx.py (1 hunks)
  • core/src/trezor/enums/CardanoCertificateType.py (1 hunks)
  • core/src/trezor/enums/CardanoDRepType.py (1 hunks)
  • core/src/trezor/enums/CardanoTxAuxiliaryDataSupplementType.py (1 hunks)
  • core/src/trezor/enums/__init__.py (2 hunks)
  • core/src/trezor/messages.py (9 hunks)
  • python/src/trezorlib/cardano.py (11 hunks)
  • python/src/trezorlib/cli/cardano.py (10 hunks)
  • python/src/trezorlib/messages.py (12 hunks)
✅ Files skipped from review due to trivial changes (3)
  • core/src/trezor/enums/CardanoTxAuxiliaryDataSupplementType.py
  • core/src/trezor/enums/CardanoDRepType.py
  • core/src/apps/cardano/helpers/protocol_magics.py
👮 Files not reviewed due to content moderation or server errors (4)
  • core/src/trezor/enums/CardanoCertificateType.py
  • core/src/apps/cardano/get_native_script_hash.py
  • core/src/apps/cardano/helpers/bech32.py
  • core/src/apps/cardano/sign_tx/ordinary_signer.py
🧰 Additional context used
🪛 Ruff (0.8.2)
core/src/apps/cardano/byron_addresses.py

71-71: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

core/src/apps/cardano/get_address.py

42-42: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

core/src/apps/cardano/native_script.py

43-48: Combine if branches using logical or operator

Combine if branches

(SIM114)


150-163: Combine if branches using logical or operator

Combine if branches

(SIM114)

core/src/apps/common/cbor.py

54-54: Ambiguous variable name: l

(E741)

core/src/apps/cardano/certificates.py

67-68: Use a single if statement instead of nested if statements

(SIM102)

core/src/apps/cardano/sign_tx/signer.py

336-337: Use a single if statement instead of nested if statements

(SIM102)


341-342: Use a single if statement instead of nested if statements

(SIM102)


350-351: Use a single if statement instead of nested if statements

(SIM102)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Gen check
  • GitHub Check: Defs check
  • GitHub Check: Style check
🔇 Additional comments (28)
core/src/apps/cardano/helpers/hash_builder_collection.py (2)

26-26: LGTM!


93-104: LGTM!

core/src/apps/cardano/helpers/credential.py (1)

56-57: LGTM!

Good use of local caching to improve performance.

Also applies to: 103-105, 180-181, 223-226

core/src/apps/common/keychain.py (1)

153-154: LGTM!

Type ignore comments are appropriate here.

Also applies to: 163-163

core/src/apps/common/cbor.py (1)

8-11: LGTM!

Clean imports and good addition of tagged set support.

Also applies to: 48-51, 308-310

core/src/all_modules.py (1)

1026-1027: LGTM!

The new Cardano enums are correctly added.

Also applies to: 1030-1031

core/src/trezor/messages.py (1)

27-29: LGTM!

The Cardano protocol updates for CVote registration and DRep support are well-structured and consistent.

Also applies to: 2124-2141, 2149-2150, 2190-2204, 2206-2232, 2235-2241, 2321-2328

common/protob/messages-cardano.proto (9)

59-62: LGTM.


64-69: LGTM.


77-80: LGTM.


82-86: LGTM.


349-358: LGTM.


369-372: LGTM.


533-539: LGTM.


412-415: LGTM.


478-482: LGTM.

core/src/apps/cardano/README.md (1)

292-297: LGTM.

core/src/apps/cardano/auxiliary_data.py (1)

1-332: No issues found

core/src/apps/cardano/certificates.py (1)

1-400: No issues found

🧰 Tools
🪛 Ruff (0.8.2)

67-68: Use a single if statement instead of nested if statements

(SIM102)

core/src/apps/cardano/layout.py (1)

1-1068: No issues found

core/src/apps/common/paths.py (5)

364-374: LGTM!


377-388: LGTM!


391-392: LGTM!


395-401: LGTM!


421-435: LGTM!

core/src/trezor/enums/__init__.py (3)

555-563: LGTM!


564-568: LGTM!


579-582: LGTM!

@somebodyLi somebodyLi enabled auto-merge (squash) February 7, 2025 07:45
@somebodyLi somebodyLi merged commit 591f96f into main Feb 7, 2025
6 checks passed
@somebodyLi somebodyLi deleted the ada_fix branch February 7, 2025 07:53
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.

3 participants