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

Generating a new wallet from mnemonics (recover) produces nil pointer exception #1

Open
pablin-dev opened this issue Oct 16, 2024 · 1 comment

Comments

@pablin-dev
Copy link
Collaborator

Running on the container:

artrolld keys add dev01 --keyring-backend test --output json --recover and passing 24 words phrase produces

#     --------------------
    # panic: runtime error: invalid memory address or nil pointer dereference
    # [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x10f6b9c]

    # goroutine 1 [running]:
    # github.com/cosmos/cosmos-sdk/codec.(*LegacyAmino).jsonMarshalAnys(0x49a8880?, {0x49a8880?, 0xc001622460?})
    # 	/go/pkg/mod/github.com/cosmos/[email protected]/codec/amino.go:72 +0x1c
    # github.com/cosmos/cosmos-sdk/codec.(*LegacyAmino).MarshalJSON(0x0, {0x49a8880, 0xc001622460})
    # 	/go/pkg/mod/github.com/cosmos/[email protected]/codec/amino.go:143 +0x25
    # github.com/artela-network/artela-rollkit/client/keys.printCreate(0xc0012b4908, 0x8b6c4c0?, 0x1, {0xc000e4ef00, 0x95}, {0x7fff6d94df52?, 0x1?})
    # 	/app/client/keys/add.go:283 +0x2a5
    # github.com/artela-network/artela-rollkit/client/keys.RunAddCmd({{0x0, 0x0, 0x0}, {0x60e4818, 0xc0017c09f0}, 0x0, {0xc0007dd680, 0xf}, {0x610a790, 0xc0014c6a80}, ...}, ...)
    # 	/app/client/keys/add.go:254 +0xc45
    # github.com/artela-network/artela-rollkit/client.runAddCmd(0xc0012b4908, {0xc00150bc20, 0x1, 0x5})
    # 	/app/client/keys.go:92 +0x345
    # github.com/spf13/cobra.(*Command).execute(0xc0012b4908, {0xc00150bbd0, 0x5, 0x5})
    # 	/go/pkg/mod/github.com/spf13/[email protected]/command.go:985 +0xaca
    # github.com/spf13/cobra.(*Command).ExecuteC(0xc001779808)
    # 	/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
    # github.com/spf13/cobra.(*Command).Execute(...)
    # 	/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
    # github.com/spf13/cobra.(*Command).ExecuteContext(...)
    # 	/go/pkg/mod/github.com/spf13/[email protected]/command.go:1034
    # github.com/cosmos/cosmos-sdk/server/cmd.Execute(0xc001779808, {0x0, 0x0}, {0xc00139d3c0, 0xe})
    # 	/go/pkg/mod/github.com/cosmos/[email protected]/server/cmd/execute.go:34 +0x187
    # main.main()
    # 	/app/cmd/artrolld/main.go:15 +0x33
@yarikbratashchuk
Copy link

Reproduced.

Seems like RegisterCrypto is not called in the command,
If added lines:

ybratashchuk@yblocal:~/artela-rollkit$ git diff client/keys/add.go
diff --git a/client/keys/add.go b/client/keys/add.go
index 7ac89a6..98779ff 100644
--- a/client/keys/add.go
+++ b/client/keys/add.go
@@ -23,6 +23,8 @@ import (
        "github.com/artela-network/artela-rollkit/ethereum/crypto/codec"
        "github.com/artela-network/artela-rollkit/ethereum/crypto/ethsecp256k1"
        cryptohd "github.com/artela-network/artela-rollkit/ethereum/crypto/hd"
+
+       cosmoscodec "github.com/cosmos/cosmos-sdk/codec"
 )

 const (
@@ -82,6 +84,9 @@ func RunAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
                return err
        }

+       aminoCodec := cosmoscodec.NewLegacyAmino()
+       codec.RegisterCrypto(aminoCodec)
+
        if dryRun, _ := cmd.Flags().GetBool(flags.FlagDryRun); dryRun {
                // use in memory keybase
                kb = keyring.NewInMemory(ctx.Codec, cryptohd.EthSecp256k1Option())

works, getting output:

ybratashchuk@yblocal:~/artela-rollkit$ artela-rollkitd keys add yb3 --keyring-backend test --output json --recover
override the existing name yb3 [y/N]: y
> Enter your bip39 mnemonic
message sound wise cheese elite ladder diagram negative eye drink property retreat catalog laptop actress volume antique shiver safe program october jazz welcome energy
{"name":"yb3","type":"local","address":"art1l6tyn0ud87d36vpmpry02ztp8spz8zvun6mj7m","pubkey":"{\"@type\":\"/artela.crypto.ethsecp256k1.PubKey\",\"key\":\"Ay9L6YZ1FVMZ1nfXKOh0AVzQ4CBRvvC489MrHLML/vW3\"}"}

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

2 participants