Skip to content
Business logic Audit finding Intermediate

Inconsistent balance when supplying transfer-on-fee or deflationary tokens

The StakingRewards contract assumes that the full amount of stakingToken is received after a safeTransferFrom call, but transfer-on-fee or deflationary tokens cause the actual received amount to be less. This leads to an inconsistency between the recorded balance and the actual token balance, which could be exploited or cause accounting errors.

Reigada Follow

Originally disclosed on Code4rena

Submitted by Reigada

Impact

In the contract StakingRewards, the stake function assume that the amount of stakingToken is transferred to the smart contract after calling the safeTransferFrom function (and thus it updates the \_balances mapping). However, this may not be true if the stakingToken is a transfer-on-fee token or a deflationary/rebasing token, causing the received amount to be less than the accounted amount in the \_balances mapping.

Same can be applied for the withdraw function.

Proof of Concept

https://github.com/code-423n4/2021-11-vader/blob/main/contracts/staking-rewards/StakingRewards.sol#L100-L102

Tools Used

Manual code review

Recommended Mitigation Steps

Get the actual received amount by calculating the difference of token balance before and after the transfer. For example: uint256 balanceBefore = stakingToken.balanceOf(address(this)); stakingToken.safeTransferFrom(msg.sender, address(this), amount); uint256 receivedAmount = stakingToken.balanceOf(address(this)) - balanceBefore; \_totalSupply = \_totalSupply.add(receivedAmount); \_balances\[msg.sender] = \_balances\[msg.sender].add(receivedAmount);

0xstormtrooper (Vader) acknowledged:

VADER / USDV fee on transfer will be removed

The original report as published on Code4rena, by Reigada. 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

The contract updates internal balances based on the requested transfer amount rather than the actual received amount, which differs for fee-on-transfer tokens.

What the attacker needed

StakingToken is a fee-on-transfer token

The fix

The contract should measure the actual received amount by checking the token balance before and after the transfer and update balances accordingly.

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 fee when transferred, so the receiver gets less than the sender sent. The contract records the full amount as if no fee was taken, so its internal balance is wrong. This can cause users to lose funds or allow someone to exploit the mismatch.

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 Reigada

View all

3 more disclosed reports, best first.

More from Vader Protocol 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.