Lack of rebalance rate limiting allow operators to drain vaults
The SimpleManager contract for Arrakis vaults lacks rate limiting on the rebalance function, allowing a malicious operator to repeatedly call rebalance within a single transaction and exploit the allowed slippage tolerance each time, thereby draining vault funds.
Source: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/25
Found by
cergyk, immeas, n33k, p12473
Summary
Operators of Arrakis vaults are constrained by the checks defined in SimpleManager.sol, these checks prevent them from causing too much of a fund loss on a single rebalance call (check univ3 pool price deviation, enforce minimum swap slippage parameters).
However since there is no rate limiting for an operator to call rebalance on SimpleManager, an operator can simply drain the vault by applying the accepted slippage a hundred times in one transaction.
Vulnerability Detail
There are mostly two safety measures for preventing an operator to extract vault funds when calling rebalance:
-
Check pool price deviation for mints: By checking that a pool price is close to a price given by a chainlink feed, operator is prevented from adding liquidity to a pool at a really unfavorable price, and backrun later to extract vault funds
-
Check slippage parameters for swap (
_checkMinReturn): By checking that a minimum amount of tokens is returned to the vault after the swap, it is preventing the operator to swap tokens at a too unfavorable price. Min amount out enforced in ArrakisV2:
As stated by the sponsor, in a public trustless setup, these slippage parameters should be restricted to ~1%.
However since an operator is not rate limited for the number of calls she can do on SimpleManager.rebalance, she can simply call it multiple times in a very short timespan, extract an arbitrarily large share of vault funds.
Impact
Vault funds can be drained by a malicious operator.
Code Snippet
Tool used
Manual Review
Recommendation
Enforce a rate limiting policy to the number of calls which can be made to SimpleManager's rebalance, or even better enforce a rate limit on loss of funds which can occur due to rebalances (by evaluating totalUnderlyingWithFees before and after the execution for example).
Discussion
ctf-sec
Operators are "semi trusted" only to be awake and adhere to the expected vault rebalancing strategy. Thus a malicious operator on the SimpleManager.sol should not be able to do anything worse than "grief" - they MAY not execute rebalances or MAY not execute the expected strategy. However the rebalances that are executed MUST NOT be exploitable by frontrun or sandwich.
Based the info from the contest readme doc, upgrading the severity to high
IAm0x52
Escalate
Should be medium not high. This attacks has multiple conditions to work. First of all the operator must become compromised. Second the profitability of a sandwich attack is highly dependent on the composition of the underlying pools and the slippage setting on the manager. If the vault is primarily trading in a 0.3% (0.6% combined buy and sell) fee pool then a slippage cap of 0.5% makes it impossible for this type of attack to work. Additionally depending on the depth of liquidity for nearby relevant buckets the cost to move the pool may outweigh any gains making it unprofitable.
sherlock-admin
Escalate
Should be medium not high. This attacks has multiple conditions to work. First of all the operator must become compromised. Second the profitability of a sandwich attack is highly dependent on the composition of the underlying pools and the slippage setting on the manager. If the vault is primarily trading in a 0.3% (0.6% combined buy and sell) fee pool then a slippage cap of 0.5% makes it impossible for this type of attack to work. Additionally depending on the depth of liquidity for nearby relevant buckets the cost to move the pool may outweigh any gains making it unprofitable.
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.
Jeiwan
Escalate
This is not a valid issue, the behaviour of operators is expected. As per the contest details (https://audits.sherlock.xyz/contests/86):
Q: Are there any off-chain mechanisms or off-chain procedures for the protocol (keeper bots, input validation expectations, etc)? Yes the SimpleManager.operators are keeper bots running the "off chain logic" that defines the "market making strategy." While it is generally expected that these keeper bots are not malicious, are mostly available/awake, and are running off chain logic to create the rebalance payloads on the expected "market making strategy," even in the absence of this where a malicious keeper bot passes arbitrary payloads to rebalance, there should be no way to extract value from these rebalances directly beyond the acceptable slippage tolerance defined in SimpleManager.
As the finding describes, operators cannot extract value from rebalance beyond the slippage tolerance. Even though if they can rebalance multiple times, they cannot get more value than is set by the slippage tolerance. This is expected behaviour and it was explicitly mentioned by the sponsor.
I also disagree with this comment: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/25#issuecomment-1634990625 The finding doesn't mention a front run or a sandwiching attack, thus the statement is not applicable. The upgrade to high severity is not justified. The demonstrated scenario in the finding is pretty much in line with the definition of operators: they are semi trusted actors that execute a strategy and cannot manipulate the price more than the specified by the slippage tolerance. The finding doesn't prove the slippage tolerance check can be avoided.
sherlock-admin
Escalate
This is not a valid issue, the behaviour of operators is expected. As per the contest details (https://audits.sherlock.xyz/contests/86):
Q: Are there any off-chain mechanisms or off-chain procedures for the protocol (keeper bots, input validation expectations, etc)? Yes the SimpleManager.operators are keeper bots running the "off chain logic" that defines the "market making strategy." While it is generally expected that these keeper bots are not malicious, are mostly available/awake, and are running off chain logic to create the rebalance payloads on the expected "market making strategy," even in the absence of this where a malicious keeper bot passes arbitrary payloads to rebalance, there should be no way to extract value from these rebalances directly beyond the acceptable slippage tolerance defined in SimpleManager.
As the finding describes, operators cannot extract value from rebalance beyond the slippage tolerance. Even though if they can rebalance multiple times, they cannot get more value than is set by the slippage tolerance. This is expected behaviour and it was explicitly mentioned by the sponsor.
I also disagree with this comment: https://github.com/sherlock-audit/2023-06-arrakis-judging/issues/25#issuecomment-1634990625 The finding doesn't mention a front run or a sandwiching attack, thus the statement is not applicable. The upgrade to high severity is not justified. The demonstrated scenario in the finding is pretty much in line with the definition of operators: they are semi trusted actors that execute a strategy and cannot manipulate the price more than the specified by the slippage tolerance. The finding doesn't prove the slippage tolerance check can be avoided.
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.
IAm0x52
Agreed with @Jeiwan that this should be invalid since the operator never violates the slippage tolerance
syjcnss
Not agree on the two escalations.
First. In the README of the audit it says 'A wide variety' of tokens will be supported. And there's no limit on the fee tier of supported pairs. So there will be vaults that are vulnerable to this attack.
Second. This bug is not about violating the the slippage tolerance. But is about leveraging the slippage tolerance to profit. This attack will definitely cause a massive loss to this protocol and I don't think this is the expected behaviour.
Jeiwan
Second. This bug is not about violating the the slippage tolerance.
Exactly. The contest description was very clear about what attack vectors involving operators are deemed valid. The slippage tolerance is not violated, thus this is not a valid attack.
But is about leveraging the slippage tolerance to profit.
This point is also addressed in the contest details:
Operators are "semi trusted" only to be awake and adhere to the expected vault rebalancing strategy. While it is generally expected that these keeper bots are not malicious
Operators are trusted to not be malicious and to execute the rebalancing strategy as its programmed. The finding doesn't demonstrate how an operator could go beyond what it's trusted to do. There's no abuse of the strategy. The slippage tolerance works as expected. Operators are expected to do multiple rebalances. Price manipulations are protected by the slippage tolerance–the amount of loss that's available by the tolerance setting is expected and acceptable by the protocol.
Jeiwan
I checked the duplicate reports of this issue, some of them are more detailed about how this can be exploited. However, all those exploit scenarios were addressed in the contest description:
where a malicious keeper bot passes arbitrary payloads to rebalance, there should be no way to extract value from these rebalances directly beyond the acceptable slippage tolerance defined in SimpleManager.
So, we have two exploiting techniques for the attack to be valid:
- Price manipulation. This is already addressed by the code: the slippage tolerance check protects against that, while allowing some expected loses.
- Payload manipulation. The finding doesn't prove that payload manipulation can break the slippage tolerance check.
Even after checking the other reports, I still believe this finding is out of scope. It describes expected behavior of operators.
JeffCX
Ok. After reading the escalation, for now I agree with the senior watson's escalation, can change the severity from high to medium
So
they are semi trusted actors that execute a strategy and cannot manipulate the price more than the specified by the slippage tolerance.
I would interpret this as "operator" are not trusted.
Second, I agree within single transaction, the slippage protection is not bypassed
but suppose we set the slippage to 1%
If operator keep doing rebalance:
- first rebalance, 99% of the token we received
- second rebalance: 98.01% of the token we received
- third rebalance: 97.02% of the token we received
...
but the attack may not be profitable for attacker :)
I would recommend downgrade the severity from high to medium (report still valid)
unless there are more proof for this statement:
This attack will definitely cause a massive loss to this protocol and I don't think this is the expected behaviour.
syjcnss
Agree with the lead judge and senior watson's escalation.
Jeiwan
My view still holds true. Since the slippage tolerance check is not avoided this is not a valid attack scenario. It was expected by the sponsor and the contest description was clear that operators are "semi trusted" and only breaking the slippage tolerance check can be considered an attack.
@hrishibhat
SergeKireev
I would like to address the escalations:
@Jeiwan: The contest page also says:
Thus a malicious operator on the SimpleManager.sol should not be able to do anything worse than "grief" - they MAY not execute rebalances or MAY not execute the expected strategy. However the rebalances that are executed MUST NOT be exploitable by frontrun or sandwich.
Here the impact is that a malicious operator can drain a big chunk of TVL in the protocol in one single transaction.
@IAm0x52 These are very interesting points:
Should be medium not high. This attacks has multiple conditions to work. First of all the operator must become compromised. Second the profitability of a sandwich attack is highly dependent on the composition of the underlying pools and the slippage setting on the manager. If the vault is primarily trading in a 0.3% (0.6% combined buy and sell) fee pool then a slippage cap of 0.5% makes it impossible for this type of attack to work. Additionally depending on the depth of liquidity for nearby relevant buckets the cost to move the pool may outweigh any gains making it unprofitable.
I agree that the operator has to be compromised as a condition.
Since the operator can use the router payload to swap on any pool, only limited by vault.maxSlippage (for which a value of 1% should be considered according to sponsor), the malicious operator can create a bogus pool with a poison token which could just be used to extract the tokens sent by Arrakis with a fee of 0.01%.
Which means 0.99% extracted on each call. Since multiple calls can be done to rebalance in a single transaction, the malicious operator can drain an arbitrary amount of funds before the owner can even try to react and change it
ctf-sec
emm it is not possible to inject own's opinion into another haha, yeah just recommend leave factual based comments and wait for sherlock to resolve the escalation, recommend changing severity to medium :)
SergeKireev
Found again the message posted by sponsor in the public discord where slippage and deviation would be considered to be 1% (step 4):
syjcnss
but suppose we set the slippage to 1%
If operator keep doing rebalance:
first rebalance, 99% of the token we received second rebalance: 98.01% of the token we received third rebalance: 97.02% of the token we received ...
So, for 100 times of rebalance we will only get 0.99**100 = 36.60% of the token left in the vault? For 300, it's very close to empty. 0.99**300 = 4.90%
If I'm right on the math above, then a compromised operator may not be needed. 100 times of rebalance is very much likely achievable in a short period like a few months in a fluctuant market. A compromised operator will make a massive loss quickly.
0ximmeas
As i stated in my dup of this, from the docs:
Operators are "semi trusted" only to be awake and adhere to the expected vault rebalancing strategy. Thus a malicious operator on the SimpleManager.sol should not be able to do anything worse than "grief"
This is doing something worse than grief, the sponsor just didn't think of this specific attack scenario. An operator can steal a significant amount of the vaults funds in a single transaction. Thus high.
Gevarist
If the operator is malicious, owner has the option to replace it.
SergeKireev
If the operator is malicious, owner has the option to replace it.
Without some kind of rate limiting, the draining can happen in one transaction, no way for the owner to mitigate it
Gevarist
How much iteration can the malicious operator do in 1 block? Less than thirty rebalance in one block for sure. The gas cost of such attack is considerable. And operators are semi-trusted, we think this issue is a medium.
SergeKireev
If we assume that gas consumed is approx 1 uniswapv3 swap (the operator can choose to do only the swap step during rebalance with 1% slippage), 30 is a good estimate of the max number of rebalances possible during 1 block.
Which caps the theft of funds during one block at (1-0.99**30) ~= 26% of the funds.
I agree @Gevarist that this attack is a bit less practical than what described in previous discussion
hrishibhat
Result: Medium Has duplicates Considering this a valid medium based on the above final comments.
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
Gevarist
We add a cooldown period during which rebalance is not possible by operator here. PR : https://github.com/ArrakisFinance/v2-manager-templates/pull/26
IAm0x52
Fix looks good. Added a cooldown period to rebalances
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 absence of a rate limit or cooldown on the rebalance function, allowing an operator to repeatedly exploit the slippage tolerance within a single transaction.
Impact
A malicious operator could drain a significant portion of vault funds in a single transaction, though the actual amount is limited by gas costs and the number of rebalances possible per block (estimated at up to 26% per block).
What the attacker needed
Compromised or malicious operator; vault with sufficient funds; slippage tolerance set (e.g., 1%)
The fix
A cooldown period was added to prevent operators from calling rebalance too frequently.
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.
In a vault, an operator is a trusted bot that moves funds around to follow a strategy. The vault allows a small loss on each move (slippage) to account for price changes. Because there is no limit on how often the operator can move funds, a bad operator can make many moves in one transaction, each losing a small amount, and quickly empty the vault.
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.