code-423n4 / 2021-04-maple-findings

0 stars 0 forks source link

Functions calculating the value of `BPT` is vulnerable to flash-loan attacks. #113

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

shw

Vulnerability details

Impact

In library/PoolLib.sol, the return value of functions BPTVal and getPoolSharesRequired are vulnerable by flash-loan attacks. The attacker can inflate the results of these two functions by swapping a large amount of liquidityAsset into the pool and swaps back after the functions are called to deceive the pool contract that BPT has a relatively high price.

Although currently BPTVal is not used and getPoolSharesRequired only affects the required staking amounts of token for a pool delegate, the code is vulnerable and could be misused by anyone in the future.

Proof of Concept

In the function BPTVal, the value of BPT in units of liquidityAsset is calculated directly from the balance of liquidityAsset in the Balancer pool (PoolLib.sol#331). For function getPoolSharesRequired, the required BPT to be burned also depends on the current balance of liquidityAsset in the pool.

Tools Used

None

Recommended Mitigation Steps

Use the balance of liquidityAsset in the previous block to eliminate the possibility of suffering from a flash-loan attack. A time-weight average price can also mitigate the problem.

lucas-manuel commented 3 years ago

We will change the name of this function to BPTVal_unsafe so onchain integrators are aware of this vulnerability.

lucas-manuel commented 3 years ago

Disagree with severity

Arachnid commented 3 years ago

Agree with Sponsors' reasoning for severity.