Auction collateralToken won’t work if token is fee-on-transfer token
The auction contract assumes that transferring a specified amount of collateral tokens results in the recipient receiving exactly that amount. If a fee-on-transfer token is used, the recipient's balance will be less, causing a balance check to fail and preventing participation in the auction.
Originally disclosed on Code4rena
Submitted by harleythedog
There are several ERC20 tokens that take a small fee on transfers/transferFroms (known as “fee-on-transfer” tokens). Most notably, USDT is an ERC20 token that has togglable transfer fees, but for now the fee is set to 0 (see the contract here: https://etherscan.io/address/0xdAC17F958D2ee523a2206206994597C13D831ec7#code). For these tokens, it should not be assumed that if you transfer x tokens to an address, that the address actually receives x tokens. In the current test environment, DAI is the only collateralToken available, so there are no issues. However, it has been noted that more pools will be added in the future, so special care will need to be taken if fee-on-transfer tokens (like USDT) are planned to be used as collateralTokens.
For example, consider the function purchaseArbitrageTokens in Auction.sol. This function transfers realCommitment amount of collateralToken to the liquidityExtension, and then calls purchaseAndBurn(realCommitment) on the liquidityExtension. The very first line of purchaseAndBurn(amount) is require(collateralToken.balanceOf(address(this)) >= amount, "Insufficient balance");. In the case of fee-on-transfer tokens, this line will revert due to the small fee taken. This means that all calls to purchaseArbitrageTokens will fail, which would be very bad when the price goes below peg, since no one would be able to participate in this auction.
Proof of Concept
See purchaseArbitrageTokens here: https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L177
See purchaseAndBurn here: https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/LiquidityExtension.sol#L117
Recommended Mitigation Steps
Add logic to transfers/transferFroms to calculate exactly how many tokens were actually sent to a specific address. In the example given with purchaseArbitrageTokens, instead of calling purchaseAndBurn with realCommitment, the contract should use the difference in the liquidityExtension balance after the transfer minus the liquidityExtension balance before the transfer.
Alex the Entreprenerd (judge) commented:
Agree with the finding, the system as a whole seem to not deal with feeOnTransfer Token Mitigation can be as simple as never using them, or refactoring to check for actual amounts received
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 does not account for tokens that deduct a fee on transfer, so it compares the received amount to the intended amount and reverts.
Impact
If fee-on-transfer tokens are used as collateral, all calls to purchaseArbitrageTokens would fail, preventing participation in the auction when the price goes below peg.
What the attacker needed
Fee-on-transfer token used as collateral
The fix
The contract should measure the actual amount received by checking the balance difference before and after the transfer, and use that amount instead of the intended 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 digital tokens take a small fee when they are sent from one account to another, so the receiver gets less than the sender intended. The auction contract checks that the receiver got the full amount and fails if it did not, which would stop people from using the auction with such tokens.
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.