Skip to content

Four checks never adopted the #232 self-scan fix — all walk the raw syn::File instead of contractimpl_functions_excluding_test #375

Description

@unrealtim-tech

Labels: bug, checks-crate
Crate: checks

Description
Closed issue #232 established that checks walking file/contractimpl_functions() without excluding #[cfg(test)] code produce false positives when the checks crate scans its own test fixtures, and fixed the checks affected at the time via crate::util::contractimpl_functions_excluding_test. Four checks added since then never got this treatment — they call visit::visit_file(&mut visitor, file) directly and walk every #[contractimpl] Item::Impl they encounter, test modules included:

  • crates/checks/src/unsafe_randomness.rs:15-19
  • crates/checks/src/unprotected_upgrade.rs:16-19 — its own #[cfg(test)] mod tests block literally contains #[contractimpl] impl C { pub fn upgrade(...) { env.invoke_wasm(...); } } with no auth call, the exact shape this check flags
  • crates/checks/src/unprotected_token_mint.rs:16-19
  • crates/checks/src/unprotected_contract_deployment.rs:16-19

Scanning the soroban-guard-checks crate's own source with these checks active would produce false positives straight out of these files' own unit tests, and any real contract that puts a fixture/mock #[contractimpl] block inside a #[cfg(test)] module will get flagged the same way.

Acceptance Criteria

  • Switch all four checks to use crate::util::contractimpl_functions_excluding_test (or its type-paired sibling) instead of manually walking visit::visit_file.
  • Add a test to each confirming a matching pattern inside a #[cfg(test)] mod tests block produces no finding.

Difficulty: intermediate

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave programbugSomething isn't workingchecks-crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions