"Equilibrium price" is not used to compute the capacity (OSDA Only)
In the OSDA bond market, the capacity calculation for quote-denominated capacity uses the oracle price without applying the base discount, resulting in a smaller-than-expected maximum payout. This can force users to split large purchases into smaller chunks, causing delays and extra gas fees.
However, in OSDA, if the capacity is denominated in the quote token, the capacity will be calculated with the oracle price instead of the discounted price.
Solidity
File: BondBaseOSDA.sol
122: function _createMarket(MarketParams memory params_) internal returns (uint256) {
..SNIP..
182: // Calculate the maximum payout amount for this market, determined by deposit interval
183: uint256 capacity = params_.capacityInQuote
184: ? params_.capacity.mulDiv(scale, price)
185: : params_.capacity;
186: market.maxPayout = capacity.mulDiv(uint256(params_.depositInterval), uint256(length));
In OSDA, it was also observed that the base discount is applied to the oracle price while calculating the price decimals because this will be the initial equilibrium price of the market. However, this "initial equilibrium price" is not used earlier when computing the capacity.
Solidity
File: BondBaseOSDA.sol
210: function _validateOracle(
211: uint256 id_,
212: IBondOracle oracle_,
213: ERC20 quoteToken_,
214: ERC20 payoutToken_,
215: uint48 baseDiscount_
216: )
..SNIP..
251: // Get the price decimals for the current oracle price
252: // Oracle price is in quote tokens per payout token
253: // E.g. if quote token is $10 and payout token is $2000,
254: // then the oracle price is 200 quote tokens per payout token.
255: // If the oracle has 18 decimals, then it would return 200 * 10^18.
256: // In this case, the price decimals would be 2 since 200 = 2 * 10^2.
257: // We apply the base discount to the oracle price before calculating
258: // since this will be the initial equilibrium price of the market.
259: int8 priceDecimals = _getPriceDecimals(
260: currentPrice.mulDivUp(
261: uint256(ONE_HUNDRED_PERCENT - baseDiscount_),
262: uint256(ONE_HUNDRED_PERCENT)
263: ),
264: oracleDecimals
265: );
Impact
As the discount is not applied to the price when computing the capacity, the price will be higher which leads to a smaller capacity. A smaller capacity will in turn result in a smaller max payout. A smaller-than-expected max payout reduces the maximum number of payout tokens a user can purchase at any single point in time, which might reduce the efficiency of a Bond market.
Users who want to purchase a large number of bond tokens have to break their trade into smaller chunks to overcome the smaller-than-expected max payout, leading to unnecessary delay and additional gas fees.
Applied the discount to obtain the "equilibrium price" before computing the capacity.
Diff
// Calculate the maximum payout amount for this market, determined by deposit interval
uint256 capacity = params_.capacityInQuote
- ? params_.capacity.mulDiv(scale, price)
+ ? params_.capacity.mulDiv(scale, price.mulDivUp(
+ uint256(ONE_HUNDRED_PERCENT - params_.baseDiscount),
+ uint256(ONE_HUNDRED_PERCENT)
+ )
+ )
: params_.capacity;
market.maxPayout = capacity.mulDiv(uint256(params_.depositInterval), uint256(length));
Discussion
UsmannK
Escalate for 10 USDC.
This issue should be Medium, not High. The issue identified is that BondBaseOFDA Auctions, in only some cases (if capacityInQuote=true), do not take into account the fixedDiscount parameter when calculating the auction's capacity.
The capacity in these cases may be under-calculated. If there is a situation as:
Payout token: DAI
Quote token: UNI
Exchange rate: 5 UNI : 1 DAI
Fixed discount: 10%
capacityInQuote: true
params_.capacity: 10
Then the final capacity will be calculated as 10/5=2 instead of 10/(4.5)=2.222.
AKA the auction will sell slightly fewer tokens than intended, and end early. This is equivalent to a very minor denial of service and is at best a medium issue by the following criteria, taken from the Sherlock docs:
Medium: There is a viable scenario (even if unlikely) that could cause the protocol to enter a state where a material amount of funds can be lost.
High: This vulnerability would result in a material loss of funds,
If the protocol made this mistake in reverse and actually took slightly extra tokens, it may be closer to a High. But that is not the case. Actually the protocol just sells slightly fewer of the owner's tokens than intended, but sells all of those at the correct price.
sherlock-admin
Escalate for 10 USDC.
This issue should be Medium, not High. The issue identified is that BondBaseOFDA Auctions, in only some cases (if capacityInQuote=true), do not take into account the fixedDiscount parameter when calculating the auction's capacity.
The capacity in these cases may be under-calculated. If there is a situation as:
Payout token: DAI
Quote token: UNI
Exchange rate: 5 UNI : 1 DAI
Fixed discount: 10%
capacityInQuote: true
params_.capacity: 10
Then the final capacity will be calculated as 10/5=2 instead of 10/(4.5)=2.222.
AKA the auction will sell slightly fewer tokens than intended, and end early. This is equivalent to a very minor denial of service and is at best a medium issue by the following criteria, taken from the Sherlock docs:
Medium: There is a viable scenario (even if unlikely) that could cause the protocol to enter a state where a material amount of funds can be lost.
High: This vulnerability would result in a material loss of funds,
If the protocol made this mistake in reverse and actually took slightly extra tokens, it may be closer to a High. But that is not the case. Actually the protocol just sells slightly fewer of the owner's tokens than intended, but sells all of those at the correct price.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
Issue is a valid medium
Given the preconditions and the impact of the incorrect calculation, considering this issue as a valid medium
sherlock-admin
Escalation accepted
Issue is a valid medium
Given the preconditions and the impact of the incorrect calculation, considering this issue as a valid medium
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
The original report as published on Sherlock, by xiaoming90. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely, the capacity calculation in BondBaseOSDA.sol uses the oracle price without applying the base discount, unlike the OFDA implementation which applies the fixed discount.
Impact
The capacity is under-calculated, leading to a smaller max payout, which may reduce market efficiency and force users to split trades, incurring delays and additional gas fees.
What the attacker needed
CapacityInQuote is true; base discount is non-zero
The fix
The discount should be applied to obtain the equilibrium price before computing the capacity; the issue was fixed in a pull request.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A bond market lets users buy tokens at a discount. The market sets a maximum amount it will pay out, based on the price of the token. In one type of market, the code forgot to include the discount when calculating that maximum, so the limit is lower than it should be. This means buyers can't purchase as many tokens at once as intended.
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.