Skip to content

feat(core/sol): add unsafe message signing support for solana#247

Merged
somebodyLi merged 1 commit intomainfrom
sol_message
Feb 12, 2025
Merged

feat(core/sol): add unsafe message signing support for solana#247
somebodyLi merged 1 commit intomainfrom
sol_message

Conversation

@somebodyLi
Copy link
Copy Markdown
Contributor

@somebodyLi somebodyLi commented Feb 12, 2025

Summary by CodeRabbit

  • New Features

    • Introduced separate handling for off-chain Solana messages, offering improved clarity in message signing.
    • Added an option to sign unsafe (arbitrary) messages with explicit user confirmation.
    • Updated the command-line interface with an unsafe signing flag for advanced users.
  • Documentation

    • Enhanced user prompts and warnings, featuring clear and localized security messages about the risks of raw signing.

@somebodyLi somebodyLi requested a review from a team as a code owner February 12, 2025 02:23
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request revises Solana message handling across the codebase. Enums, message types, and methods have been renamed to emphasize off-chain and unsafe signing. Protocol buffer definitions, CLI commands, and UI elements now use updated naming conventions and new parameters. Localization strings have been extended to include raw signing warnings. Changes affect core modules, Trezor enumerations, message definitions, and translations.

Changes

File(s) Change Summary
common/protob/messages-solana.proto
common/protob/messages.proto
Renamed Solana enums and messages to off-chain variants; replaced on-chain types with off-chain; added SolanaSignUnsafeMessage; updated wire attributes.
core/src/all_modules.py
core/src/apps/solana/sign_offchain_message.py
core/src/apps/solana/sign_unsafe_message.py
core/src/apps/workflow_handlers.py
Updated Solana signing methods and enums; renamed sign_message to sign_offchain_message; added sign_unsafe_message; adjusted message type mapping in workflow handler.
core/src/trezor/enums/MessageType.py
core/src/trezor/enums/__init__.py
Renamed Solana message types and enums to off-chain versions; introduced SolanaSignUnsafeMessage.
core/src/trezor/lvglui/i18n/keys.py
core/src/trezor/lvglui/i18n/locales/...
Added new constants and translations for Solana raw signing warnings and prompts across multiple languages.
core/src/trezor/lvglui/scrs/template.py Modified the Message class to include an optional warning_banner_text parameter for non-standard messages.
core/src/trezor/messages.py Renamed SolanaSignMessage to SolanaSignOffChainMessage; updated message fields; introduced SolanaSignUnsafeMessage; made the public_key optional in signatures.
core/src/trezor/ui/layouts/lvgl/__init__.py Updated confirm_sol_message to include an is_unsafe parameter, enabling UI warnings based on message safety.
python/src/trezorlib/cli/sol.py
python/src/trezorlib/messages.py
python/src/trezorlib/solana.py
Revised CLI commands and message constructors to use off-chain enums; added --unsafe option; renamed functions and updated parameters to support unsafe message signing.
✨ 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: 1

🧹 Nitpick comments (2)
core/src/trezor/lvglui/scrs/template.py (2)

560-561: Add type hints for new parameters.

-        is_standard: bool = True,
-        warning_banner_text: str | None = None,
+        is_standard: bool = True,
+        warning_banner_text: str | None = None,

584-585: Improve readability of the warning banner text fallback.

-                warning_banner_text
-                or _(i18n_keys.CONTENT__NON_STANDARD_MESSAGE_SIGNATURE),
+                warning_banner_text if warning_banner_text is not None
+                else _(i18n_keys.CONTENT__NON_STANDARD_MESSAGE_SIGNATURE),
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b52dad and 8cb0604.

📒 Files selected for processing (26)
  • common/protob/messages-solana.proto (2 hunks)
  • common/protob/messages.proto (1 hunks)
  • core/src/all_modules.py (2 hunks)
  • core/src/apps/solana/sign_offchain_message.py (5 hunks)
  • core/src/apps/solana/sign_unsafe_message.py (1 hunks)
  • core/src/apps/workflow_handlers.py (1 hunks)
  • core/src/trezor/enums/MessageType.py (1 hunks)
  • core/src/trezor/enums/__init__.py (2 hunks)
  • core/src/trezor/lvglui/i18n/keys.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/de.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/en.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/es.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/fr.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/it.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/ja.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/ko.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/pt_br.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/ru.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/zh_cn.py (1 hunks)
  • core/src/trezor/lvglui/i18n/locales/zh_hk.py (1 hunks)
  • core/src/trezor/lvglui/scrs/template.py (2 hunks)
  • core/src/trezor/messages.py (2 hunks)
  • core/src/trezor/ui/layouts/lvgl/__init__.py (2 hunks)
  • python/src/trezorlib/cli/sol.py (2 hunks)
  • python/src/trezorlib/messages.py (5 hunks)
  • python/src/trezorlib/solana.py (1 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • core/src/apps/solana/sign_offchain_message.py
  • python/src/trezorlib/solana.py
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Defs check
  • GitHub Check: Gen check
  • GitHub Check: Style check
🔇 Additional comments (31)
python/src/trezorlib/cli/sol.py (4)

35-41: LGTM! Message version and format dictionaries updated correctly.


73-73: LGTM! Unsafe flag option added with clear help text.


81-83: LGTM! Unsafe message signing logic implemented correctly.

Also applies to: 86-89


90-93: LGTM! Return value handling updated for unsafe signing.

core/src/trezor/enums/MessageType.py (1)

309-311: LGTM! Message types added with unique values.

core/src/apps/workflow_handlers.py (1)

261-264: LGTM! Message handlers added correctly.

core/src/trezor/lvglui/i18n/locales/zh_hk.py (1)

865-869: LGTM! Translations added with clear risk warnings.

core/src/trezor/lvglui/i18n/locales/zh_cn.py (1)

865-869: LGTM! Clear and effective risk communication.

The translations effectively warn users about the risks of raw message signing while maintaining clarity and accuracy.

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

713-719: LGTM! Well-structured enums.

The enums follow consistent naming patterns and provide clear versioning and format options.

core/src/trezor/lvglui/i18n/locales/ko.py (1)

865-869: LGTM! Clear and effective risk communication.

The translations effectively warn users about the risks of raw message signing while maintaining clarity and accuracy.

core/src/trezor/lvglui/i18n/locales/ja.py (1)

865-869: LGTM!

The Japanese translations accurately convey the meaning and security implications of the Solana raw signing feature.

core/src/trezor/lvglui/i18n/locales/en.py (1)

865-869: LGTM!

The English text clearly communicates the feature's purpose and associated security risks.

core/src/trezor/lvglui/i18n/locales/pt_br.py (1)

865-869: LGTM!

The Brazilian Portuguese translations maintain accuracy while using natural language constructs.

core/src/trezor/lvglui/i18n/locales/ru.py (1)

865-869: LGTM! The Russian translations accurately convey the security warnings and maintain consistency with other languages.

core/src/trezor/lvglui/i18n/locales/it.py (1)

865-869: LGTM! The Italian translations effectively communicate the security risks while maintaining linguistic accuracy.

core/src/trezor/lvglui/i18n/locales/es.py (1)

865-869: LGTM! The Spanish translations properly warn users about security implications while maintaining natural language flow.

core/src/trezor/lvglui/i18n/locales/de.py (1)

865-869: LGTM!

The German translations for Solana raw signing are clear and accurate.

core/src/trezor/lvglui/i18n/locales/fr.py (1)

865-869: LGTM!

The French translations for Solana raw signing are clear and accurate.

core/src/all_modules.py (1)

132-135: LGTM!

The module imports and enum declarations are properly structured.

Also applies to: 802-807

core/src/trezor/lvglui/i18n/keys.py (1)

1886-1898: LGTM!

The new constants are well-structured and provide clear security warnings for raw signing functionality.

core/src/trezor/ui/layouts/lvgl/__init__.py (1)

1343-1347: LGTM!

The function signature update and warning banner implementation properly handle unsafe message signing scenarios.

Also applies to: 1360-1363

python/src/trezorlib/messages.py (5)

768-770: LGTM!

The enum definition is clear and well-structured.


772-775: LGTM!

The enum values are well-defined and properly scoped.


9849-9873: LGTM!

The message type is well-structured with proper typing and defaults.


9875-9890: LGTM!

Clean and minimal implementation for unsafe message signing.


9892-9907: LGTM!

The signature type maintains backward compatibility while adding new fields.

common/protob/messages-solana.proto (3)

11-13: LGTM!

The enum renaming improves clarity by explicitly indicating off-chain message handling.

Also applies to: 18-21


65-71: LGTM!

The message type renaming maintains consistency and improves clarity.

Also applies to: 88-91


79-82: LGTM!

The new message type follows the established pattern and serves its intended purpose.

common/protob/messages.proto (1)

451-453: LGTM!

The message type IDs and wire direction attributes are consistent.

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

62-63: LGTM!

The changes to the Solana message types are well-structured and consistent with the codebase patterns.

Also applies to: 854-906

@somebodyLi somebodyLi merged commit 09fcf34 into main Feb 12, 2025
6 checks passed
@somebodyLi somebodyLi deleted the sol_message branch February 12, 2025 03:08
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