1

As I understand bitcoinj library contains wrapper for bitcoin-core functions - NativeSecp256k1. I am trying to call one of methods from this wrapper:

NativeSecp256k1.secKeyVerify(byteArrayOf(...))

But I got a crash:

java.lang.UnsatisfiedLinkError: No implementation found for int org.bitcoin.NativeSecp256k1.secp256k1_ec_seckey_verify(java.nio.ByteBuffer, long) (tried Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify and Java_org_bitcoin_NativeSecp256k1_secp256k1_1ec_1seckey_1verify__Ljava_nio_ByteBuffer_2J) at org.bitcoin.NativeSecp256k1.secp256k1_ec_seckey_verify(Native Method) at org.bitcoin.NativeSecp256k1.secKeyVerify(NativeSecp256k1.java:134) at com.my.app.MainActivity.onCreate(MainActivity.kt:15) at android.app.Activity.performCreate(Activity.java:6251) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

It looks like bitcoinj library contains the wrapper but doesn't contains native library which used in this wrapper. How to fix this issue?

BArtWell
  • 4,176
  • 10
  • 63
  • 106

1 Answers1

1

Bitcoinj uses JNI to load a C library for secp256k1 curve operations. If the lib is imported correctly... and since you are trying to access it directly, you might be missing the System.loadLibrary('secp256k1') call

Check here : https://github.com/bitcoinj/bitcoinj/blob/2ec193f8479425c3a66bebf5f2d3493e39e88f7c/core/src/main/java/org/bitcoin/Secp256k1Context.java

To build the compiles sources for the lib, its describes in the comment block of the NativeSecp256k1 class, here : https://github.com/bitcoinj/bitcoinj/blob/2ec193f8479425c3a66bebf5f2d3493e39e88f7c/core/src/main/java/org/bitcoin/NativeSecp256k1.java#L34

ehanoc
  • 2,187
  • 18
  • 23
  • When I am trying to call `System.loadLibrary("secp256k1")` I got an error `couldn't find "libsecp256k1.so"`. – BArtWell Jun 24 '19 at 16:31
  • 1
    @BArtWell you need to have the compiled binaries. This described here https://github.com/bitcoinj/bitcoinj/blob/2ec193f8479425c3a66bebf5f2d3493e39e88f7c/core/src/main/java/org/bitcoin/NativeSecp256k1.java#L34 . But you'll need to adapt to your android project. Check examples how to use JNI – ehanoc Jun 24 '19 at 19:18
  • How are you importing bitcoinj into your project? – ehanoc Jun 24 '19 at 19:25
  • Thank you for help. It works for me with MinGW and the command `./configure --enable-ecmult-static-precomputation --enable-experimental --with-bignum=no --with-asm=arm --host=arm-linux-androideabi CC=armv7a-linux-androideabi21-clang CFLAGS="-mthumb -march=armv7-a" CCASFLAGS="-Wa,-mthumb -Wa,-march=armv7-a" --enable-jni --enable-experimental --enable-module-schnorr --enable-module-ecdh`. Also I replace config.guess and config.sub with this: http://git.savannah.gnu.org/gitweb/?p=config.git;a=tree – BArtWell Jun 25 '19 at 14:19