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

PRECISION LOSS of account balance in evm module export #621

Closed
RevelationOfTuring opened this issue Nov 26, 2020 · 4 comments · Fixed by #619
Closed

PRECISION LOSS of account balance in evm module export #621

RevelationOfTuring opened this issue Nov 26, 2020 · 4 comments · Fixed by #619

Comments

@RevelationOfTuring
Copy link

RevelationOfTuring commented Nov 26, 2020

System info: [Include Ethermint commit, operating system name, and other relevant details]
NOTE:Works on the bug fix branch fedekunze/617-fix-export
commit:8165a448
operating system:macOS Catalina 10.15.6
go version:go1.15.2 darwin/amd64

Steps to reproduce:

  1. start a single node blockchain with the script:
#!/bin/bash

KEY="turing"
CHAINID="ethermint-8"
MONIKER="localtestnet"

# remove existing daemon and client
rm -rf ~/.ethermint*

make install

ethermintcli config keyring-backend test

# Set up config for CLI
ethermintcli config chain-id $CHAINID
ethermintcli config output json
ethermintcli config indent true
ethermintcli config trust-node true

# if $KEY exists it should be deleted
ethermintcli keys add $KEY --recover <<EOF
cry awake zoo goose borrow cargo service perfect wonder police strategy dry stomach leisure boil feel message dragon romance season orient satoshi pulse consider
EOF

ethermintcli keys add alice --recover <<EOF
bundle apart grain trust domain roast purpose lift unique grain pink airport fresh woman useless auction exchange fall narrow right muscle defy dream magic
EOF

ethermintcli keys add bob --recover <<EOF
fringe core giant grab people impact base tennis hero mix chimney bicycle access prize length debris acid exile demise fragile island horror kitten obtain
EOF

# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer)
ethermintd init $MONIKER --chain-id $CHAINID

# Change parameter token denominations to aphoton
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="aphoton"' >$HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="aphoton"' >$HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="aphoton"' >$HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="aphoton"' >$HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json

# Enable faucet
cat $HOME/.ethermintd/config/genesis.json | jq '.app_state["faucet"]["enable_faucet"]=true' >$HOME/.ethermintd/config/tmp_genesis.json && mv $HOME/.ethermintd/config/tmp_genesis.json $HOME/.ethermintd/config/genesis.json

# Allocate genesis accounts (cosmos formatted addresses)
ethermintd add-genesis-account $(ethermintcli keys show $KEY -a) 9999999999999999999999999999aphoton
ethermintd add-genesis-account $(ethermintcli keys show alice -a) 5555555555555555555555555555aphoton
ethermintd add-genesis-account $(ethermintcli keys show bob -a) 4444444444444444444444444444aphoton

# Sign genesis transaction
ethermintd gentx --name $KEY --amount=1000000000000000000aphoton --keyring-backend test

# Collect genesis tx
ethermintd collect-gentxs

echo -e '\n\ntestnet faucet enabled'
echo -e 'to transfer tokens to your account address use:'
echo -e "ethermintcli tx faucet request 100aphoton --from $KEY\n"

# Run this to ensure everything worked and that the genesis file is setup correctly
ethermintd validate-genesis

# Command to run the rest server in a different terminal/window
echo -e '\nrun the following command in a different terminal/window to run the REST server and JSON-RPC:'
echo -e "ethermintcli rest-server --laddr \"tcp://localhost:8545\" --unlock-key $KEY --chain-id $CHAINID --trace\n"
#nohup ethermintcli rest-server --laddr tcp://localhost:8545 --unlock-key turing --chain-id $CHAINID --trace &

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
ethermintd start --pruning=nothing --rpc.unsafe --log_level "main:info,state:info,mempool:info" --trace

# ethermintcli rest-server --laddr tcp://localhost:8545 --unlock-key turing --chain-id ethermint-1 --trace
  1. stop the node after block producing.
  2. export the genesis file:
ethermintd export --for-zero-height --log_level="*:error" --height=1 > ~/genesis.json

Precision loss:
image

image

Expected behavior: [What you expected to happen]

It's expected to keep consistent between the balances in both evm and auth.

Actual behavior: [What actually happened]

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

@RevelationOfTuring RevelationOfTuring changed the title precision LOSS of account balance in evm module export PRECISION LOSS of account balance in evm module export Nov 26, 2020
@fedekunze
Copy link
Contributor

thanks for the bug report. Will look into it 👍

@fedekunze
Copy link
Contributor

looks like it's not a bug but just a format mismatch

@RevelationOfTuring
Copy link
Author

RevelationOfTuring commented Nov 26, 2020

looks like it's not a bug but just a format mismatch

In my own opinion, there will be a deflation or inflation of account in evm module when u import the exported genesis file. The total supply of evm native coin is going to be unpredictable.

I prefer to use sdk.Int instead of big.Int in GenesisAccount.Balance and have made a local branch that fixed this problem. I am willing to push a PR if you need it.

Expected for ur better solution on this.
@fedekunze

@fedekunze
Copy link
Contributor

fedekunze commented Nov 26, 2020

Yeah I opened a PR with the same approach: #623

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

Successfully merging a pull request may close this issue.

2 participants