Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

evm invariants check failed when executing hybrid tx #743

Closed
summerpro opened this issue Jan 21, 2021 · 1 comment
Closed

evm invariants check failed when executing hybrid tx #743

summerpro opened this issue Jan 21, 2021 · 1 comment
Labels
stale stale PRs that will be closed if no further action occurs Status: On Ice Type: User Reported

Comments

@summerpro
Copy link
Contributor

summerpro commented Jan 21, 2021

System info: [Include Ethermint commit, operating system name, and other relevant details]

  • in branch development

Steps to reproduce:

  1. [First Step]
  • execute evm tx in blockHeight 100.
  • account message will be written to Store and CommitStateDB
  1. [Second Step]
  • execute transafer tx in blockHeight 100
  • account message will be written to Store,but account message in CommitStateDB is not equal to account message in Store.
  1. [and so on...]
  • execute crisis tx in blockHeight 100 to do invariants check, it may be failed, because evm invariants check will require the data in the Store to be consistent with the data in CommitStateDB

Additional info: [Include gist of relevant config, logs, etc.]

// BalanceInvariant checks that all auth module's EthAccounts in the application have the same balance
// as the EVM one.
func (k Keeper) BalanceInvariant() sdk.Invariant {
	return func(ctx sdk.Context) (string, bool) {
		var (
			msg   string
			count int
		)

		k.accountKeeper.IterateAccounts(ctx, func(account authexported.Account) bool {
			ethAccount, ok := account.(*ethermint.EthAccount)
			if !ok {
				// ignore non EthAccounts
				return false
			}

			evmDenom := k.GetParams(ctx).EvmDenom
			accountBalance := ethAccount.GetCoins().AmountOf(evmDenom)
			evmBalance := k.GetBalance(ctx, ethAccount.EthAddress())

			if evmBalance.Cmp(accountBalance.BigInt()) != 0 {
				count++
				msg += fmt.Sprintf(
					"\tbalance mismatch for address %s: account balance %s, evm balance %s\n",
					account.GetAddress(), accountBalance.String(), evmBalance.String(),
				)
			}

			return false
		})

		broken := count != 0

		return sdk.FormatInvariant(
			types.ModuleName, balanceInvariant,
			fmt.Sprintf("account balances mismatches found %d\n%s", count, msg),
		), broken
	}
}

// NonceInvariant checks that all auth module's EthAccounts in the application have the same nonce
// sequence as the EVM.
func (k Keeper) NonceInvariant() sdk.Invariant {
	return func(ctx sdk.Context) (string, bool) {
		var (
			msg   string
			count int
		)

		k.accountKeeper.IterateAccounts(ctx, func(account authexported.Account) bool {
			ethAccount, ok := account.(*ethermint.EthAccount)
			if !ok {
				// ignore non EthAccounts
				return false
			}

			evmNonce := k.GetNonce(ctx, ethAccount.EthAddress())

			if evmNonce != ethAccount.Sequence {
				count++
				msg += fmt.Sprintf(
					"\nonce mismatch for address %s: account nonce %d, evm nonce %d\n",
					account.GetAddress(), ethAccount.Sequence, evmNonce,
				)
			}

			return false
		})

		broken := count != 0

		return sdk.FormatInvariant(
			types.ModuleName, nonceInvariant,
			fmt.Sprintf("account nonces mismatches found %d\n%s", count, msg),
		), broken
	}
}
@github-actions
Copy link

github-actions bot commented Mar 8, 2021

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the stale stale PRs that will be closed if no further action occurs label Mar 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
stale stale PRs that will be closed if no further action occurs Status: On Ice Type: User Reported
Projects
None yet
Development

No branches or pull requests

2 participants