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

Update missing_owner_check to not report local variables, duplicate warnings #72

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

S3v3ru5
Copy link
Contributor

@S3v3ru5 S3v3ru5 commented Jan 30, 2024

The PR fixes two things:

  1. In Anchor projects, some of the accounts are of type Anchor's AccountInfo. The developers use to_account_info on the Anchor's AccountInfo. The Anchor's AccountInfo is essentially alias to Solana AccountInfo. So, for the expression x.to_account_info() where x is Anchor's AccountInfo type, the lint reports the same line twice first for x and the second x.to_account_info() as both expressions are considered of type Solana AccountInfo.

    • The lint is update to ignore to_account_info() method calls if the receiver is of type AccountInfo.
  2. The lint reports local variables whose owner might have already been checked.

Consider the following code pattern

let cpi_program = self.system.to_account_info();
[...]
CpiContext::new(cpi_program, ...);

The self.system is of Anchor type Program<> which verifies the key() and does not need owner check.

As the cpi_program is as same self.system the program does not need check the owner again.

The lint is updated to ignore expressions which are local variables. Another reason to ignore local variables is because of duplicate warnings:

if the variable has type AccountInfo then the rhs of the assignment operation must also have AccountInfo. The lint will already check the rhs expression for missing_owner_check and reports the rhs expression if there is no owner check. There is no need to report the local variable which points to the same account again.

@smoelius smoelius added this pull request to the merge queue Feb 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Feb 7, 2024
…ings when to_account_info is called on Anchor's AccountInfo.
@smoelius smoelius added this pull request to the merge queue Feb 7, 2024
Merged via the queue into master with commit 8413fe9 Feb 7, 2024
3 checks passed
@smoelius smoelius deleted the fix-missing-owner branch February 7, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants