Open VictorTrustyDev opened 11 months ago
The legacy EthAccount
stores code hash.
=> Introduce new store that store code hash.
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(?).
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.
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.
Store code hash:
Multiple account types:
x/evm
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:
x/claims
x/incentives
Notes:
StateDB::GetAccount
: if code hash of account is nil or empty code hash, evmtypes.EmptyCodeHash
will be returned along with the Account as usual.StateDB::DeleteAccount
minor changes: if account is not a contract account (read first post for condition), will be rejected with error. (Previously only check if it is EthAccount)
Test status:
go test
. One test failed, 2423 passed.should transfer tokens to the recipient and perform recovery
from x/recovery
module that I have no idea why failed (already failed pre-poc and I spent no time to investigate)Migration (for existing chains) based on this implementation
evmtypes.EthAccount
back to authtypes.BaseAccount
.EthAccount
like the idea.
8 bytes of account number
Uint64ToBigEndian
@VictorTrustyDev Why do you need the account number?
@fedekunze account destruction, account re-initialize. I explain this in "Pieces of solution" point 2.
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:x/vesting
moduleevmtypes.EmptyCodeHash
32 bytes value that also exists in every non-contractEthAccount
(see prove).Request:
EthAccount
authtypes.BaseAccount
as default proto account, compatible with EVM module.x/evm
non-genesis account now only support export/import only accounts with either code or storagelen(code_hash) > 0 && code_hash <> evmtypes.EmptyCodeHash
instead of saving it into everyEthAccount
record. This change will slightly lower gas fee required to read from store in non-evm TxsAware:
x/auth
keeperRemoveAccount
Mindset changes:
CodeHash
record (len(code_hash) == 0 || code_hash == evmtypes.EmptyCodeHash
will be removed from store)len(address_bytes) == 20
. If it is inblockedAddrs
byx/bank
, will be an error instateDb.Commit()
phrase.Migration aware (if any chain planned to implement this):