Skip to content
Business logic Audit finding Advanced

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.

neko_nyaa Follow with 8olidity, Bnke0x0 and 7 others

Originally disclosed on Code4rena

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.

  1. 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.

  2. Alice1 places an auction with some baseToken, and a token Q as the quoteToken.

  3. Alice2 places a bid with 1000e18 quote tokens.

    • The transfer succeeds, but the contract is not credited any tokens.
  4. Token Q is launched on the local chain.

  5. Bob places a bid with 1001e18 quote tokens.

  6. Alice2 cancels her own bid, recovering her (supposedly) 1000e18 refund bid back.

  7. 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


The original report as published on Code4rena, by neko_nyaa. 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

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

  1. Token Q is expected on the local chain but not yet deployed.
  2. Alice1 creates an auction using token Q as the quote token.
  3. Alice2 bids with quote tokens; the transfer succeeds but no tokens are credited.
  4. Token Q is deployed on the local chain.
  5. Bob bids with quote tokens, which are actually transferred.
  6. 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.

More by neko_nyaa

View all

1 more disclosed report, best first.

More from Size

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.