Skip to content
Business logic Audit finding Intermediate

_depositAmount requires to be updated to contract balance increase

The deposit function assumes the transferred amount equals the requested amount, but fee-on-transfer tokens deliver less. An attacker could deposit such a token and receive shares based on the larger nominal amount, causing the protocol to leak value.

MaratCerby Follow

Originally disclosed on Code4rena

Submitted by MaratCerby, also found by berndartmueller, cccz, CertoraInc, IllIllI, and reassor

AaveV3YieldSource.sol#L231-L242

Every time transferFrom or transfer function in ERC20 standard is called there is a possibility that underlying smart contract did not transfer the exact amount entered. It is required to find out contract balance increase/decrease after the transfer. This pattern also prevents from re-entrancy attack vector.

Recommended Mitigation Steps

Recommended code: function supplyTokenTo(uint256 _depositAmount, address _to) external override nonReentrant { uint256 _shares = _tokenToShares(_depositAmount); require(_shares > 0, “AaveV3YS/shares-gt-zero”);

address _underlyingAssetAddress = _tokenAddress();

uint256 balanceBefore = IERC20(_underlyingAssetAddress).balanceOf(address(this)); // remembering asset balance before the transfer
IERC20(_underlyingAssetAddress).safeTransferFrom(msg.sender, address(this), _depositAmount);
_depositAmount = IERC20(_underlyingAssetAddress).balanceOf(address(this)) - balanceBefore; // updating actual amount to the contract balance increase

_pool().supply(_underlyingAssetAddress, _depositAmount, address(this), REFERRAL_CODE);

_mint(_to, _shares);

emit SuppliedTokenTo(msg.sender, _shares, _depositAmount, _to);

}

PierrickGT (PoolTogether) acknowledged and commented:

This scenario would only happen if we use fee on transfer tokens. We don’t plan to support fee on transfer token, so for this reason, I have acknowledged the issue but we won’t implement the code suggestion.

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

This could lead to protocol leakage rather than risk of total funds loss. Downgrading to Medium Risk. Reentrancy isn’t an issue since the function is marked nonReentrant.


The original report as published on Code4rena, by MaratCerby. 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 contract calculates shares from the requested deposit amount instead of measuring the actual balance increase after the transfer.

Impact

This could lead to protocol leakage rather than risk of total funds loss; reentrancy is not an issue because the function is marked nonReentrant.

What the attacker needed

Fee-on-transfer token supported; attacker can call supplyTokenTo

The fix

The code should record the balance before the transfer and use the actual balance increase as the deposit amount; the project acknowledged the issue but chose not to implement the change because it does not plan to support fee-on-transfer tokens.

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.

Some tokens take a small fee when they are transferred, so the receiver gets less than the sender sent. This code assumes the full amount arrives and gives out shares based on that full amount. That means the protocol can end up with less money than the shares are worth, and other users lose out.

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 MaratCerby

View all

2 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.