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

     1  package circuits
     2  
     3  import (
     4  	"github.com/consensys/gnark/frontend"
     5  )
     6  
     7  type andCircuit struct {
     8  	Op1, Op2, Res frontend.Variable
     9  }
    10  
    11  func (circuit *andCircuit) Define(api frontend.API) error {
    12  	d := api.And(circuit.Op1, circuit.Op2)
    13  
    14  	api.AssertIsEqual(d, circuit.Res)
    15  	return nil
    16  }
    17  
    18  func init() {
    19  
    20  	good := []frontend.Circuit{
    21  		&andCircuit{
    22  			Op1: (1),
    23  			Op2: (1),
    24  			Res: (1),
    25  		},
    26  		&andCircuit{
    27  			Op1: (1),
    28  			Op2: (0),
    29  			Res: (0),
    30  		},
    31  		&andCircuit{
    32  			Op1: (0),
    33  			Op2: (1),
    34  			Res: (0),
    35  		},
    36  		&andCircuit{
    37  			Op1: (0),
    38  			Op2: (0),
    39  			Res: (0),
    40  		},
    41  	}
    42  
    43  	bad := []frontend.Circuit{
    44  		&andCircuit{
    45  			Op1: (1),
    46  			Op2: (1),
    47  			Res: (0),
    48  		},
    49  		&andCircuit{
    50  			Op1: (1),
    51  			Op2: (0),
    52  			Res: (1),
    53  		},
    54  		&andCircuit{
    55  			Op1: (0),
    56  			Op2: (1),
    57  			Res: (1),
    58  		},
    59  		&andCircuit{
    60  			Op1: (0),
    61  			Op2: (0),
    62  			Res: (1),
    63  		},
    64  		&andCircuit{
    65  			Op1: (42),
    66  			Op2: (1),
    67  			Res: (1),
    68  		},
    69  		&andCircuit{
    70  			Op1: (1),
    71  			Op2: (1),
    72  			Res: (42),
    73  		},
    74  	}
    75  
    76  	addNewEntry("and", &andCircuit{}, good, bad, nil)
    77  }