Skip to content

Commit

Permalink
fix: improving vague assumption (#55)
Browse files Browse the repository at this point in the history
* fix: improving vague assumption

* fix: bounding totalWeight to its max

* fix: rm min weight in bind method

* fix: totalweight min bound
  • Loading branch information
wei3erHase authored Jun 4, 2024
1 parent 3a6c086 commit 259c898
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/unit/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ abstract contract BasePoolTest is Test, BConst, Utils, BMath {
uint256 _totalSupply
) internal pure {
uint256 _normalizedWeight = bdiv(_tokenInDenorm, _totalWeight);
vm.assume(_normalizedWeight < BONE); // TODO: why this? if the weights are between allowed it should be fine
vm.assume(_normalizedWeight < bdiv(MAX_WEIGHT, MAX_TOTAL_WEIGHT));

uint256 _zaz = bmul(bsub(BONE, _normalizedWeight), _swapFee);
uint256 _tokenAmountInAfterFee = bmul(_tokenAmountIn, bsub(BONE, _zaz));
Expand Down Expand Up @@ -373,7 +373,7 @@ contract BPool_Unit_GetTotalDenormalizedWeight is BasePoolTest {
contract BPool_Unit_GetNormalizedWeight is BasePoolTest {
function test_Returns_NormalizedWeight(address _token, uint256 _weight, uint256 _totalWeight) public {
_weight = bound(_weight, MIN_WEIGHT, MAX_WEIGHT);
_totalWeight = bound(_totalWeight, MIN_WEIGHT, MAX_WEIGHT * MAX_BOUND_TOKENS);
_totalWeight = bound(_totalWeight, MIN_WEIGHT, MAX_TOTAL_WEIGHT);
vm.assume(_weight < _totalWeight);
_setRecord(_token, BPool.Record({bound: true, index: 0, denorm: _weight, balance: 0}));
_setTotalWeight(_totalWeight);
Expand Down Expand Up @@ -672,7 +672,7 @@ contract BPool_Unit_Bind is BasePoolTest {
}

_fuzz.balance = bound(_fuzz.balance, MIN_BALANCE, type(uint256).max);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT, MAX_TOTAL_WEIGHT - MIN_WEIGHT);
_fuzz.totalWeight = bound(_fuzz.totalWeight, 0, MAX_TOTAL_WEIGHT - MIN_WEIGHT);
_fuzz.denorm = bound(_fuzz.denorm, MIN_WEIGHT, MAX_TOTAL_WEIGHT - _fuzz.totalWeight);
}

Expand Down Expand Up @@ -2371,7 +2371,7 @@ contract BPool_Unit_JoinswapExternAmountIn is BasePoolTest {
// safe bound assumptions
_fuzz.tokenInDenorm = bound(_fuzz.tokenInDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_WEIGHT * MAX_BOUND_TOKENS);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);

_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max);
_fuzz.tokenInBalance = bound(_fuzz.tokenInBalance, MIN_BALANCE, type(uint256).max);
Expand Down Expand Up @@ -2551,7 +2551,7 @@ contract BPool_Unit_JoinswapPoolAmountOut is BasePoolTest {
// safe bound assumptions
_fuzz.tokenInDenorm = bound(_fuzz.tokenInDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_WEIGHT * MAX_BOUND_TOKENS);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);

_fuzz.poolAmountOut = bound(_fuzz.poolAmountOut, INIT_POOL_SUPPLY, type(uint256).max - INIT_POOL_SUPPLY);
_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max - _fuzz.poolAmountOut);
Expand Down Expand Up @@ -2636,7 +2636,7 @@ contract BPool_Unit_JoinswapPoolAmountOut is BasePoolTest {
// Replicating _assumeHappyPath, but removing irrelevant assumptions and conditioning the revert
_fuzz.tokenInDenorm = bound(_fuzz.tokenInDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_WEIGHT * MAX_BOUND_TOKENS);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);
_fuzz.tokenInBalance = bound(_fuzz.tokenInBalance, MIN_BALANCE, type(uint256).max / MAX_IN_RATIO);
_fuzz.poolAmountOut = bound(_fuzz.poolAmountOut, INIT_POOL_SUPPLY, type(uint256).max - INIT_POOL_SUPPLY);
_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max - _fuzz.poolAmountOut);
Expand Down Expand Up @@ -2799,7 +2799,7 @@ contract BPool_Unit_ExitswapPoolAmountIn is BasePoolTest {
// safe bound assumptions
_fuzz.tokenOutDenorm = bound(_fuzz.tokenOutDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_WEIGHT * MAX_BOUND_TOKENS);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);
_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max);

// max
Expand Down Expand Up @@ -2881,7 +2881,7 @@ contract BPool_Unit_ExitswapPoolAmountIn is BasePoolTest {
// Replicating _assumeHappyPath, but removing irrelevant assumptions and conditioning the revert
_fuzz.tokenOutDenorm = bound(_fuzz.tokenOutDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_WEIGHT * MAX_BOUND_TOKENS);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);
_fuzz.tokenOutBalance = bound(_fuzz.tokenOutBalance, MIN_BALANCE, type(uint256).max / MAX_OUT_RATIO);
_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max);
vm.assume(_fuzz.totalSupply < type(uint256).max - _fuzz.poolAmountIn);
Expand Down Expand Up @@ -3063,7 +3063,7 @@ contract BPool_Unit_ExitswapExternAmountOut is BasePoolTest {
// safe bound assumptions
_fuzz.tokenOutDenorm = bound(_fuzz.tokenOutDenorm, MIN_WEIGHT, MAX_WEIGHT);
_fuzz.swapFee = bound(_fuzz.swapFee, MIN_FEE, MAX_FEE);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * MAX_BOUND_TOKENS, MAX_TOTAL_WEIGHT);
_fuzz.totalWeight = bound(_fuzz.totalWeight, MIN_WEIGHT * TOKENS_AMOUNT, MAX_TOTAL_WEIGHT);

// min
_fuzz.totalSupply = bound(_fuzz.totalSupply, INIT_POOL_SUPPLY, type(uint256).max);
Expand Down

0 comments on commit 259c898

Please sign in to comment.