corelib_imports 0.1.2
Useful Corelib non-public functions, structs, and traits made public and re-exported through 2023_10 edition
This package provides controlled access to non-public functions, structs, and traits from the Cairo Corelib library through selective re-exports.
The package leverages Cairo edition 2023_10 to access internal Cairo Corelib components that are not part of the standard public API. These utilities expose performance-critical operations for cryptographic computations, particularly optimized bounded integer arithmetic and circuit operations used throughout the Garaga ecosystem.
Cairo's visibility system restricts access to internal modules by default. This package uses feature flags (e.g., #[feature("bounded-int-utils")]
) to expose specific internal APIs that would otherwise be inaccessible. The approach follows established patterns in the Cairo ecosystem, similar to the Stwo Cairo verifier's bounded integer utilities.
bounded_int
Re-exports core bounded integer utilities with compile-time guarantees:
BoundedInt<T>
: Type-safe integer arithmetic with compile-time boundsAddHelper
, MulHelper
, DivRemHelper
: Optimized arithmetic operationsupcast
, downcast
: Safe type conversions between integer boundsbounded_int_div_rem
: Efficient division with remainder operationscircuit
Circuit construction and optimization utilities:
CircuitData
, CircuitDefinition
: Circuit representation typesu384
, u96
: Extended precision integer types for cryptographic operationsAddInputResult
: Circuit input accumulationconversions
: Specialized arithmetic helpers for multi-precision operationsinteger
Extended integer operations:
u128s_from_felt252
: Efficient felt252 to u128 conversion utilitiesU128sFromFelt252Result
: Result type for safe conversionsarray
& keccak
Utility functions:
array_slice
: Efficient array slicing operationscairo_keccak
, keccak_add_u256_be
: Keccak hash operationsuse corelib_imports::bounded_int::{BoundedInt, DivRemHelper, bounded_int_div_rem};
// Efficient division with compile-time bounds checking
let result = bounded_int_div_rem(dividend, divisor);
use corelib_imports::circuit::conversions::{
DivRemU96By32, NZ_POW64_TYPED, POW32, UnitInt
};
// High-precision arithmetic for cryptographic circuits
let quotient = DivRemU96By32::div_rem(value, NZ_POW32_TYPED);
use corelib_imports::bounded_int::{downcast, upcast};
use corelib_imports::integer::{u128s_from_felt252};
// Safe conversions between integer types
let converted = upcast(bounded_value);
let (low, high) = u128s_from_felt252(felt_value);
These utilities are extensively used across Garaga's elliptic curve operations, finite field arithmetic, and cryptographic circuit implementations for optimal performance.
Version 0.1.2
Uploaded 1 week ago
Size 2.3 KB
Run the following command in your project dir
scarb add corelib_imports@0.1.2
Or add the following line to your Scarb.toml
corelib_imports = "0.1.2"