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

Refactor signing code #25386

Merged
merged 9 commits into from
Sep 18, 2024
Merged

Refactor signing code #25386

merged 9 commits into from
Sep 18, 2024

Conversation

supermassive
Copy link
Collaborator

@supermassive supermassive commented Aug 30, 2024

Resolves brave/brave-browser#41121

Refactored parts of core/ui responsible of signing transactions/messages:

  • Merged SignTransactionRequest and SignAllTransactionsRequest into SignSolTransactionsRequest. This is SOL only. Both dApp signTransaction and signAllTransactions are still there but internally there is only one implementation.
  • Refactored SimulationService to run SOL simulations separately for SignSolTransactionsRequest and TransactionInfo. Also instead of sending ids instead of corresponding payloads from ui to core.
  • TxService.GetTransactionMessageToSign is moved to proxies. Each explicitly specifies what is returned (vs mojo union).
  • Added EthereumSignatureVRS EthereumSignatureBytes SolanaSignature FilecoinSignature to distinguish signature type in type-safe manner.

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Browser with this PR should behave in the same way as previous versions for these scenarios:

  • Adding HW accounts for Ledger/Trezor for ETH, SOL, FIL
  • Transaction signing with Ledger for ETH, SOL, FIL
  • Message signing with Ledger for ETH, SOL
  • Transaction signing with Trezor for ETH
  • Message signing with Trezor for ETH

@github-actions github-actions bot added CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet feature/web3/wallet/core labels Aug 30, 2024
@supermassive supermassive force-pushed the refactor_signing_code branch 3 times, most recently from f578b42 to 0c60869 Compare September 1, 2024 13:02
@supermassive supermassive force-pushed the refactor_signing_code branch 4 times, most recently from 98134f8 to c5993a3 Compare September 10, 2024 08:14
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@github-actions github-actions bot added the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Sep 11, 2024
@github-actions github-actions bot removed the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Sep 11, 2024
@supermassive supermassive marked this pull request as ready for review September 12, 2024 02:10
@supermassive supermassive requested review from a team as code owners September 12, 2024 02:10
Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

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

core code LGTM but this needs an issue and a manual test plan filled, thanks.

Copy link
Member

@goodov goodov left a comment

Choose a reason for hiding this comment

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

sources-gni-reviewers lgtm

return;
}
maybeShowPendingTransactions();
maybeShowSignTxRequestLayout();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm not grasping the whole picture here, but what happened to the ETH pending transactions? The method maybeShowSignTxRequestLayout() was in charge of processing both (SOL + ETH pending transaction requests).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybeShowSignTxRequestLayout -> SIGN_TRANSACTION
maybeShowSignAllTxRequestLayout -> SIGN_ALL_TRANSACTIONS
were both in charge of SOL transactions only.

Now both cases are covered by a single type
maybeShowSignSolTransactionsRequestLayout -> SIGN_SOL_TRANSACTIONS

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, then there's something sketchy going on: the method maybeShowSignSolTransactionsRequestLayout is called for all transactions (ETH too). ETH pending transactions need it otherwise the panel won't show up.

Here is a quick recording. Precondition: 1 ETH pending transaction. Observe how the breakpoint for the method maybeShowSignSolTransactionsRequestLayout is hit and processed anyway.

Screencast.from.13-09-2024.13.53.02.webm

Here is another recording, same ETH pending transaction, but the method maybeShowSignSolTransactionsRequestLayout was commented. Result: the wallet panel is never displayed.

Screencast.from.13-09-2024.13.59.18.webm

Let's continue on DMs.


private void maybeShowSignAllTxRequestLayout() {
// TODO(apaymyshev): refactor this to have a better name.
private void maybeShowSignSolTransactionsRequestLayout() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm going to take care of this in my next PR, entangle the chains and and detach the logic that is not related to SOL transactions!

Copy link
Collaborator

@simoarpe simoarpe left a comment

Choose a reason for hiding this comment

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

👍 Android part looks good!

Copy link
Member

@onyb onyb left a comment

Choose a reason for hiding this comment

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

frontend ++

Nice work on the typing. Please add a test plan covering the common hardware wallet signing scenarios.

@@ -99,11 +97,16 @@ export const ConnectHardwareWalletPanel = ({
const request = signMessageData?.at(0)
const isSigning = request && request.id !== -1

const { account: messageAccount } = useAccountQuery(request?.accountId)
const { account: singMessageAccount } = useAccountQuery(request?.accountId)
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo

Copy link
Contributor

[puLL-Merge] - brave/brave-core@25386

Description

This PR makes significant changes to the Brave Wallet codebase, particularly focusing on the handling of Solana transactions and hardware wallet interactions. The changes streamline the process of signing Solana transactions, improve type safety, and refactor several components to handle hardware wallet signatures more consistently across different cryptocurrencies.

Changes

Changes

  1. brave_wallet.mojom:

    • Removed SignTransactionRequest and SignAllTransactionsRequest, replaced with SignSolTransactionsRequest.
    • Introduced new types for hardware wallet signatures: EthereumSignatureVRS, EthereumSignatureBytes, SolanaSignature, and FilecoinSignature.
    • Updated various method signatures to use these new types.
  2. brave_wallet_service.cc and brave_wallet_service.h:

    • Replaced methods for handling separate sign transaction and sign all transactions requests with a single method for Solana transactions.
    • Updated signature processing methods to use the new signature types.
  3. eth_transaction.cc and eth_transaction.h:

    • Modified ProcessVRS method to work with byte arrays instead of strings.
  4. eth_tx_manager.cc and eth_tx_manager.h:

    • Updated methods to use the new EthereumSignatureVRS type.
  5. solana_transaction.cc and solana_transaction.h:

    • Modified to work with the new SolanaSignature type.
  6. Various UI components (React):

    • Updated to work with the new SignSolTransactionsRequest instead of separate sign transaction and sign all transactions requests.
    • Modified hardware wallet interaction logic to use the new signature types.
  7. iOS changes:

    • Updated CryptoStore, SignTransactionView, and other components to work with the new SignSolTransactionsRequest.
    • Modified mock objects and preview content to reflect the new API changes.

Possible Issues

  • The changes are extensive and touch many parts of the codebase, which could introduce integration issues.
  • Some platform-specific code (e.g., iOS) may need further testing to ensure compatibility with the new types and methods.

Security Hotspots

  • The handling of hardware wallet signatures has changed significantly. Ensure that all signature verification processes are still secure and correctly implemented across all supported cryptocurrencies.
  • The removal of separate methods for signing single and multiple transactions in favor of a unified approach should be carefully reviewed to ensure it doesn't introduce any security vulnerabilities.

@supermassive supermassive merged commit 2a4e387 into master Sep 18, 2024
17 of 18 checks passed
@supermassive supermassive deleted the refactor_signing_code branch September 18, 2024 08:57
@github-actions github-actions bot added this to the 1.72.x - Nightly milestone Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build feature/web3/wallet/core feature/web3/wallet puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor wallet's hardware signing code
7 participants