diff --git a/foundry.toml b/foundry.toml index fdb2aa0f..bd346497 100644 --- a/foundry.toml +++ b/foundry.toml @@ -26,7 +26,7 @@ src = 'src/interfaces/' [fuzz] runs = 1000 -max_test_rejects = 20_000_000 +max_test_rejects = 1000000 [rpc_endpoints] mainnet = "${MAINNET_RPC}" diff --git a/src/contracts/BPool.sol b/src/contracts/BPool.sol index e7f282e1..33aa0e13 100644 --- a/src/contracts/BPool.sol +++ b/src/contracts/BPool.sol @@ -335,8 +335,7 @@ contract BPool is BBronze, BToken, BMath { spotPriceAfter = calcSpotPrice(inRecord.balance, inRecord.denorm, outRecord.balance, outRecord.denorm, _swapFee); require(spotPriceAfter >= spotPriceBefore, 'ERR_MATH_APPROX'); require(spotPriceAfter <= maxPrice, 'ERR_LIMIT_PRICE'); - // TODO: re-enable when fuzzing is complete - // require(spotPriceBefore <= bdiv(tokenAmountIn, tokenAmountOut), 'ERR_MATH_APPROX'); + require(spotPriceBefore <= bdiv(tokenAmountIn, tokenAmountOut), 'ERR_MATH_APPROX'); emit LOG_SWAP(msg.sender, tokenIn, tokenOut, tokenAmountIn, tokenAmountOut); diff --git a/test/unit/BPool.t.sol b/test/unit/BPool.t.sol index 99b91357..10e3342e 100644 --- a/test/unit/BPool.t.sol +++ b/test/unit/BPool.t.sol @@ -7,7 +7,7 @@ import {MockBPool} from 'test/smock/MockBPool.sol'; import {BConst} from 'contracts/BConst.sol'; import {BMath} from 'contracts/BMath.sol'; import {IERC20} from 'contracts/BToken.sol'; -import {Test, console} from 'forge-std/Test.sol'; +import {Test} from 'forge-std/Test.sol'; import {LibString} from 'solmate/utils/LibString.sol'; import {Utils} from 'test/unit/Utils.sol'; @@ -552,11 +552,9 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath { } function _assumeHappyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) internal view { - // weights - vm.assume(_fuzz.tokenInDenorm >= MIN_WEIGHT); - vm.assume(_fuzz.tokenInDenorm <= MAX_WEIGHT); - vm.assume(_fuzz.tokenOutDenorm >= MIN_WEIGHT); - vm.assume(_fuzz.tokenOutDenorm <= MAX_WEIGHT); + // safe bound assumptions + _fuzz.tokenInDenorm = bound(_fuzz.tokenInDenorm, MIN_WEIGHT, MAX_WEIGHT); + _fuzz.tokenOutDenorm = bound(_fuzz.tokenOutDenorm, MIN_WEIGHT, MAX_WEIGHT); // min vm.assume(_fuzz.tokenInBalance >= MIN_BALANCE); @@ -574,13 +572,13 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath { vm.assume(_ratio < type(uint256).max / _scale); // MAX_IN_RATIO - // vm.assume(_fuzz.tokenInBalance < type(uint256).max / MAX_IN_RATIO); vm.assume(_fuzz.tokenAmountIn <= bmul(_fuzz.tokenInBalance, MAX_IN_RATIO)); - // uint _spotPriceBefore = calcSpotPrice(_fuzz.tokenInBalance, _fuzz.tokenInDenorm, _fuzz.tokenOutBalance, _fuzz.tokenOutDenorm, MIN_FEE); - // uint _tokenAmountOut = calcOutGivenIn(_fuzz.tokenInBalance, _fuzz.tokenInDenorm, _fuzz.tokenOutBalance, _fuzz.tokenOutDenorm, _fuzz.tokenAmountIn, MIN_FEE); - // vm.assume(_tokenAmountOut > 0); - // vm.assume(_spotPriceBefore <= bdiv(_fuzz.tokenAmountIn, _tokenAmountOut)); + // L338 BPool.sol + uint _spotPriceBefore = calcSpotPrice(_fuzz.tokenInBalance, _fuzz.tokenInDenorm, _fuzz.tokenOutBalance, _fuzz.tokenOutDenorm, MIN_FEE); + uint _tokenAmountOut = calcOutGivenIn(_fuzz.tokenInBalance, _fuzz.tokenInDenorm, _fuzz.tokenOutBalance, _fuzz.tokenOutDenorm, _fuzz.tokenAmountIn, MIN_FEE); + vm.assume(_tokenAmountOut > BONE); + vm.assume(bmul(_spotPriceBefore, _tokenAmountOut) <= _fuzz.tokenAmountIn); } modifier happyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) {