BathToken.sol#removeFilledTradeAmount()
can cause a sudden drop in price per share which leads to user's loss when they redeems their shares
#341
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
Lines of code
https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/rubiconPools/BathToken.sol#L294-L303
Vulnerability details
In the current implementation,
underlyingBalance()
isIERC20(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()
, theoutstandingAmount
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
= DAIBathTokenA.totalSupply
= 10,000 * 1e18BathTokenA
= 10,000 DAIBathTokenA
Pool, got10,000 * 1e18
sharesBathTokenA
= 20,000 DAIplaceMarketMakingTrades
on Pair, placed a offer:pay_amt
= 1,000 * 1e18,buy_gem
= USDC,buy_amt
= 1,000 * 1e6BathTokenA
= 19,000 DAIoutstandingAmount
= 1,000 * 1e181,000 * 1e6
USDC toBathTokenA
contract:BathTokenA
= 19,000 DAIBathTokenA
= 1,000 USDCoutstandingAmount
= 1,000 * 1e18scrubStrategistTrades()
on PairBathTokenA
= 19,000 DAIBathTokenA
= 1,000 USDCoutstandingAmount
= 0Recommendation
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().
The text was updated successfully, but these errors were encountered: