Attacker can front-run Bond buyer and make them buy it for a lower payout than expected
The MuteBond contract increases epochStart after each purchase, which lowers the bond price for subsequent buyers. An attacker can front-run a victim's deposit by making small purchases, causing the victim to receive a lower payout than expected.
Submitted by 0xA5DF, also found by HollaDieWaldfee (1, 2) and chaduke (1, 2, 3)
The MuteBond contract contains a feature in which after each purchase the epochStart increases by 5% of the time passed since epochStart, this (in most cases) lowers the bond’s price (i.e. buyer gets less payout) for future purchases.
An attacker can exploit this feature to front-run a deposit/purchase tx and lower the victim’s payout.
This can also happen by innocent users purchasing before the victim’s tx is included in the blockchain.
Another (less likely) scenario in which this can happen is when the owner changes the config in a way that lowers the price (e.g. lowering max price, extending epoch duration), if the owner tx executes while a user’s deposit() tx is in the mempool the user would end up with less payout than intended.
Side note: the term ‘bond price’ might be confusing since it refers to the payout the buyer gets divided by the value the buyer pays, so a higher price is actually in favor of the buyer.
Impact
User ends up buying bond for a lower payout than intended.
Proof of Concept
In the PoC below, an attacker manages to make the buyer purchase a bond at a price lower by 32% than intended.
File: test/bonds.ts
it('Front run PoC', async function () {
// let price reach the max price
await time.increase(60 * 60 * 24 * 7)
// price when victim sends out the tx to the mempool
var expectedPrice = await bondContract.bondPrice()
const startPrice = new BigNumber(100).times(Math.pow(10,18))
let minPurchasePayout = new BigNumber(Math.pow(10,16));
// using dynamic price didn't work out so I'm using the lowest price
var minPurchaseValue = minPurchasePayout.times(1e18).div(startPrice).plus(1);
// attacker buys the lowest amount 20 times
for(let i = 0; i< 20; i++){
await bondContract.connect(buyer1).deposit(minPurchaseValue.toFixed(), buyer1.address, false)
}
var init_dmute = await dMuteToken.GetUnderlyingTokens(buyer1.address)
let depositValue = new BigNumber(10).times(Math.pow(10,18)).toFixed();
var price = await bondContract.connect(buyer1).deposit(depositValue, buyer1.address, false)
var post_dmute = await dMuteToken.GetUnderlyingTokens(buyer1.address)
var dmute_diff = new BigNumber(post_dmute.toString()).minus(init_dmute.toString());
var actualPrice = dmute_diff.times(1e18).div(depositValue);
var receipt = (await price.wait())
// compare the expected price with the actual price
// expected price = 200; actual price = 135.8; meaning actual price is ~68% of expected price
console.log({expectedPrice, actualPrice:actualPrice.toString()});
})
Recommended Mitigation Steps
Add a min payout parameter so that users can specify the expected payout. The tx should revert if the actual payout is lower than expected.
mattt21 (Mute Switch) confirmed
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 bond price is recalculated based on the time since epochStart, and each purchase increases epochStart, which reduces the price for the next buyer without any slippage protection.
Impact
The victim buys the bond for a lower payout than intended; the proof of concept shows a 32% lower price, but this depends on the attacker's actions and the victim not setting a minimum payout.
What the attacker needed
Attacker can front-run victim's transaction; victim does not set a minimum payout
The fix
Add a minimum payout parameter so users can specify the expected payout and the transaction reverts if the actual payout is lower.
How it was found
- Let the bond price reach its maximum by waiting.
- Attacker makes 20 small deposits to lower the price.
- Victim sends a deposit transaction expecting the original price.
- Victim's transaction executes at the lowered price, receiving less payout.
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 bond is a contract where you pay now and get a payout later. The price of the bond changes after each purchase, so if someone buys just before you, your payout can drop. An attacker can deliberately make small purchases to push the price down before your transaction is processed.
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.