informalsystems / hermes

IBC Relayer in Rust
https://hermes.informal.systems
Apache License 2.0
450 stars 329 forks source link

Adding a key to Hermes creates the wrong address #3985

Closed tot-truong closed 6 months ago

tot-truong commented 6 months ago

Summary of Bug

When adding a key to Hermes it creates the wrong address for the injective-1 mainnet (compared using injectived).

Version

hermes 1.8.2

Steps to Reproduce

Using injectived => inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7

$ injectived version
Version v1.12.1 (e1ab66c)
Compiled at 20240429-0857 using Go go1.21.3 (amd64)

injectived keys add aa-test --recover
> Enter your bip39 mnemonic
that upper concert rice water duck body deny mom bulb crop warfare ugly focus worry expand ribbon gift exist knee pave zoo simple hazard
{"name":"aa-test","type":"local","address":"inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7","pubkey":"{\"@type\":\"/injective.crypto.v1beta1.ethsecp256k1.PubKey\",\"key\":\"ApIXFaJWETKktnjBeDB4xW1+FRL//s92jPhn50BrpwpR\"}"}

hd-path "m/44'/60'/0'/0/0" => inj1etzf7nsxsqs8xhtnw0qu0kzateqj9qcgwm3l66 => EXPECTED inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7

$ hermes version
2024-05-07T15:53:33.042568Z  INFO ThreadId(01) running Hermes v1.8.2
hermes 1.8.2
$ echo "that upper concert rice water duck body deny mom bulb crop warfare ugly focus worry expand ribbon gift exist knee pave zoo simple hazard" > mnemonic.txt;hermes --config main.toml keys add --chain injective-1 --key-name test --hd-path "m/44'/60'/0'/0/0" --mnemonic-file mnemonic.txt
2024-05-07T15:47:43.920337Z  INFO ThreadId(01) running Hermes v1.8.2
SUCCESS Restored key 'test' (inj1etzf7nsxsqs8xhtnw0qu0kzateqj9qcgwm3l66) on chain injective-1

No hd path set => inj1yvvuw3nm4fphmxjeuwhjek6wqmvepnze94kjxv

$ echo "that upper concert rice water duck body deny mom bulb crop warfare ugly focus worry expand ribbon gift exist knee pave zoo simple hazard" > mnemonic.txt;hermes --config main.toml keys add --chain injective-1 --key-name test --mnemonic-file mnemonic.txt --overwrite
2024-05-07T15:49:34.166285Z  INFO ThreadId(01) running Hermes v1.8.2
2024-05-07T15:49:34.167439Z  WARN ThreadId(01) key test will be overwritten
SUCCESS Restored key 'test' (inj1yvvuw3nm4fphmxjeuwhjek6wqmvepnze94kjxv) on chain injective-1

Hermes config main.toml

[global]
log_level = "info"

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = false
auto_register_counterparty_payee = false

[mode.packets.ics20_max_memo_size]
enabled = true
size = 32768

[mode.packets.ics20_max_receiver_size]
enabled = true
size = 2048

[rest]
enabled = false
host = "127.0.0.1"
port = 3000

[telemetry]
enabled = false
host = "127.0.0.1"
port = 3001

[telemetry.buckets.latency_submitted]
start = 500
end = 20000
buckets = 10

[telemetry.buckets.latency_confirmed]
start = 1000
end = 30000
buckets = 10

[[chains]]
type = "CosmosSdk"
id = "injective-1"
rpc_addr = "https://rpc-injective.whispernode.com/"
grpc_addr = "https://injective-grpc.publicnode.com/"
rpc_timeout = "10s"
# trusted_node = false
account_prefix = "inj"
key_name = 'injective_relayer'
key_store_type = "Test"
store_prefix = "ibc"
default_gas = 100000
max_gas = 400000
gas_multiplier = 1.1
max_msg_num = 1 # 30 / relay only 1 packet, otherwise max gas is exceeded
max_tx_size = 180000
# max_grpc_decoding_size = 33554432
# query_packets_chunk_size = 50
clock_drift = "5s"
max_block_time = "30s"
client_refresh_rate = "1/3"
ccv_consumer_chain = false
memo_prefix = 'test'
sequential_batch_tx = false

