Funds are locked because borrowFee is not correctly implemented in BigBang
The BigBang market adds a borrow opening fee to the user's debt but only mints the borrowed amount, so the user owes more than exists in total supply. As a result, users cannot fully repay and their collateral remains locked.
0x007 Follow with Koolex, 0xrugpull_detector and 2 others
Originally disclosed on Code4rena
Submitted by 0x007, also found by Koolex, 0xrugpull_detector, 0xnev, and SaeedAlipoor01988
There’s borrowOpeningFee for markets. In Singularity, this fee is accumulated over assets as a reward to asset depositors. In BigBang, assets is USD0 which would be minted and burned on borrow, and repay respectively. BigBang does not collect fees, because it uses the same mechanism as Singularity and therefore it would demand more than minted amount from user when it’s time to repay.
This results in a bird and egg situation where Users can’t fully repay a borrowed amount unless they borrow even more.
Proof of Concept
Let’s look at how borrow works
function _borrow(
address from,
address to,
uint256 amount
) internal returns (uint256 part, uint256 share) {
uint256 feeAmount = (amount * borrowOpeningFee) / FEE_PRECISION; // A flat % fee is charged for any borrow
(totalBorrow, part) = totalBorrow.add(amount + feeAmount, true);
require(
totalBorrowCap == 0 || totalBorrow.elastic <= totalBorrowCap,
"BigBang: borrow cap reached"
);
userBorrowPart[from] += part;
//mint USDO
IUSDOBase(address(asset)).mint(address(this), amount);
//deposit borrowed amount to user
asset.approve(address(yieldBox), amount);
yieldBox.depositAsset(assetId, address(this), to, amount, 0);
share = yieldBox.toShare(assetId, amount, false);
emit LogBorrow(from, to, amount, feeAmount, part);
}
As can be seen above, amount would be minted to user, but the userBorrowPart is amount + fee. When it’s time to repay, user have to return amount + fee in other to get all their collateral.
Assuming the user borrowed 1,000 USD0 and borrowOpeningFee is at the default value of 0.5%. Then the user’s debt would be 1,005. If there’s only 1 user, and the totalSupply is indeed 1,000, then there’s no other way for the user to get the extra 5 USD0. Therefore he can’t fully redeem his collateral and would have at least 5 * (1 + collateralizationRate) USD0 worth of collateral locked up. This fund cannot be accessed by the user, nor is it used by the protocol. It would be sitting at yieldbox forever earning yields for no one.
This issue becomes more significant when there are more users and minted amount. If more amount is minted more funds are locked.
It might seem like user Alice could go to the market to buy 5 USD0 to fully repay. But the reality is that he is transferring the unfortunate disaster to another user. Cause no matter what, Owed debts would always be higher than totalSupply.
This debt would keep accumulating after each mint and every burn. For example, assuming that one 1 billion of USD0 was minted and 990 million was burned in the first month. totalSupply and hence circulating supply would be 10 million, but user debts would be 15 million USD0. That’s 5 million USD that can’t be accessed by user nor fee collector.
Recommended Mitigation Steps
borrowOpeningFee should not be added to userBorrowPart. If fee is to implemented, then fee collector should receive collateral or USD0 token.
0xRektora (Tapioca) confirmed via duplicate issue 739
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The borrow function adds the opening fee to the user's debt without minting the corresponding fee amount, creating a permanent shortfall between total debt and total supply.
Impact
Users cannot fully repay their debt and their collateral remains locked in the yield box, with the locked amount growing as more is borrowed and repaid.
What the attacker needed
A BigBang market with a non-zero borrow opening fee; A user borrows from the market
The fix
The borrow opening fee should not be added to the user's debt; if a fee is to be charged, the fee collector should receive collateral or USD0 tokens instead.
How it was found
- User borrows an amount from the BigBang market.
- The contract calculates a fee and adds amount plus fee to the user's debt.
- The contract mints only the borrowed amount to the user.
- When repaying, the user must return the borrowed amount plus the fee to recover collateral.
- Because the fee was never minted, the user cannot obtain enough tokens to fully repay.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you borrow money, the system records that you owe the borrowed amount plus a fee. But it only creates the borrowed amount, not the extra fee. So you can never get enough of that money to pay back the full debt, and your collateral stays stuck.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.