Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty EVM bytecode after upload #11

Open
ducphamle2 opened this issue Oct 5, 2024 · 4 comments
Open

Empty EVM bytecode after upload #11

ducphamle2 opened this issue Oct 5, 2024 · 4 comments

Comments

@ducphamle2
Copy link
Collaborator

Context

When running the e2e test, I encountered an EVM bug of not being able to query or execute any EVM contracts after uploading. The request always returned an empty response.

To Reproduce

Steps to reproduce the behavior:

  1. Upload an EVM Solidity contract. Eg: ERC20 contraxt
  2. Invoke a simple contract query. Eg: a decimals() query

Expected behavior

A decimals() query should return the contract's decimals()

Screenshots

image

@ducphamle2
Copy link
Collaborator Author

After a day of debugging, I found the root cause of the bug. The Ethermint repo was querying an EVM contract's bytecodes from an EVM account casted from the AccountI of auth module.

Below is the GetCode logic to get the EVM bytecodes before querying or executing the contract:
image

@ducphamle2
Copy link
Collaborator Author

If the stateObject is not available -> we will query the contract's account and use its bytecodes:

image

However, the SetAccount method, doesn't store any contract's code hash because by default, every BaseAccount is not an EthAccount:

image

Note that the CodeHash field is the EVM contract bytecodes' key. If it isn't stored anywhere -> can't retrieve the bytecodes

@ducphamle2
Copy link
Collaborator Author

A simple fix is to add the following logic to SetAccount:

if !ok && account.IsContract() {
		if baseAcct, isBaseAccount := acct.(*authtypes.BaseAccount); isBaseAccount {
			acct = &ethermint.EthAccount{
				BaseAccount: baseAcct,
				CodeHash:    codeHash.Hex(),
			}
		} else {
			return errorsmod.Wrapf(types.ErrInvalidAccount, "type %T, address %s", acct, addr)
		}
	}

It will check if the account is a contract. If it is, then it will cast the BaseAccount to EthAccount and store it

@ducphamle2
Copy link
Collaborator Author

ducphamle2 commented Oct 5, 2024

This bug is resolved in #13. The actual implementation is in oraichain/ethermint-cosmos-0.50@3c8d318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant