Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

recover_key not working on v1.8 #1231

Open
SleepingProgrammer opened this issue Nov 6, 2021 · 1 comment
Open

recover_key not working on v1.8 #1231

SleepingProgrammer opened this issue Nov 6, 2021 · 1 comment

Comments

@SleepingProgrammer
Copy link

I'm trying to add ECDSA signature verification to my contract.

However, using the example ECDSA from 3 years ago doesn't seem to work anymore. There are tons of errors I'm getting but this is one of the errors:

error: too many arguments to function call, expected 2, have 5 auto n = eosio::recover_key(&digest, (char *)&sig, sizeof(sig), pub, 34);

I checked the API and it does say that there should be 5 parameters but the compiler seems to be only expecting 2. Any suggestions?

My contract code (referenced):
`///@abi action
void ecrecover(std::string data, const signature &sig)
{
std::string tmp;
checksum256 digest;
sha256(&data[0], data.size(), &digest);

char pub[34]; // public key without checksum
auto n = recover_key(&digest, (char *)&sig, sizeof(sig), pub, 34);
assert(n == 34);

std::string pubhex = to_hex(pub, sizeof(pub)).substr(2); // remove leading '00'
tmp = hex_to_string(pubhex.c_str());
strcpy(pub, tmp.c_str());

checksum160 chksm;
ripemd160(pub, 33, &chksm);

tmp = hex_to_string(pubhex + to_hex(&chksm, 20).substr(0,8)); // append checksum

unsigned char encoded[37  * 137 / 100];
base58encode(tmp, 37, encoded);
tmp = "EOS" + std::string(reinterpret_cast<char*>(encoded));
assert(tmp.length() == 53);
print(tmp);

}

///@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");

}`

@conr2d
Copy link
Contributor

conr2d commented Jun 18, 2022

__attribute__((eosio_wasm_import))
int recover_key( const struct capi_checksum256* digest, const char* sig, size_t siglen, char* pub, size_t publen );

By default, C API is not accessible any more. Your mentioning recover_key with 5 arguments is C API (considered as low-level interface and not recommended to be called directly), so it becomes hidden. You need to set your build configuration manually or use the following C++ API with 2 arguments (recommended way).

namespace eosio {
  eosio::public_key recover_key( const eosio::checksum256& digest, const eosio::signature& sig );
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants
@conr2d @SleepingProgrammer @sanaraufx and others