Module variable

Module variable 

Source
Expand description

Variable types and constant value support for circuit construction.

This module provides the foundation for rSnark’s flexible variable system, including support for BigInt constants and automatic type conversion.

§Key Features

  • Automatic constant conversion: Primitive types are automatically converted to BigInt constants
  • Type safety: Strong typing ensures correct variable usage in circuits
  • Generic support: Works with generic circuit structures
  • BigInt precision: Support for arbitrary precision arithmetic

§Supported Constant Types

The following primitive types are automatically converted to circuit constants:

  • Unsigned integers: u8, u16, u32, u64, u128
  • Signed integers: i8, i16, i32, i64, i128
  • Boolean: bool

§Usage in Circuits

impl Circuit for MyCircuit {
    fn define(&self, api: &mut impl API) {
        // All these literals are automatically converted to BigInt constants
        let result = api.add(&self.input, &42_u32);
        let scaled = api.mul(&result, &1000_i64);
        let flag = api.select(&true, &result, &0);
    }
}

Structs§

CircuitVariable

Traits§

Variable
A trait that defines types that can be used as API parameters in circuit construction.