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

Hash_to_curve property-based testing #34

Closed mratsim closed 3 years ago

mratsim commented 4 years ago

As highlighted by https://github.com/status-im/nim-blscurve/pull/30/commits/6a4e452e8c9594e876a10961863c688ccfa63a5a in #30, we need better coverage of input message ranges as from time-to-time we need to call FP2 normalization to put the FP2 back in 0 ..< Prime range, especially after multiplication (norm calls)

https://github.com/status-im/nim-blscurve/blob/501f1fc3a0d2ab7954dc294d571ffd7aa969d55d/blscurve/hash_to_curve.nim#L279-L323

One way to do that would be to add property-based testing.

Invariants that hash_to_curve should abide to are available in the test suite from:

Other relevant repo to generate test vectors:

Example property based testing: https://github.com/status-im/nim-stint/blob/9e49b00148884a01d61478ae5d2c69b543b93ceb/tests/property_based_uint256.nim

mratsim commented 3 years ago

See #75 for a thorough audit.