ArrakisMetaVault::setModule Malicious executor can drain the vault by calling withdraw after initializePosition
A malicious executor could call setModule with crafted payloads to withdraw all vault funds to an arbitrary address after a new module was whitelisted. This allowed theft of all funds in the vault.
cergyk Follow with cu5t0mPe0, iamandreiski and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-03-arrakis-judging/issues/50
Found by
cergyk, cu5t0mPe0, iamandreiski, juaan
Summary
A malicious executor, after a new module is whitelisted by an admin, can drain the vault by calling ArrakisStandardManager.setModule() with a malicious payloads_.
Vulnerability Detail
The setModule() function of the ArrakisStandardManager contract allows an executor to set a new module for a vault: ArrakisStandardManager.sol#L438.
It calls ValantisModule.withdraw(), to withdraw the funds from the pool and transfer to the new module: ValantisHOTModule.sol#L235.
Once the vault's funds are in the new module, the first malicious payloads_ is executed and calls ValantisModule::initializePosition to deposit the liquidity back into the pool: ValantisHOTModule.sol#L148.
Lastly, the second payloads_ of the malicious executor gets executed and calls ValantisModulePublic::withdraw which calls ValantisModule::withdraw on the new module and withdraws all funds to an arbitrary address: ValantisHOTModule.sol#L203.
Impact
Theft of all funds in the vault.
Scenario
- Owner whitelists a legitimate new module with
ArrakisMetaVault::whitelistModules. - Malicious public vault executor calls
ArrakisStandardManager::setModulewith a maliciouspayloads_.- It calls
ArrakisMetaVault::setModule. - It calls
ValantisModulePublic::withdrawwhich calls_module.withdraw(module_, BASE)to withdraw all vault's funds from old to new module. - Malicious executor has provided two payloads
- The first one calls
ValantisModule::initializePositionto deposit liquidity into the new pool. - Then the second malicious
payloads_is executed and contains a call toValantisModule::withdrawwith attacker as the receiver
- The first one calls
- It calls
Please note that instead of calling
withdrawon the new module, enabling direct theft of funds, the executor can also callwithdrawManagerBalancewhich would transfer all the balance of the module to the manager. Or also not call any function at all (payloads is an empty array), and leave the balances in the module.
Code Snippet
Tool used
Manual Review
Recommendation
Check that the reserves in the new pool are correct after setting the new module, similarly to what is currently done at the end of ArrakisStandardManager::rebalance:
https://github.com/sherlock-audit/2024-03-arrakis/blob/d7946ee784ca8df3246d723e8b92529447e23bb7/arrakis-modular/src/ArrakisStandardManager.sol#L391-L414
Discussion
0xjuaan
Hi @0xffff11, #45 is a completely different issue and should not be duped with this one
WangSecurity
Tagging here the Watsons who submitted and escalated their findings about malicious executor exploiting the protocol via setModules in ArrakisStandardManager:
@CergyK @0xjuaan @cu5t0mPeo @iamandreiski (I assume there might be more, please tag everyone I've missed)
Here're the escalated findings:
- #35
- #21
- #27
- #14
- #45
- if there are any missing please also send them in this discussion.
Gentlemen, I've got you all here, as we all know in the README it says the executor for Arrakis Standard Manager (let's call it ASM) is RESTRICTED during rebalance actions. These vulnerabilities above are about exploiting setModules, so as I understand, the executor in that case is TRUSTED. So I've got three questions here:
- Is there any evidence that the sponsors agree they're untrusted and restricted for
setModulesor it's only forrebalanceindeed? - Are your submissions possible via
rebalanceor only viasetModules? - #27 and #14 are dups of each other and as I understand they're about the problem with new modules being incorrectly set, but both mention malicious executor, which is trusted in that case. Are they possible with a TRUSTED executor and without a mistake?
Let's keep the discussions here and then, depending on the answers to these questions, we could move the talks to issues individually.
cu5t0mPeo
@WangSecurity Hi, here is the sponsor's explanation about the executor in my private thread:
"When the executor is calling setModule, he will interact with the module through the vault. The module functions exposed to the vault should be safely implemented. In this case, the executor isn't trusted, so the module's exposed function to setModule should be safe."
0xjuaan
Furthermore, it does not make sense for an actor to be trusted to use one function non-maliciously, but untrusted for a different function.
Sponsor's intention is confirmed here:
0xjuaan
Also @WangSecurity, #14 and #27 do not involve any special malicious actions. Its a mistake in the code. Whenever setModule is called (with perfectly correct payloads), all the funds are sent to the ArrakisStandardManager incorrectly.
WangSecurity
Thank you for these clarifications.
Furthermore, it does not make sense for an actor to be trusted to use one function non-maliciously, but untrusted for a different function.
Fair enough, still wanted to get a confirmation. Let's proceed to each individual issue.
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/ArrakisFinance/arrakis-modular/pull/88
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 setModule function does not verify that the new module's reserves are correct after executing the provided payloads, allowing an executor to withdraw funds.
Impact
Theft of all funds in the vault.
What the attacker needed
Owner whitelists a new module; Attacker is a public vault executor
The fix
The protocol team fixed this issue in the following PRs/commits: https://github.com/ArrakisFinance/arrakis-modular/pull/88
How it was found
- Owner whitelists a legitimate new module with ArrakisMetaVault::whitelistModules.
- Malicious public vault executor calls ArrakisStandardManager::setModule with a malicious payloads_.
- It calls ArrakisMetaVault::setModule.
- It calls ValantisModulePublic::withdraw which calls _module.withdraw(module_, BASE) to withdraw all vault's funds from old to new module.
- Malicious executor has provided two payloads: the first calls ValantisModule::initializePosition to deposit liquidity into the new pool.
- Then the second malicious payloads_ is executed and contains a call to ValantisModule::withdraw with attacker as the receiver.
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 is a smart contract that holds funds. An executor is someone allowed to perform certain actions on the vault. The setModule function lets an executor switch the vault to a new module (a helper contract). The bug is that the executor can include extra instructions (payloads) that move all the vault's money to themselves.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.