Skip to main content
The 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

Source: circuit/types/src/lib.rs:23-46

Field

Structure

Field elements are the fundamental building block:
Source: 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 :
Source: 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:
Source: circuit/types/integers/src/lib.rs:52-62, circuit/types/integers/src/lib.rs:83-87

Creation

Source: 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:
Source: circuit/types/group/src/lib.rs:43-75

Curve Constraints

Group elements are constrained to lie on the twisted Edwards curve:
Source: 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:
Scalars have the same operations as Field but over the scalar field.

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:
Source: circuit/environment/src/helpers/mode.rs:54-78

Testing Circuit Types

Best Practices

  1. Use constants when possible - Constant operations generate no constraints
  2. Minimize multiplications - Each multiplication = 1 constraint
  3. Cache bit decompositions - to_bits_le() is expensive, cache results
  4. Choose appropriate integer sizes - Larger integers = more constraints
  5. Test constraint counts - Always verify expected resource usage

See Also