Skip to content
Business logic Audit finding Intermediate

Members lose SPARTA tokens in removeLiquiditySingle()

When a member called removeLiquiditySingle() asking only for SPARTA, the SPARTA portion of their LP tokens was left in the Router contract instead of being returned to them. The member effectively lost that SPARTA, which could later be claimed by other transactions that remove SPARTA from the Router.

0xRajeev Follow

Originally disclosed on Code4rena

Submitted by 0xRajeev, also found by cmichel and XXX

When a member calls removeLiquiditySingle() requesting only SPARTA in return, i.e. toBASE = true, the LP tokens are transferred to the Pool to withdraw the constituent SPARTA and TOKENs back to the Router. The withdrawn TOKENs are then transferred back to the Pool to convert to SPARTA and directly transferred to the member from the Pool. However, the member’s SPARTA are left behind in the Router instead of being returned along with converted SPARTA from the Pool.

In other words, the _member’s BASE SPARTA tokens that were removed from the Pool along with the TOKENs are never sent back to the_member because the _token’s transferred to the Pool are converted to SPARTA and only those are sent back to member directly from the Pool via swapTo().

This effectively results in member losing the SPARTA component of their Pool LP tokens which get left behind in the Router and are possibly claimed by future transactions that remove SPARTA from Router.

LPs sent to Pool, SPARTA and TOKENs withdrawn from Pool to Router, TOKENs from Router sent to Pool, and TOKENs in Pool converted to BASE SPARTA and sent to member directly from the Pool.

Recommend:

  1. BASE SPARTA should also be transferred to the Pool before swapTo() so they get sent to the member along with the converted TOKENs via swapTo()
  2. Use swap(BASE) instead of swapTo() so that TOKENs are swapped for BASE SPARTA in Pool and sent back to ROUTER. Then send all the SPARTA from ROUTER to member.

verifyfirst (Spartan) confirmed:

This bug was missed in a last minute edit before pushing to code423n4, wouldn’t have made it past testNet testing. However, it is a good find.

The original report as published on Code4rena, by 0xRajeev. 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 Router withdrew both SPARTA and TOKENs from the Pool but only forwarded the TOKENs to the Pool for conversion, never sending the withdrawn SPARTA back to the member.

Impact

The member loses the SPARTA component of their LP tokens, and that SPARTA could be claimed by later transactions that remove SPARTA from the Router.

What the attacker needed

Member holds Pool LP tokens; member calls removeLiquiditySingle with toBASE true

The fix

The report recommends either sending the withdrawn SPARTA to the Pool before swapTo() so it reaches the member, or using swap(BASE) so all SPARTA is returned to the Router and then forwarded to the member.

How it was found

  1. A member calls removeLiquiditySingle() with toBASE set to true, asking for only SPARTA.
  2. The LP tokens are transferred to the Pool and both SPARTA and TOKENs are withdrawn to the Router.
  3. Only the TOKENs are sent from the Router to the Pool and converted to SPARTA, which is sent to the member directly from the Pool.
  4. The SPARTA that was withdrawn to the Router is never forwarded, so it stays there.

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 liquidity pool holds two kinds of tokens together, and people who add them get pool tokens in return. When they cash out asking for only one of the two tokens, the contract is supposed to convert everything and send it back. Here a coding mistake meant one half of the payout stayed stuck inside the contract instead of reaching the person.

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 0xRajeev

View all

61 more disclosed reports, best first.

More from Spartan Protocol 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.