Flash loan manipulation on getPoolShareWeight of Utils
The pool share weight calculation uses the current pool balance, which can be inflated by a flash loan swap, allowing an attacker to temporarily increase their voting power and rewards. The attacker can then deposit LP tokens, gain disproportionate influence, and swap back with minimal loss.
Submitted by shw
The getPoolShareWeight function returns a user’s pool share weight by calculating how many SPARTAN the user’s LP tokens account for. However, this approach is vulnerable to flash loan manipulation since an attacker can swap a large number of TOKEN to SPARTAN to increase the number of SPARTAN in the pool, thus effectively increasing his pool share weight.
According to the implementation of getPoolShareWeight, a user’s pool share weight is calculated by uints * baseAmount / totalSupply, where uints is the number of user’s LP tokens, totalSupply is the total supply of LP tokens, and baseAmount is the number of SPARTAN in the pool. Thus, a user’s pool share weight is proportional to the number of SPARTAN in the pool. Consider the following attack scenario:
- Supposing the attacked pool is SPARTAN-WBNB. The attacker first prepares some LP tokens (WBNB-SPP) by adding liquidity to the pool.
- The attacker then swaps a large number of WBNB to SPARTAN, which increases the pool’s
baseAmount. He could split his trade into small amounts to reduce slip-based fees. - The attacker now wants to increase his weight in the
DaoVault. He adds his LP tokens to the pool by calling thedepositfunction ofDao. Daothen callsdepositLPofDaoVault, causing the attacker’s weight to be recalculated. Due to the large proportion of SPARTAN in the pool, the attacker’s weight is artificially increased.- With a higher member weight, the attacker can, for example, vote the current proposal with more votes than he should have or obtain more rewards when calling
harvestof theDaocontract. - The attacker then swaps back SPARTAN to WBNB and only loses the slip-based fees.
Referenced code: Utils.sol#L46-L50, Utils.sol#L70-L77, DaoVault.sol#L44-L56, Dao.sol#L201, and Dao.sol#L570.
A possible mitigation is to record the current timestamp when a user’s weight in the DaoVault or BondVault is recalculated and force the new weight to take effect only after a certain period, e.g., a block time. This would prevent the attacker from launching the attack since there is typically no guarantee that he could arbitrage the WBNB back in the next block.
SamusElderg (Spartan) confirmed and disagreed with severity:
Recommended mitigation has been included in contributors ongoing discussions to make this more resistant to manipulation
Keeping high risk because of impact
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 pool share weight is calculated from the instantaneous pool balance, which can be manipulated within a single transaction via a flash loan.
Impact
An attacker could temporarily gain disproportionate voting power and rewards, though the attack requires paying swap fees and the text does not confirm actual exploitation.
What the attacker needed
Access to a flash loan or large capital; ability to add liquidity to the pool; ability to call deposit on Dao
The fix
The weight should be recorded with a timestamp and only take effect after a delay, such as one block, to prevent same-transaction manipulation.
How it was found
- The attacker adds liquidity to obtain LP tokens for the target pool.
- The attacker swaps a large amount of WBNB to SPARTAN, possibly in small trades to reduce fees, increasing the pool's SPARTAN balance.
- The attacker deposits their LP tokens into the DaoVault via the Dao contract, triggering a weight recalculation.
- The inflated SPARTAN balance causes the attacker's weight to be artificially increased.
- The attacker uses the higher weight to vote or harvest more rewards.
- The attacker swaps back SPARTAN to WBNB, losing only slip-based fees.
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 lets someone borrow a huge amount of cryptocurrency without collateral, as long as they return it in the same transaction. Here, the pool's share weight is based on how much of a token is in the pool at that moment, so an attacker can temporarily flood the pool with that token, making their share look bigger, and then take advantage of the inflated weight before undoing the swap.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.