github.com/consensys/gnark@v0.11.0/internal/backend/circuits/reference_small.go (about)

     1  package circuits
     2  
     3  import (
     4  	"math/big"
     5  
     6  	"github.com/consensys/gnark/frontend"
     7  )
     8  
     9  const nbConstraintsRefSmall = 5
    10  
    11  type referenceSmallCircuit struct {
    12  	X frontend.Variable
    13  	Y frontend.Variable `gnark:",public"`
    14  }
    15  
    16  func (circuit *referenceSmallCircuit) Define(api frontend.API) error {
    17  	for i := 0; i < nbConstraintsRefSmall; i++ {
    18  		circuit.X = api.Mul(circuit.X, circuit.X)
    19  	}
    20  	api.AssertIsEqual(circuit.X, circuit.Y)
    21  	return nil
    22  }
    23  
    24  func init() {
    25  	var circuit, good, bad referenceSmallCircuit
    26  
    27  	good.X = (2)
    28  
    29  	// compute expected Y
    30  	var expectedY big.Int
    31  	expectedY.SetUint64(2)
    32  
    33  	for i := 0; i < nbConstraintsRefSmall; i++ {
    34  		expectedY.Mul(&expectedY, &expectedY)
    35  	}
    36  
    37  	good.Y = (expectedY)
    38  
    39  	bad.X = (3)
    40  	bad.Y = (expectedY)
    41  
    42  	addEntry("reference_small", &circuit, &good, &bad, nil)
    43  }