Unsafe usage of ERC20 transfer and transferFrom
The VotingEscrow contract calls ERC20 transfer and transferFrom functions and checks their return values, but some tokens like USDT and BNB do not return a boolean, causing those calls to revert. This means the contract would not work with such tokens, potentially preventing users from depositing or withdrawing.
Originally disclosed on Code4rena
Submitted by CertoraInc, also found by 0x1f8b, 0xSky, CodingNameKiki, DecorativePineapple, jonatascm, Noah3o6, oyc_109, pedr02b2, peritoflores, and Waze
https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L425-L428 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L485-L488 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L546 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L657 https://github.com/code-423n4/2022-08-fiatdao/blob/fece3bdb79ccacb501099c24b60312cd0b2e4bb2/contracts/VotingEscrow.sol#L676
Some ERC20 tokens functions don’t return a boolean, for example USDT, BNB, OMG. So the VotingEscrow contract simply won’t work with tokens like that as the token.
Proof of Concept
The USDT’s transfer and transferFrom functions doesn’t return a bool, so the call to these functions will revert although the user has enough balance and the VotingEscrow contract won’t work, assuming that token is USDT.
Tools Used
Manual auditing - VS Code, some hardhat tests and me :)
Recommended Mitigation Steps
Use the OpenZepplin’s safeTransfer and safeTransferFrom functions.
lacoop6tu (FIAT DAO) disputed and commented:
In our case the token is a BalancerV2 Pool Token which returns the boolean
Justin Goro (judge) commented:
This should be acknowledged, not disputed, since there is nothing in documentation suggesting the token is inherently safe to use.
@Justin Goro it’s a no-issue in our specific case bc we will use VotingEscrow in combination with
tokenwhich returns bool upon transfer/transferFrom. So at best this is a QA issue bc we should document that. some wardens actually asked us about what token we will be using pointing out the issue.Now even if you’d want to award wardens who reported the issue it should then be a Med Risk bc if VotingEscrow is deployed with an unsafe
tokenppl would simply not be able to deposit into the contract but no funds would be at risk.
Fyi, even though we don’t think this is an issue, we will make use of safeTransfer and safeTransferFrom so its a helpful submission nonetheless.
Justin Goro (judge) commented:
It’s tokens like BNB that led me to maintain the high risk rating. For BNB, transferFrom returns a bool but transfer doesn’t. In other words, users can stake but not unstake on any protocol that doesn’t use safeTransfer.
I agree that wardens should contact sponsors but it’s not a channel we can really monitor. So although the net result is a documentation fix rather than a bug fix, it’s a documentation fix informed by the identification of a potentially show stopping bug rather than something like “Comment typo: it should be Bitcoin, not bit coin”.
IllIllI (warden) reviewed mitigation:
The sponsor disputed the issue because the token it’s planned to be used with does correctly return a boolean. However, the sponsor decided to make a change to address the finding as Issue 18. The fix properly replaces the
require()statements that check for successful transfers, with calls to OpenZeppelin’ssafeTransfer(). The PR also replaces the internal definition of theIERC20interface with OpenZeppelin’s version. The prior version of the code’sIERC20included the functiondecimals(), which is not one of the required functions for the interface, so it’s possible for the code to encounter a token without this function, but it would be immediately apparent what happened because the constructor is the function that callsdecimals(). The change to using OpenZeppelin required making this distinction more visible due to the fact that they’re defined separately asIERC20andIERC20Metadata. The new code is not checking that the token actually supports the function (e.g. using asafeDecimals()-like function), but it is not any worse off that it had been prior to the change.
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 assumes all ERC20 tokens return a boolean from transfer and transferFrom, but some tokens do not, causing the call to revert.
Impact
If the contract is used with a token that does not return a boolean, users may be unable to deposit or withdraw, but no funds are at risk.
What the attacker needed
VotingEscrow deployed with a token that does not return bool
The fix
The contract was fixed by replacing the require statements with OpenZeppelin's safeTransfer and safeTransferFrom functions.
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 (like USDT) don't follow the full standard when sending tokens: they don't send back a 'yes' or 'no' signal. The contract expects that signal and treats its absence as an error, so it stops working. This means users couldn't deposit or withdraw those tokens.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.