Skip to content
Business logic Audit finding Intermediate

Yield source does not correctly calculate share conversions

The yield source's share conversion functions do not return one share for one token, so a depositor could receive fewer tokens than expected when withdrawing. In an edge case with only one depositor and high yield, a withdrawal could return zero tokens.

IllIllI Follow

Originally disclosed on Code4rena

Submitted by IllIllI

The aTokens’ value is pegged to the value of the corresponding supplied asset at a 1:1 ratio and can be safely stored, transferred or traded. All yield collected by the aTokens’ reserves are distributed to aToken holders directly by continuously increasing their wallet balance.

https://docs.aave.com/developers/tokens/atoken

Impact

Incorrect share conversions lead to incorrect pricing of assets and loss of principal. aTokens are rebasing tokens, which means that holders of the token have their balanceof() increase over time, but each token is still redeemable for exactly one underlying asset. Any formula that does not return one out for one in is incorrect.

Proof of Concept

File: contracts/AaveV3YieldSource.sol   #X

352     /**
353      * @notice Calculates the number of shares that should be minted or burnt when a user deposit or withdraw.
354      * @param _tokens Amount of asset tokens
355      * @return Number of shares.
356      */
357     function _tokenToShares(uint256 _tokens) internal view returns (uint256) {
358       uint256 _supply = totalSupply();
359
360       // shares = (tokens * totalShares) / yieldSourceATokenTotalSupply
361       return _supply == 0 ? _tokens : _tokens.mul(_supply).div(aToken.balanceOf(address(this)));
362     }
363
364     /**
365      * @notice Calculates the number of asset tokens a user has in the yield source.
366      * @param _shares Amount of shares
367      * @return Number of asset tokens.
368      */
369     function _sharesToToken(uint256 _shares) internal view returns (uint256) {
370       uint256 _supply = totalSupply();
371
372       // tokens = (shares * yieldSourceATokenTotalSupply) / totalShares
373       return _supply == 0 ? _shares : _shares.mul(aToken.balanceOf(address(this))).div(_supply);
374     }

AaveV3YieldSource.sol#L352-L374

The above code is used for both supplyTokenTo() and redeemToken() and does not return one for one. Consider the following chain of events:

  1. There are no deposits yet
  2. Alice deposits one wBTC, getting back a AaveV3YieldSource share, while the yield source gets the aToken
  3. Some time later a total of one extra wBTC worth of aToken is generated as yield and is in the balanceOf(this)
  4. Alice attempts to withdraw her one share but gets zero wBTC, because (tokens{1} * totalSupply(){1}) / aToken.balanceOf(this){2} is zero

Recommended Mitigation Steps

There does not need to be a conversion function - one share must always equal one token.

PierrickGT (PoolTogether) acknowledged and commented:

This is a plausible but unlikely scenario since it assumes that only Alice has deposited into the yield source and that the interest rate is so high that 1 more wBTC is now in the yield source. Also, the calculation is wrong since 1 wBTC would represent 1 ether or 1000000000000000000 wei. So the actual calculation would return (1000000000000000000 * 1000000000000000000) / 2000000000000000000 = 500000000000000000 wei or 0.5 wBTC.

We also periodically capture the interest accumulated in the yield source by calling the PrizeFlush contract: pooltogether/PrizeFlush.sol#L105. The capture of the interest happens here: pooltogether/PrizeSplitStrategy.sol#L51.

For these reasons, I’ve acknowledged the issue but we won’t change how shares are calculated.

Justin Goro (judge) decreased severity to Medium and commented:

Downgraded severity as this is more of a value leakage situation, especially given the unlikely edge case of an ERC20 token that sets decimals to 0 and uses low base values.


The original report as published on Code4rena, by IllIllI. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 conversion functions use a ratio based on the contract's aToken balance and total share supply, but aTokens are rebasing and should be treated as one-to-one with the underlying asset.

Impact

In an unlikely edge case, a user could lose principal because a withdrawal returns fewer tokens than deposited, possibly zero; the project acknowledged the issue but chose not to fix it.

What the attacker needed

Only one depositor in the yield source; High yield causes aToken balance to double; Token with low decimals or base value

The fix

The conversion functions should be removed so that one share always equals one token, as the report recommends.

How it was found

  1. No deposits exist yet.
  2. Alice deposits one wBTC and receives one share; the yield source receives the aToken.
  3. Later, yield accrues so the contract's aToken balance equals two wBTC.
  4. Alice tries to withdraw her one share but receives zero wBTC because the conversion formula rounds down.

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.

This is a smart contract for a savings pool. It gives out 'shares' when you deposit tokens. The code that converts between shares and tokens is wrong: it should always be one share for one token, but it uses a formula that can give you less when you withdraw. In a rare case, you could get nothing back.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by IllIllI

View all

119 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.