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

[libsecp256k1] illegal argument: secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx) #40

Open
DerXanRam opened this issue Dec 15, 2023 · 5 comments

Comments

@DerXanRam
Copy link

Hello brother. When i try to get my address from PK using the below code, it returns an error of [libsecp256k1] illegal argument: secp256k1_ecmult_gen_context_is_built(&ctx->ecmult_gen_ctx)

the coed is

#include <ethc/account.h>
#include <ethc/hex.h>
#include <ethc/keccak256.h>
#include <iostream>

using namespace std;

void test_eth_account_address_get()
{
    struct eth_account account;
    uint8_t privkey[32] = {0xdc, 0xdf, 0x91, 0xb7, 0xb2, 0x9c, 0x4c, 0x06,
                           0x77, 0x33, 0x1b, 0x65, 0x5c, 0x0c, 0x6c, 0xf4,
                           0xe7, 0x1b, 0x6f, 0x87, 0x19, 0x27, 0x3a, 0x11,
                           0x2e, 0xe6, 0x5b, 0x63, 0x9b, 0x88, 0x8f, 0xfa};
    char out[40];
    eth_account_from_privkey(&account, privkey);
    eth_account_address_get(out, &account);
    cout << out << endl;
}
int main()
{
    test_eth_account_address_get();
}
@DerXanRam
Copy link
Author

@mhw0 any result?

@mhw0
Copy link
Owner

mhw0 commented Dec 18, 2023

Hello. Interesting, I can't reproduce this on Mac. Is this random thing or happens every time?

@mhw0
Copy link
Owner

mhw0 commented Dec 18, 2023

It runs just fine on my machine. I think I'll need some linux machine to test this.

@zzzzzzch
Copy link
Contributor

zzzzzzch commented May 29, 2024

I've run into this issue as well. In my project, libsecp256k1 was introduced as a third party, and I'm not sure if it was the build issue that caused this problem.
So I modified the eth_ecdsa_pubkey_get function in ecdsa.c:

int eth_ecdsa_pubkey_get(uint8_t *dest, const uint8_t *privkey) {
  secp256k1_context *secp_ctx;
  // ....
  
  // secp_ctx = secp256k1_context_create(SECP256K1_CONTEXT_NONE);
  secp_ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN |
                                      SECP256K1_CONTEXT_VERIFY);
  // ...
}

using this workaround the error is gone.

Later I built libsecp256k1 and the sample code separately trying to figure out why, but the issue just didn't occur. I didn't further investigate because of the time


Just commenting here as a clue

@mhw0
Copy link
Owner

mhw0 commented May 29, 2024

Hey @zzzzzzch thank you for the investigation! I'll take a look myself. Again, thank you.

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

No branches or pull requests

3 participants