[chains.event_source]
mode = "push"
url = "wss://rpc-injective.whispernode.com/websocket"
batch_delay = "500ms"

[chains.trust_threshold]
numerator = 2
denominator = 3

[chains.gas_price]
price = 700000000.0
denom = "inj"

[chains.packet_filter]
policy = "allow"
list = [
]
[chains.packet_filter.min_fees]

# [chains.dynamic_gas_price]
# enabled = false
# multiplier = 1.1
# max = 0.6

[chains.address_type]
derivation = "cosmos"

[chains.excluded_sequences]

# [tracing_server]
# enabled = false
# port = 5555

Acceptance Criteria


For Admin Use

taitruong commented 6 months ago

Can confirm, having the same issue. Hermes creates completely different Injective address - as compared to injectived or rly.

adizere commented 6 months ago

Thanks for reporting this!

You mean the problem appears when you skip specifying --hd-path "m/44'/60'/0'/0/0" as parameter to keys add command ?

tot-truong commented 6 months ago

I mean injective uses "m/44'/60'/0'/0/0". I would have expected Hermes to create the same key as the injetived would create but in either case - with or without the hd-path parameter - I do not get the the expected key.

On Thu, 9 May 2024, 00:19 Adi Seredinschi, @.***> wrote:

Thanks for reporting this!

You mean the problem appears when you skip specifying --hd-path "m/44'/60'/0'/0/0" as parameter to keys add command ?

— Reply to this email directly, view it on GitHub https://github.com/informalsystems/hermes/issues/3985#issuecomment-2100941359, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY4WK5CVPP2ALCMCAU3NS4LZBJGBPAVCNFSM6AAAAABHLLCJOGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBQHE2DCMZVHE . You are receiving this because you authored the thread.Message ID: @.***>

taitruong commented 6 months ago

Any updates here? Bug can be reproduce and Injective addresses arent properly created - even with hd path m/44'/60'/0'/0/0 (results to different address compared to using injectived cli).

romac commented 6 months ago

According to the Injective documentation:

By default, the keyring generates a eth_secp256k1 keypair. The keyring also supports ed25519 keys, which may be created by passing the --algo ed25519 flag. A keyring can of course hold both types of keys simultaneously.

If I configure address_type accordingly:

[[chain]]
id = 'injective-1'
# ...
address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } }

I then get the expected address:

$ hermes --config injective.toml keys add --chain injective-1 --key-name test --hd-path "m/44'/60'/0'/0/0" --mnemonic-file mnemonic.txt --overwrite
2024-05-22T09:36:52.022765Z  INFO ThreadId(01) running Hermes v1.8.2+25f547595
2024-05-22T09:36:52.023353Z  WARN ThreadId(01) key test will be overwritten
SUCCESS Restored key 'test' (inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7) on chain injective-1
romac commented 6 months ago

@tot-truong What do you think we could document better on the Hermes side to prevent such issues? The address_type config is mentioned in the config.toml, but perhaps we should have a dedicated section in the guide?

taitruong commented 5 months ago

According to the Injective documentation:

By default, the keyring generates a eth_secp256k1 keypair. The keyring also supports ed25519 keys, which may be created by passing the --algo ed25519 flag. A keyring can of course hold both types of keys simultaneously.

If I configure address_type accordingly:

[[chain]]
id = 'injective-1'
# ...
address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } }

I then get the expected address:

$ hermes --config injective.toml keys add --chain injective-1 --key-name test --hd-path "m/44'/60'/0'/0/0" --mnemonic-file mnemonic.txt --overwrite
2024-05-22T09:36:52.022765Z  INFO ThreadId(01) running Hermes v1.8.2+25f547595
2024-05-22T09:36:52.023353Z  WARN ThreadId(01) key test will be overwritten
SUCCESS Restored key 'test' (inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7) on chain injective-1

@romac we have tested with address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } } and it generates wrong injective address.

Have u tried restoring key using injectived? In our case injectived produces a different address.

romac commented 5 months ago

Is the address I got not the very same address output by injectived? inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7

I will try with injectived as soon as I get a chance, in the meantime can you please share full logs and Hermes config with the address_type I shared above?

tot-truong commented 5 months ago

Is the address I got not the very same address output by injectived? inj1mzy2fz8wzq069r8z20m2fcvsdye3pr7qrwfvx7

