erc4626-tests icon indicating copy to clipboard operation
erc4626-tests copied to clipboard

maxDeposit() implements a upper bound: test fails with "The `vm.assume` cheatcode rejected too many inputs"

Open bmarcot opened this issue 3 years ago • 8 comments

We are integrating the property test suite as part of the verification of our vault contracts. Unfortunately all tests are failing with the following error:

Test result: FAILED. 0 passed; 1 failed; finished in 15.18s

Failing tests:
Encountered 1 failing test in contracts/test/ERC4626StdTest.sol:ERC4626StdTest
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxDeposit((address[4],uint256[4],uint256[4],int256)) (runs: 22, μ: 447892, ~: 465089)

Encountered a total of 1 failing tests, 0 tests succeeded

I figured that the problem might be related to the fixed upper boud in the maxDeposit() of the function. The function is implemented to limit the number of assets in the vault. Removing the bound let the test pass, but it does not make sense w.r.t to the contract's logic.

function maxDeposit(address) public view override returns (uint256) {
    if (totalAssets() > MAX_TOTAL_ASSETS) {
        return 0;
    }
    return MAX_TOTAL_ASSETS - IERC20(asset()).balanceOf(address(this));
}

Is it possible to bound the "assets" value in fuzzer? For example, an input of 4888566203988820057829237745407778857278425300380918631855130364758515 does not make sense in our case.

[470198] ERC4626StdTest::test_maxDeposit(([0xabAde514b7e828bD42Cb5272b26F2ebBbDa794F0, 0x5D32577cCD88F4c9D850dAD9D4A28ec7F23D963e, 0x683eF4386bbec40e87bF86e2181193Cf91c495AD, 0xbE411Fe80fd84Fe87F69b5356Bd74f8Ce5276EEf], [22698694737177962168034904413051506502332361420, 4888566203988820057829237745407778857278425300380918631855130364758515, 56852593677044934, 32556299], [2692848953710946714442091, 0, 17461643070425363004, 5566649], 0))

Thanks!

bmarcot avatar Nov 09 '22 08:11 bmarcot

There are multiple options.

  1. You can simply increase the max_test_rejects value, like FOUNDRY_FUZZ_MAX_TEST_REJECTS=1000000 forge test. But this may increase the testing time.

  2. If only the maxDeposit test fails, you can override the test_maxDeposit() function to limit the assets value. For example, this shows how to clamp the fuzz inputs for test_maxWithdraw().

  3. If multiple tests fail due to the similar reason, and you don't want to test the scenarios with large asset balances, then you can override the setUpVault() function to limit the fuzz inputs similarly to the above. But this may exclude some edge case inputs, missing some bugs if any.

daejunpark avatar Nov 11 '22 04:11 daejunpark

@daejunpark I have tried all the suggested options none of them seem to work

Tunji17 avatar May 18 '23 09:05 Tunji17

@Tunji17 would you mind providing reproduction examples for that?

daejunpark avatar May 18 '23 18:05 daejunpark

I was trying to run these tests against a basic solmate implementation of the 4626 vault, I kept getting this error

Running 26 tests for test/Vault.t.sol:ERC4626StdTest
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFail_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFail_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_deposit_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_deposit_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_mint_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_mint_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_redeem_deposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_redeem_mint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_withdraw_deposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_withdraw_mint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_asset((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_convertToAssets((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_convertToShares((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_deposit((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxDeposit((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxMint((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxRedeem((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxWithdraw((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_mint((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewDeposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewMint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewRedeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewWithdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_redeem((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_totalAssets((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_withdraw((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
Test result: FAILED. 0 passed; 26 failed; finished in 11.18s

All the tests are failing out of the box, i have tried increasing FOUNDRY_FUZZ_MAX_TEST_REJECTS like you suggested, tried reducing FOUNDRY_FUZZ_RUNS which also didn’t work, I tried overiding some of the tests and limiting the assets value using the clamp function like you suggested still didn’t pass those tests and lastly i tried overriding the setUpVault and limiting the asset value also with the clamp function that didn’t work also

Tunji17 avatar May 19 '23 05:05 Tunji17

I was trying to run these tests against a basic solmate implementation of the 4626 vault, I kept getting this error

Running 26 tests for test/Vault.t.sol:ERC4626StdTest
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFail_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] testFail_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_deposit_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_deposit_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_mint_redeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_mint_withdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_redeem_deposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_redeem_mint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_withdraw_deposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_RT_withdraw_mint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_asset((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_convertToAssets((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_convertToShares((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_deposit((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxDeposit((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxMint((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxRedeem((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_maxWithdraw((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_mint((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewDeposit((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewMint((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewRedeem((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_previewWithdraw((address[4],uint256[4],uint256[4],int256),uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_redeem((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_totalAssets((address[4],uint256[4],uint256[4],int256)) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: The `vm.assume` cheatcode rejected too many inputs (65536 allowed)] test_withdraw((address[4],uint256[4],uint256[4],int256),uint256,uint256) (runs: 0, μ: 0, ~: 0)
Test result: FAILED. 0 passed; 26 failed; finished in 11.18s

All the tests are failing out of the box, i have tried increasing FOUNDRY_FUZZ_MAX_TEST_REJECTS like you suggested, tried reducing FOUNDRY_FUZZ_RUNS which also didn’t work, I tried overiding some of the tests and limiting the assets value using the clamp function like you suggested still didn’t pass those tests and lastly i tried overriding the setUpVault and limiting the asset value also with the clamp function that didn’t work also

@Tunji17 Were you able to find a solution to the problem? I am facing the same issue. All tests fail due to vm.assume cheatcode rejected too many inputs

0xmonsoon avatar Jun 07 '23 17:06 0xmonsoon

@0xmonsoon No, i gave up and just used the tests provided by solmate, then converted the ones with input to fuzzy tests

Tunji17 avatar Jun 08 '23 07:06 Tunji17

I am having the same problem as @Tunji17 and @0xmonsoon.

> forge --version
forge 0.2.0 (08a629a 2023-06-03T00:04:22.625130135Z)

0xdcota avatar Jun 25 '23 22:06 0xdcota

SAME ISSUE

Namaskar-1F64F avatar Feb 13 '24 05:02 Namaskar-1F64F