Skip to content

bug: fuzzer dict does not contain immutables #1168

@mds1

Description

@mds1

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (233ab70 2022-04-01T00:51:18.292928+00:00)

What command(s) is the bug in?

forge test

Operating System

macOS (amd)

Describe the bug

Below is a contract and test that have very little state, so you'd expect both tests to fail relatively quickly because the fuzzer should try using each owner address as input. However, this does not happen, and most of the time these tests pass, whether I use 100 or 100k fuzz runs. I have not yet investigated this, but potential causes:

  1. Values are not actually being added to the dictionary
  2. Values improperly encoded/formatted before being added
  3. All random fuzz inputs (or other useless state, such as nonces, gas used, etc.) are being added to the dictionary, blowing up its size and making it less likely for the owner addresses to be used
pragma solidity 0.8.13;

import "ds-test/test.sol";
import "forge-std/Vm.sol";

contract FuzzerDict {
  // Immutables should get added to the dictionary.
  address public immutable immutableOwner;
  // Regular storage variables should also get added to the dictionary.
  address public storageOwner;

  constructor(address _immutableOwner, address _storageOwner) {
    immutableOwner = _immutableOwner;
    storageOwner = _storageOwner;
  }
}

contract FuzzerDictTest is DSTest {
  FuzzerDict fuzzerDict;
  Vm vm = Vm(HEVM_ADDRESS);

  function setUp() public {
    fuzzerDict = new FuzzerDict(address(100), address(200));
  }

  // Fuzzer should try `fuzzerDict.immutableOwner()` as input, causing this to fail
  function testImmutableOwner(address who) public {
    assertTrue(who != fuzzerDict.immutableOwner());
  }

  // Fuzzer should try `fuzzerDict.storageOwner()` as input, causing this to fail
  function testStorageOwner(address who) public {
    assertTrue(who != fuzzerDict.storageOwner());
  }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions