status-im / nim-blscurve

Nim implementation of BLS signature scheme (Boneh-Lynn-Shacham) over Barreto-Lynn-Scott (BLS) curve BLS12-381
Apache License 2.0
26 stars 11 forks source link

Segfaults in message signing test #3

Closed mratsim closed 6 years ago

mratsim commented 6 years ago

The current usage test segfaults for ECP_BLS381_SP_DSA call:

https://github.com/status-im/nim-milagro-crypto/blob/cd608671cfd5efb7e72a29e6e295e511c8f9e11e/tests/all_tests.nim#L97-L117

Running LLDB, segfaulting happens at line 580 of ecp_BLS381.c

https://github.com/status-im/nim-milagro-crypto/blob/cd608671cfd5efb7e72a29e6e295e511c8f9e11e/src/generated/ecp_BLS381.c#L571-L580

mratsim commented 6 years ago

Edit, actually the issue is in the message verification test (unittest.nim mangling doesn't help).

Backtrace shows that pubkey dereferencing poses issue:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x000000010000d466 test`ECP_BLS381_fromOctet(P=0x00007ffeefbfe0b8, W=0x0000000100046190) at ecp_BLS381.c:580
    frame #1: 0x000000010000f730 test`ECP_BLS381_VP_DSA(sha=32, W=0x0000000100046190, F=0x0000000100046070, C=0x0000000100046310, D=0x0000000100046320) at ecdh_BLS381.c:315

Trying to do pubkey.val[0] in Nim also segfaults