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

[Miracl] Default init to infinity point #122

Open mratsim opened 2 years ago

mratsim commented 2 years ago

https://github.com/status-im/nim-blscurve/pull/120#discussion_r681980253

mratsim commented 2 years ago

We unfortunately need one of those default init RFC in Nim https://github.com/nim-lang/RFCs/issues/252.

The portable patterns are

# Low-level
var P {.noInit.}: ECP2_BLS12381
P.setInf
# High-level
var p {.noInit.}: Aggregate
p.init(firstElem)

If we need really empty aggregate within BLScurve (instead of just handling the special case at serialization/deserialization) we could add the following function with caveats for Miracl backend:

  func initEmpty*(agg: var Aggregate) {.inline.} =
    ## Initialize an empty aggregate signature or public key.
    ## This is a delicate procedure to use.
    ## 
    ## ⚠ Empty public-key or signatures created by this procedure
    ##   are infinity points to allow further aggregation.
    ##   - Some protocols might serialize an empty aggregate differently
    ##     from an infinity point, for example Ethereum:
    ##       Empty aggregate:         0x0000...0000
    ##       Infinity point ("zero"): 0xc000...0000
    ##   - Some protocols, like BLS signatures, might not allow raw empty aggregates of certain kind.
    agg.point.inf()

BLST has no public API to create infinity points (though default init is by chance the infinity point).