PrePOMarket.setFinalLongPayout() shouldn’t be called twice.
The contract's setFinalLongPayout function could be called more than once, letting an admin change the final payout after users had already redeemed tokens. If the payout was lowered after some redemptions, the market could hold too little collateral to pay remaining token holders.
hansfriese Follow with Trust, unforgiven and 1 other
Originally disclosed on Code4rena
Submitted by hansfriese, also found by Trust, unforgiven, and cccz
If finalLongPayout is changed twice by admin fault, the market would be insolvent as it should pay more collateral than it has.
Proof of Concept
If finalLongPayout is less than MAX_PAYOUT, it means the market is ended and longToken Price = finalLongPayout, shortToken Price = MAX_PAYOUT - finalLongPayout.
So when users redeem their long/short tokens, the total amount of collateral tokens will be the same as the amount that users transferred during mint().
Btw in setFinalLongPayout(), there is no validation that this function can’t be called twice and the below scenario would be possible.
- Let’s assume there is one user
Bobin the market for simplicity. Bobtransferred 100 amounts ofcollateraland got 100 long/short tokens. The market has 100collateral.- The market admin set
finalLongPayout = 60 * 1e16andBobredeemed 100longTokenand received 60collateral. The market has 40collateralnow. - After that, the admin realized
finalLongPayoutis too high and changedfinalLongPayout = 40 * 1e16again. Bobtries to redeem 100shortTokenand receive 60collateralbut the market can’t offer as it has 40collateralonly.
When there are several users in the market, some users can’t redeem their long/short tokens as the market doesn’t have enough collaterals.
Recommended Mitigation Steps
We should modify setFinalLongPayout() like below so it can’t be finalized twice.
function setFinalLongPayout(uint256 _finalLongPayout) external override onlyOwner {
require(finalLongPayout > MAX_PAYOUT, "Finalized already"); //++++++++++++++++++++++++
require(_finalLongPayout >= floorLongPayout, "Payout cannot be below floor");
require(_finalLongPayout <= ceilingLongPayout, "Payout cannot exceed ceiling");
finalLongPayout = _finalLongPayout;
emit FinalLongPayoutSet(_finalLongPayout);
}
ramenforbreakfast (prePO) 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 setFinalLongPayout function lacked a check that the payout had not already been finalised, so the owner could overwrite it after redemptions had begun.
Impact
Some users could be unable to redeem their long or short tokens because the market would not hold enough collateral to pay them.
What the attacker needed
Market owner acts twice; users redeem between the two calls
The fix
The function should be changed so it cannot finalise the payout a second time, for example by requiring that the payout is still above the maximum before setting it.
How it was found
- A user deposits collateral and receives an equal number of long and short tokens.
- The admin sets the final long payout to a value below the maximum, ending the market.
- The user redeems long tokens and receives collateral based on that payout.
- The admin sets the final long payout again to a lower value.
- The user tries to redeem short tokens but the market lacks enough collateral to pay.
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 market contract lets people deposit collateral and receive two kinds of tokens, long and short. When the market ends, an admin sets a final payout value that decides how much collateral each token is worth. The bug is that this value could be set again after people had already cashed out, so the money left in the contract no longer matched what the remaining tokens were promised.
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.