Skip to content
Business logic Audit finding Intermediate

Vault can’t receive deposits if underlying token charges fees on transfer

The vault's deposit and sponsor functions check that the vault's balance increases by exactly the transferred amount after a safeTransferFrom. If the underlying token charges a fee on transfer, the balance increase is smaller, so the check fails and the function reverts, making deposits and sponsorships impossible.

Ruhum Follow

Originally disclosed on Code4rena

Submitted by Ruhum, also found by harleythedog, Tomio, and WatchPug

Some ERC20 tokens charge a fee for every transfer. If the underlying token of a vault is such a token any deposit to the protocol will fail.

Some tokens have the possibility of adding fees later on, e.g. USDT. So those have to be covered too.

Generally, the user would also receive fewer tokens on withdrawing in such a scenario but that’s not the protocol’s fault.

I rated the issue as medium since part of the protocol become unavailable in such a situation.

Proof of Concept

https://github.com/code-423n4/2022-01-sandclock/blob/main/sandclock/contracts/Vault.sol#L583-L585

_transferAndCheckUnderlying() is used to deposit and sponsor the vault. It checks that after a safeTransferFrom() the same exact amount is sent to the balance of the vault. But, if fees are enabled the values won’t match, causing the function to revert. Thus, it won’t be able to deposit or sponsor the vault in any way.

Recommended Mitigation Steps

One possibility would be to simply not use ERC20 tokens with fees.

ryuheimat (Sandclock) disputed:

We don’t use tokens with fees

naps62 (Sandclock) commented:

The only place where we mention USDT is on an old pitch deck (not up to date anymore). The codebase itself doesn’t mention it, and all tests are done with USDC and DAI as examples

dmvt (judge) commented:

I’m going to let this issue stand given that #164 is also valid. Supported or not, fee on transfer tokens would cause a loss of funds in the scenario described. As the USDT example shows (in both issues), many stables can be upgraded and add a fee later.

The original report as published on Code4rena, by Ruhum. 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 deposit path assumes the vault's balance grows by exactly the transferred amount, which is false for fee-on-transfer tokens.

Impact

Deposits and sponsorships into the vault would revert for fee-on-transfer tokens, making that part of the protocol unavailable; the team disputes that such tokens are supported.

What the attacker needed

Underlying token charges a transfer fee

The fix

The vault should either reject fee-on-transfer tokens explicitly or measure the actual balance change instead of assuming an exact amount.

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 cut every time they are moved between wallets, so the receiver gets less than the sender sent. This vault checks that it received exactly the amount it asked for, so with such a token the check always fails and nobody can put money in. The team says they do not plan to use these tokens, but the judge noted that a token like USDT could add such a fee later.

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 Ruhum

View all

55 more disclosed reports, best first.

More from Sandclock 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.