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

bugfix-2972 | rusk-wallet: Refactor wallet struct to make impossible states impossible #3091

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

Conversation

welf
Copy link
Contributor

@welf welf commented Nov 29, 2024

Closes #2972

  • Move version to the file property in Wallet. If we have a valid wallet file, then we know its version.
  • Move the functionalities of wallet path wrapper and wallet file from their implementations to traits (why we need to do it is described here: rusk-wallet: Separate API interfaces from their implementations #3093)
  • Move path validations to the WalletPath creation methods.
  • Add tests for the WalletPath struct creation (WalletPath:new, WalletPath::try_from, and WalletPath::from_str).
  • Add tests for WalletFilePath and SecureWalletFile traits

@welf welf added fix:vulnerability Issues related to fix vulnerabilities of the architecture or software module:rusk-wallet Issues related to rusk wallet labels Nov 29, 2024
@welf welf requested review from Daksh14 and moCello November 29, 2024 12:26
@welf welf force-pushed the bugfix-2972-rusk-wallet-refactor-wallet-struct-to-make-impossible-states-impossible branch from bddee85 to 1bcc58b Compare November 29, 2024 12:35
@welf welf force-pushed the bugfix-2972-rusk-wallet-refactor-wallet-struct-to-make-impossible-states-impossible branch from 1bcc58b to e7c803f Compare November 29, 2024 15:55
@welf welf force-pushed the bugfix-2972-rusk-wallet-refactor-wallet-struct-to-make-impossible-states-impossible branch 3 times, most recently from 5c4c141 to 3d6fabe Compare December 1, 2024 16:08
Copy link
Contributor

@Daksh14 Daksh14 left a comment

Choose a reason for hiding this comment

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

Please next time keep the changes as atomic as you can, I can see the changes are ordered in the description of the PR but it just makes it harder to review

Copy link
Contributor

@Daksh14 Daksh14 left a comment

Choose a reason for hiding this comment

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

I have lots of RFC(s) and comments for this refactor, we can sync to go over them also if thats easier

rusk-wallet/src/wallet.rs Outdated Show resolved Hide resolved
#[derive(Debug, Clone)]
pub struct WalletFile {
path: WalletPath,
pwd: Vec<u8>,
Copy link
Contributor

@Daksh14 Daksh14 Dec 2, 2024

Choose a reason for hiding this comment

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

Saving the password here in the memory is necessary? I don't think its secure also given this struct is gonna live for the duration of the wallet's instance. Can we have it like before where the password wasn't stored in memory or the ptr to it isn't stored in memory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't touch the WalletFile shape and it had the pwd property before refactoring.

/// Name of the network
pub network: Option<String>,
network: Option<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have network in the wallet path? It seems irrelevant to have it here, we have the settings.rs file in the binary folder (which should be moved to the library IMO) which has the network there, I don't think we should duplicate that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't touch the WalletPath shape and it had the network property before refactoring.

use crate::Error;

/// Provides access to a secure wallet file
pub trait SecureWalletFile: Debug + Send + Sync + Clone {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have 2 abstractions now, SecureWalletFile and WalletFilePath I'm not a big fan of abstractions themselves and we should only keep these abstractions if a user is going to use them as a library and something needs to be implemented. IMO we can remove both of these abstractions since we only have one implementor and keep it as simple as we can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have discussed it with @Daksh14 and decided to leave the final decision on @ZER0

}

/// Get the seed and address from the file
fn get_seed_and_address(&self) -> Result<(Seed, u8), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic should be inside the file.rs where the rest of DatFileVersion structs and magic numbers are defined


/// Sets the network name for different cache locations.
/// e.g, devnet, testnet, etc.
fn set_network_name(&mut self, network: Option<String>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We're duplicating a lot of methods here, we have 2 traits that have duplicate methods why is that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are dealing primarily with Wallet that has the file: F property. The user of the wallet doesn't have to know how the file: F is implemented and that it has the associated PathBufferWrapper. Hence I re-exported getters of the PathBufferWrapper in the SecureWalletFile trait to make the file's API more user-friendly and enable user to call all necessary functions from the file.

@welf welf force-pushed the bugfix-2972-rusk-wallet-refactor-wallet-struct-to-make-impossible-states-impossible branch from 3d6fabe to bc482df Compare December 4, 2024 09:24
@welf welf force-pushed the bugfix-2972-rusk-wallet-refactor-wallet-struct-to-make-impossible-states-impossible branch from bc482df to e634e9f Compare December 4, 2024 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix:vulnerability Issues related to fix vulnerabilities of the architecture or software module:rusk-wallet Issues related to rusk wallet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rusk-wallet: Refactor Wallet struct to make impossible states impossible
4 participants