Skip to content
Business logic Audit finding Intermediate

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.

  1. Let’s assume there is one user Bob in the market for simplicity.
  2. Bob transferred 100 amounts of collateral and got 100 long/short tokens. The market has 100 collateral.
  3. The market admin set finalLongPayout = 60 * 1e16 and Bob redeemed 100 longToken and received 60 collateral. The market has 40 collateral now.
  4. After that, the admin realized finalLongPayout is too high and changed finalLongPayout = 40 * 1e16 again.
  5. Bob tries to redeem 100 shortToken and receive 60 collateral but the market can’t offer as it has 40 collateral only.

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


The original report as published on Code4rena, by hansfriese. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. A user deposits collateral and receives an equal number of long and short tokens.
  2. The admin sets the final long payout to a value below the maximum, ending the market.
  3. The user redeems long tokens and receives collateral based on that payout.
  4. The admin sets the final long payout again to a lower value.
  5. 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.

More by hansfriese

View all

65 more disclosed reports, best first.

More from prePO contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.