neo-project / Neo.Cryptography.BLS12_381

MIT License
6 stars 3 forks source link

Naming convention problem for scalar multiplication operation of GT point #5

Closed AnnaShaleva closed 1 year ago

AnnaShaleva commented 1 year ago

Native CryptoLib contract contains bls12381Mul method that, according to the method's name and parameters, defines multiplication operation over BLS12-381 point and a scalar. In particular, for a point of GT type we have the following implementation: https://github.com/neo-project/neo/blob/df534f6b0c700e1c7b3eb1315c4560fedce793b8/src/Neo/SmartContract/Native/CryptoLib.BLS12_381.cs#L106 The * operator for GT and Scalar is defined in https://github.com/neo-project/Neo.Cryptography.BLS12_381/blob/844bc3a4f7d8ba2c545ace90ca124f8ada4c8d29/src/Neo.Cryptography.BLS12_381/Gt.cs#L102 There's a comment about it as far:

        // This is a simple double-and-add implementation of group element
        // multiplication, moving from most significant to least
        // significant bit of the scalar.
        //
        // We skip the leading bit because it's always unset for Fq
        // elements.

Inside this implementation, the "doubling" operation is used: https://github.com/neo-project/Neo.Cryptography.BLS12_381/blob/844bc3a4f7d8ba2c545ace90ca124f8ada4c8d29/src/Neo.Cryptography.BLS12_381/Gt.cs#L118

From the first glance at the implementation, it's not actually clear that * operator for GT isn't a scalar multiplication as for G1 and G2 points (not the https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication#Double-and-add). Actually, this operation is nothing but an exponentiation operation. And public Gt Double() squares the given GT point.

It seems to me that there's a naming convention problem here. At the first glance, it was quite confusing to me. I'd suggest defining some Exp method for GT points instead of overriding the * operation for GT point and a scalar. So that the exponentiation operation can be recognized by the reader immediately. I'd also suggest adjusting the exponentiation comment wrt this change.

vncoelho commented 1 year ago

I think that this is the standard for Paring Friendly Curves.

AnnaShaleva commented 1 year ago

this is the standard for Paring Friendly Curves

Could you, please, provide some reference to the standard? Because in several go-based crypto libs it's called like Exp, see the example.

vncoelho commented 1 year ago

When the PR was merged I remember that checked these ones here:

https://eprint.iacr.org/2006/372.pdf

https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-pairing-friendly-curves-02#name-bls-curves

https://www.math.uwaterloo.ca/~ajmeneze/publications/pairings.pdf

AnnaShaleva commented 1 year ago

OK, thank you for the resonse, let's keep it as is.