Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

token-2022: prevent an already configured confidential account to be configured again #3216

Conversation

samkim-crypto
Copy link
Contributor

The confidential_transfer::ConfigureAccount, should fail if run on an already configured account as stated in the description. However, this is currently not enforced in the processor logic, allowing users to overwrite the account state.

This PR adds a check in the ConfigureAccount processor logic to prevent accounts from being configured again.

Thank you @joncinque for the catch!

@samkim-crypto samkim-crypto force-pushed the prevent-confidential-account-reconfig branch from 179cfcc to 5be8bfa Compare June 3, 2022 14:57
@samkim-crypto
Copy link
Contributor Author

Added the overwrite flag on initialize_extension. If the flag is set, then initialize_extension will overwrite an existing extension (if it exists) with the default extension state. If the flag is not set, then initialize_extension will return an error if the extension was already initialized.

I ended up just dividing the logic in init_or_get_extension to get_extension and init_extension since the overwrite flag felt unnatural in init_or_get_extension. I hope this change does not break the original readability of the code.

@samkim-crypto
Copy link
Contributor Author

One alternative to having a boolean flag overwrite is to have two separate functions init_extension_overwrite and init_extension for better readability.

joncinque
joncinque previously approved these changes Jun 3, 2022
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks good to me, but let's see what @CriesofCarrots thinks too, since I think we used to have init and get separated, but there was a good reason to unify them.

@joncinque joncinque requested a review from CriesofCarrots June 3, 2022 19:16
@mergify mergify bot dismissed joncinque’s stale review June 4, 2022 00:07

Pull request has been modified.

Copy link
Contributor

@CriesofCarrots CriesofCarrots left a comment

Choose a reason for hiding this comment

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

Lgtm, I can't remember any specific reason for the old api.

I do find the bool a little unintuitive to read, but I don't want 2 different functions, and can't really think of a reasonable alternative, so let's go with it

@samkim-crypto
Copy link
Contributor Author

Great! Thanks for the review.

@samkim-crypto samkim-crypto merged commit c2a3ecd into solana-labs:master Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants