No slippage control when minting and redeeming FPS
The Equity contract allows minting and redeeming FPS without any slippage control, so the price changes with the ZCHF reserve. An attacker can sandwich a user's transaction to profit at the user's expense.
Submitted by cccz, also found by joestakey, joestakey, giovannidisiena, giovannidisiena, santipu_, DishWasher, SolidityATL, KIntern_NA, and ToonVH
When minting and redeeming FPS in Equity, there is no slippage control. Since the price of FPS will change with the zchf reserve in the contract, users may suffer from sandwich attacks.
Consider the current contract has a zchf reserve of 1000 and a total supply of 1000.
Alice considers using 4000 zchf to mint FPS. Under normal circumstances, the contract reserve will rise to 5000 zchf, and the total supply will rise to (5000/1000)**(1/3)*1000 = 1710, that is, alice will get 1710 - 1000 = 710 FPS.
Bob holds 400 FPS, and bob observes alice’s transaction in MemPool, bob uses MEV to preemptively use 4000 zchf to mint 710 FPS.
When alice’s transaction is executed, the contract reserve will increase from 5000 to 9000 zchf, and the total supply will increase from 1710 to (9000/5000)**(1/3)*1710 = 2080, that is, alice gets 2080-1710 = 370FPS.
Then bob will redeem 400 FPS, the total supply will drop from 2080 to 1680, and the contract reserve will drop from 9000 to (1689/2080)**3*9000 = 4742, that is, bob gets 9000-4742 = 4258 zchf.
Bob’s total profit is 310 FPS and 258 zchf.
Proof of Concept
https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Equity.sol#L241-L255 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Equity.sol#L266-L270 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Equity.sol#L275-L282 https://github.com/code-423n4/2023-04-frankencoin/blob/1022cb106919fba963a89205d3b90bf62543f68f/contracts/Equity.sol#L290-L297
Recommended Mitigation Steps
Consider setting minFPSout and minZCHFout parameters to allow slippage control when minting and redeeming FPS
luziusmeisser (Frankencoin) 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 mint and redeem functions lack parameters for minimum output, so users cannot specify a slippage tolerance.
Impact
Users can lose value to sandwich attacks, as shown by Bob profiting 310 FPS and 258 ZCHF at Alice's expense.
What the attacker needed
Attacker can front-run transactions; victim mints or redeems FPS
How it was found
- Bob observes Alice's mint transaction in the mempool.
- Bob front-runs by minting FPS with a large amount of ZCHF.
- Alice's transaction executes at a worse price, giving her fewer FPS.
- Bob redeems his FPS for a profit.
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 you buy or sell a token, the price can change while your transaction waits. Without a limit on how much you accept, someone can jump ahead of you, buy first, and sell after you, making a profit from the price change you caused. This is called a sandwich attack.
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.