Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

isOnCurve not right #31

Closed
pantaovay opened this issue Feb 28, 2022 · 5 comments
Closed

isOnCurve not right #31

pantaovay opened this issue Feb 28, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@pantaovay
Copy link

isOnCurve not right

Base 58 Publickey:
q5xfHVuAsGmKRTmJNshERHHkVnHKxRX3cKzz5cYnFRn

It show return true for isOnCurve function. But false returned

@neverything
Copy link
Contributor

@pantaovay not sure I'm getting the problem. Does it return trueor false for isOnCurve?

Sidenote, I had an issue with the getProgramAddress and solved it by checking multiple nonce values, see #12 (comment) for details.

@pantaovay
Copy link
Author

@neverything

For address q5xfHVuAsGmKRTmJNshERHHkVnHKxRX3cKzz5cYnFRn, it is on curve, the function should return true. Buf it returns false.

I checked #12 , the reason that the function generates false PDA is isOnCurse issue. If isOnCurve function works right, it has no issue.

I use another way to avoid this because the isOnCurve function in the other js lib is very difficult.

    public static function isOnCurve(PublicKey $publicKey): bool
    {
        try {
            $response = Di::getHttpClient()->sendGetRequest(sprintf(
                'http://127.0.0.1:3000/publickey/%s/is_on_curve',
                $publicKey->toBase58()
            ));

            $responseBody = json_decode($response->getBody()->getContents(), true);
            if (!is_array($responseBody) || !isset($responseBody['is_on_curve'])) {
                throw new \Exception($responseBody['error_code']);
            }

            return (bool) $responseBody['is_on_curve'];
        } catch (\Exception $exception) {
            Di::getLogger()->error('Check is on curve error: ' . $exception->getMessage());

            return false;
        }
    }

@gabrielkoerich
Copy link
Contributor

gabrielkoerich commented Mar 31, 2022

I found out here that sodium_crypto_sign_ed25519_pk_to_curve25519($binaryString) is almost always returning a SodiumException with "conversion failed" message.

Using \ParagonIE_Sodium_Compat::crypto_sign_ed25519_pk_to_curve25519($binaryString) I was able to get the correct address

@neverything neverything added bug Something isn't working good first issue Good for newcomers labels Apr 22, 2022
@neverything
Copy link
Contributor

@gabrielkoerich good catch, this does indeed seem like a bug. Feel free to write a pull request for it or I will eventually get to it in the future as it's bothering me a little 😄

@neverything
Copy link
Contributor

This is fixed in 7b1e6ae thanks to @gabrielkoerich

Not creating a new release yet, see #36

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants