ZenGo-X / curv

Rust language general purpose elliptic curve cryptography.
MIT License
264 stars 111 forks source link

point and scalar validation #88

Open omershlo opened 3 years ago

omershlo commented 3 years ago

Thanks to @ra-- who raised this issue:

_I noticed that there were some unsafe unwrap calls/missing checks. E.g. https://github.com/ZenGo-X/curv/blob/master/src/elliptic/curves/secp256_k1.rs#L148 the scalar may be 0. Or here https://github.com/ZenGo-X/curv/blob/master/src/elliptic/curves/secp256_k1.rs#L160. Basically add, sub, mul, and invert should check whether the result is 0. For points, there are unsafe unwraps as well. Here for example: https://github.com/ZenGo-X/curv/blob/master/src/elliptic/curves/secp256_k1.rs#L414._

Error handling should be added as part of the point and scalar traits by way of returning Result. Here is an example: https://github.com/nash-io/nash-rust/pull/17/commits/0910eb7fa5400de1a37ebfa8b6bc412930de636f#diff-bf4822a262bb2d66887c738137845d7b