Skip to content
Business logic Audit finding Advanced

Pool deviation check in SimpleManager on rebalance can be bypassed

The SimpleManager contract checks price deviation before a swap but not after, allowing a malicious operator to manipulate the pool price during the swap and then add liquidity at an unfavourable price, which can be backrun to steal vault funds.

cergyk Follow with n33k

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/26

Found by

cergyk, n33k

Summary

In SimpleManager a price deviation check is enforced to prevent an operator to add liquidity to a UniV3 pool at a really unfavorable price during rebalance and backrun to extract vault funds. We will show here that this check can be entirely bypassed by a malicious operator.

Vulnerability Detail

Rebalance context

During a call to SimpleManger.rebalance, the following operations are run:

  • 1/ Enforce price deviation not too large for mint pools:

https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/SimpleManager.sol#L366-L385

and correct slippage parameter for swap: https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-manager-templates/contracts/SimpleManager.sol#L318-L354

  • 2/ Remove liquidity on specified UniV3 ranges (we are not going to use it here)

  • 3/ Use a low level call to a whitelisted Router to execute a swap

https://github.com/sherlock-audit/2023-06-arrakis/blob/main/v2-core/contracts/ArrakisV2.sol#L334-L336

  • 4/ Enforce received amounts from the swap

  • 5/ Provide liquidity on specified UniV3 ranges

  • 6/ Enforce provided amounts during addLiquidity (these parameters are provided by operator and unbounded, so they can be (0, 0), and check is a noop).

Exploit description

We are going to use the swap step (3/) to imbalance the pools after the check of price deviation (1/) is passed, so the liquidity provided in 5/ is done at a really unfavorable price, and can be backrun by the operator to extract funds from the vault.

To not trigger the slippage protection after the swap, we are going to use the router to swap on a totally unrelated pool of tokens controlled by the malicious operator: PSN/PSN2 (PSN stands for Poison).

PSN token has a callback in the _transfer function to make a large swap on UNIv3 pool where the operator is going to provide liquidity in 5/, to deviate it a lot.

after the call to the router is done, no changes to the balances of the vault have been made, the slippage checks out.

Liquidity provided at 5/ is done at a terrible price for some of the ranges, and the operator backruns for a nice profit.

NB: All these steps can be run inside a flashloan callback, to not use attacker own funds

Impact

An arbitrary amount can be drained from the vault by an operator

Code Snippet

Tool used

Manual Review

Recommendation

Ideally the check on price deviation should be enforced right before the liquidity providing.

Discussion

syjcnss

Escalate

This one should be a valid high and my #187 should be the only duplicate of this.

This one and #187 both showed that the swap.router.call calls into a malicious ERC20 contract that manipulates liquidity pool prices to bypass slippage checks and sandwich attack liquidity adding. I've added additional proof in the comment.

#43, #135, #213 are clearly unrelated and should be reevaluated.

#213 should be a dup of #181. They are all about missing checks on burn pools.

sherlock-admin

Escalate

This one should be a valid high and my #187 should be the only duplicate of this.

This one and #187 both showed that the swap.router.call calls into a malicious ERC20 contract that manipulates liquidity pool prices to bypass slippage checks and sandwich attack liquidity adding. I've added additional proof in the comment.

#43, #135, #213 are clearly unrelated and should be reevaluated.

#213 should be a dup of #181. They are all about missing checks on burn pools.

You've created a valid escalation!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

SergeKireev

Agree with @syjcnss

P12473

PSN token has a callback in the _transfer function to make a large swap on UNIv3 pool where the operator is going to provide liquidity in 5/, to deviate it a lot.

The core of this exploit requires a PSN/PSN2 pool where the PSN tokens have a malicious _transfer function but according to the README These should be assumed to use SimpleManager.sol and Chainlink oracle feed(s) and thus only support "Major" tokens with suitable chainlink oracle support..

how easy is it For one to create a malicious token and to provide a feed for it on chainlink?

syjcnss

@P12473 The section 1. on the swap slippage check in my comment in #187 should be able to anwser your question.

SergeKireev

PSN token has a callback in the _transfer function to make a large swap on UNIv3 pool where the operator is going to provide liquidity in 5/, to deviate it a lot.

The core of this exploit requires a PSN/PSN2 pool where the PSN tokens have a malicious _transfer function but according to the README These should be assumed to use SimpleManager.sol and Chainlink oracle feed(s) and thus only support "Major" tokens with suitable chainlink oracle support..

How easy is it for one to create a malicious token and to provide a feed for it on chainlink?

@syjcnss explained it very well in his linked comment.

I would like to add there is no need for chainlink feeds on poison tokens, since they would only be passed inside the payload used for the router call, and Arrakis never decodes this payload

P12473

PSN token has a callback in the _transfer function to make a large swap on UNIv3 pool where the operator is going to provide liquidity in 5/, to deviate it a lot.

The core of this exploit requires a PSN/PSN2 pool where the PSN tokens have a malicious _transfer function but according to the README These should be assumed to use SimpleManager.sol and Chainlink oracle feed(s) and thus only support "Major" tokens with suitable chainlink oracle support.. How easy is it for one to create a malicious token and to provide a feed for it on chainlink?

@syjcnss explained it very well in his linked comment.

I would like to add there is no need for chainlink feeds on poison tokens, since they would only be passed inside the payload used for the router call, and Arrakis never decodes this payload

Ah yes, apologies for that. Great explanation shared by @syjcnss 💯

SergeKireev

Also obviously agree with @syjcnss that this should be of high severity since impact is unbounded theft of funds by an operator

Gevarist

operators are semi trusted, we should consider this issue as medium.

hrishibhat

@Gevarist Readme says:

However the rebalances that are executed MUST NOT be exploitable by frontrun or sandwich. I think this should be a high based on another duplicate and POC here: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/187#issuecomment-1636038030

kassandraoftroy

(EDITED after some thought and discussion) ... Hmm I'm still not convinced this is a high. For me a high is when an arbitrary address can extract value, not a semi-trusted party.

Here: However the rebalances that are executed MUST NOT be exploitable by frontrun or sandwich. we refer to a THIRD PARTY being able to frontrun or sandwich the rebalance. If ONLY whitelisted manager operator themself can frontrun/sandwich/extract it's still a medium to me, to be fair to "Real" high's that allow an arbitrary address to exploit the contract.

syjcnss

The readme also says about the operator self sandwich,

HOWEVER in this "Public Vault" setting the "Manager" role is taken by the SimpleManager.sol smart contract which should add additional checks that make it impossible for SimpleManager.operators to frontrun/sandwich their own rebalance transactions and extract value beyond the accepted slippage tolerance defined in the SimpleManager smart contract for any Arrakis V2 vault managed by SimpleManager.

Having this, However the rebalances that are executed MUST NOT be exploitable by frontrun or sandwich. doesn't look like only referring to THIRD PARTY sandwich to me.

The attack breaks the above trust assumption in readme and will result in a material loss of funds.

hrishibhat

Result: High Has duplicates Based on the context of the readme, the assumption set is that there is a clear possibility of having a malicious operator. Given that there is a clear loss of funds as show in this issue and #187 Considering this a valid high based on the above comments

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

Gevarist

We add another deviation check after minting part of rebalance on SimpleManager.sol. PR : https://github.com/ArrakisFinance/v2-manager-templates/pull/26

IAm0x52

Fix looks good. Deviation is checked before and after each rebalance to prevent pool becoming imbalanced between calls

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

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 price deviation check is performed only before the swap and not again before adding liquidity, allowing the pool price to be manipulated in between.

Impact

An arbitrary amount can be drained from the vault by an operator.

What the attacker needed

Malicious operator role; whitelisted router; malicious token with callback

The fix

The price deviation check should be enforced right before providing liquidity, and a fix was later applied to check deviation before and after each rebalance.

How it was found

  1. The operator initiates a rebalance, passing the price deviation check.
  2. The operator uses a whitelisted router to swap on a malicious pool, triggering a callback that manipulates the target pool's price.
  3. The operator adds liquidity at the manipulated, unfavourable price.
  4. The operator backruns the transaction to extract funds from the vault.

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 vault lets an operator rebalance funds by swapping and adding liquidity. The contract checks the price before the swap but not after, so the operator can use a malicious token to skew the price during the swap and then add liquidity at a bad rate, profiting at the vault's expense.

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 cergyk

View all

29 more disclosed reports, best first.

More from Arrakis Valantis SOT Audit

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.