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

BathToken.sol#removeFilledTradeAmount() can cause a sudden drop in price per share which leads to user's loss when they redeems their shares #341

Closed
code423n4 opened this issue May 28, 2022 · 1 comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L294-L303

Vulnerability details

function removeFilledTradeAmount(uint256 amt) external onlyPair {
    outstandingAmount = outstandingAmount.sub(amt);
    emit LogRemoveFilledTradeAmount(
        IERC20(underlyingToken),
        amt,
        underlyingBalance(),
        outstandingAmount,
        totalSupply
    );
}

In the current implementation, underlyingBalance() is IERC20(underlyingToken).balanceOf(address(this)) + outstandingAmount.

However, when an order is fulfilled or partially fulfilled, the buy_gem (non-underlyingToken assets) will send to this BathToken contract.

When the strategist calls BathPair.sol#scrubStrategistTrades() -> BathToken.sol#removeFilledTradeAmount(), the outstandingAmount will be reduced, thus suddenly decreases the price per share for this BathToken.

If a user redeems the shares now, they will suffer an unfair loss of value.

PoC

Given:

  • BathTokenA = DAI
  • BathTokenA.totalSupply = 10,000 * 1e18
  • DAI balanceOf BathTokenA = 10,000 DAI
  1. Alice deposited 10,000 DAI to BathTokenA Pool, got 10,000 * 1e18 shares
  • DAI balanceOf BathTokenA = 20,000 DAI
  1. Strategist called placeMarketMakingTrades on Pair, placed a offer: pay_amt = 1,000 * 1e18, buy_gem = USDC, buy_amt = 1,000 * 1e6
  • DAI balanceOf BathTokenA = 19,000 DAI
  • outstandingAmount = 1,000 * 1e18
  1. Someone took the offer, sent 1,000 * 1e6 USDC to BathTokenA contract:
  • DAI balanceOf BathTokenA = 19,000 DAI
  • USDC balanceOf BathTokenA = 1,000 USDC
  • outstandingAmount = 1,000 * 1e18
  1. Strategist called scrubStrategistTrades() on Pair
  • DAI balanceOf BathTokenA = 19,000 DAI
  • USDC balanceOf BathTokenA = 1,000 USDC
  • outstandingAmount = 0
  1. Alice redeemed all shares, got 95,000 DAI back.

Recommendation

Consider adding a new variable to track rebalancingAmount on BathToken.

BathToken should be notified for any pending rebalancing amount changes via BathPair in order to avoid sudden surge of pricePerShare over rebalancePair().

rebalancingAmount should be considered as part of underlyingBalance().

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels May 28, 2022
code423n4 added a commit that referenced this issue May 28, 2022
@bghughes bghughes added the duplicate This issue or pull request already exists label Jun 3, 2022
@bghughes
Copy link
Collaborator

bghughes commented Jun 3, 2022

Duplicate of #337 #113 #221 #210

@bghughes bghughes closed this as completed Jun 3, 2022
@HickupHH3 HickupHH3 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants