exthereum / exth_crypto

Cryptographic Functions used by Exthereum
MIT License
22 stars 18 forks source link

issues when compiling on Ubuntu 16.04 #7

Closed paulperegud closed 6 years ago

paulperegud commented 6 years ago

I've used clean ubuntu (docker image).

priv = :crypto.strong_rand_bytes(36)
<<160, 63, 212, 98, 57, 42, 207, 204, 239, 249, 39, 101, 98, 246, 229, 244, 187,
  111, 18, 115, 11, 187, 130, 40, 236, 172, 107, 111, 246, 61, 241, 249, 196,
  92, 86, 174>>

iex(3)> ExthCrypto.Signature.get_public_key(priv)

17:52:12.574 [warn]  The on_load function for module libsecp256k1 returned:
{:error, {:load_failed, 'Failed to load NIF library: \'/exth_crypto/_build/dev/lib/libsecp256k1/priv/libsecp256k1_nif.so: invalid ELF header\''}}

** (UndefinedFunctionError) function :libsecp256k1.ec_pubkey_create/2 is undefined (module :libsecp256k1 is not available)
    :libsecp256k1.ec_pubkey_create(<<160, 63, 212, 98, 57, 42, 207, 204, 239, 249, 39, 101, 98, 246, 229, 244, 187, 111, 18, 115, 11, 187, 130, 40, 236, 172, 107, 111, 246, 61, 241, 249, 196, 92, 86, 174>>, :uncompressed)
    lib/signature/signature.ex:32: ExthCrypto.Signature.get_public_key/1

There must be a problem with compilation flags.

root@ce4d60d784fa:/exth_crypto# file _build/dev/lib/libsecp256k1/priv/libsecp256k1_nif.so
_build/dev/lib/libsecp256k1/priv/libsecp256k1_nif.so: Mach-O 64-bit x86_64 bundle
paulperegud commented 6 years ago

What works:

1) install libgmp-dev
2) mix deps.get
3) cd deps/libsecp256k1
4) rebar compile
5) cd ../..
6) mix compile

mix tries to compile libsecp256k1 using rebar3 instead of rebar, which leads to bad results.

hayesgm commented 6 years ago

Building the NIF is pretty janky right now. We only use the library to get derive a public key from an ECDSA signature as this is not available in erlang's crypto module. I assume the math isn't that difficult and it's probably worth building it directly into exth_crypto to remove this dependency.