Skip to content

Anyone can trigger flashloan to a strategy #27

@c4-bot-9

Description

@c4-bot-9

Lines of code

https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/flashloan/BalancerFlashLender.sol#L98-L133

Vulnerability details

Proof of Concept

BalancerFlashLender is created to initiate flashloans from strategies. So when flashLoan is called, then BalancerFlashLender initiates flashloan on balancer with borrower as encoded data.

Then later balancer will call receiveFlashLoan and BalancerFlashLender will trigger vault with onFlashLoan callback.

First of all, flashloan can be initiated on balancer by anyone and even with amount 0. Also user can pass any data as userData. In our case, attacker will put address of Vault and additional params. He will provide BalancerFlashLender as recipient, so balancer will trigger BalancerFlashLender.

Then BalancerFlashLender will trigger vault, which was passed as borrower.

The check inside the vault will also pass and call will be considered valid. Now attacker can use own crafted data to execute smth with vault. For example, he can use _repayAndWithdraw to withdraw any profit from contract to own address.

Impact

Attacker can steal funds.

Tools Used

VsCode

Recommended Mitigation Steps

BalancerFlashLender should store some variable like: flashloanInitated, when someone requested flashloan through it. And then in case if balancer triggered receiveFlashLoan, BalancerFlashLender should check if the variable is indeed true and set it to false later.

Assessed type

Error

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 (Med Risk)Assets not at direct risk, but function/availability of the protocol could be impacted or leak value🤖_02_groupAI based duplicate group recommendationbugSomething isn't workingdowngraded by judgeJudge downgraded the risk level of this issueduplicate-2satisfactorysatisfies C4 submission criteria; eligible for awards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions