Skip to content

completed state growth inspector example#217

Open
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
buggythanos:state-growth-inspector-example
Open

completed state growth inspector example#217
buggythanos wants to merge 1 commit intobnb-chain:mainfrom
buggythanos:state-growth-inspector-example

Conversation

@buggythanos
Copy link

@buggythanos buggythanos commented Jan 25, 2026

Description

Adds the State Growth Inspector to the BNBChain Cookbook. The tool analyzes and monitors blockchain state growth on BNB Smart Chain (BSC). It reads contract storage slots, tracks state changes over time, calculates growth rates and trends, and assesses risk levels (LOW, MEDIUM, HIGH). It includes a Web UI and CLI for analyzing contract state, growth over block ranges, and comparing contracts.

state-growth-inspector-example

Motivation: Helps developers, auditors, and researchers identify state bloat, monitor storage usage, optimize contract storage, and detect potential issues with contract state management. Useful for DeFi protocol monitoring and storage optimization.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Unit tests: npm test (Jest). Coverage includes:
    • isEmptySlot - correctly identifies empty vs non-empty storage slots (all zeros detection)
    • getBSCProvider - creates provider with default RPC URL and respects BSC_RPC_URL environment variable
    • Edge case handling for empty strings and various hex formats
  • Build: npm run build (TypeScript compiles without errors)
  • Setup: bash setup.sh (installs dependencies, creates .env from template, builds project, runs tests)
  • Manual testing:
    • Web UI: npm start → open http://localhost:3000 → test three main features:
      • Analyze State: Enter contract address → verify storage slots, code size, storage density display
      • Growth Analysis: Enter contract address, start/end blocks, interval → verify growth rate, trend, risk level calculation
      • Compare Contracts: Enter two contract addresses → verify side-by-side comparison with differences
    • API endpoints: Tested POST /api/analyze, POST /api/growth, and POST /api/compare with various BSC contract addresses (e.g., PancakeSwap Router V2: 0x10ED43C718714eb63d5aA57B78B54704E256024E)
    • CLI: npm start <contract-address> for single snapshot analysis and npm start <contract-address> <start-block> <end-block> for growth analysis over block ranges

Reproduction steps:

  1. Clone repository
  2. Run bash setup.sh (or chmod +x setup.sh && ./setup.sh)
  3. Run npm test to verify all tests pass
  4. Run npm run build to verify TypeScript compilation
  5. Start server: npm start
  6. Open browser to http://localhost:3000 and test with BSC contract addresses
  7. Alternatively, test CLI: npm start <contract-address> [start-block] [end-block]

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@vivixu-cmd
Copy link

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

@buggythanos
Copy link
Author

Congratulations! You have received a Cookbook reward. Please reply with your BSC wallet address.Thanks

Hi there, thank you!
0x4e5d4a29F7b02c8cf1310D112A42231Bde049180

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