I will try with injectived as soon as I get a chance, in the meantime can you please share full logs and Hermes config with the address_type I shared above?

Even when adding the address type to the hermes config

[[chain]]
id = 'injective-1'
# ...
address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } }

I still get the wrong address

$ echo "that upper concert rice water duck body deny mom bulb crop warfare ugly focus worry expand ribbon gift exist knee pave zoo simple hazard" > mnemonic.txt;hermes --config main.toml keys add --overwrite --chain injective-1 --key-name test --hd-path "m/44'/60'/0'/0/0" --mnemonic-file mnemonic.txt
2024-06-03T01:52:39.199791Z  INFO ThreadId(01) running Hermes v1.8.2
2024-06-03T01:52:39.200152Z  WARN ThreadId(01) key test will be overwritten
SUCCESS Restored key 'test' (inj1etzf7nsxsqs8xhtnw0qu0kzateqj9qcgwm3l66) on chain injective-1
tot-truong commented 5 months ago

I wonder if the reason is that your on a different version than me on Hermes?

Hermes v1.8.2 vs v1.8.2+25f547595

Here is the full main.toml

[global]
log_level = "info"

[mode.clients]
enabled = true
refresh = true
misbehaviour = true

[mode.connections]
enabled = false

[mode.channels]
enabled = false

[mode.packets]
enabled = true
clear_interval = 100
clear_on_start = true
tx_confirmation = false
auto_register_counterparty_payee = false

[mode.packets.ics20_max_memo_size]
enabled = true
size = 32768

[mode.packets.ics20_max_receiver_size]
enabled = true
size = 2048

[rest]
enabled = false
host = "127.0.0.1"
port = 3000

[telemetry]
enabled = false
host = "127.0.0.1"
port = 3001

[telemetry.buckets.latency_submitted]
start = 500
end = 20000
buckets = 10

[telemetry.buckets.latency_confirmed]
start = 1000
end = 30000
buckets = 10

[[chains]]
type = "CosmosSdk"
id = "injective-1"
rpc_addr = "https://rpc-injective.whispernode.com/"
grpc_addr = "https://injective-grpc.publicnode.com/"
rpc_timeout = "10s"
# trusted_node = false
account_prefix = "inj"
key_name = 'injective_relayer'
key_store_type = "Test"
store_prefix = "ibc"
default_gas = 100000
max_gas = 400000
gas_multiplier = 1.1
max_msg_num = 1 # 30 / relay only 1 packet, otherwise max gas is exceeded
max_tx_size = 180000
# max_grpc_decoding_size = 33554432
# query_packets_chunk_size = 50
clock_drift = "5s"
max_block_time = "30s"
client_refresh_rate = "1/3"
ccv_consumer_chain = false
memo_prefix = 'test'
sequential_batch_tx = false
address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } }

[chains.event_source]
mode = "push"
url = "wss://rpc-injective.whispernode.com/websocket"
batch_delay = "500ms"

[chains.trust_threshold]
numerator = 2
denominator = 3

[chains.gas_price]
price = 700000000.0
denom = "inj"

[chains.packet_filter]
policy = "allow"
list = [
]
[chains.packet_filter.min_fees]

# [chains.dynamic_gas_price]
# enabled = false
# multiplier = 1.1
# max = 0.6

[chains.address_type]
derivation = "cosmos"

[chains.excluded_sequences]

# [tracing_server]
# enabled = false
# port = 5555

mnemonic.txt

romac commented 5 months ago

You are specifying address_type twice and therefore overriding the correct definition by the wrong one.

Try removing the second one

[chains.address_type]
derivation = "cosmos"

and only keep

address_type = { derivation = 'ethermint', proto_type = { pk_type = '/ethermint.crypto.v1.ethsecp256k1.PubKey' } }
tot-truong commented 5 months ago
echo "that upper concert rice water duck body deny mom bulb crop warfare ugly focus worry expand ribbon gift exist knee pave zoo simple hazard" > mnemonic.txt;hermes --config main.toml keys add --overwrite --chain injective-1 --key-name test --hd-path "m/44'/60'/0'/0/0" --mnemonic-file mnemonic.txt

Thanks 100x, that worked! The proper address is now created!