Skip to content
Business logic Audit finding Intermediate

ERC-20 allowance bypass: spender can force sender to pay extra fees beyond approved amount

The ERC-20 transferFrom function deducts a transaction fee from the sender's balance without checking that the total amount (transfer plus fee) is within the approved allowance. A spender could therefore cause the sender to lose more tokens than the sender approved.

dd0x7e8 Follow with 0xAadi, 0xgh0stcybers3c and 7 others

Originally disclosed on Code4rena

Submitted by dd0x7e8, also found by 0xAadi, 0xgh0stcybers3c, Daniel526, deeney, djshan_eden, JCN, mxteem, Roger, and unnamed

https://github.com/code-423n4/2025-01-next-generation/blob/499cfa50a56126c0c3c6caa30808d79f82d31e34/contracts/Token.sol#L166

Finding description and impact

The EURFToken contract includes a transaction fee mechanism where a percentage of the transferred amount is deducted as a fee. This fee is deducted from the sender’s balance additionally. However, in the transferFrom function, which allows spender addresses to transfer tokens on behalf of the actual owner, the contract does not account for the fact that the total deducted amount (including fees) may exceed the approved allowance.

Specifically, if a user approves a spender to transfer 100 tokens, and the transaction fee is 10%, the spender will effectively cause the owner to lose 110 tokens (100 for the transfer and 10 for the fee); even though the allowance was only 100. This violates the ERC-20 standard, where the spender should only be able to transfer up to the approved amount.

function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
    transferSanity(sender, recipient, amount);
    return super.transferFrom(sender, recipient, amount);
}
  • The function calls transferSanity(sender, recipient, amount), which deducts additional fees without checking if amount + fee exceeds the allowance.
  • The actual deduction happens in _payTxFee(sender, amount), which is triggered before executing the transfer:
function transferSanity(address sender, address recipient, uint256 amount) internal {
    adminSanity(sender, recipient);
    if (_txfeeRate > 0) _payTxFee(sender, amount);
}
  • _payTxFee(sender, amount) calculates the transaction fee and deducts it directly from the sender’s balance, without ensuring that the allowance covers it:
function _payTxFee(address from, uint256 txAmount) internal override {
    uint256 txFees = calculateTxFee(txAmount);
    if (balanceOf(from) < txFees + txAmount) revert BalanceTooLow(txFees + txAmount, balanceOf(from));
    if (_feesFaucet != address(0)) _update(from, _feesFaucet, txFees);
    emit FeesPaid(from, txFees);
}

Proof of Concept

The PoC built on Foundry framework to show that the decreased balance exceeds the approved allowance in transferFrom function.

    function test_transferFrom_exceedAllowance() public {
        vm.startPrank(alice);
        token.approve(address(this), 100e6);
        vm.stopPrank();
        uint256 balBefore = token.balanceOf(alice);
        console.log("calling transferFrom to transfer 100 EURF");
        token.transferFrom(alice, bob, 100e6);
        assertGe(balBefore - token.balanceOf(alice), 100e6);
    }

Test result:

[PASS] test_transferFrom_exceedAllowance() (gas: 87670)
Logs:
  calling transferFrom to transfer 100 EURF

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 6.62ms (867.42µs CPU time)

Ran 1 test suite in 138.69ms (6.62ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Recommended mitigation steps

Modify transferFrom to ensure that the spender’s allowance covers both the transfer amount and fees:

function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
    uint256 txFees = calculateTxFee(amount);
    uint256 totalCost = amount + txFees;

    require(allowance(sender, msg.sender) >= totalCost, "ERC20: transfer amount exceeds allowance");

    transferSanity(sender, recipient, amount);
    return super.transferFrom(sender, recipient, amount);
}

With this update, Bob can only transfer 100 EURF if Alice explicitly approves at least 110 EURF, preventing unintended token loss.

0xsomeone (judge) commented:

The submission and its duplicates outline that the fee charged by the system is imposed on top of the actual transfer amount. This behavior is highly non-standard, can result in significant issues with DeFi systems, and results in an important issue around allowances. Specifically, a user approved for an amount X is able to affect up to X + fee which effectively goes against the EIP-20 standard.

I consider this observation to be a justifiably medium-level issue as any fee imposed by the system should be a subset of the amount transferred rather than charged on top.

aivarsb (Next Generation) commented:

We would like to clarify our position on this finding:

Current Project Scope: As noted in our initial project planning, the fee capability will not be utilized in the initial deployment of the project. The transaction fee rate will be set to zero at launch.

Implementation Decision: Given that the fee functionality will not be active initially, we have made the decision to defer code modifications addressing this issue until we determine that fee implementation is necessary for our platform.

Future Considerations: We have documented this finding in our internal development roadmap. Should we decide to implement the fee mechanism in the future, we will incorporate the recommended fix to ensure the total amount (transfer + fee) is properly checked against the approved allowance before executing the transfer.


The original report as published on Code4rena, by dd0x7e8. 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 transferFrom function calls transferSanity which deducts a fee from the sender before checking that the total amount (transfer plus fee) does not exceed the allowance.

Impact

A spender could cause the sender to lose more tokens than the approved allowance, which violates the ERC-20 standard and could disrupt DeFi systems that rely on allowances.

What the attacker needed

A token with a non-zero transaction fee; sender has approved a spender; spender calls transferFrom

The fix

The transferFrom function should check that the allowance covers both the transfer amount and the fee before executing the transfer.

How it was found

  1. Alice approves a spender to transfer 100 tokens.
  2. The spender calls transferFrom to transfer 100 tokens from Alice to Bob.
  3. The contract deducts a 10% fee from Alice's balance in addition to the 100 tokens, so Alice loses 110 tokens total.

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.

In many tokens, you can let someone else spend your tokens up to a limit you set. This token also takes a fee from you when you send tokens. The bug is that when someone else spends your tokens, the fee is taken from you as well, but the code does not check that the total taken (spent amount plus fee) is within the limit you set. So the other person can make you lose more than you agreed to.

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 dd0x7e8

View all

1 more disclosed report, best first.

More from Next Generation

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.