Skip to content
Business logic Audit finding Intermediate

Swivel: Taker is charged fees twice in exitVaultFillingVaultInitiate

In the exitVaultFillingVaultInitiate function, the taker is charged a fee twice: the maker transfers less than the full premium to the taker, and the taker is then also charged a fee, so the taker's net balance is the premium minus twice the fee. The maker ends up with a higher balance than expected and the taker cannot recover the extra fees.

itsmeSTYJ Follow

Originally disclosed on Code4rena

Submitted by itsmeSTYJ, also found by gpersoon.

Impact

Taker is charged fees twice in exitVaultFillingVaultInitiate() . Maker is transferring less than premiumFilled to taker and then taker is expected to pay fees i.e. taker’s net balance is premiumFilled - 2*fee

Recommended Mitigation Steps

function exitVaultFillingVaultInitiate(Hash.Order calldata o, uint256 a, Sig.Components calldata c) internal {
  bytes32 hash = validOrderHash(o, c);

  require(a <= (o.principal - filled[hash]), 'taker amount > available volume');

  filled[hash] += a;

  uint256 premiumFilled = (((a * 1e18) / o.principal) * o.premium) / 1e18;
  uint256 fee = ((premiumFilled * 1e18) / fenominator[3]) / 1e18;

  Erc20 uToken = Erc20(o.underlying);
  // transfer premium from maker to sender
  uToken.transferFrom(o.maker, msg.sender, premiumFilled);

  // transfer fee in underlying to swivel from sender
  uToken.transferFrom(msg.sender, address(this), fee);

  // transfer <a> vault.notional (nTokens) from sender to maker
  require(MarketPlace(marketPlace).p2pVaultExchange(o.underlying, o.maturity, msg.sender, o.maker, a), 'vault exchange failed');

  emit Exit(o.key, hash, o.maker, o.vault, o.exit, msg.sender, a, premiumFilled);
}

JTraversa (Swivel) confirmed

0xean (judge) commented:

Based on

3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).

This is being upgraded to a high risk. The duplicate of it was at that level by the submitting warden and considering that fees are being incorrectly taken from the taker and not the maker, the maker ends up with a higher balance than expected and the taker has no way to recoup these fees (assets are now lost).

JTraversa (Swivel) commented:

Is that how it is interpreted? I’d assume that high risk would imply a valid attack path that a user could use to drain deposited funds based on that description.

I won’t fight this one obviously, just think there’s a clear differentiation between this and the other high risk issue.

The original report as published on Code4rena, by itsmeSTYJ. 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 fee is deducted from the premium before it is transferred to the taker, and then the taker is charged the fee again, so the fee is applied twice to the taker instead of once to the maker.

Impact

The taker loses the fee amount twice and the maker ends up with a higher balance than expected; the taker has no way to recoup the extra fees, so assets are lost.

What the attacker needed

A taker exits a filled vault order

The fix

The fee should be charged once and to the correct party (the maker), not deducted from the taker's premium and then charged again.

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.

This is a smart contract for trading where one side (the taker) exits a position and should receive a premium payment from the other side (the maker). A fee is meant to be taken once, but the code takes it twice from the taker, so the taker loses money and the maker gains it. The taker has no way to get those extra fees back.

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 itsmeSTYJ

View all

9 more disclosed reports, best first.

More from Swivel v3 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.