Skip to content

fix: duplicate identity keys created in multiple wallets#289

Merged
QuantumExplorer merged 22 commits into
v0.9-devfrom
fix/duplicate-keys
May 30, 2025
Merged

fix: duplicate identity keys created in multiple wallets#289
QuantumExplorer merged 22 commits into
v0.9-devfrom
fix/duplicate-keys

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented May 22, 2025

When we load more than 1 wallet into Dash Evo Tool, identity keys in second one sometimes are the same as corresponding identities in first one.

Core issue was that private keys were not correctly regenerated when switching to another wallet. This has been fixed. Wallet update logic was refactored to have one central place where it happens.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@lklimek lklimek changed the base branch from master to v0.9-dev May 22, 2025 13:56
@lklimek lklimek marked this pull request as ready for review May 22, 2025 14:52
@lklimek
Copy link
Copy Markdown
Contributor Author

lklimek commented May 22, 2025

@coderabbitai review all

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 22, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Get PR details
gh pr view 289 --json title,body,state,author,baseRefName,headRefName,additions,deletions,changedFiles

# Get a list of files changed in the PR
gh pr view 289 --json files --jq '.files[].path'

# Get more details about the files including additions and deletions
gh pr view 289 --json files

Length of output: 1205


🏁 Script executed:

#!/bin/bash
# Get the diff for each changed file
for file in src/context.rs src/database/identities.rs src/database/initialization.rs src/database/wallet.rs src/model/wallet/mod.rs src/ui/identities/add_new_identity_screen/mod.rs; do
  echo "========== DIFF for $file =========="
  git diff origin/v0.9-dev..origin/fix/duplicate-keys -- "$file"
done

# Let's also check for any README or project description to understand the project better
if [ -f "README.md" ]; then
  echo "========== README.md =========="
  head -n 50 README.md
fi

Length of output: 4476


🏁 Script executed:

#!/bin/bash
# Let's get the diffs using GitHub CLI instead
for file in src/context.rs src/database/identities.rs src/database/initialization.rs src/database/wallet.rs src/model/wallet/mod.rs src/ui/identities/add_new_identity_screen/mod.rs; do
  echo "========== DIFF for $file =========="
  gh pr diff 289 --patch | grep -A 50000 "^diff --git a/$file b/$file" | grep -B 50000 -m 2 "^diff --git" | head -n -1 || echo "Could not get diff for $file"
done

# Let's also check if the PR has a description that gives more context
gh pr view 289

Length of output: 15483


@lklimek I've completed a review of PR #289, which addresses the issue of duplicate identity keys being created when multiple wallets are loaded.

Core Issue & Fix

The main problem appears to be in the identity key generation process where a hardcoded index (0) was being used when calling identity_authentication_ecdsa_private_key(), causing different wallets to generate identical keys. The fix correctly replaces this hardcoded value with identity_id_number to ensure uniqueness across wallets.

- wallet.identity_authentication_ecdsa_private_key(app_context.network, 0, 0, Some(&app_context))
+ wallet.identity_authentication_ecdsa_private_key(app_context.network, identity_id_number, 0, Some(&app_context))

This change is applied consistently to all four key derivation calls, ensuring that each wallet's identity keys are properly isolated.

Additional Improvements

  1. Database Fixes:

    • Added migration to fix devnet network name storage (from devnet: to devnet)
    • Incremented database version to 8 to handle the migration
  2. Error Handling & Debugging:

    • Added extensive tracing to wallet operations, which will help identify similar issues in the future
    • Added more detailed logging when adding identities to wallets
  3. Memory Safety:

    • Fixed potential panic in wallet seed drop by properly checking the variant before calling zeroize()

Overall Assessment

This PR looks good and directly addresses the reported issue. The changes are focused and include appropriate logging to help with debugging. The database migration ensures that existing users will have their data corrected automatically.

The PR is ready to be merged once all CI checks pass.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR centralizes wallet update logic in the UI and ensures identity private keys are regenerated when switching wallets, fixes secure seed erasure in the wallet model, and adds database tracing, version bump, and network-string fixes to prevent duplicate identity keys across wallets.

  • Refactor AddNewIdentityScreen: introduce update_wallet, ensure_correct_identity_keys, and update_identity_key to streamline identity key handling
  • Securely erase wallet seed in WalletSeed’s Drop, add doc for identity_registration_ecdsa_private_key
  • Instrument database loading with tracing::trace!, bump DB version to 8 with migration, fix devnet network name handling

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/ui/identities/add_new_identity_screen/mod.rs Centralize wallet selection and identity key regeneration logic
src/model/wallet/mod.rs Update WalletSeed drop cleanup and add identity key method doc
src/database/wallet.rs Add tracing::trace! logs for wallet loading steps
src/database/initialization.rs Bump DEFAULT_DB_VERSION to 8 and add identity network fix-up
src/database/identities.rs Log saving identity without wallet
src/context.rs Simplify Devnet network string from devnet: to devnet
Comments suppressed due to low confidence (3)

src/model/wallet/mod.rs:234

  • The original close() call ensured all cleanup was done; now only Open variants zeroize the seed. Verify that no sensitive data remains in other variants and that close() isn’t required to perform additional cleanup steps.
if let WalletSeed::Open(open_seed) = self {

src/database/initialization.rs:7

  • The DB version has been bumped to 8—ensure any external documentation or migration guides are updated to reflect this new version.
pub const DEFAULT_DB_VERSION: u16 = 8;

src/context.rs:225

  • Switching from devnet:<name> to a fixed devnet representation may break existing configurations or tooling. Verify that all consumers of this value have been updated accordingly.
Network::Devnet => "devnet".to_string(),

Comment thread src/ui/identities/add_new_identity_screen/mod.rs
Comment thread src/ui/identities/add_new_identity_screen/mod.rs Outdated
Comment thread src/ui/identities/add_new_identity_screen/mod.rs
Comment thread src/ui/identities/add_new_identity_screen/mod.rs Outdated
Comment thread src/database/wallet.rs
Comment thread src/database/identities.rs Outdated
Comment thread src/context.rs Outdated
)?;

Ok(())
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this stops us from being able to use multiple devnets

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As discussed, we drop multi-devnet approach.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

okay

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this only updates one table... there are many tables that have a network.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed, please double-check if I didn't miss sth

@lklimek lklimek moved this to In review / testing in Platform team May 23, 2025
@lklimek lklimek requested a review from QuantumExplorer May 29, 2025 09:21
@QuantumExplorer QuantumExplorer merged commit 6018340 into v0.9-dev May 30, 2025
1 check passed
@QuantumExplorer QuantumExplorer deleted the fix/duplicate-keys branch May 30, 2025 08:52
@github-project-automation github-project-automation Bot moved this from In review / testing to Done in Platform team May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants