phoreproject / bls

Go implementation of the BLS12-381 pairing
Apache License 2.0
89 stars 31 forks source link

Missing domain parameter #6

Closed prestonvanloon closed 5 years ago

prestonvanloon commented 5 years ago

We're blocked on updating the recent changes (https://github.com/prysmaticlabs/prysm/issues/2724) due to an incompatible API change.

Many of the BLS methods required by ethereum specify using a particular domain for certain data. https://github.com/ethereum/eth2.0-specs/blob/dev/specs/bls_signature.md#hash_to_g2

The API previously supported this until changes in e8b4690ab0071f642301bfd78da5d74c1730c2c1 removed the domain parameter.

meyer9 commented 5 years ago

Fixed in 11029fcb3eb7540e06cce27de39bf876c53446ad

I did not add the uncompressed version because it uses a different format for Jacobian points.

See test for usage:

var expectedSerializedG2, _ = hex.DecodeString("a6ef29e7241e1a1cc60fee328e3290c023d55a6701db500eefab7f91391a8b8726fd0024121e64637281f907137fe268187b4baca36388e96194b73a7d532f6eea6bc098778dbfd3404584613b5ba9da97d5602e31fdbe9270b863876529b254")

func TestHashG2WithDomain(t *testing.T) {
    actualHash := bls.HashG2WithDomain([32]byte{}, 0)

    compressedPoint := bls.CompressG2(actualHash.ToAffine())

    if !bytes.Equal(expectedSerializedG2, compressedPoint[:]) {
        t.Fatal("expected hash to match test")
    }
}