EscanBE / evermint

Evermint is a fork of open source Evmos, maintains bug fixes, customization and enable developers to fork and transform to their chain, fully customized naming, in just 2 steps. For research and development purpose.
GNU Lesser General Public License v3.0
3 stars 3 forks source link

Feature Request: Expand account compatible #55

Open VictorTrustyDev opened 11 months ago

VictorTrustyDev commented 11 months ago

Evermint is fork of Evmos v12.1.6 for research & development purpose

Update Sep 2024: implemented in Evermint by #129


Currently, Evermint is using EthAccount as the default proto account and the only type of account supported. That causes some limit:

Request:

Aware:

Mindset changes:

Migration aware (if any chain planned to implement this):

VictorTrustyDev commented 11 months ago

Pieces of solution

  1. The legacy EthAccount stores code hash. => Introduce new store that store code hash.

  2. To be able to compatible with x/auth keeper::RemoveAccount, as well as a protection layer in case of code logic-if any, the new dedicated storages must has key is combination of address & account number. When an account is removed, the account and the account number will be removed from store so if the same account address is created again, with another account number, key pointer will refer to nil value. When contract is deleted, the key must be removed too. Noway an account can be created again with the same account number, except core team do it on purpose(?).

  3. Cosmos does support 20 bytes and 32 bytes address (like ICA) but code hash is only used to store contract's code hash so only 20 bytes address is considered. If any account with len(address_bytes) != 20 then it is absolutely not a contract.

Store:

New Code Hash store Key-Prefix:

prefixCodeHash (iota=4)
KeyPrefixCodeHash = []byte{prefixCodeHash}

Key: 1 bytes of store key code hash prefix + 20 bytes of address + 8 bytes of account number Uint64ToBigEndian. To maintains absolute key length = 29 bytes, if bytes of account number is less than 8, must append prefix 0x00 until reached 8 bytes.

Test-cases:

  1. Store code hash:

    • Not contains the byte hash equals to empty code hash of non-contract account
  2. Multiple account types:

    • Other account types must be able to work with x/evm
VictorTrustyDev commented 11 months ago

Proof of Concept #56

I have made a branch to prove that the above solution that is, at this moment, seems to work perfectly with even all deprecated modules of Evmos.

15 commits for 15 implementation steps:

  1. remove EthAccount type
  2. define new store key for storing code hash
  3. remove registration of concrete interface
  4. introduce new type CodeHash for typed code & convenient method
  5. expand x/evm keeper with new methods to work with code hash & account type checking
  6. use default proto BaseAccount by x/auth
  7. migrate x/evm genesis account behavior
  8. genesis account is now base account
  9. update test with new account spec
  10. update statedb to use new code hash implementation
  11. update keeper to use new code hash implementation & account specification
  12. use BaseAccount instead of EthAccount in utils_test
  13. vesting now convert back to BaseAccount instead of EthAccount
  14. fix implementation & testcases for deprecated module x/claims
  15. fix implementation & testcases for deprecated module x/incentives

Notes:


Test status:


Migration (for existing chains) based on this implementation

  1. Migrate accounts:
    • Convert evmtypes.EthAccount back to authtypes.BaseAccount.
    • Call EVM keeper to store code hash of the removed EthAccount
yihuang commented 11 months ago

like the idea.

fedekunze commented 7 months ago

8 bytes of account number Uint64ToBigEndian

@VictorTrustyDev Why do you need the account number?

VictorTrustyDev commented 7 months ago

@fedekunze account destruction, account re-initialize. I explain this in "Pieces of solution" point 2.