Skip to content

bug(forge): Invariant tests broken after recent update #5606

@0xfarhaan

Description

@0xfarhaan

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 (3fec8c1 2023-08-11T00:53:21.210226000Z)

What command(s) is the bug in?

forget test

Operating System

macOS (Apple Silicon)

Describe the bug

With the recent nightly releases our invariant test suite is broken for maple-core-v2 (https://github.com/maple-labs/maple-core-v2)

I've been debugging and found that this nightly release works: https://github.com/foundry-rs/foundry/releases/tag/nightly-ca67d15f4abd46394b324c50e21e66f306a1162d

But the release right after causing the test suite to fail: https://github.com/foundry-rs/foundry/releases/tag/nightly-16208aa91fc65e7a99ef68ba1bc8d4b4f9ac8f62

I started debugging and noticed that the targetContract behavior doesn't seem to be working as expected. We have one target contract that we define which then handles and distributes all the calls for us. But I noticed that other contracts (such as non targeted handlers) are now being called directly (not via the target contract we defined).

Here is an example of how we define our target contract https://github.com/maple-labs/maple-core-v2/blob/3a49435209614ded4c34c4bbd57e2ceb59a1d3e0/tests/invariants/BasicInvariants.t.sol#L81

Here is an example trace below:

Traces:
  [0] DistributionHandler::distributorEntryPoint(115792089237316195423570985008687907853269984665640564039457584007913129639935 [1.157e77])
    ├─ [0] console::log(DH:ENTRY_POINT) [staticcall]
    │   └─  ()
    ├─ [0] 0xe54a55121A47451c5727ADBAF9b9FC1643477e25::a6c4cff2(ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
    │   ├─ [2498] BasicInvariants::currentTimestamp() [staticcall]
    │   │   └─ ← 1685721539 [1.685e9]
    │   ├─ [0] VM::warp(1685721539 [1.685e9])
    │   │   └─  ()
    │   ├─ [0] console::log(handlerBase.entryPoint(%s), 115792089237316195423570985008687907853269984665640564039457584007913129639935 [1.157e77]) [staticcall]
    │   │   └─  ()
    │   ├─ [0] console::log(handlerBase.entryPoint() totalWeight, 100) [staticcall]
    │   │   └─  ()
    │   ├─ [0] 0xe54a55121A47451c5727ADBAF9b9FC1643477e25::deposit(115792089237316195423570985008687907853269984665640564039457584007913129639935 [1.157e77])
    │   │   ├─ [498] BasicInvariants::currentTimestamp() [staticcall]
    │   │   │   └─ ← 1685721539 [1.685e9]
    │   │   ├─ [476672] VM::warp(1685721539 [1.685e9])
    │   │   │   └─  ()
    │   │   ├─ [414811] VM::startPrank(@	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB])
    │   │   │   └─  ()
    │   │   ├─ [0] console::log(lpHandler.deposit(%s), 115792089237316195423570985008687907853269984665640564039457584007913129639935 [1.157e77]) [staticcall]
    │   │   │   └─  ()
    │   │   ├─ [47276] MockERC20::mint(@	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], 39675502443893022040240438 [3.967e25])
    │   │   │   ├─ emit Transfer(owner_: 0x0000000000000000000000000000000000000000, recipient_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], amount_: 39675502443893022040240438 [3.967e25])
    │   │   │   └─  ()
    │   │   ├─ [27377] MockERC20::approve(MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2], 39675502443893022040240438 [3.967e25])
    │   │   │   ├─ emit Approval(owner_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], spender_: MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2], amount_: 39675502443893022040240438 [3.967e25])
    │   │   │   └─ ← true
    │   │   ├─ [139120] MaplePool::deposit(39675502443893022040240438 [3.967e25], @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB])
    │   │   │   ├─ [80550] Proxy::canCall(0x503a6465706f7369740000000000000000000000000000000000000000000000, @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], 0x00000000000000000000000000000000000000000020d19d4c15b391cdf3b1360000000000000000000000004cca5a3bb90ed438e9e5e4ccd2fda4767f8716ab) [staticcall]
    │   │   │   │   ├─ [75524] PoolManager::canCall(0x503a6465706f7369740000000000000000000000000000000000000000000000, @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], 0x00000000000000000000000000000000000000000020d19d4c15b391cdf3b1360000000000000000000000004cca5a3bb90ed438e9e5e4ccd2fda4767f8716ab) [delegatecall]
    │   │   │   │   │   ├─ [2537] PoolManagerFactory::mapleGlobals() [staticcall]
    │   │   │   │   │   │   └─ ← NonTransparentProxy: [0x5991A2dF15A8F6A256D3Ec51E99254Cd3fb576A9]
    │   │   │   │   │   ├─ [10490] NonTransparentProxy::isFunctionPaused(0x7bd243de) [staticcall]
    │   │   │   │   │   │   ├─ [5183] Globals::isFunctionPaused(0x7bd243de) [delegatecall]
    │   │   │   │   │   │   │   └─ ← false
    │   │   │   │   │   │   └─ ← false
    │   │   │   │   │   ├─ [2859] MockERC20::balanceOf(MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2]) [staticcall]
    │   │   │   │   │   │   └─ ← 0
    │   │   │   │   │   ├─ [12356] Proxy::assetsUnderManagement() [staticcall]
    │   │   │   │   │   │   ├─ [7366] FixedTermLoanManager::assetsUnderManagement() [delegatecall]
    │   │   │   │   │   │   │   └─ ← 0
    │   │   │   │   │   │   └─ ← 0
    │   │   │   │   │   ├─ [12321] Proxy::assetsUnderManagement() [staticcall]
    │   │   │   │   │   │   ├─ [7331] OpenTermLoanManager::assetsUnderManagement() [delegatecall]
    │   │   │   │   │   │   │   └─ ← 0
    │   │   │   │   │   │   └─ ← 0
    │   │   │   │   │   └─ ← true,
    │   │   │   │   └─ ← true,
    │   │   │   ├─ emit Transfer(owner_: 0x0000000000000000000000000000000000000000, recipient_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], amount_: 39675502443893022040240438 [3.967e25])
    │   │   │   ├─ emit Deposit(caller_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], owner_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], assets_: 39675502443893022040240438 [3.967e25], shares_: 39675502443893022040240438 [3.967e25])
    │   │   │   ├─ [21527] MockERC20::transferFrom(@	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2], 39675502443893022040240438 [3.967e25])
    │   │   │   │   ├─ emit Approval(owner_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], spender_: MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2], amount_: 0)
    │   │   │   │   ├─ emit Transfer(owner_: @	lp: [0x4CCA5A3bB90ed438E9e5E4cCd2Fda4767F8716aB], recipient_: MaplePool: [0xDfC10BC83D8D74F493F894bC003BE0c4D91c52c2], amount_: 39675502443893022040240438 [3.967e25])
    │   │   │   │   └─ ← true
    │   │   │   └─ ← 39675502443893022040240438 [3.967e25]
    │   │   ├─ [343678] VM::stopPrank()
    │   │   │   └─ ← 0x00000000000000000000000000000000000000000020d19d4c15b391cdf3b136
    │   │   ├─ [67237] BasicInvariants::setCurrentTimestamp(1685721539 [1.685e9])
    │   │   │   └─  ()
    │   │   └─  ()
    │   ├─ [23437] BasicInvariants::setCurrentTimestamp(1685721539 [1.685e9])
    │   │   └─  ()
    │   └─  ()
    └─  ()

  [0] DistributionHandler::distributorEntryPoint(1783337552764758011541237039385682083260693588267778546324578154709 [1.783e66])
    ├─ [0] console::log(DH:ENTRY_POINT) [staticcall]
    │   └─  ()
    ├─ [0] 0x89CA9F4f77B267778EB2eA0Ba1bEAdEe8523af36::a6c4cff2(0000000010ef0daf0348b01a57b8a7d45a23c47b227a653702c9e4e3ff76b8d5)
    │   ├─ [2498] BasicInvariants::currentTimestamp() [staticcall]
    │   │   └─ ← 1685721539 [1.685e9]
    │   ├─ [183384] VM::warp(1685721539 [1.685e9])
    │   │   └─  ()
    │   ├─ [0] console::log(handlerBase.entryPoint(%s), 1783337552764758011541237039385682083260693588267778546324578154709 [1.783e66]) [staticcall]
    │   │   └─  ()
    │   ├─ [0] console::log(handlerBase.entryPoint() totalWeight, 100) [staticcall]
    │   │   └─  ()
    │   ├─ [135805] 0x89CA9F4f77B267778EB2eA0Ba1bEAdEe8523af36::makePayment(1783337552764758011541237039385682083260693588267778546324578154709 [1.783e66])
    │   │   ├─ [498] BasicInvariants::currentTimestamp() [staticcall]
    │   │   │   └─ ← 1685721539 [1.685e9]
    │   │   ├─ [61546] VM::warp(1685721539 [1.685e9])
    │   │   │   └─  ()
    │   │   ├─ [0] console::log(ftlHandler.makePayment(%s), 1783337552764758011541237039385682083260693588267778546324578154709 [1.783e66]) [staticcall]
    │   │   │   └─  ()
    │   │   ├─ [33037] BasicInvariants::setCurrentTimestamp(1685721539 [1.685e9])
    │   │   │   └─  ()
    │   │   └─  ()
    │   ├─ [23437] BasicInvariants::setCurrentTimestamp(1685721539 [1.685e9])
    │   │   └─  ()
    │   └─  ()
    └─  ()

  [42622] 0x89CA9F4f77B267778EB2eA0Ba1bEAdEe8523af36::040eb909(00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000003f1f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000006b56)
    ├─ [0] console::log(handlerBase.setSelectorWeight() Called with weight:, 16159 [1.615e4]) [staticcall]
    │   └─  ()
    └─  ()

  [0] DistributionHandler::distributorEntryPoint(7934)
    ├─ [0] console::log(DH:ENTRY_POINT) [staticcall]
    │   └─  ()
    ├─ [46487] 0x89CA9F4f77B267778EB2eA0Ba1bEAdEe8523af36::a6c4cff2(0000000000000000000000000000000000000000000000000000000000001efe)
    │   ├─ [2498] BasicInvariants::currentTimestamp() [staticcall]
    │   │   └─ ← 1685721539 [1.685e9]
    │   ├─ [16018] VM::warp(1685721539 [1.685e9])
    │   │   └─ ← "HB:INVALID_WEIGHTS"
    │   ├─ [0] console::log(handlerBase.entryPoint(%s), 7934) [staticcall]
    │   │   └─  ()
    │   ├─ [0] console::log(handlerBase.entryPoint() totalWeight, 16259 [1.625e4]) [staticcall]
    │   │   └─  ()
    │   └─ ← 0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001248423a494e56414c49445f574549474854530000000000000000000000000000
    └─  ()

Test result: FAILED. 0 passed; 1 failed; 0 skipped; finished in 272.79ms
Ran 1 test suites: 0 tests passed, 1 failed, 0 skipped (1 total tests)

Failing tests:
Encountered 1 failing test in tests/invariants/BasicInvariants.t.sol:BasicInvariants
[FAIL. Reason: HB:INVALID_WEIGHTS] statefulFuzz_fixedTermLoanManager_A_basic() (runs: 1, calls: 7, reverts: 1)

The contract 0x89CA9F4f77B267778EB2eA0Ba1bEAdEe8523af36 and function handlerBase.setSelectorWeight() should not be directly called but you can see from the trace that it is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions