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-signer-check lint to handle anchor programs separately #86

Merged
merged 8 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 52 additions & 52 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The current lints are:
| [`insecure_account_close`](lints/insecure_account_close) | lint for [9-closing-accounts](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/9-closing-accounts) |
| [`missing_owner_check`](lints/missing_owner_check) | lint for [2-owner-checks](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/2-owner-checks) |
| [`missing_signer_check`](lints/missing_signer_check) | lint for [0-signer-authorization](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/0-signer-authorization) |
| [`sysvar_get`](lints/sysvar_get) | Reports uses of `Sysvar::from_account_info` instead of `Sysvar::get` |
| [`type_cosplay`](lints/type_cosplay) | lint for [3-type-cosplay](https://github.com/coral-xyz/sealevel-attacks/tree/master/programs/3-type-cosplay) |

## Usage
Expand Down
6 changes: 5 additions & 1 deletion crate/diffs/missing_signer_check.diff
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/missing_signer_che
> #[allow(dead_code)]
> fn main() {}
Only in ../../../../lints/missing_signer_check/ui/insecure/src: lib.stderr
Only in ../../../../lints/missing_signer_check/ui: insecure-non-anchor
diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/missing_signer_check/ui/recommended/Cargo.toml
19c19,21
< anchor-lang = "0.20.0"
Expand All @@ -40,8 +41,11 @@ diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/missing_signer_check
diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/missing_signer_check/ui/secure/src/lib.rs
1a2
> use anchor_lang::solana_program::entrypoint::ProgramResult;
21a23,25
21a23,27
>
> // This is a false positive as the lint does not check for `is_signer` checks if the
> // program is an anchor program. The lint should be updated to remove the false positive.
> #[allow(dead_code)]
> fn main() {}
Only in ../../../../lints/missing_signer_check/ui/secure/src: lib.stderr
Only in ../../../../lints/missing_signer_check/ui: secure-non-anchor
19 changes: 18 additions & 1 deletion crate/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub const ANCHOR_LANG_ACCOUNT: [&str; 4] = ["anchor_lang", "accounts", "account"
pub const ANCHOR_LANG_ACCOUNT_LOADER: [&str; 4] =
["anchor_lang", "accounts", "account_loader", "AccountLoader"];
pub const ANCHOR_LANG_PROGRAM: [&str; 4] = ["anchor_lang", "accounts", "program", "Program"];
pub const ANCHOR_LANG_INTERFACE: [&str; 4] = ["anchor_lang", "accounts", "interface", "Interface"];
pub const ANCHOR_LANG_SYSTEM_ACCOUNT: [&str; 4] =
["anchor_lang", "accounts", "system_account", "SystemAccount"];
pub const ANCHOR_LANG_ACCOUNT_DESERIALIZE: [&str; 2] = ["anchor_lang", "AccountDeserialize"];
Expand All @@ -20,7 +21,11 @@ pub const ANCHOR_LANG_TRY_DESERIALIZE: [&str; 3] =
// key() method call path
pub const ANCHOR_LANG_KEY: [&str; 3] = ["anchor_lang", "Key", "key"];
pub const ANCHOR_LANG_TO_ACCOUNT_INFOS_TRAIT: [&str; 2] = ["anchor_lang", "ToAccountInfos"];

// CpiContext::new()
pub const ANCHOR_CPI_CONTEXT_NEW: [&str; 4] = ["anchor_lang", "context", "CpiContext", "new"];
// CpiContext::new_with_signer()
pub const ANCHOR_CPI_CONTEXT_NEW_SIGNER: [&str; 4] =
["anchor_lang", "context", "CpiContext", "new_with_signer"];
pub const BORSH_TRY_FROM_SLICE: [&str; 4] = ["borsh", "de", "BorshDeserialize", "try_from_slice"];

pub const CORE_BRANCH: [&str; 5] = ["core", "ops", "try_trait", "Try", "branch"];
Expand All @@ -29,6 +34,8 @@ pub const CORE_CLONE: [&str; 4] = ["core", "clone", "Clone", "clone"];
pub const SOLANA_PROGRAM_ACCOUNT_INFO: [&str; 3] =
["solana_program", "account_info", "AccountInfo"];
pub const SOLANA_PROGRAM_INVOKE: [&str; 3] = ["solana_program", "program", "invoke"];
// Instruction {..}
pub const SOLANA_PROGRAM_INSTRUCTION: [&str; 3] = ["solana_program", "instruction", "Instruction"];
pub const SOLANA_PROGRAM_CREATE_PROGRAM_ADDRESS: [&str; 4] = [
"solana_program",
"pubkey",
Expand All @@ -37,3 +44,13 @@ pub const SOLANA_PROGRAM_CREATE_PROGRAM_ADDRESS: [&str; 4] = [
];

pub const SPL_TOKEN_INSTRUCTION: [&str; 2] = ["spl_token", "instruction"];

pub const SYSVAR_FROM_ACCOUNT_INFO: [&str; 4] =
["solana_program", "sysvar", "Sysvar", "from_account_info"];
pub const SYSVAR_CLOCK: [&str; 3] = ["solana_program", "clock", "Clock"];
pub const SYSVAR_EPOCH_REWARDS: [&str; 3] = ["solana_program", "epoch_rewards", "EpochRewards"];
pub const SYSVAR_EPOCH_SCHEDULE: [&str; 3] = ["solana_program", "epoch_schedule", "EpochSchedule"];
pub const SYSVAR_FEES: [&str; 3] = ["solana_program", "fees", "Fees"];
pub const SYSVAR_LAST_RESTART_SLOT: [&str; 3] =
["solana_program", "last_restart_slot", "LastRestartSlot"];
pub const SYSVAR_RENT: [&str; 3] = ["solana_program", "rent", "Rent"];
Loading