Solmate’s ERC20 does not check for token contract’s existence, which opens up possibility for a honeypot attack
The contract uses Solmate's SafeTransferLib, which does not check that the token address has code, so a transfer from an empty address succeeds silently without crediting tokens. An attacker could exploit this to create a honeypot auction and steal a victim's funds once the real token is deployed.
Submitted by neko_nyaa, also found by 8olidity, Bnke0x0, brgltd, ctf_sec, djxploit, horsefacts, jayphbee, Matin, and TwelveSec.
When bidding, the contract pulls the quote token from the bidder to itself.
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);
However, since the contract uses Solmate’s SafeTransferLib
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
Therefore if the token address is empty, the transfer will succeed silently, but not crediting the contract with any tokens.
This error opens up room for a honeypot attack similar to the Qubit Finance hack in January 2022.
In particular, it has became popular for protocols to deploy their token across multiple networks using the same deploying address, so that they can control the address nonce and ensuring a consistent token address across different networks.
E.g. 1INCH has the same token address on Ethereum and BSC, and GEL token has the same address on Ethereum, Fantom and Polygon. There are other protocols have same contract addresses across different chains, and it’s not hard to imagine such thing for their protocol token too, if any.
Proof of Concept
Assuming that Alice is the attacker, Bob is the victim. Alice has two accounts, namely Alice1 and Alice2. Denote token Q as the quote token.
-
Token Q has been launched on other chains, but not on the local chain yet. It is expected that token Q will be launched on the local chain with a consistent address as other chains.
-
Alice1 places an auction with some
baseToken, and a token Q as thequoteToken. -
Alice2 places a bid with
1000e18quote tokens.- The transfer succeeds, but the contract is not credited any tokens.
-
Token Q is launched on the local chain.
-
Bob places a bid with
1001e18quote tokens. -
Alice2 cancels her own bid, recovering her (supposedly)
1000e18refund bid back. -
Alice1 cancels her auction, recovering her base tokens back.
As a result, the contract’s Q token balance is 1e18, Alice gets away with all her base tokens and 1000e18 Q tokens that are Bob’s. Alice has stolen Bob’s funds.
Recommended Mitigation Steps
Consider using OpenZeppelin’s SafeERC20 instead, which has checks that an address does indeed have a contract.
Ragepit (SIZE) confirmed and commented on duplicate issue #318:
Incredibly unlikely but confirming as Medium given the good argument in #48
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
Likely the use of Solmate's SafeTransferLib, which does not verify that the token address contains code, so calls to an empty address return success without transferring tokens.
Impact
An attacker could steal a victim's quote tokens by exploiting the silent success of transfers to an empty token address, though the project considered the scenario incredibly unlikely.
What the attacker needed
Token not yet deployed on local chain; attacker controls two accounts; victim bids after token deployment
The fix
The contract should use OpenZeppelin's SafeERC20, which checks that the token address has code.
How it was found
- Token Q is expected on the local chain but not yet deployed.
- Alice1 creates an auction using token Q as the quote token.
- Alice2 bids with quote tokens; the transfer succeeds but no tokens are credited.
- Token Q is deployed on the local chain.
- Bob bids with quote tokens, which are actually transferred.
- Alice2 cancels her bid and Alice1 cancels the auction, recovering their funds and stealing Bob's tokens.
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.
A smart contract can call another contract to move tokens, but if that other address has no code, the call still 'succeeds' without doing anything. This means a fake token address can be used to make it look like a payment was made when nothing was transferred. An attacker can then trick someone into bidding real tokens into an auction that was set up with this fake address.
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.