[evm] Prevent invalid FunToken mappings in createFunTokenFromERC20
even though they are harmless.
#2063
Labels
x: evm
Relates to Nibiru EVM or the EVM Module
Purpose / Abstract
This issue takes a bit of nuance and context to understand. I thought about it while filling out the audit scope doc for Code4rena since it asks about compatibility expectations with different EIPs (Etherum Improvement Proposals).
Versions Impacted: Main branch as of 2024-10-05 (commit: 37913c4)
Key Takeaway
I argue that it is possible to create
FunToken
mappings that are unusable dueto having an
ERC20Addr
for a contract that only partially implements the ERC20standard.
This doesn't present a security issue because transaction message calls that use
the mapping, such as
ConvertCoinToEvm
, will simply fail to be executed. Withthat said, it still seems like bad practice to allow the creation of these
invalid mappings in state even if they can't do damage.
The rest of this description outlines a proof for this argument, and an explanation on how to correct it is in the "Recommended Solution" section.
[FunToken definition]
ERC20 Methods Used with FunTokens
There are two code paths when creating a
FunToken
mapping. Those are creatingthe mapping from an existing Bank Coin and creating the mapping from an existing
ERC20 (marked by the
FunToken.isMadeFromCoin
field). When creating from a coin,we have (
isMadeFromCoin=true
) and the ERC20 deployed is guaranteed to be validbecause the contrac embedded in the binary is used (x/evm/embeds/ERC20Minter.sol).
However when creating the
FunToken
mapping from an ERC20 address, the contractalready exists and only certain methods are called.
[Expand Call Digram for "createFunTokenFromERC20"]
The comprehensive list of methods from the ERC20 specification that are used with
FunToken
mappings is as follows:createFunTokenFromERC20
ConvertCoinToEvm
for existing ERC20s to transfer tokens from the EVM module account to the recipientConvertCoinToEvm
for native coins wrapped as ERC20s to create new tokensConvertCoinToEvm
sends a coin with a valid "FunToken" mapping to the given recipient address ("to_eth_addr") in the corresponding ERC20 representation.[Expand Call Digram for "ConvertCoinToEvm"]
What this all means
In the current version of Nibiru EVM (commit: 37913c4), as long as the contract used for
FunToken.Erc20Addr
duringcreatFunTokenFromERC20
implementsname
,symbol
, anddecimals
and followsthe exact ABI of the ERC20 specification for these methods, it is possible to create a
FunToken
mapping in state. However if the contract used is missing
transferFrom
,transfer
,mint
, orbalanceOf
, its usage will fail duringConvertCoinToEvm
or the precompile methodFunToken.bankSend
Recommended Solution
Validate that the other methods required from the ERC20 standard are implemented
during the creation of
FunToken
mappings. Likely, there are functions exportedfrom go-ethereum that make this easy to do.
The text was updated successfully, but these errors were encountered: