1

Specs

I am using the function recover_key from the library crypto.h at the following link: https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/crypto.h

Code

int compressed_size = recover_key(&digest, (char *)signature, sizeof(signature),(char *)compressed, sizeof(compressed));

Error

I call the function multiple times but at a certain point, like the third time, the following function fails, with the following error:

2018-09-27T09:01:48.492 thread-0 main.cpp:3091 main ] Failed with error: Assert Exception (10) secp256k1_ecdsa_recover_compact( detail::_get_context(), (unsigned char*) digest.data(), (unsigned char*) c.begin() + 1, (unsigned char*) my->_key.begin(), (int*) &pk_len, 1, (*c.begin() - 27) & 3 ):

Additional Info

The problem is that when the function fails the parameters provided are exactly at the same format than the other two times.

What I want

How can I solve this issue? How can I make the key recovery work everytime?

0

Here's one way of doing it:

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>
#include <eosiolib/crypto.h>
using namespace eosio;

class ec: public eosio::contract {
  public:
      using contract::contract;

  ///@abi action
  void ecverify(std::string data, const signature &sig, const public_key &pk)
  {
    checksum256 digest;
    sha256(&data[0], data.size(), &digest);

    assert_recover_key(&digest, (const char *)&sig, sizeof(sig), (const char *)&pk, sizeof(pk));
    print("VALID");
  }
};

EOSIO_ABI( ec, (ecverify) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.