Skip to content

feat: Integrate with Foundry test suite to correlate findings with failing tests #12

Description

@Nanle-code

Overview

Foundry is the dominant smart contract development framework. Teams using Foundry already have test suites that exercise their contracts. ChainProof can provide significantly more value by correlating its static findings with existing Foundry tests — identifying which findings already have test coverage, which are untested, and even suggesting test scaffolds for unexercised vulnerability patterns.

Proposed Integration

Phase 1: Test Coverage Correlation

  1. Run forge coverage --report lcov to generate LCOV coverage data
  2. Parse the LCOV file to determine which lines are covered
  3. For each ChainProof finding, check if the flagged line is covered by existing tests
  4. Add testCoverage: boolean field to Finding — if true, a test exercises this code path (but may not assert the vulnerability)

Phase 2: Foundry Test Scaffolding

For findings with no test coverage, generate a Foundry test stub:

// Auto-generated by ChainProof — test stub for CP-107 finding at Vault.sol:42
contract VaultReentrancyTest is Test {
    Vault vault;
    AttackContract attacker;

    function setUp() public {
        vault = new Vault();
        attacker = new AttackContract(address(vault));
    }

    function test_reentrancy_withdraw_line42() public {
        // TODO: Fund vault and attacker, then call attacker.attack()
        // ChainProof detected: external call before state update in withdraw()
        vm.expectRevert(); // placeholder — fill in actual assertion
        attacker.attack();
    }
}

Phase 3: Foundry Invariant Test Hints

For CP-101 (overflow) findings, suggest property-based invariant test functions using Foundry's vm.assume and assertLe patterns.

CLI Integration

# Run scan and correlate with Foundry coverage
chainproof scan contracts/ --foundry --coverage-report lcov.info

# Generate test stubs for uncovered findings
chainproof scan contracts/ --generate-tests test/chainproof/

Acceptance Criteria

  • LCOV parser in packages/core/src/integrations/lcov.ts
  • testCoverage: boolean field added to Finding
  • Coverage correlation displayed in Markdown report and terminal table
  • Test stub generator for CP-107, CP-101, CP-115, CP-116 findings
  • --foundry CLI flag that auto-detects and runs forge coverage
  • --generate-tests <dir> CLI flag that writes stubs
  • Generated test files are valid Solidity that compile with Foundry

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions