Fund loss or theft by attacker with creating a flash loan and setting SuperVault as receiver so executeOperation() will be get called by lendingPool but with attackers specified params
The SuperVault contract's executeOperation() function can be called by anyone via Aave flash loans because it only checks that the caller is the lending pool, not that the vault initiated the loan. An attacker can specify malicious parameters to trigger rebalance or leverage operations with manipulated swap data, causing the vault to lose funds through bad trades or fees.
Originally disclosed on Code4rena
Submitted by unforgiven, also found by Picodes
According to Aave documentation, when requesting flash-loan, it’s possible to specify a receiver, so function executeOperation() of that receiver will be called by lendingPool. https://docs.aave.com/developers/v/2.0/guides/flash-loans In the SuperVault there is no check to prevent this attack so attacker can use this and perform griefing attack and make miner contract lose all its funds. or he can create specifically crafted params so when executeOperation() is called by lendingPool, attacker could steal vault’s user funds.
Proof of Concept
To exploit this attacker will do this steps:
- will call
Aave lendingPoolto get a flash-loan and specifySuperVaultasreceiverof flash-loan. and also create a specificparamsthat invokeOperation.REBALANCEaction to change user vault’s collateral. lendingPoolwill callexecuteOperation()ofSuperVaultwith attacker specified data.executeOperation()will checkmsg.senderand will process the function call which will cause some dummy exchanges that will cost user exchange fee and flash-loan fee.- attacker will repeat this attack until user losses all his funds.
function executeOperation(
address[] calldata assets,
uint256[] calldata amounts,
uint256[] calldata premiums,
address,
bytes calldata params
) external returns (bool) {
require(msg.sender == address(lendingPool), "SV002");
(Operation operation, bytes memory operationParams) = abi.decode(params, (Operation, bytes));
IERC20 asset = IERC20(assets[0]);
uint256 flashloanRepayAmount = amounts[0] + premiums[0];
if (operation == Operation.LEVERAGE) {
leverageOperation(asset, flashloanRepayAmount, operationParams);
}
if (operation == Operation.REBALANCE) {
rebalanceOperation(asset, amounts[0], flashloanRepayAmount, operationParams);
}
if (operation == Operation.EMPTY) {
emptyVaultOperation(asset, amounts[0], flashloanRepayAmount, operationParams);
}
asset.approve(address(lendingPool), flashloanRepayAmount);
return true;
}
To steal user fund in SupperVault attacker needs more steps. in all these actions (Operation.REBALANCE, Operation.LEVERAGE, Operation.EMPTY) contract will call aggregatorSwap() with data that are controlled by attacker.
function aggregatorSwap(
uint256 dexIndex,
IERC20 token,
uint256 amount,
bytes memory dexTxData
) internal {
(address proxy, address router) = _dexAP.dexMapping(dexIndex);
require(proxy != address(0) && router != address(0), "SV201");
token.approve(proxy, amount);
router.call(dexTxData);
}
Attacker can put special data in dexTxData that make contract to do an exchange with bad price. To do this, attacker will create a smart contract that will do this steps:
- manipulate price in exchange with flash loan.
- make a call to
executeOperation()byAave flash-loanwithreceiverand specificparamsso thatSuperVaultwill make calls to manipulated exchange for exchanging. - do the reverse of #1 and pay the flash-loan and steal the user fund.
The details are: Attacker can manipulate swapping pool price with flash-loan, then Attacker will create specific params and perform steps 1 to 4. so contract will try to exchange tokens and because of attacker price manipulation and specific dexTxData, contract will have bad deals. After that, attacker can reverse the process of swap manipulation and get his flash-loan tokens and some of SuperVault funds and. then pay the flash-loan.
Tools Used
VIM
Recommended Mitigation Steps
There should be some state variable which stores the fact that SuperVault imitated flash-loan. When contract tries to start flash-loan, it sets the isFlash to True and executeOperation() only accepts calls if isFlash is True. and after the flash loan code will set isFlash to False.
m19 (Mimo DeFi) confirmed and commented:
We definitely confirm this issue and intend to fix it.
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 executeOperation() function lacks a check that the flash loan was initiated by the vault itself, allowing anyone to trigger it via Aave with arbitrary parameters.
Impact
An attacker could cause the vault to lose funds through repeated griefing attacks or steal user funds by manipulating exchange prices and using crafted swap data.
What the attacker needed
Attacker can initiate Aave flash loans; vault has funds
The fix
The contract should track whether it initiated a flash loan with a state variable and only allow executeOperation() when that flag is set.
How it was found
- Call Aave lendingPool to get a flash loan and specify SuperVault as receiver, with params that invoke Operation.REBALANCE.
- lendingPool calls executeOperation() of SuperVault with attacker-specified data.
- executeOperation() checks msg.sender and processes the call, causing dummy exchanges that cost user exchange fee and flash-loan fee.
- Attacker repeats this attack until user loses all funds.
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 flash loan is a loan that must be repaid in the same transaction. The vault has a function that is supposed to be called only by the lending pool during a flash loan, but it does not check that the vault itself started the loan. An attacker can start a flash loan and set the vault as the receiver, so the lending pool calls the vault's function with attacker-controlled data, letting the attacker make the vault perform harmful actions.
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.