Skip to content
Business logic Audit finding Intermediate

Inconsistent balance when fee-on transfer tokens.

The staking contract records the token balance after a safe transfer, which can be lower than the amount actually staked if the token charges a transfer fee. An attacker could exploit this to cause an inconsistent accounting of staked balances.

asutorufos Follow

Originally disclosed on Code4rena

Submitted by asutorufos

There are ERC20 tokens that may make certain customizations to their ERC20 contracts.

One type of these tokens is deflationary tokens that charge a certain fee for every transfer() or transferFrom().

Proof of Concept

[https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/Staking.sol#:~:text=Invalid%20address%22)%3B-,uint256%20totalTokeAmount%20%3D%20IERC20Upgradeable(TOKE_TOKEN).balanceOf(,)%3B,-%7D](https://github.com/code-423n4/2022-06-yieldy/blob/main/src/contracts/Staking.sol#:~:text=Invalid%20address%22%29%3B-,uint256%20totalTokeAmount%20%3D%20IERC20Upgradeable(TOKE_TOKEN%29.balanceOf(,%29%3B,-%7D)

When IERC20Upgradeable(TOKE_TOKEN) get set to totalTokeAmount it will be different once safetransfer have fees as some types of tokens may charge a certain fee for transfer and transferfrom.

It may be better to get the before balance then safetransferfrom then get the after balance to make sure no fees were added.

toshiSat (Yieldy) acknowledged and commented:

We will not support deflationary tokens. We will document this.


The original report as published on Code4rena, by asutorufos. 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 uses the token balance after a fee-on-transfer transfer instead of measuring the actual amount received.

Impact

The contract's internal accounting could become inconsistent, potentially allowing a user to gain more stake than intended or causing loss of funds.

What the attacker needed

Fee-on-transfer token used; token transfer charges a fee

The fix

The contract should measure the balance before and after the transfer to account for any fees, or explicitly not 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. The contract checks the balance after the transfer, so it sees less than the user intended to stake. This can make the contract's records wrong.

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 from Yieldy contest

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.