Blog

ERC 404

This new ERC404 hype seems to have a funny side-effect in its _transfer, which can invoked via transferFrom (only allows to transfer 1e18) and transfer (allows to transfer any amount):



As you can see, a transfer does two things:

a) Adjust balanceOf from sender and recipient

b) Burn tokens from sender and mint tokens for recipient

The crux here is that the tokens_to_burn and tokens_to_mint is calculated as follows:

(balanceBeforeSender / 1e18) - (balanceOf[from] / 1e18)
(balanceOf[to] / 1e18) -
(balanceBeforeReceiver / 1e18)

So let's assume we have an initial balance of 1e18 and transfer 0.5e18 tokens, this means that our balance is decrease by 0.5e18 and the recipient balance is increased by 0.5e18.

So far so good - now let's go to the burn/mint.

Due to the arithmetic operation highlighted above, this will be as follows:

(1e18 / 1e18) - (0.5 / 1e18) = 1e18, hence 1e18 are burned since solidity rounds down, but at the same time nothing is minted, since the arithmetic operation for mint is as follows:

(0.5e18 / 1e18 - (0 / 1e18) = 0, hence 0 tokens are minted to the recipient.

So to summarize: We can transfer tokens which correctly change the balanceOf mapping but the actual ERC721 part, which is the burn/mint that keeps track of the owner will not be correctly reflected (result in an actual loss, while still having a partial balance).

RT if you would like to learn more about ERC404 (lmao)


Another funny fact about ERC404:

As we know, this is the transferFrom function, which is invoked upon swaps by the router. Currently, this function is triggered using the second condition, since the UniswapV2 router will transfer more than the "minted" amount in:



However, in such a scenario where only a very tiny amount is being bought which is converted to the corresponding token amount below the "minted" value, the pair will actually receive 1e18 instead of the desired amount, due to the first condition being fulfilled. The swap however is just using the provided small amount, not the full 1e18 received.

(Assuming the caller has granted the router spend approvals for ERC721 purposes lmao)

This means that (1e18-amount) is actually donated to the pair, since it is automatically sync'd post-swap, resulting in this being distributed as fee for the liquidity providers