Skip to content

feat: add detector for complex struct getters with omitted members#2971

Open
ep0chzer0 wants to merge 1 commit intocrytic:masterfrom
ep0chzer0:feature/struct-getter-omitted-members
Open

feat: add detector for complex struct getters with omitted members#2971
ep0chzer0 wants to merge 1 commit intocrytic:masterfrom
ep0chzer0:feature/struct-getter-omitted-members

Conversation

@ep0chzer0
Copy link
Contributor

Summary

Adds a new informational detector (complex-struct-getter) that identifies public state variables containing structs where the automatic getter omits array and mapping members.

Closes #2779

Problem

Solidity's auto-generated getters for public struct variables silently skip array and mapping members. This can cause confusion about data accessibility and lead to integration issues:

struct UserData {
    string name;           // ✓ Returned by getter
    uint256 balance;       // ✓ Returned by getter
    uint256[] tokenIds;    // ✗ Omitted
    mapping(address => uint256) allowances; // ✗ Omitted
}

UserData public userData; // Getter won't return tokenIds or allowances

Detection Logic

  • Iterates public state variables with struct types
  • Identifies array and mapping members omitted from the getter
  • Recursively checks nested structs for deeply omitted members
  • Handles recursive struct types safely (prevents infinite loops)
  • Reports all omitted members with their types

Test Coverage

7 contracts covering:

  • DirectArrayMapping — struct with both arrays and mappings (flagged)
  • NestedStruct — nested struct containing an array (flagged)
  • MappingOnly — struct with only a mapping (flagged)
  • SimpleStruct — struct with only elementary types (NOT flagged)
  • PrivateComplex — complex struct but internal visibility (NOT flagged)
  • NoStruct — plain state variables, no structs (NOT flagged)
  • NestedSimple — nested struct with only elementary types (NOT flagged)

Files Changed

  • slither/detectors/variables/complex_struct_getter.py — New detector
  • slither/detectors/all_detectors.py — Register detector
  • tests/e2e/detectors/test_detectors.py — Add test entry
  • tests/e2e/detectors/test_data/complex-struct-getter/ — Test contract and artifact
  • tests/e2e/detectors/snapshots/ — Expected output snapshot

All 382 detector tests pass (381 existing + 1 new).

Add a new informational detector that identifies public state variables
containing structs where the automatic getter omits array and mapping
members. Solidity's generated getters skip these types, which may cause
confusion about data accessibility.

The detector:
- Finds public state variables with struct types
- Identifies array and mapping members that are omitted from the getter
- Recursively checks nested structs for deeply omitted members
- Handles recursive struct types safely
- Lists all omitted members with their types

Closes crytic#2779
@ep0chzer0 ep0chzer0 requested a review from smonicas as a code owner February 23, 2026 18:28
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.

Enhancement: Detect Complex Struct Getters with Omitted Members

1 participant