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: remove Hash-Check from FW upgrade (it is performed on-device-connect anyway #16949

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

peter-sanderson
Copy link
Contributor

Copy link

github-actions bot commented Feb 12, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 26
  • More info

Learn more about 𝝠 Expo Github Action

@peter-sanderson peter-sanderson force-pushed the remove-hash-check-after-fw-upgrade branch 3 times, most recently from 5cba0bc to 90240f6 Compare February 12, 2025 13:23
@peter-sanderson peter-sanderson marked this pull request as ready for review February 12, 2025 13:24
Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request removes the firmware hash validation logic from multiple parts of the codebase. The changes include deleting assertions in tests that previously checked the check property, eliminating the calculateFirmwareHash function and related hash validation logic in the firmware update process, and updating the function signature of the update function to use a consolidated parameter object. Additionally, UI components and middleware logic that handled firmware hash error reporting have been removed, and corresponding Redux actions, reducers, and thunks managing firmware hash errors were eliminated. Changes in API types also reflect a simplification by renaming and restructuring the firmware update response type. Overall, the modifications streamline the firmware update process by focusing on version verification rather than firmware hash integrity checks.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd59256 and 79db32a.

📒 Files selected for processing (14)
  • packages/connect/src/core/__tests__/onCallFirmwareUpdate.test.ts (0 hunks)
  • packages/connect/src/core/onCallFirmwareUpdate.ts (3 hunks)
  • packages/connect/src/types/api/__tests__/management.ts (0 hunks)
  • packages/connect/src/types/api/firmwareUpdate.ts (1 hunks)
  • packages/suite/src/actions/firmware/__fixtures__/firmwareActions.ts (0 hunks)
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx (0 hunks)
  • packages/suite/src/components/firmware/index.tsx (0 hunks)
  • packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1 hunks)
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts (0 hunks)
  • packages/suite/src/views/firmware/FirmwareModal.tsx (1 hunks)
  • packages/suite/src/views/onboarding/steps/FirmwareStep.tsx (1 hunks)
  • suite-common/firmware/src/firmwareActions.ts (0 hunks)
  • suite-common/firmware/src/firmwareReducer.ts (0 hunks)
  • suite-common/firmware/src/firmwareThunks.ts (1 hunks)
💤 Files with no reviewable changes (8)
  • packages/suite/src/components/firmware/index.tsx
  • packages/suite/src/actions/firmware/fixtures/firmwareActions.ts
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts
  • suite-common/firmware/src/firmwareReducer.ts
  • suite-common/firmware/src/firmwareActions.ts
  • packages/connect/src/types/api/tests/management.ts
  • packages/connect/src/core/tests/onCallFirmwareUpdate.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/suite/src/views/onboarding/steps/FirmwareStep.tsx
  • packages/connect/src/types/api/firmwareUpdate.ts
  • packages/suite/src/views/firmware/FirmwareModal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (15)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: prepare_android_test_app
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
🔇 Additional comments (5)
suite-common/firmware/src/firmwareThunks.ts (1)

130-131: LGTM! Simplified firmware update flow.

The code now directly sets the status to 'done' after processing the firmware update response, aligning with the PR objective of removing hash validation.

packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1)

4-4: LGTM! Removed hash validation related imports.

The removal of hash validation related imports aligns with the PR objective.

Also applies to: 12-12

packages/connect/src/core/onCallFirmwareUpdate.ts (3)

301-304: LGTM! Improved function signature.

The introduction of OnCallFirmwareUpdateParams type improves code readability by consolidating parameters into a single object.


306-309: LGTM! Updated function signature.

The function now accepts a single parameter object, improving maintainability.


503-509: LGTM! Simplified return type.

The return type now focuses on version validation, aligning with the PR objective of removing hash validation.

✨ 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

@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: 0

🧹 Nitpick comments (1)
suite-common/firmware/src/firmwareThunks.ts (1)

130-131: LGTM! Consider enhancing error reporting.

The removal of hash validation logic simplifies the firmware update process. However, the error reporting for unexpected version changes could be more descriptive.

Consider adding more context to the error report:

-                error: 'Unexpected firmware version change during firmware update.',
+                error: `Unexpected firmware version change during firmware update. Expected: ${releaseVersion}, Got: ${installedVersion}`,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e925744 and 90240f6.

📒 Files selected for processing (14)
  • packages/connect/src/core/__tests__/onCallFirmwareUpdate.test.ts (0 hunks)
  • packages/connect/src/core/onCallFirmwareUpdate.ts (3 hunks)
  • packages/connect/src/types/api/__tests__/management.ts (0 hunks)
  • packages/connect/src/types/api/firmwareUpdate.ts (1 hunks)
  • packages/suite/src/actions/firmware/__fixtures__/firmwareActions.ts (0 hunks)
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx (0 hunks)
  • packages/suite/src/components/firmware/index.tsx (0 hunks)
  • packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1 hunks)
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts (0 hunks)
  • packages/suite/src/views/firmware/FirmwareModal.tsx (1 hunks)
  • packages/suite/src/views/onboarding/steps/FirmwareStep.tsx (1 hunks)
  • suite-common/firmware/src/firmwareActions.ts (0 hunks)
  • suite-common/firmware/src/firmwareReducer.ts (0 hunks)
  • suite-common/firmware/src/firmwareThunks.ts (1 hunks)
💤 Files with no reviewable changes (8)
  • packages/suite/src/components/firmware/index.tsx
  • suite-common/firmware/src/firmwareActions.ts
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts
  • suite-common/firmware/src/firmwareReducer.ts
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx
  • packages/connect/src/core/tests/onCallFirmwareUpdate.test.ts
  • packages/connect/src/types/api/tests/management.ts
  • packages/suite/src/actions/firmware/fixtures/firmwareActions.ts
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: PR-check / node-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: PR-check / node-override init-api-flaky
  • GitHub Check: PR-check / web-override init-api-flaky
  • GitHub Check: PR-check / web-authorizeCoinjoin cancelCoinjoinAuthorization passphrase unlockPath setBusy checkFirmwareAuthenticity keepSession cancel.test info.test resetDevice-api
  • GitHub Check: build-deploy
  • GitHub Check: prepare_android_test_app
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build-web
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
🔇 Additional comments (8)
packages/connect/src/core/onCallFirmwareUpdate.ts (4)

12-12: No issues with updated import.

The addition of PROTO to the import statement aligns with the usage in the file.


301-305: Good introduction of type safety for function parameters.

Defining OnCallFirmwareUpdateParams improves readability and helps ensure correctness by grouping params: Params and context: Context into a single object.


309-309: Clearer destructuring of parameters.

Switching the function signature to async ({ params, context }: OnCallFirmwareUpdateParams) clarifies the inputs and aligns with the newly introduced type.


503-503: Confirm firmware integrity approach.

Returning only version checks (without hash checks) is consistent with the goal of removing redundancy. Ensure the on-device logic still provides any necessary signature/hash validations to maintain firmware integrity.

packages/connect/src/types/api/firmwareUpdate.ts (1)

19-19: Streamlined response type.

Replacing the older union type with FirmwareUpdateResponse containing version comparison fields cleanly aligns with the removal of firmware hash checks.

packages/suite/src/views/onboarding/steps/FirmwareStep.tsx (1)

22-22: Removed reference to firmware hash state.

Eliminating firmwareHashInvalid from the destructuring call aligns with the overall removal of hash validation logic in the firmware update flow.

packages/suite/src/views/firmware/FirmwareModal.tsx (1)

14-14: LGTM! Import cleanup aligns with PR objective.

The removal of FirmwareUpdateHashCheckError import is consistent with moving hash validation to device connection.

packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1)

4-4: LGTM! Analytics cleanup aligns with PR objective.

The removal of hash-check related imports streamlines the analytics middleware while preserving essential firmware update tracking.

Copy link
Contributor

@mroz22 mroz22 left a comment

Choose a reason for hiding this comment

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

ack

Copy link
Contributor

@Lemonexe Lemonexe left a comment

Choose a reason for hiding this comment

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

LGTM!

});

if (fwAuto.success) {
fwAuto.payload.check.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

not important, but what was this code actually supposed to do?
String.toLowerCase() does not mutate, so this code does nothing really... 😄

@peter-sanderson peter-sanderson force-pushed the remove-hash-check-after-fw-upgrade branch from 90240f6 to fd59256 Compare February 13, 2025 10:26
Copy link

@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: 0

🧹 Nitpick comments (1)
suite-common/firmware/src/firmwareThunks.ts (1)

134-145: Consider improving error reporting for version mismatch.

The error reporting for unexpected firmware version changes could be enhanced to provide more context to users.

Consider adding more details to the error report:

 reportCheckFail('Firmware version', {
     model: device.features?.internal_model,
     revision: device.features?.revision,
     vendor: device.features?.fw_vendor,
     bootloaderVersion,
     binaryVersion,
     installedVersion,
     releaseVersion,
-    error: 'Unexpected firmware version change during firmware update.',
+    error: `Unexpected firmware version change during firmware update. Expected ${binaryVersion.join('.')} but got ${installedVersion.join('.')}`,
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90240f6 and fd59256.

📒 Files selected for processing (14)
  • packages/connect/src/core/__tests__/onCallFirmwareUpdate.test.ts (0 hunks)
  • packages/connect/src/core/onCallFirmwareUpdate.ts (3 hunks)
  • packages/connect/src/types/api/__tests__/management.ts (0 hunks)
  • packages/connect/src/types/api/firmwareUpdate.ts (1 hunks)
  • packages/suite/src/actions/firmware/__fixtures__/firmwareActions.ts (0 hunks)
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx (0 hunks)
  • packages/suite/src/components/firmware/index.tsx (0 hunks)
  • packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1 hunks)
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts (0 hunks)
  • packages/suite/src/views/firmware/FirmwareModal.tsx (1 hunks)
  • packages/suite/src/views/onboarding/steps/FirmwareStep.tsx (1 hunks)
  • suite-common/firmware/src/firmwareActions.ts (0 hunks)
  • suite-common/firmware/src/firmwareReducer.ts (0 hunks)
  • suite-common/firmware/src/firmwareThunks.ts (1 hunks)
💤 Files with no reviewable changes (8)
  • packages/suite/src/components/firmware/index.tsx
  • suite-common/firmware/src/firmwareActions.ts
  • packages/suite/src/middlewares/wallet/storageMiddleware.ts
  • packages/suite/src/actions/firmware/fixtures/firmwareActions.ts
  • packages/suite/src/components/firmware/FirmwareUpdateHashCheckError.tsx
  • packages/connect/src/core/tests/onCallFirmwareUpdate.test.ts
  • suite-common/firmware/src/firmwareReducer.ts
  • packages/connect/src/types/api/tests/management.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/suite/src/views/onboarding/steps/FirmwareStep.tsx
  • packages/suite/src/views/firmware/FirmwareModal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: build-deploy
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: prepare_android_test_app
  • GitHub Check: build-web
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (5)
packages/connect/src/types/api/firmwareUpdate.ts (1)

19-25: LGTM! Type definition aligns with firmware hash validation removal.

The simplified FirmwareUpdateResponse type now correctly focuses on version-related properties, removing unnecessary hash validation fields. This change aligns with the PR objective of removing hash checks from the firmware upgrade process.

suite-common/firmware/src/firmwareThunks.ts (1)

130-131: LGTM! Simplified firmware update status handling.

The code now directly sets the status to 'done' after firmware update, removing the intermediate hash validation steps. This aligns with the PR objective as hash validation is now performed during device connection.

packages/suite/src/middlewares/suite/analyticsMiddleware.ts (1)

4-4: LGTM! Simplified firmware update analytics.

The removal of hash validation related imports and error reporting aligns with the PR objective. The analytics now correctly focuses on tracking firmware update success/failure without hash validation events.

packages/connect/src/core/onCallFirmwareUpdate.ts (2)

301-304: LGTM! Improved function parameter organization.

The new OnCallFirmwareUpdateParams type provides better organization of function parameters by grouping them into a single object.


503-509: LGTM! Simplified firmware update response.

The response now correctly focuses on version validation without hash checks, aligning with the PR objective. The version checks ensure that:

  1. The installed version matches the binary version
  2. The installed version matches the requested release version (if applicable)

@peter-sanderson
Copy link
Contributor Author

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the remove-hash-check-after-fw-upgrade branch from fd59256 to 79db32a Compare February 13, 2025 14:13
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