github.com/consensys/gnark-crypto@v0.14.0/kzg/kzg.go (about)

     1  // Package kzg provides constructor for curved-typed KZG SRS
     2  //
     3  // For more details, see ecc/XXX/fr/kzg package
     4  package kzg
     5  
     6  import (
     7  	"io"
     8  
     9  	"github.com/consensys/gnark-crypto/ecc"
    10  
    11  	kzg_bls12377 "github.com/consensys/gnark-crypto/ecc/bls12-377/kzg"
    12  	kzg_bls12378 "github.com/consensys/gnark-crypto/ecc/bls12-378/kzg"
    13  	kzg_bls12381 "github.com/consensys/gnark-crypto/ecc/bls12-381/kzg"
    14  	kzg_bls24315 "github.com/consensys/gnark-crypto/ecc/bls24-315/kzg"
    15  	kzg_bls24317 "github.com/consensys/gnark-crypto/ecc/bls24-317/kzg"
    16  	kzg_bn254 "github.com/consensys/gnark-crypto/ecc/bn254/kzg"
    17  	kzg_bw6633 "github.com/consensys/gnark-crypto/ecc/bw6-633/kzg"
    18  	kzg_bw6756 "github.com/consensys/gnark-crypto/ecc/bw6-756/kzg"
    19  	kzg_bw6761 "github.com/consensys/gnark-crypto/ecc/bw6-761/kzg"
    20  )
    21  
    22  type Serializable interface {
    23  	io.ReaderFrom
    24  	io.WriterTo
    25  	BinaryDumper
    26  
    27  	WriteRawTo(w io.Writer) (n int64, err error)
    28  	UnsafeReadFrom(r io.Reader) (int64, error)
    29  }
    30  
    31  type BinaryDumper interface {
    32  	WriteDump(w io.Writer, maxPkPoints ...int) error
    33  	ReadDump(r io.Reader, maxPkPoints ...int) error
    34  }
    35  
    36  type SRS Serializable
    37  
    38  // NewSRS returns an empty curved-typed SRS object
    39  // that implements io.ReaderFrom and io.WriterTo interfaces
    40  func NewSRS(curveID ecc.ID) SRS {
    41  	switch curveID {
    42  	case ecc.BN254:
    43  		return &kzg_bn254.SRS{}
    44  	case ecc.BLS12_377:
    45  		return &kzg_bls12377.SRS{}
    46  	case ecc.BLS12_378:
    47  		return &kzg_bls12378.SRS{}
    48  	case ecc.BLS12_381:
    49  		return &kzg_bls12381.SRS{}
    50  	case ecc.BLS24_315:
    51  		return &kzg_bls24315.SRS{}
    52  	case ecc.BLS24_317:
    53  		return &kzg_bls24317.SRS{}
    54  	case ecc.BW6_761:
    55  		return &kzg_bw6761.SRS{}
    56  	case ecc.BW6_633:
    57  		return &kzg_bw6633.SRS{}
    58  	case ecc.BW6_756:
    59  		return &kzg_bw6756.SRS{}
    60  	default:
    61  		panic("not implemented")
    62  	}
    63  }