Skip to content
Business logic Audit finding Intermediate

Users do not receive owed tokens if TokenSender contract cannot cover their owed amount.

The TokenSender contract silently skips sending owed output tokens when its balance is insufficient, leaving users without compensation for fees. An attacker could drain the contract's balance before a victim's redemption, causing the victim to lose the expected rebate.

trustindistrust Follow with Trust, fs0c and 2 others

Originally disclosed on Code4rena

Submitted by trustindistrust, also found by Trust, fs0c, imare, and chaduke ​

The TokenSender.send() method is called during the course of users withdrawing or redeeming tokens from the protocol. The method is called via DepositHook.hook(), RedeemHook.hook(), and WithdrawHook.hook(). These in turn are called in prePOMarket.redeem() or Collateral.deposit()|.withdraw() ​ TokenSender.send() contains some logic to return early without sending any of the “outputToken”, such as if the price of the outputToken has fallen below an adjustable lower bound, or if the amount would be 0. ​ However, it also checks its own balance to see if it can cover the required amount. If it cannot, it simply doesn’t send tokens. These tokens are intended to be a compensation for fees paid elsewhere in the process, and thus do represent a value loss. ​

function send(address recipient, uint256 unconvertedAmount) external override onlyAllowedMsgSenders {
    uint256 scaledPrice = (_price.get() * _priceMultiplier) / MULTIPLIER_DENOMINATOR;
    if (scaledPrice <= _scaledPriceLowerBound) return;
    uint256 outputAmount = (unconvertedAmount * _outputTokenDecimalsFactor) / scaledPrice;
    if (outputAmount == 0) return;
    if (outputAmount > _outputToken.balanceOf(address(this))) return; // don't send if not enough balance
    _outputToken.transfer(recipient, outputAmount);
}

​ The documentation in ITokenSender.sol states this is so the protocol doesn’t halt the redeem and deposit/withdraw actions.

Impact

The warden agrees that the protocol halting is generally undesirable.

​However, there isn’t any facility in the code for the user who triggered the overage amount to be able to later receive their tokens when the contract is topped up. They must rely upon governance to send them any owed tokens. This increases centralization risks and isn’t necessary. ​

Since the contract makes no attempt to track the tokens that should have been sent, manually reviewing and verifying owed tokens becomes a non-trivial task if any more than a handful of users were affected. ​

Since the user did receive their underlying collateral in any case and the loss isn’t necessarily permanent, medium seems to be the right severity for this issue.

Proof of Concept

​ Bob wants to redeem his long and short tokens via PrePOMarket.redeem(). However, Alice’s redemption prior to his, significantly drained the TokenSender contract of its tokens. As a result, Bob’s redemption fails to benefit him in the amount of the outputToken he should have received in compensation for the fees paid.

Because the quantity of tokens paid to Bob is partially dependent upon the token’s price at the time of redemption, the protocol might shoulder more downside loss (token price dropped compared to when Bob redeemed, must pay out more tokens) or Bob might suffer upside loss (price went up compared to time of redemption, Bob loses the difference). ​

Bob’s recourse is to contact the project administrators and try to have his tokens sent to him manually. Agreeing to a value adds friction to the process.

Recommended Mitigation Steps

​ The TokenSender contract should track users whose balance wasn’t covered in a mapping, as well as a function for them to manually claim tokens later on if the contract’s balance is topped up.

Such a function might record the price at redemption time, or it might calculate it with the current price.

Picodes (judge) commented:

In my understanding, if the refunds are all used, they aren’t owed anything and pay the regular fees. The design seems to be that there is a way to give temporary discounts or fee refunds but it is not mandatory.

ramenforbreakfast (prePO) disagreed with severity and commented:

I believe this issue is a duplicate of #311, although this one is more fleshed out and would consider as the primary issue. I agree with lowering this to QA since there is no expectation of rewards, and the frontend would be able to reliably inform the user whether they would receive a rebate, nothing is being misrepresented on-chain. Token rewards are only a possible incentive, not an owed liability, to users.

Picodes (judge) commented:

The front-end cannot properly mitigate the possibility of front running and someone taking all the available rebates before a user transaction. Therefore, in my opinion, due to the lack of safety checks, Medium severity is appropriate as a user could think he’d receive a rebate but won’t receive it.


The original report as published on Code4rena, by trustindistrust. 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

The TokenSender contract does not track or queue owed tokens when its balance is insufficient, so users have no way to claim them later.

Impact

Users may not receive the output tokens they are owed as compensation for fees, and must rely on governance to send them manually; the loss is not necessarily permanent.

What the attacker needed

TokenSender balance insufficient; User redeems or withdraws tokens

The fix

The TokenSender contract should track users whose balance wasn’t covered in a mapping and provide a function for them to manually claim tokens later if the contract is topped up.

How it was found

  1. Alice redeems her tokens, draining the TokenSender contract's balance.
  2. Bob then redeems his tokens via PrePOMarket.redeem().
  3. TokenSender.send() checks its balance, finds it insufficient, and returns without sending Bob's owed output tokens.

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 users withdraw or redeem tokens, the protocol sometimes gives them extra tokens as a fee rebate. If the contract that sends these rebates runs out of tokens, it just skips the payment without telling anyone. A user who expected a rebate might get nothing, and there is no automatic way for them to claim it later.

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 trustindistrust

View all

1 more disclosed report, 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.