Existing Circuit Breaker Implementation Allow Faster Taker To Extract Payout Tokens From Market
The circuit breaker only closes the market after a transaction that breaches the maximum debt limit, allowing a taker to purchase more payout tokens than intended. An attacker could exploit a sudden drop in the quote token's value to extract payout tokens at almost no cost, up to the maximum payout limit.
hansfriese Follow with xiaoming90
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-11-bond-judging/issues/21
Found by
hansfriese, xiaoming90
Summary
The current implementation of the circuit breaker is not optimal. Thus, the market maker will lose an excessive amount of payout tokens if a quoted token suddenly loses a large amount of value, even with a circuit breaker in place.
Vulnerability Detail
When the amount of the payout tokens purchased by the taker exceeds the term.maxDebt, the taker is still allowed to carry on with the transaction, and the market will only be closed after the current transaction is completed.
https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L427
File: BondBaseSDA.sol
426: // Circuit breaker. If max debt is breached, the market is closed
427: if (term.maxDebt < market.totalDebt) {
428: _close(id_);
429: } else {
430: // If market will continue, the control variable is tuned to to expend remaining capacity over remaining market duration
431: _tune(id_, currentTime, price);
432: }
Assume that the state of the SDAM at T0 is as follows:
term.maxDebtis 110 (debt buffer = 10%)maxPayoutis 100market.totalDebtis 99
Assume that the quoted token suddenly loses a large amount of value (e.g. stablecoin depeg causing the quote token to drop to almost zero). Bob decided to purchase as many payout tokens as possible before reaching the maxPayout limit to maximize the value he could extract from the market. Assume that Bob is able to purchase 50 bond tokens at T1 before reaching the maxPayout limit. As such, the state of the SDAM at T1 will be as follows:
term.maxDebt= 110maxPayout= 100market.totalDebt= 99 + 50 = 149
In the above scenario, Bob's purchase has already breached the term.maxDebt limit. However, he could still purchase the 50 bond tokens in the current transaction.
Impact
In the event that the price of the quote token falls to almost zero (e.g. 0.0001 dollars), then the fastest taker will be able to extract as many payout tokens as possible before reaching the maxPayout limit from the market. The extracted payout tokens are essentially free for the fastest taker. Taker gain is maker loss.
Additionally, in the event that a quoted token suddenly loses a large amount of value, the amount of payout tokens lost by the market marker is capped at the maxPayout limit instead of capping the loss at the term.maxDebt limit. This resulted in the market makers losing more payout tokens than expected, and their payout tokens being sold to the takers at a very low price (e.g. 0.0001 dollars).
The market makers will suffer more loss if the maxPayout limit of their markets is higher.
Code Snippet
https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L427
Tool used
Manual Review
Recommendation
Considering only allowing takers to purchase bond tokens up to the term.maxDebt limit.
For instance, based on the earlier scenario, only allow Bob to purchase up to 11 bond tokens (term.maxDebt[110] - market.totalDebt[99]) instead of allowing him to purchase 50 bond tokens.
If Bob attempts to purchase 50 bond tokens, the market can proceed to purchase the 11 bond tokens for Bob, and the remaining quote tokens can be refunded back to Bob. After that, since the term.maxDebt (110) == market.totalDebt (110), the market can trigger the circuit breaker to close the market to protect the market from potential extreme market conditions.
This ensures that bond tokens beyond the term.maxDebt limit would not be sold to the taker during extreme market conditions.
Discussion
Evert0x
Message from sponsor
We acknowledge that this can be an issue in an edge case, but do not believe it is a High severity issue. Specifically, it requires a quote token to rapidly collapse in value AND a market to be configured with a large maxPayout (i.e. long deposit interval). Additionally, the potential updates (limiting purchase amount, reverting the transaction) have their own issues. Reverting the transaction will leave the market open, allow a retry transaction with a smaller amount, and have the price continue decaying (perhaps allowing additional buys) if the owner doesn't recognize the issue and close the market. Limiting the purchase amount requires a large amount of refactoring and would introduce additional gas costs for the checks required. We do not believe protecting from the edge case warrants the additional costs.
Evert0x
Downgrading to medium because of comment from protocol
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
Impact
The fastest taker could extract payout tokens at almost no cost, and the market maker's loss is capped at the maximum payout limit rather than the maximum debt limit, potentially causing greater losses.
What the attacker needed
Quote token suddenly loses value; market has large maxPayout; attacker can submit transaction quickly
The fix
The protocol should limit purchases to the remaining debt capacity (maxDebt minus totalDebt) and refund any excess, then close the market if the limit is reached.
How it was found
- The market is configured with a maximum debt limit and a maximum payout limit.
- The quote token suddenly loses most of its value.
- A taker purchases as many payout tokens as possible in one transaction.
- The purchase causes total debt to exceed the maximum debt limit, but the transaction still completes.
- The market is closed only after the transaction, allowing the taker to extract payout tokens cheaply.
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.
A market has a safety limit on how much debt it can take. The code checks this limit only after a trade finishes, so a trader can exceed the limit in a single trade. If the token they pay with suddenly becomes worthless, they can buy a lot of the market's tokens very cheaply before the market shuts down.
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.