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(wallet): Add a debug option to enable bitcoin testnet #22971

Merged
merged 4 commits into from
Apr 10, 2024

Conversation

nuo-xu
Copy link
Contributor

@nuo-xu nuo-xu commented Apr 8, 2024

Resolves brave/brave-browser#37256

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:

In order to test this PR, you need to set up a feature flag in two ways:

If you are building this PR locally on your Xcode, duplicate Debug scheme and add --enable-features=BraveWalletBitcoin in your Arguments Passed On Launch, then build.
If you are testing using a TF build. Add BraveWalletBitcoin under Settings/BraveCore Switches/Enable Features (Enable Enable Features and a fresh launch is required)
Note: Bitcoin balance fetching will be addressed in a separate issue brave/brave-browser#36966
All BTC balance will be displayed as 0 value. Send BTC will be addressed in a separate issue brave/brave-browser#36968

In order to enable bitcoin testnet, please go to browser setting, under Developer Options, go to View Brave Wallet Debug Menu. There is a toggle to turn on or off bitcoin testnet.

bitcoin flag simulator_screenshot_3E94504A-39D5-4CE0-B900-D25FA03BC787
Show Testnets Enable Bitcoin Testnet Expected Behaviour
x x
  • no testnets are displayed in network picker or filter
  • can only create bitcoin mainnet account
  • No BTC neither on mainnet nor testnet in portfolio
  • Only Bitcoin on mainnet if there is any will be displayed in Accounts Tab
  • x
  • testnets(but list does not contain Bitcoin testnet) are displayed in network picker or filter
  • can only create bitcoin mainnet account
  • only BTC on mainnet in portfolio
  • only Bitcoin on mainnet if there is any will be displayed in Accounts Tab
  • testnets(including bitcoin testnet) are displayed in network picker or filter
  • can create both bitcoin mainnet and testnet account
  • BTC on mainnet and testnet in portfolio(if bitcoin testnet are selected in filter)
  • Both Bitcoin on mainnet or testnet if there is any will be displayed in Accounts Tab
  • Note: due to 37192 the selected network for bitcoin coin type will NOT be updated correctly. if you change the selected account to bitcoin account, please make sure the selected network is correctly selected
    x
  • no testnets are displayed in network picker or filter
  • can create both bitcoin mainnet and testnet account
  • only BTC on mainnet in portfolio(if bitcoin testnet are selected in filter)
  • Both Bitcoin on mainnet or testnet if there is any will be displayed in Accounts Tab
  • Note: due to 37192 the selected network for bitcoin coin type will NOT be updated correctly. if you current selected network for bitcoin coin type is bitcoin is mainnet, there is no way to update the selected network to bitcoin testnet when testnet is not enabled from wallet settings.

    @nuo-xu nuo-xu requested a review from StephenHeaps April 8, 2024 19:51
    @nuo-xu nuo-xu self-assigned this Apr 8, 2024
    @nuo-xu nuo-xu requested a review from a team as a code owner April 8, 2024 19:51
    @nuo-xu nuo-xu added CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 labels Apr 8, 2024
    @nuo-xu nuo-xu force-pushed the wallet/ios-debug-bitcoin-testnet branch from 5425e70 to ea4c7d6 Compare April 9, 2024 18:14
    Copy link
    Contributor

    github-actions bot commented Apr 9, 2024

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

    Description

    This PR adds a new debug menu for the Brave Wallet which allows enabling the Bitcoin Testnet network and accounts. It also updates various parts of the wallet to respect the new Bitcoin Testnet preference.

    Changes

    Changes

    BraveWalletDebugMenu.swift

    • Added a new SwiftUI view for the Brave Wallet debug menu
    • Contains a toggle to enable/disable the Bitcoin Testnet

    SettingsViewController.swift

    • Added an observer to set up the keyring and crypto stores
    • Added a function to display the new Brave Wallet debug menu
    • Added a new row in the debug menu to open the Brave Wallet debug menu

    Various files in BraveWallet/:

    • Updated to filter out Bitcoin Testnet accounts and network if the preference is disabled
    • Updated to pass the Bitcoin Testnet preference when fetching accounts
    • Updated tests to handle the new Bitcoin Testnet preference

    WalletPreferences.swift

    • Added a new preference isBitcoinTestnetEnabled to track if Bitcoin Testnet is enabled

    Security Hotspots

    1. Medium risk: The isBitcoinTestnetEnabled preference is not encrypted and stored in plain text. If an attacker gains access to the device, they could potentially enable the testnet and trick the user into transacting with testnet coins thinking they are mainnet.

    2. Low risk: The new debug menu is only accessible through the debug settings which are typically not user facing. However, a tech savvy user could still potentially access these settings.

    3. Low risk: The Bitcoin Testnet toggle is a simple boolean and not vulnerable to injection attacks. However, it's good practice to still validate and sanitize any data read from UserDefaults.

    In summary, the main changes look good from a security perspective. The main risk is around the unencrypted storage of the testnet preference which could be mitigated by encrypting it. Additionally, the debug menu access should be restricted if possible.

    @nuo-xu nuo-xu merged commit 633320c into master Apr 10, 2024
    19 checks passed
    @nuo-xu nuo-xu deleted the wallet/ios-debug-bitcoin-testnet branch April 10, 2024 03:29
    @github-actions github-actions bot added this to the 1.66.x - Nightly milestone Apr 10, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    CI/skip-android Do not run CI builds for Android CI/skip-macos-x64 Do not run CI builds for macOS x64 CI/skip-windows-x64 Do not run CI builds for Windows x64 puLL-Merge
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    Wallet: Optional Bitcoin testnet support via Debug section
    2 participants