snarkvm-circuit-types crate provides circuit equivalents of all console primitive types. Each circuit type tracks constraints and generates R1CS representations for zero-knowledge proofs.
Type Hierarchy
circuit/types/src/lib.rs:23-46
Field
Structure
Field elements are the fundamental building block:circuit/types/field/src/lib.rs:49-73
Operations
Field operations generate constraints:Constraint Costs
Source:
circuit/types/field/src/ (various operation files)
Boolean
Structure
Booleans are field elements constrained to :circuit/types/boolean/src/lib.rs:40-72
Boolean Operations
Constraint Costs
Source:
circuit/types/boolean/src/ (various operation files)
Integer
Structure
Integers are represented as bit vectors:circuit/types/integers/src/lib.rs:52-62, circuit/types/integers/src/lib.rs:83-87
Creation
circuit/types/integers/src/lib.rs:104-116
Operations
Integers support checked and wrapping arithmetic:Constraint Costs
For N-bit integers:
Source:
circuit/types/integers/src/ (various operation files)
Group
Structure
Group elements represent points on an elliptic curve:circuit/types/group/src/lib.rs:43-75
Curve Constraints
Group elements are constrained to lie on the twisted Edwards curve:circuit/types/group/src/lib.rs:79-96
Operations
Constraint Costs
Source:
circuit/types/group/src/ (various operation files)
Scalar
Scalar elements are from the scalar field of the curve:Address
Addresses are x-coordinates of group elements:StringType
Strings are UTF-8 byte arrays:String length is limited by
Environment::MAX_STRING_BYTES (currently 128 bytes). This prevents unbounded constraint growth.Mode Propagation
Operation modes are determined by inputs:circuit/environment/src/helpers/mode.rs:54-78
Testing Circuit Types
Best Practices
- Use constants when possible - Constant operations generate no constraints
- Minimize multiplications - Each multiplication = 1 constraint
- Cache bit decompositions -
to_bits_le()is expensive, cache results - Choose appropriate integer sizes - Larger integers = more constraints
- Test constraint counts - Always verify expected resource usage
See Also
- Circuit Overview - Constraint system architecture
- Circuit Environment - Environment trait and constraints
- Console Types - Primitive types that circuits mirror