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

rusk-wallet: Refactor Wallet struct to make impossible states impossible #2972

Open
welf opened this issue Nov 14, 2024 · 0 comments · May be fixed by #3091
Open

rusk-wallet: Refactor Wallet struct to make impossible states impossible #2972

welf opened this issue Nov 14, 2024 · 0 comments · May be fixed by #3091
Assignees
Labels
fix:vulnerability Issues related to fix vulnerabilities of the architecture or software module:rusk-wallet Issues related to rusk wallet type:enhancement Issues concerning code or feature improvement (performance, refactoring, etc)

Comments

@welf
Copy link
Contributor

welf commented Nov 14, 2024

Currently, our Wallet struct allows for an inconsistent state:

pub struct Wallet<F: SecureWalletFile + Debug> {
    ...
    file: Option<F>,
    file_version: Option<DatFileVersion>,
}

This structure allows for an inconsistent state where file could be None while file_version is Some(_), or vice versa. This not only introduces potential errors but also complicates the code, requiring unnecessary unwrapping of both file and file_version even when one has already been successfully unwrapped. Consequently, the code becomes more verbose and harder to understand and maintain.

A potential solution is to combine both values into a single data structure:

pub struct Wallet<F: SecureWalletFile + Debug> {
    ...
    file: Option<(F, DatFileVersion)>,
}

or

pub struct FileData<F: SecureWalletFile + Debug> {
    file: F,
    file_version: DatFileVersion
}

pub struct Wallet<F: SecureWalletFile + Debug> {
    ...
    file: Option<FileData<F>>,
}

Expected behaviour
The design of the Wallet struct should prevent impossible state.

@welf welf added fix:vulnerability Issues related to fix vulnerabilities of the architecture or software type:enhancement Issues concerning code or feature improvement (performance, refactoring, etc) module:rusk-wallet Issues related to rusk wallet labels Nov 14, 2024
@welf welf self-assigned this Nov 14, 2024
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 type:enhancement Issues concerning code or feature improvement (performance, refactoring, etc)
Projects
None yet
1 participant