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

Not return err when pass random str or invalid privateKey to func PrivateKeyFromBase58 #232

Open
Almazatun opened this issue Jul 21, 2024 · 7 comments · May be fixed by #234
Open

Not return err when pass random str or invalid privateKey to func PrivateKeyFromBase58 #232

Almazatun opened this issue Jul 21, 2024 · 7 comments · May be fixed by #234

Comments

@Almazatun
Copy link

I just tried to use the func to validate private key but got some other behavior that func.

https://github.com/gagliardetto/solana-go/blob/main/keys.go#L48

It's correct behavior ?

@Almazatun
Copy link
Author

Almazatun commented Jul 21, 2024

Also, I want to add some notes if pass incorrect value or random str the func and call public method PublicKey() or call Sign(pk) not return error argument but call panic. But the methods should return err argument.

panic: runtime error: slice bounds out of range [x:x] | panic: ed25519: bad private key length

If pass correct privateKey, everything will be fine and return publicKey.

@pikomonde
Copy link
Contributor

I just tried to use the func to validate private key but got some other behavior that func.

https://github.com/gagliardetto/solana-go/blob/main/keys.go#L48

It's correct behavior ?

Hi @Almazatun , can you explain what is the "some other behaviour"?

Also, I want to add some notes if pass incorrect value or random str the func and call public method PublicKey() or call Sign(pk) not return error argument but call panic. But the methods should return err argument.

panic: runtime error: slice bounds out of range [x:x] | panic: ed25519: bad private key length

If pass correct privateKey, everything will be fine and return publicKey.

Can you give the sample of the code that give that exact error? It will help us to debugging. Thank you

@Almazatun
Copy link
Author

@pikomonde Thank you very much for your reply. The PrivateKeyFromBase58 method returns two values. If I guess that means if pass invalid privateKey should be returned err that does not equal nil. But instead of this behavior, you will get err = nil.

invalidPrivateKey := "6HsFaXKVD7mo43oTbdqyGgAnYFeNNhqY75B3JGJ6K8a227KjjG3uW3v"

_, err := solana.PrivateKeyFromBase58(invalidPk)

fmt.Println(err)

Is this the correct behavior of the method?

@pikomonde
Copy link
Contributor

Ah, I got your question now. My question is, how do you know that 6HsFaXKVD7mo43oTbdqyGgAnYFeNNhqY75B3JGJ6K8a227KjjG3uW3v is an invalid private key? Is there any docs on Solana that classify that this particular private key is invalid?

@Almazatun
Copy link
Author

Almazatun commented Jul 30, 2024

@pikomonde You can copy and paste it to phantom wallet for checking.

@pikomonde
Copy link
Contributor

I'm not sure if it is the correct behaviour or not (I think we need to compare with solana's official client)

But I think it is invalid because it is not on the a valid "ed25519" pair, and unfortunately the golang's "crypto/ed25519" package not providing a valid validation for it. Need to implement using this: https://security.stackexchange.com/questions/233099/validating-an-ed25519-public-key (haven't check it yet)

So I think there are 2 action items:

@pikomonde
Copy link
Contributor

Just realized that there is already a function provided by this library:

solana.IsOnCurve("6HsFaXKVD7mo43oTbdqyGgAnYFeNNhqY75B3JGJ6K8a227KjjG3uW3v")

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

Successfully merging a pull request may close this issue.

2 participants