-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Component
Forge
Describe the feature you would like
Feature Request
Allow the usage of targetContract(address(this)); for Invariant Testing
Example
Allow:
contract CryticToFoundry is Test, TargetFunctions, FoundryAsserts {
function setUp() public {
setup();
targetContract(address(this));
}to work
Example Repro: https://github.com/GalloDaSballo/foundry-targetContract-repro
Context
An extremely common way of writing invariant tests uses Target Function, explicit functions that tell the fuzzer how to explore state
Source:
https://github.com/Recon-Fuzz/create-chimera-app (Recon)
https://github.com/perimetersec/arachne (PerimeterSec)
https://github.com/euler-xyz/euler-vault-kit/tree/master/src (Enigma Dark)
https://github.com/CodeHawks-Contests/2025-02-gamma/blob/main/test/fuzzing/echidna/CryticToFoundry.sol (Guardian Audits)
As it stands targetFunctions doesn't allow passing address(this)
This prevents these testing suites from being easily reusable with Foundry
Current logs:
Encountered 2 failing tests in test/recon/CryticToFoundry.sol:CryticToFoundry
[FAIL: failed to set up invariant testing environment: No contracts to fuzz.] invariant_count_never_gt_0() (runs: 0, calls: 0, reverts: 0)
[FAIL: failed to set up invariant testing environment: No contracts to fuzz.] invariant_number_never_zero() (runs: 0, calls: 0, reverts: 0)Request
Allow us to pass targetContract(address(this)); which will allow us to use the same suite with no changes
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status