Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is not meant to be merged (but could be in the future if a lint strategy is created). The only notable file in this PR is in
ui/recommended/init_expansion.rs
. I was trying to figure out what exactly anchor does to fix this exploit with their[#account(init)]
macro, and see if it might provide some insight into what exactly "initialization" of an account means. This file contains the macro expansion (all of it happens in thetry_accounts()
method as far as I can tell). Theinit
attribute expands to a large block of code, and I've made comments on the parts I found more interesting.Some other miscellaneous notes:
account.state
is equal to a certain enum variant. Thus, the Account struct uses an enum to tell if an account has already been initialized. However, a bool could just as easily be used, as is done in theMint
struct here. So a common "initialization" flag may be either an enum or bool. I can't think of an easy way to detect if the enum/bool is meant to be used as as initialization flag or not though, besides checking it'sIdent
??In summary, a lint for this exploit could be made by:
AccountInfo.data
struct contains an "initialization flag". The SPL token library has a flag in their Mint and Account structs, and it seems like this is a reasonable way to not reinitialize accounts.