Random Number Generation
TheArcisRNG struct provides access to randomness within MPC circuits. All random values are generated within the MPC context.
Basic Usage
The
width parameter in gen_integer_from_width must be known at compile time.Public vs Secret Random Integers
gen_public_integer_from_width when you need randomness that does not need to stay secret within the MPC computation—for example, nonce generation. The value is visible to Arx nodes during execution but is not automatically included in the circuit output; you still control what gets returned.
Range-Based Generation
To generate integers within a specific range, usegen_integer_in_range:
n_attempts=24 gives a failure probability below 2^-24.
The
n_attempts parameter must be known at compile time.Shuffling
Shuffle arrays in-place with cryptographic uniformity:What Works and What Doesn’t
Cryptographic Operations
SHA3 Hashing
Arcis provides SHA3-256 and SHA3-512 hash functions:Arcis uses SHA3 (Keccak) rather than SHA-2/SHA-512 because SHA3 has a more efficient circuit structure for MPC evaluation.
Ed25519 Signatures
Arcis provides Ed25519 signature operations using SHA3-512 internally (ArcisEd25519).Signature Verification
Key Generation
Only the public verifying key is revealed. The secret key is never revealed in plaintext; it exists only as secret shares distributed across Arx nodes. Arcium uses a dishonest majority model—privacy is maintained as long as at least one node remains honest, even if every other node colludes.
MXE Cluster Signing
Sign messages using the MXE cluster’s collective key:Public Key Operations
Work with X25519 public keys:Advanced: Coordinate Extraction
Advanced: Coordinate Extraction
For advanced use, work with the Montgomery X coordinate directly:Coordinate extraction is for advanced cryptographic operations such as:
- Custom ECDH key exchange implementations
- Key derivation from shared secrets
- Interoperability with external systems that work with raw Curve25519 coordinates
- Zero-knowledge proof inputs that require field elements
from_base58() or from_uint8() for standard public key handling.Reveal Constraints
Learn where
.reveal() and .from_arcis() can be called.BaseField25519 Operations
BaseField25519 (integers modulo 2^255 - 19) is the native field element for Arcis MPC circuits. Use it for raw field arithmetic without truncation or overflow — cryptographic primitives, Pedersen commitments, curve coordinate work.
For bounded arithmetic, comparison-heavy logic, or when you need bitwise operations and division operators, use regular integers (u8..u128) instead.
Construction
| Method | Description |
|---|---|
BaseField25519::from_u8(x) … from_u128(x) | Convert unsigned int to field element |
BaseField25519::from_i8(x) … from_i128(x) | Convert signed int to field element |
BaseField25519::from_usize(x) / from_isize(x) | Platform-sized conversions |
BaseField25519::from_bool(x) | true → 1, false → 0 |
BaseField25519::power_of_two(exp) | Returns 2^exp as a field element |
from_* functions work both in plaintext Rust and inside #[encrypted] blocks.
Extraction (unchecked)
| Method | Description |
|---|---|
.to_u8_unchecked() … .to_u128_unchecked() | Extract as unsigned int |
.to_i8_unchecked() … .to_i128_unchecked() | Extract as signed int |
.to_bool_unchecked() | Extract as bool |
Arithmetic
All operations wrap modulo2^255 - 19 (not at integer type boundaries).
| Operation | Syntax | Assign variant |
|---|---|---|
| Addition | a + b | a += b |
| Subtraction | a - b | a -= b |
| Multiplication | a * b | a *= b |
| Negation | -a | — |
Comparisons
==, !=, <, <=, >, >= — all produce bool.
Serialization
| Method | Description |
|---|---|
.to_le_bytes() -> [u8; 32] | Little-endian byte representation |
Division Methods
| Method | Description | Division by Zero |
|---|---|---|
safe_inverse() | Returns the field inverse | Returns 0 |
field_division(divisor) | Field division (a * divisor^-1) | Returns 0 |
euclidean_division(divisor) | Signed Euclidean division | Panics |
Differences from Regular Integers
BaseField25519 is not an integer type. The following operations available on u8..u128 are not supported:
- No
/or%operators — use.field_division()or.euclidean_division()instead - No
>>,<<(shift operators are not supported;&,|,^are booleans-only across all types) - No
MIN,MAX,BITSconstants - No
.min(),.max(),.abs()and no.sort()on arrays of field elements - No
.to_be_bytes()— only.to_le_bytes() - No
ascasts — usefrom_*/to_*_uncheckedmethods
Pack<BaseField25519> provides no compression — each value already occupies one full field element. Only use Pack with smaller types like [u8; N].Data Packing
ThePack<T> type provides bit-level compression for onchain storage efficiency.
Why Packing Matters
In Arcis, all values are stored as field elements (~255 bits / 32 bytes each). Without packing:- A single
u8(8 bits) uses one full field element [u8; 256]uses 256 field elements
[u8; 256]= 256 bytes total- Each field element packs ~26 bytes (208 usable bits)
- Packed: ⌈256 / 26⌉ = 10 field elements
- Compression: 256 → 10 = ~26x fewer field elements
u8 would use a full field element (256 elements total). This significantly reduces onchain storage costs and transaction sizes.
When to Use Pack
- Large arrays of small integers (
[u8; N],[u16; N]) - Data that needs to be stored onchain
- Input/output parameters approaching transaction size limits
Basic Usage
Client-side Packing
How to use generated packers with encrypted inputs in TypeScript.
Simple Example
Pack<T> use cases. The “Practical Example” below shows advanced usage with encrypted types.
Practical Example
Pack with Crypto Types
Cryptographic types likeVerifyingKey are often passed as Pack<VerifyingKey>:
Machine Learning
Arcis includes basic ML primitives for privacy-preserving inference.Logistic Regression
Linear Regression
Available ML Functions
| Function | Description |
|---|---|
LogisticRegression::new(coef, intercept) | Create logistic regression model |
LogisticRegression::predict(x, threshold) | Binary classification |
LogisticRegression::predict_proba(x) | Probability output |
LinearRegression::new(coef, intercept) | Create linear regression model |
LinearRegression::predict(x) | Continuous prediction |
ArcisMath::sigmoid(x) | Sigmoid activation function |
logit(p) | Inverse of sigmoid |
expit(x) | Alias for sigmoid |
ML models support up to 100 features (
MAX_FEATURES = 100). For larger models, consider feature selection or dimensionality reduction.Summary
| Primitive | Use Case | Key Methods |
|---|---|---|
ArcisRNG | Random values | bool(), gen_integer_from_width(), gen_public_integer_from_width(), gen_integer_in_range(), gen_uniform(), shuffle() |
SHA3_256/512 | Hashing | new(), digest() |
SecretKey | Ed25519 keys | new_rand(), from_bytes() |
VerifyingKey | Signature verification | from_secret_key(), verify() |
MXESigningKey | Cluster signing | sign() |
ArcisX25519Pubkey | Public keys | from_base58(), from_uint8(), to_x(), new_from_x() |
BaseField25519 | Field arithmetic | from_*(), to_*_unchecked(), power_of_two(), to_le_bytes(), safe_inverse(), field_division(), euclidean_division() |
Pack<T> | Efficient storage | new(), unpack() |
LogisticRegression | Binary classification | new(), predict(), predict_proba() |
LinearRegression | Regression | new(), predict() |
ArcisMath | Math functions | sigmoid() |
What’s Next?
Best Practices
Performance optimization, debugging, and testing strategies.
Quick Reference
Concise syntax lookup for all Arcis patterns.
Operations
Full function and method reference.