Skip to content
Audit finding Intermediate

Market Price Lower Than Expected

The market price calculation in one function rounded down instead of up, contrary to the whitepaper, causing makers to sell tokens at a lower price than expected. This also led to a higher payout and lower total debt, further reducing future market prices.

xiaoming90 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-11-bond-judging/issues/20

Found by

xiaoming90

Summary

The market price does not conform to the specification documented within the whitepaper. As a result, the computed market price is lower than expected.

Vulnerability Detail

The following definition of the market price is taken from the whitepaper. Taken from Page 13 of the whitepaper - Definition 25

The integer implementation of the market price must be rounded up per the whitepaper. This ensures that the integer implementation of the market price is greater than or equal to the real value of the market price so as to protect makers from selling tokens at a lower price than expected.

Within the BondBaseSDA.marketPrice function, the computation of the market price is rounded up in Line 688, which conforms to the specification.

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L687

Solidity
File: BondBaseSDA.sol
687:     function marketPrice(uint256 id_) public view override returns (uint256) {
688:         uint256 price = currentControlVariable(id_).mulDivUp(currentDebt(id_), markets[id_].scale);
689: 
690:         return (price > markets[id_].minPrice) ? price : markets[id_].minPrice;
691:     }

However, within the BondBaseSDA._currentMarketPrice function, the market price is rounded down, resulting in the makers selling tokens at a lower price than expected.

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L631

Solidity
File: BondBaseSDA.sol
631:     function _currentMarketPrice(uint256 id_) internal view returns (uint256) {
632:         BondMarket memory market = markets[id_];
633:         return terms[id_].controlVariable.mulDiv(market.totalDebt, market.scale);
634:     }

Impact

Loss for the makers as their tokens are sold at a lower price than expected.

Additionally, the affected BondBaseSDA._currentMarketPrice function is used within the BondBaseSDA._decayAndGetPrice function to derive the market price. Since a lower market price will be returned, this will lead to a higher amount of payout tokens. Subsequently, the lastDecayIncrement will be higher than expected, which will lead to a lower totalDebt. Lower debt means a lower market price will be computed later.

Code Snippet

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L687

https://github.com/sherlock-audit/2022-11-bond/blob/main/src/bases/BondBaseSDA.sol#L631

Tool used

Manual Review

Recommendation

Ensure the market price is rounded up so that the desired property can be achieved and the makers will not be selling tokens at a lower price than expected.

Diff
function _currentMarketPrice(uint256 id_) internal view returns (uint256) {
    BondMarket memory market = markets[id_];
-   return terms[id_].controlVariable.mulDiv(market.totalDebt, market.scale);
+   return terms[id_].controlVariable.mulDivUp(market.totalDebt, market.scale);
}

Discussion

Evert0x

Message from sponsor


Agree with this issue. We have updated the price calculation in _currentMarketPrice() to round up to match the specification.

xiaoming9090

Fixed in https://github.com/Bond-Protocol/bonds/commit/a77f0150dd4bf401a1b30c16eca4865bb69c59d3

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.

How it worked

Root cause

Likely the use of a rounding-down division function instead of a rounding-up one in the market price calculation.

Impact

Makers could lose funds because tokens are sold at a lower price, and the error compounds over time, further lowering prices.

What the attacker needed

None

The fix

The price calculation was updated to round up, matching the specification.

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 a smart contract calculates a price, it must round the result in a specific direction to be fair. Here, one function rounded down instead of up, so sellers received less money than they should have. This is a rounding error that can cause financial loss.

More by xiaoming90

View all

122 more disclosed reports, best first.

More from Bond Options

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.