Skip to content

Error when platform has bcmath but not gmp extension #2

@brianrlewis

Description

@brianrlewis

@digitaldonkey digitaldonkey

If I run the sample code in Readme.md it causes the following error if the server/platform running the code does not have the php-gmp extension installed, but does have php-bcmath installed.

The dependency simplito/elliptic-php requires either gmp or bcmath to be installed as you can see in BigInteger.php.

First it tries to do the operation using gmp but if gmp is not installed it uses bcmath as a fallback.

This problem can be fixed (within this repo) by removing the '0x' that is prefixed to the $message_hash in EcRecover.php on line 20.

So this line

$message_hash =  '0x' . Keccak::hash(self::personalSignAddHeader($message), 256);

changes to this

$message_hash = Keccak::hash(self::personalSignAddHeader($message), 256);

Once that change has been implemented the sample code in Readme.md runs fine using both the gmp and bcmath methods.

I'm not sure if the proper solution here is for this repo to be modified as described above or if simplito/elliptic-php should somehow be modified instead. However if you look at the the README.md for simplito/elliptic-php under "Verifying Ethereum Signature" you can see that the example does not prefix the hash with '0x'.

For reference here is the exact code I am running that causes an error. This is the same code from Readme.md, just with a couple typo fixes.

        use Ethereum\EcRecover;

        $address = '0xbe93f9bacbcffc8ee6663f2647917ed7a20a57bb';
        $message = 'hello world';
        $signature = '0xce909e8ea6851bc36c007a0072d0524b07a3ff8d4e623aca4c71ca8e57250c4d0a3fc38fa8fbaaa81ead4b9f6bd03356b6f8bf18bccad167d78891636e1d69561b';
        
        // Verify known address
        $valid = EcRecover::personalVerifyEcRecover($message,  $signature,  $address);
        
        // Recover unknown address
        $recoveredAddress = EcRecover::personalEcRecover($message, $signature);
        if ($recoveredAddress === $address) {
          echo 'Jay! it was a long way here. ';
        }

This is the error I am getting:

Exception
Invalid characters
vendor/simplito/bigint-wrapper-php/lib/BigInteger.php:328

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions