Incompatibility with fee-on-transfer/inflationary/deflationary/rebasing tokens, on both base tokens and quote tokens, with varying impacts
The SizeSealed contract does not correctly handle ERC20 tokens whose balances change unexpectedly, such as fee-on-transfer or rebasing tokens. For base tokens, fee-on-transfer tokens make the contract unusable, and rebasing tokens can lock funds; for quote tokens, fee-on-transfer tokens can cause a denial of service or fund loss, and rebasing tokens can lock funds.
Submitted by neko_nyaa, also found by 141345, 0x52, 0xc0ffEE, 0xSmartContract, c7e7eff, cccz, cryptostellar5, fs0c, hansfriese, horsefacts, Josiah, KingNFT, ladboy233, Lambda, minhtrng, pashov, R2, RaymondFam, Ruhum, rvierdiiev, sashik_eth, TomJ, tonisives, Trust, TwelveSec, and wagmi.
https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L163 https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L96-L105
The following report describes two issues with how the SizeSealed contract incorrectly handles several so-called “weird ERC20” tokens, in which the token’s balance can change unexpectedly:
- How the contract cannot handle fee-on-transfer base tokens, and
- How the contract incorrectly handles unusual ERC20 tokens in general, with stated impact.
Base tokens
Let us first note how the contract attempts to handle sudden balance change to the baseToken:
https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L96-L105
uint256 balanceBeforeTransfer = ERC20(auctionParams.baseToken).balanceOf(address(this));
SafeTransferLib.safeTransferFrom(
ERC20(auctionParams.baseToken), msg.sender, address(this), auctionParams.totalBaseAmount
);
uint256 balanceAfterTransfer = ERC20(auctionParams.baseToken).balanceOf(address(this));
if (balanceAfterTransfer - balanceBeforeTransfer != auctionParams.totalBaseAmount) {
revert UnexpectedBalanceChange();
}
The effect is that the operation will revert with the error UnexpectedBalanceChange() if the received amount is different from what was transferred.
Quote tokens
Unlike base tokens, there is no such check when transferring the quoteToken from the bidder:
https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L163
SafeTransferLib.safeTransferFrom(ERC20(a.params.quoteToken), msg.sender, address(this), quoteAmount);
Since line 150 stores the quoteAmount as a state variable, which will be used later on during outgoing transfers (see following lines), this results in incorrect state handling.
It is worth noting that this will effect all functions with outgoing transfers, due to reliance on storage values.
- https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L327
- https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L351
- https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L381
- https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol#L439
Proof of concept
Consider the following scenario, describing the issue with both token types:
- Alice places an auction, her base token is a rebasing token (e.g. aToken from Aave).
- Bob places a bid with
1e18quote tokens. This quote token turns out to be a fee-on-transfer token, and the contract actually received1e18 - fee. - Some time later, Alice cancels the auction and withdraws her aTokens.
- Bob is now unable to withdraw his bid, due to failed transfers for the contract not having enough balance.
For Alice’s situation, she is able to recover her original amount. However, since aTokens increases one’s own balance over time, the “interest” amount is permanently locked in the contract.
Bob’s situation is somewhat more recoverable, as he can simply send more tokens to the contract itself, so that the contract’s balance is sufficient to refund Bob his tokens. However, given that Bob now has to incur more transfer fees to get his own funds back, I consider this a leakage of value.
It is worth noting that similar impacts will happen to successful auctions as well, although it is a little more complicated, and that it varies in the matter of who is affected.
Impact
For the base token:
-
For fee-on-transfer tokens, the contract is simply unusable on these tokens.
- There exists many popular fee-on-transfer tokens, and potential tokens where the fees may be switched on in the future.
-
For rebasing tokens, part of the funds may be permanently locked in the contract.
For the quote token:
-
If the token is a fee-on-transfer, or anything that results in the contract holding lower amount than stored, then this actually results in a denial-of-service, since outgoing transfers in e.g.
withdraw()will fail due to insufficient balance.- This may get costly to recover if a certain auction is popular, but is cancelled, so the last bidder to withdraw takes all the damage.
- This can also be considered fund loss due to quote tokens getting stuck in the contract.
-
For rebasing tokens, part of the funds may be permanently locked in the contract (same effect as base token).
Remarks
While technically two separate issues are described, they do have many overlappings, and both comes down to correct handling of unusual ERC20 tokens, hence I have decided to combine these into a single report.
Another intention was to highlight the similarities and differences between balance handling of base tokens and quote tokens, which actually has given rise to part of the issue itself.
Recommended Mitigation Steps
For both issues:
- Consider warning the users about the possibility of fund loss when using rebasing tokens as the quote token.
- Adding ERC20 recovering functions is an option, however this should be done carefully, so as not to accidentally pull out base or quote tokens from ongoing auctions.
For the base token issue:
-
Consider using two parameters for transferring base tokens: e.g.
amountToTransferInfor the amount to be pulled in, andauctionParams.totalBaseAmountfor the actual amount received, then check the received amount is appropriate.- The calculation for these two amount should be the auction creator’s responsibility, however this can be made a little easier for them by checking amount received is at least
auctionParams.totalBaseAmountinstead of exact, and possibly transferring the surplus amount back to the creator.
- The calculation for these two amount should be the auction creator’s responsibility, however this can be made a little easier for them by checking amount received is at least
For the quote token issue:
- Consider adding a check for
quoteAmountto be correctly transferred, or check the actual amount transferred in the contract instead of using the function parameter, or something similar to the base token’s mitigation.
Additionally, consider using a separate internal function for pulling tokens, to ensure correct transfers.
0xean (judge) commented on duplicate issue #255:
debating between M and H on this one. Currently leaning towards H since there is a direct loss of funds and no documentation stating these types of tokens aren’t supported (nor checks to disable them).
using this issue to gather all of the various manifestations of “special” ERC20 tokens not being supported. While rebasing tokens would need to be handled differently than fee on transfer, the underlying issue is close enough to not separate them all out
Ragepit (SIZE) confirmed duplicate issue #255
0xean (judge) commented on duplicate issue #255:
Thought about this one more and look back at some similar past findings from myself and other judges and feel that M is the correct severity here. code-423n4/org#3 for a conversation on the topic.
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
Impact
For base tokens, fee-on-transfer tokens make the contract unusable and rebasing tokens can permanently lock part of the funds; for quote tokens, fee-on-transfer tokens can cause a denial of service or fund loss, and rebasing tokens can permanently lock part of the funds.
What the attacker needed
Auction uses a fee-on-transfer or rebasing token; attacker is a bidder or auction creator
The fix
The contract should check the actual amount received for quote tokens and use separate parameters for the amount to transfer in and the amount expected, checking that the received amount is appropriate.
How it was found
- Alice creates an auction using a rebasing token as the base token.
- Bob bids with a fee-on-transfer quote token, so the contract receives less than the bid amount.
- Alice cancels the auction and withdraws her base tokens.
- Bob cannot withdraw his bid because the contract lacks sufficient balance.
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 are unusual: when you send them, the receiver may get less than you sent (fee-on-transfer), or the balance may change over time (rebasing). This report explains that the auction contract assumes the amount sent always equals the amount received, so with these tokens it can fail to refund bidders or lock funds.
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.