github.com/consensys/gnark@v0.11.0/frontend/circuit.go (about)

     1  /*
     2  Copyright © 2020 ConsenSys Software Inc.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package frontend
    18  
    19  // Circuit must be implemented by user-defined circuit. The best way to define a
    20  // circuit is to define a type which contains all the witness elements as fields
    21  // and declare `Define` method on the type.
    22  //
    23  // For example, the following is a minimal valid circuit:
    24  //
    25  //	type MyCircuit struct {
    26  //	    X frontend.Variable `gnark:"-,public"`
    27  //	    Y frontend.Variable `gnark:"-,secret"`
    28  //	}
    29  //
    30  //	func (c *MyCircuit) Define(api frontend.API) error {
    31  //	    api.AssertIsEqual(c.X, c.Y)
    32  //		return nil
    33  //	}
    34  //
    35  // See the documentation for [schema.TagOpt] for how to use tags to define the
    36  // behaviour of the compiler and schema parser.
    37  type Circuit interface {
    38  	// Define declares the circuit's Constraints
    39  	Define(api API) error
    40  }