github.com/ethereum/go-ethereum@v1.16.1/crypto/bn256/gnark/gt.go (about)

     1  package bn256
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  
     7  	"github.com/consensys/gnark-crypto/ecc/bn254"
     8  )
     9  
    10  // GT is the affine representation of a GT field element.
    11  //
    12  // Note: GT is not explicitly used in mainline code.
    13  // It is needed for fuzzing.
    14  type GT struct {
    15  	inner bn254.GT
    16  }
    17  
    18  // Pair compute the optimal Ate pairing between a G1 and
    19  // G2 element.
    20  //
    21  // Note: This method is not explicitly used in mainline code.
    22  // It is needed for fuzzing. It should also be noted,
    23  // that the output of this function may not match other
    24  func Pair(a_ *G1, b_ *G2) *GT {
    25  	a := a_.inner
    26  	b := b_.inner
    27  
    28  	pairingOutput, err := bn254.Pair([]bn254.G1Affine{a}, []bn254.G2Affine{b})
    29  
    30  	if err != nil {
    31  		// Since this method is only called during fuzzing, it is okay to panic here.
    32  		// We do not return an error to match the interface of the other bn256 libraries.
    33  		panic(fmt.Sprintf("gnark/bn254 encountered error: %v", err))
    34  	}
    35  
    36  	return &GT{
    37  		inner: pairingOutput,
    38  	}
    39  }
    40  
    41  // Unmarshal deserializes `buf` into `g`
    42  //
    43  // Note: This method is not explicitly used in mainline code.
    44  // It is needed for fuzzing.
    45  func (g *GT) Unmarshal(buf []byte) error {
    46  	return g.inner.SetBytes(buf)
    47  }
    48  
    49  // Marshal serializes the point into a byte slice.
    50  //
    51  // Note: This method is not explicitly used in mainline code.
    52  // It is needed for fuzzing.
    53  func (g *GT) Marshal() []byte {
    54  	bytes := g.inner.Bytes()
    55  	return bytes[:]
    56  }
    57  
    58  // Exp raises `base` to the power of `exponent`
    59  //
    60  // Note: This method is not explicitly used in mainline code.
    61  // It is needed for fuzzing.
    62  func (g *GT) Exp(base GT, exponent *big.Int) *GT {
    63  	g.inner.Exp(base.inner, exponent)
    64  	return g
    65  }