Skip to content
Business logic Audit finding Intermediate

Wrong init code hash

The contract uses an incorrect init code hash for UniswapV2 pair address calculation, which does not match the latest UniswapV2 repository. This could cause the contract to interact with the wrong pair contract, potentially leading to risks when liquidity is insufficient.

hansfriese Follow with nadin

Originally disclosed on Code4rena

Submitted by hansfriese, also found by nadin

An init code hash is used to calculate the address of UniswapV2 pair contract. But the init code hash is not same as the latest UniswapV2 repository.

Proof of Concept

UniswapV2Library.pairFor uses the following value as the init code hash of UniswapV2Pair.

    hex"e18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303" // init code hash

But it is different from the init code hash of the uniswap v2 repository.

I tested this using one of the top UniswapV2 pairs. DAI-USDC is in the third place here.

The token addresses are as follows:

DAI: 0x6B175474E89094C44Da98b954EedeAC495271d0F

USDC: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48

And the current UniswapV2Factory address is 0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f here.

The pair address calculated is 0x6983E2Da04353C31c7C42B0EA900a40B1D5bf845. And we can’t find pair contract in the address.

So I think the old version of UniswapV2Factory and pair are used here. And it can cause a risk when liquidity is not enough for the pair.

Recommended Mitigation Steps

Integrate the latest version of UniswapV2.

kyscott18 (Numoen) acknowledged and commented:

I should have been more specific, but the init code hash that I submitted is the sushiswap one.


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

Impact

The contract may compute incorrect pair addresses, which could cause it to interact with the wrong or non-existent pair, potentially leading to risks when liquidity is not enough for the pair.

What the attacker needed

None

The fix

The contract should be updated to use the correct init code hash from the latest UniswapV2 repository.

How it was found

  1. Identify the init code hash used in UniswapV2Library.pairFor.
  2. Compare it with the init code hash from the UniswapV2 repository.
  3. Calculate the pair address for DAI-USDC using the given token addresses and factory address.
  4. Check that the calculated address does not correspond to an existing pair contract.

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 uses a fixed value (init code hash) to compute the address of a trading pair contract. If that value is wrong, the computed address will be wrong, so the contract may talk to a different or non-existent pair. This can cause problems if there isn't enough liquidity in the actual pair.

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 hansfriese

View all

65 more disclosed reports, best first.

More from Numoen contest

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.