paritytech / libsecp256k1

Pure Rust Implementation of secp256k1.
Apache License 2.0
177 stars 87 forks source link

Jacobian point comparison doesn't seem to work #42

Open tuxxy opened 4 years ago

tuxxy commented 4 years ago

I've noticed that comparing Jacobian points doesn't seem to work very well. I discovered this after trying to compare jacobian_basepoint_g == scalar_one * jacobian_basepoint_g.

The only way to get the comparison to succeed is to convert them to Affine via Affine::from_gej and then perform the comparison. It seems the library needs a proper Jacobian point comparison function implemented.

sorpaas commented 4 years ago

@tuxxy Yeah looks like the current Eq was a simple derive of Jacobian struct. It has a scale factor z, with different xs and ys might still represent the same value. I removed the flawed derive.

For now converting Jacobian to Affine and then do the comparison should be the way to go. Let me see if there could be better more efficient ways.

tuxxy commented 4 years ago

@sorpaas See here for a Solidity implementation of efficient Jacobian point comparison we wrote to use in our smart contracts. It should be helpful enough for your interest. :)