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

Divide stack usage by 255 (keystore EIP 2333) #61

Open mratsim opened 4 years ago

mratsim commented 4 years ago

See https://github.com/status-im/nim-blscurve/pull/60

This implements keystore primitives for EIP-2333 (draft) ethereum/EIPs#2333

This will unblock status-im/nim-beacon-chain#1093

cc @zah

Ready:

Note that the spec requires over 16KB of stack for parent_SK_to_Lamport_PK image

the lamport_0 and lamport_1 are of size 255 * 32 bytes, in the code we reorder the spec and reuse the same lamport buffer.

https://github.com/status-im/nim-blscurve/blob/96f203394d49a0031bc51450eec387b9abd9bf2c/blscurve/eth2_keygen.nim#L74-L103

We could further divide stack usage by 255 (!) if we have an alternative HKDF Expand iterator:

https://github.com/status-im/nim-blscurve/blob/96f203394d49a0031bc51450eec387b9abd9bf2c/blscurve/hkdf.nim#L139-L152

Note: the tree might change to 32 instead of 255 as per https://github.com/ethereum/EIPs/issues/2337