Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bmarcot opened this issue Nov 9, 2022 · 8 comments

Comments

@bmarcot
Copy link

bmarcot commented Nov 9, 2022

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 bmarcot changed the title maxDeposit() is implemented with a upper bound, test fails with "The vm.assume cheatcode rejected too many inputs" maxDeposit() implements a upper bound: test fails with "The vm.assume cheatcode rejected too many inputs" Nov 9, 2022
@daejunpark
Copy link
Collaborator

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.

@Tunji17
Copy link

Tunji17 commented May 18, 2023

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

@daejunpark
Copy link
Collaborator

@Tunji17 would you mind providing reproduction examples for that?

@Tunji17
Copy link

Tunji17 commented May 19, 2023

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

@0xmonsoon
Copy link

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

@Tunji17
Copy link

Tunji17 commented Jun 8, 2023

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

@0xdcota
Copy link

0xdcota commented Jun 25, 2023

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

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

@Namaskar-1F64F
Copy link

SAME ISSUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants